volo_d5_448.sail_in1k 是 timm 库中的 Vision Outlooker (VOLO) 模型,在 ImageNet-1K 上进行了预训练。VOLO 引入了新颖的 outlook 注意力机制,专注于更精细级别的特征编码,在图像分类任务上实现了最先进的性能。
主要特点:
该模型已在华为昇腾 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_448.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d5_448.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d5_448.sail_in1k --image test_image.jpg| 指标 | CPU | NPU |
|---|---|---|
| 平均推理时间 | 12249.37 ms | 23.09 ms |
| 加速比(CPU/NPU) | - | 530.49x |
CPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 701 | 12.8434% (class_701) |
| 2 | 21 | 9.1424% (class_21) |
| 3 | 22 | 7.3802% (class_22) |
| 4 | 916 | 5.2781% (class_916) |
| 5 | 107 | 3.8061% (class_107) |
NPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 701 | 12.8037% (class_701) |
| 2 | 21 | 9.0366% (class_21) |
| 3 | 22 | 7.2172% (class_22) |
| 4 | 916 | 5.2745% (class_916) |
| 5 | 107 | 3.8351% (class_107) |
| 指标 | 数值 |
|---|---|
| Logits 最大绝对误差 | 0.02870369 |
| Logits 平均绝对误差 | 0.00230662 |
| Logits 余弦相似度 | 0.99999243 |
| 概率最大绝对误差 | 0.00162923 |
| 概率平均绝对误差 | 0.00000765 |
| Top-1 匹配 | 是 |
| Top-5 重叠 | 5/5 |
NPU 与 CPU 推理误差 < 1%。 NPU 与 CPU 输出的最大概率差异为 0.1629%,远低于 1% 的阈值。Logits 的余弦相似度为 0.99999243,表明输出分布几乎完全一致。因此,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.9999924302 | 0.0008% |
结论: CPU 与 NPU 精度误差为 0.0008%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved