本仓库包含了 timm 中的 swin_small_patch4_window7_224.ms_in22k 模型在华为昇腾 NPU 上的适配与推理实现。
swin_small_patch4_window7_224.ms_in22k (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.3920s |
| NPU 推理耗时 | 0.0187s |
| MAE (平均绝对误差) | 0.00143343 |
| Max Error (最大误差) | 0.01227427 |
| MSE (均方误差) | 3.47e-06 |
| 相对误差 | 0.00167263 |
| 误差百分比 | 0.1673 |
| 余弦相似度 | 0.99999861 |
| Top-5 索引一致性 | 是 |
结论: NPU 与 CPU 推理误差 < 1%
| 设备 | 推理耗时 (s) |
|---|---|
| CPU | 0.3920 |
| NPU | 0.0187 |
CPU inference time: 0.3920s
Top-5 indices: [21668, 12009, 12037, 21678, 11624]
Top-5 values: [7.03355, 5.939153, 5.467514, 5.365609, 5.237698]
NPU inference time: 0.0187s
Top-5 indices: [21668, 12009, 12037, 21678, 11624]
Top-5 values: [7.038897, 5.939375, 5.462682, 5.371977, 5.241243]
CPU/NPU Relative Error: 0.1673%Mean Absolute Error (MAE): 0.00143343
Max Absolute Error: 0.01227427
Cosine Similarity: 0.99999861
Relative Error: 0.00167263运行截图由 acend- 工具生成,展示推理成功画面。