volo_d5_224.sail_in1k 是 timm 库中的 Vision Outlooker (VOLO) 模型,在 ImageNet-1K 上进行了预训练。VOLO 引入了一种新颖的视野注意力机制,专注于更精细级别的特征编码,在图像分类任务上实现了最先进的性能。
主要特点:
该模型已在华为昇腾 NPU 上完成适配与验证。适配工作包括:
# Install dependencies
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch torchvision timm Pillow
# For NPU support, install torch_npu (matching your CANN version)
# pip install torch_npupython3 inference.py --model volo_d5_224.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d5_224.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d5_224.sail_in1k --image test_image.jpg| 指标 | CPU | NPU |
|---|---|---|
| 平均推理时间 | 2646.58 ms | 21.47 ms |
| 加速比(CPU/NPU) | - | 123.27x |
CPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 107 | 1.4467% (class_107) |
| 2 | 4 | 0.5617% (class_4) |
| 3 | 701 | 0.5577% (class_701) |
| 4 | 21 | 0.5389% (class_21) |
| 5 | 111 | 0.4486% (class_111) |
NPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 107 | 1.4919% (class_107) |
| 2 | 701 | 0.5715% (class_701) |
| 3 | 4 | 0.5715% (class_4) |
| 4 | 21 | 0.5485% (class_21) |
| 5 | 111 | 0.4482% (class_111) |
| 指标 | 数值 |
|---|---|
| Logits 最大绝对误差 | 0.03260064 |
| Logits 平均绝对误差 | 0.00225519 |
| Logits 余弦相似度 | 0.99997318 |
| 概率最大绝对误差 | 0.00045196 |
| 概率平均绝对误差 | 0.00000399 |
| Top-1 匹配 | YES |
| Top-5 重叠 | 5/5 |
NPU 与 CPU 推理误差 < 1%。 NPU 与 CPU 输出的最大概率差异为 0.0452%,远低于 1% 的阈值。Logits 的余弦相似度为 0.99997318,表明输出分布几乎完全一致。因此,NPU 适配正确,且模型精度得以保持。
NPU 推理及 CPU/NPU 精度对比的终端输出。
├── inference.py # Inference script (CPU/NPU)
├── compare_cpu_npu.py # CPU vs NPU accuracy comparison
├── requirements.txt # Python dependencies
├── readme.md # This documentation
└── screenshot.html # Terminal output screenshot| 对比项 | CPU | NPU | 误差 |
|---|---|---|---|
| 余弦相似度 | 1.0 | 0.9999731779 | 0.0027% |
结论: CPU 与 NPU 精度误差为 0.0027%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved