volo_d3_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_d3_224.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d3_224.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d3_224.sail_in1k --image test_image.jpg| Metric | CPU | NPU |
|---|---|---|
| Average Inference Time | 890.84 ms | 16.79 ms |
| Speedup (CPU/NPU) | - | 53.06x |
CPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 1 | 21 | 0.4644% (class_21) |
| 2 | 701 | 0.4113% (class_701) |
| 3 | 22 | 0.3448% (class_22) |
| 4 | 107 | 0.3434% (class_107) |
| 5 | 557 | 0.3065% (class_557) |
NPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 1 | 21 | 0.4755% (class_21) |
| 2 | 701 | 0.4215% (class_701) |
| 3 | 22 | 0.3501% (class_22) |
| 4 | 107 | 0.3485% (class_107) |
| 5 | 557 | 0.3130% (class_557) |
| Metric | Value |
|---|---|
| Max Logits Absolute Error | 0.02578402 |
| Mean Logits Absolute Error | 0.00210414 |
| Cosine Similarity (Logits) | 0.99996656 |
| Max Probability Absolute Error | 0.00011181 |
| Mean Probability Absolute Error | 0.00000300 |
| 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.0112%, which is well below the 1% threshold. The cosine similarity of logits is 0.99996656, 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.9999665618 | 0.0033% |
结论: CPU 与 NPU 精度误差为 0.0033%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved