yolov10:基于 PyTorch 与 Ascend NPU 的目标检测性能调优项目

可用于在 Ascend 910 NPU 上优化 YOLOv10n 模型性能,提升目标检测效率。通过 CPU 绑核、流水并发等优化,平均 latency 降至 11.97ms,吞吐量达 83.52fps,且保证精度与 CPU 输出一致。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago

YOLOv10 Ascend NPU 性能调优

昇腾 Model-Agent 大赛 — 赛道二:模型调优(800I A2) Tag: #+NPU

模型信息

字段 值
模型名称 YOLOv10n
任务 目标检测 (Object Detection)
原始权重地址 https://www.modelscope.cn/models/AI-ModelScope/yolov10
适配硬件 Ascend 910 NPU
框架 PyTorch + torch_npu

使用 Skills

  • ai4s-main
  • ai4s-basic
  • ai4s-perf-tuning
  • ai4s-profiling
  • ai4s-precision-alignment
  • ascend-optimization
  • ascend-affinity-operator
  • verify-agent
  • optimizer-agent
  • quantify-agent
  • review
  • security-review
  • simplify
  • verify
  • run
  • gitcode-publish

权重下载方式

# 通过 ModelScope SDK 下载
pip install modelscope
python -c "from modelscope import snapshot_download; snapshot_download('AI-ModelScope/yolov10', cache_dir='./.cache')"

本地权重路径

model_weights/
  yolov10n.pt   (11.4M, 检测模型)

Baseline 性能

指标 CPU NPU Baseline
平均 latency 232.96 ms 13.02 ms
吞吐量 4.29 fps 76.83 fps

优化前后性能对比

指标 优化前 (NPU) 优化后 (NPU) 提升
平均 latency 13.02 ms 3.11 ms 4.19x
吞吐量 76.83 fps 321.67 fps 4.19x
总 speedup (vs CPU) 17.9x 74.9x -

关键优化手段

  1. 完全绕过 ultralytics predictor:直接 model.model(tensor) 调用,消除约 6 ms 的 host 侧 stream_inference / Results 封装开销
  2. fuse v10Detect head:移除 one2many 分支,减少 inference-only 计算量
  3. torch.compile(model.model, backend='npu'):充分融合算子,进一步压缩 NPU 执行时间
  4. FP16 半精度推理:half() 减少显存与计算量
  5. inference_mode():替代默认模式,减少 autograd 开销
  6. 最小化后处理:仅保留 conf threshold + scale_boxes,去掉冗余 NMS 和对象封装
  7. CPU 绑核 + 流水并发:CPU_AFFINITY_CONF=2、TASK_QUEUE_ENABLE=2

精度对比

  • CPU 与 NPU 输出检测框:5/5 完全一致
  • 置信度最大绝对差异:0.0001
  • match_within_1_percent: true

人工复核截图

见 artifacts/ 目录:

  • run_npu_screenshot.png
  • accuracy_compare_screenshot.png
  • performance_benchmark_screenshot.png

日志索引

文件 说明
logs/model_selection.md 模型选择记录
logs/environment.txt 环境信息
logs/run_npu.log NPU 推理日志
logs/accuracy_compare.log 精度对比日志
logs/performance_benchmark.log 性能 benchmark
logs/summary.json 汇总 JSON
logs/baseline_cpu.json CPU baseline 结果
logs/baseline_npu_clean.json NPU baseline 结果
logs/optimized_npu_env.json NPU 优化后结果
logs/optimized_npu_v5.json 最终 bypass+compile 结果

快速开始

pip install -r requirements.txt

# CPU baseline
python inference.py --device cpu

# NPU baseline
python inference.py --device npu:0

# NPU 最终优化版本 (bypass + fuse + compile + fp16)
python inference_optimized_v5.py --device npu:0

硬件信息

Ascend910 x2
CANN 8.5.1
PyTorch 2.9.0+cpu
torch_npu 2.9.0.post1

Introduction

可用于在 Ascend 910 NPU 上优化 YOLOv10n 模型性能,提升目标检测效率。通过 CPU 绑核、流水并发等优化,平均 latency 降至 11.97ms,吞吐量达 83.52fps,且保证精度与 CPU 输出一致。【此简介由AI生成】

Customize your domain