本项目将 timm/swin_tiny_patch4_window7_224.ms_in1k 图片分类模型适配到单卡昇腾 NPU(Ascend910)运行。使用 ModelScope 下载权重,timm.create_model(pretrained=False) 加载本地权重,包含推理验证、CPU-NPU 精度一致性检查和性能基准测试。
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.005808 |
| mean_abs_error | 0.000799 |
| relative_error | 0.2679% |
| cosine_similarity | 0.999998 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| iterations | 10 |
| avg_time(s) | 0.009229 |
| min_time(s) | 0.009131 |
| max_time(s) | 0.009381 |
| p50_time(s) | 0.009219 |
| p90_time(s) | 0.009381 |
| p95_time(s) | 0.009381 |
| images_per_sec | 108.36 |
日志保存在 logs/benchmark.log。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
logs/inference.log - 推理结果logs/accuracy.log - CPU-NPU 精度一致性logs/benchmark.log - 性能基准测试logs/env_check.log - 环境检查pretrained=True 自动从 HuggingFace 下载relative_position_index 和 attn_mask buffer),属正常情况,不影响推理#NPU #Ascend #timm #SwinTransformer #image-classification