volo_d2_384.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_d2_384.sail_in1k --device cpu --image test_image.jpgpython3 inference.py --model volo_d2_384.sail_in1k --device npu --image test_image.jpgpython3 compare_cpu_npu.py --model volo_d2_384.sail_in1k --image test_image.jpg| Metric | CPU | NPU |
|---|---|---|
| Average Inference Time | 2199.27 ms | 10.92 ms |
| Speedup (CPU/NPU) | - | 201.48x |
CPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 1 | 111 | 1.0334% (class_111) |
| 2 | 701 | 1.0222% (class_701) |
| 3 | 21 | 0.8589% (class_21) |
| 4 | 128 | 0.4400% (class_128) |
| 5 | 615 | 0.3473% (class_615) |
NPU Top-5:
| Rank | Class ID | Probability |
|---|---|---|
| 1 | 701 | 1.0195% (class_701) |
| 2 | 111 | 1.0180% (class_111) |
| 3 | 21 | 0.8545% (class_21) |
| 4 | 128 | 0.4370% (class_128) |
| 5 | 615 | 0.3441% (class_615) |
| Metric | Value |
|---|---|
| Max Logits Absolute Error | 0.01558757 |
| Mean Logits Absolute Error | 0.00176075 |
| Cosine Similarity (Logits) | 0.99998015 |
| Max Probability Absolute Error | 0.00015451 |
| Mean Probability Absolute Error | 0.00000226 |
| Top-1 Match | NO |
| Top-5 Overlap | 5/5 |
NPU and CPU inference error < 1%. The maximum probability difference between NPU and CPU outputs is 0.0155%, which is well below the 1% threshold. The cosine similarity of logits is 0.99998015, 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.9999801517 | 0.002% |
结论: CPU 与 NPU 精度误差为 0.002%,小于 1% 精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理。
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpuModel loaded successfully on NPU
Inference completed
Results saved