本仓库包含了 timm 中的 vit_betwixt_patch16_reg4_gap_256.sbb2_e200_in12k 模型在华为昇腾 NPU 上的适配与推理实现。
vit_betwixt_patch16_reg4_gap_256.sbb2_e200_in12k (timm / HuggingFace Hub)本模型基于 timm 库加载预训练权重,模型权重通过 ModelScope 下载。在昇腾 NPU 上通过 torch_npu 实现硬件加速。
pip install -r requirements.txtpython inference.pypip install -r requirements.txtpython inference.pypython compare_cpu_npu.py| 指标 | 数值 |
|---|---|
| CPU 推理耗时 | 0.6136s |
| NPU 推理耗时 | 0.0060s |
| MAE (平均绝对误差) | 0.02803545 |
| Max Error (最大误差) | 0.06621647 |
| MSE (均方误差) | 0.00083837 |
| 相对误差 | 0.00291793 |
| 误差百分比 | 0.2918 |
| 余弦相似度 | 0.99999975 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 0.6136 |
| NPU | 0.0060 |
CPU inference time: 0.6136s
Top-5 indices: [11740, 6062, 7104, 7347, 4230]
Top-5 values: [-1.144134, -1.590754, -1.916364, -2.229811, -3.567806]
NPU inference time: 0.0060s
Top-5 indices: [11740, 6062, 7104, 7347, 4230]
Top-5 values: [-1.129711, -1.564686, -1.904059, -2.227988, -3.534455]
CPU/NPU Relative Error: 0.2918%Mean Absolute Error (MAE): 0.02803545
Max Absolute Error: 0.06621647
Cosine Similarity: 0.99999975
Relative Error: 0.00291793运行截图由 acend- 工具生成,展示推理成功画面。