volo_d1_224.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_d1_224.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d1_224.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d1_224.sail_in1k --image test_image.jpg| Metric | CPU | NPU |
|---|---|---|
| Average Inference Time | 322.47 ms | 10.84 ms |
| Speedup (CPU/NPU) | - | 29.75x |
CPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 1 | 107 | 1.2626% (class_107) |
| 2 | 701 | 1.1308% (class_701) |
| 3 | 21 | 0.9452% (class_21) |
| 4 | 111 | 0.7461% (class_111) |
| 5 | 4 | 0.5336% (class_4) |
NPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 1 | 107 | 1.2632% (class_107) |
| 2 | 701 | 1.1404% (class_701) |
| 3 | 21 | 0.9540% (class_21) |
| 4 | 111 | 0.7461% (class_111) |
| 5 | 4 | 0.5336% (class_4) |
| Metric | Value |
|---|---|
| Max Logits Absolute Error | 0.01002026 |
| Mean Logits Absolute Error | 0.00119452 |
| Cosine Similarity (Logits) | 0.99999410 |
| Max Probability Absolute Error | 0.00009572 |
| Mean Probability Absolute Error | 0.00000161 |
| 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.0096%, which is well below the 1% threshold. The cosine similarity of logits is 0.99999410, 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.9999940991 | 0.0006% |
结论: CPU 与 NPU 精度误差为 0.0006%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved