本仓库包含了 timm 中的 swin_large_patch4_window12_384.ms_in22k_ft_in1k 模型在华为昇腾 NPU 上的适配与推理实现。
swin_large_patch4_window12_384.ms_in22k_ft_in1k (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 推理耗时 | 3.9796s |
| NPU 推理耗时 | 0.0180s |
| MAE (平均绝对误差) | 0.00345132 |
| Max Error (最大误差) | 0.01743028 |
| MSE (均方误差) | 1.929e-05 |
| 相对误差 | 0.00529257 |
| 误差百分比 | 0.5293 |
| 余弦相似度 | 0.99998698 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 3.9796 |
| NPU | 0.0180 |
CPU inference time: 3.9796s
Top-5 indices: [605, 613, 446, 844, 551]
Top-5 values: [3.796593, 3.102452, 3.096802, 3.050753, 2.987546]
NPU inference time: 0.0180s
Top-5 indices: [605, 613, 446, 844, 551]
Top-5 values: [3.79937, 3.108566, 3.090411, 3.039253, 2.984609]
CPU/NPU Relative Error: 0.5293%Mean Absolute Error (MAE): 0.00345132
Max Absolute Error: 0.01743028
Cosine Similarity: 0.99998698
Relative Error: 0.00529257运行截图由 acend- 工具生成,展示推理成功画面。