volo_d4_448.sail_in1k是timm库中的Vision Outlooker(VOLO)模型,在ImageNet-1K上进行了预训练。VOLO引入了一种新颖的outlook attention机制,专注于更精细级别的特征编码,在图像分类任务上实现了最先进的性能。
主要特点:
该模型已在华为Ascend 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_d4_448.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d4_448.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d4_448.sail_in1k --image test_image.jpg| 指标 | CPU | NPU |
|---|---|---|
| 平均推理时间 | 7735.78 ms | 14.20 ms |
| 加速比(CPU/NPU) | - | 544.73x |
CPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 21 | 9.8915% (class_21) |
| 2 | 701 | 6.4755% (class_701) |
| 3 | 22 | 5.9511% (class_22) |
| 4 | 107 | 5.7421% (class_107) |
| 5 | 92 | 3.9060% (class_92) |
NPU Top-5:
| 排名 | 类别 ID | 概率 |
|---|---|---|
| 1 | 21 | 9.6863% (class_21) |
| 2 | 701 | 6.4017% (class_701) |
| 3 | 107 | 5.8312% (class_107) |
| 4 | 22 | 5.8247% (class_22) |
| 5 | 92 | 3.8504% (class_92) |
| 指标 | 数值 |
|---|---|
| Logits 最大绝对误差 | 0.04243207 |
| Logits 平均绝对误差 | 0.00297077 |
| Logits 余弦相似度 | 0.99998587 |
| 概率最大绝对误差 | 0.00205237 |
| 概率平均绝对误差 | 0.00001281 |
| Top-1 匹配 | YES |
| Top-5 重叠 | 5/5 |
NPU 与 CPU 推理误差 < 1%。 NPU 与 CPU 输出的最大概率差异为 0.2052%,远低于 1% 的阈值。Logits 的余弦相似度为 0.99998587,表明输出分布几乎完全一致。因此,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.9999858737 | 0.0014% |
结论: CPU 与 NPU 精度误差为 0.0014%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved