volo_d5_448.sail_in1k is a Vision Outlooker (VOLO) model from the timm library, pre-trained on ImageNet-1K. VOLO introduces a novel outlook attention mechanism that focuses on finer-level feature encoding, achieving state-of-the-art performance on image classification tasks.
Key features:
This model has been adapted and verified on Huawei Ascend NPU. The adaptation involves:
# 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| Metric | CPU | NPU |
|---|---|---|
| Average Inference Time | 12249.37 ms | 23.09 ms |
| Speedup (CPU/NPU) | - | 530.49x |
CPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 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:
| Rank | Class ID | Probability |
|---|---|---|
| 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) |
| Metric | Value |
|---|---|
| Max Logits Absolute Error | 0.02870369 |
| Mean Logits Absolute Error | 0.00230662 |
| Cosine Similarity (Logits) | 0.99999243 |
| Max Probability Absolute Error | 0.00162923 |
| Mean Probability Absolute Error | 0.00000765 |
| Top-1 Match | YES |
| Top-5 Overlap | 5/5 |
NPU and CPU inference error < 1%. The maximum probability difference between NPU and CPU outputs is 0.1629%, which is well below the 1% threshold. The cosine similarity of logits is 0.99999243, indicating near-identical output distributions. Therefore, the NPU adaptation is correct and maintains model accuracy.
Terminal output of NPU inference and CPU/NPU accuracy comparison.
├── 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