本项目将 timm/resnet50.a3_in1k 图片分类模型适配到华为昇腾 NPU(Ascend910)单卡环境。使用 ModelScope snapshot_download 下载权重,timm.create_model(pretrained=False) 加载本地权重,包含推理验证、CPU-NPU 精度一致性检查和性能基准测试。
pip install -r requirements.txt
python inference.py推理输出示例:
Output shape: torch.Size([1, 1000])
Top-5 predictions:
class_655: 0.1750
class_578: 0.0643
class_697: 0.0625
class_445: 0.0623
class_774: 0.0396对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.010023 |
| mean_abs_error | 0.002029 |
| relative_error | 0.0219% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_latency | 5.41 ms |
| min_latency | 5.31 ms |
| max_latency | 5.55 ms |
| p50 | 5.39 ms |
| p90 | 5.54 ms |
| p95 | 5.54 ms |
| throughput | 184.70 images/sec |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png
logs/inference.log - 推理结果logs/accuracy.log - 精度验证结果logs/benchmark.log - 性能基准测试结果timm.create_model(pretrained=False) + 本地权重加载,不使用 HuggingFace 直连下载#NPU #Ascend #image-classification #resnet50 #timm