volo_d3_448.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_d3_448.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d3_448.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d3_448.sail_in1k --image test_image.jpg| 指标 | CPU | NPU |
|---|---|---|
| 平均推理时间 | 4574.32 ms | 14.07 ms |
| 加速比(CPU/NPU) | - | 325.22x |
CPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 107 | 0.6296% (class_107) |
| 2 | 111 | 0.5650% (class_111) |
| 3 | 21 | 0.5348% (class_21) |
| 4 | 701 | 0.5229% (class_701) |
| 5 | 4 | 0.3851% (class_4) |
NPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 107 | 0.6317% (class_107) |
| 2 | 111 | 0.5598% (class_111) |
| 3 | 21 | 0.5333% (class_21) |
| 4 | 701 | 0.5234% (class_701) |
| 5 | 4 | 0.3871% (class_4) |
| 指标 | 数值 |
|---|---|
| Logits 最大绝对误差 | 0.00910270 |
| Logits 平均绝对误差 | 0.00116716 |
| Logits 余弦相似度 | 0.99998283 |
| 概率最大绝对误差 | 0.00005158 |
| 概率平均绝对误差 | 0.00000133 |
| Top-1 匹配 | YES |
| Top-5 重叠 | 5/5 |
NPU 与 CPU 推理误差 < 1%。 NPU 与 CPU 输出的最大概率差异为 0.0052%,远低于 1% 的阈值。Logits 的余弦相似度为 0.99998283,表明输出分布几乎完全一致。因此,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.9999828339 | 0.0017% |
结论: CPU 与 NPU 精度误差为 0.0017%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved