本仓库包含了 timm 中的 swin_base_patch4_window7_224.ms_in22k_ft_in1k 模型在华为昇腾 NPU 上的适配与推理实现。
swin_base_patch4_window7_224.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 推理耗时 | 0.6084s |
| NPU 推理耗时 | 0.0176s |
| MAE (平均绝对误差) | 0.00137776 |
| Max Error (最大误差) | 0.00662065 |
| MSE (均方误差) | 2.97e-06 |
| 相对误差 | 0.00208424 |
| 误差百分比 | 0.2084 |
| 余弦相似度 | 0.99999844 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 0.6084 |
| NPU | 0.0176 |
CPU inference time: 0.6084s
Top-5 indices: [605, 916, 746, 549, 577]
Top-5 values: [4.059277, 3.045228, 3.018265, 2.970159, 2.941985]
NPU inference time: 0.0176s
Top-5 indices: [605, 916, 746, 549, 577]
Top-5 values: [4.055797, 3.043832, 3.017739, 2.966475, 2.937246]
CPU/NPU Relative Error: 0.2084%Mean Absolute Error (MAE): 0.00137776
Max Absolute Error: 0.00662065
Cosine Similarity: 0.99999844
Relative Error: 0.00208424运行截图由 acend- 工具生成,展示推理成功画面。