本项目将 timm/tf_efficientnet_b0.ns_jft_in1k 图片分类模型适配到华为昇腾 NPU(Ascend910),使其能够在单卡 NPU 上完成推理、精度验证和性能基准测试。
timm.create_model(pretrained=False) + 本地权重加载pip install -r requirements.txt
python inference.py推理输出 Top-5 预测结果,日志保存在 logs/inference.log。
Model: timm/tf_efficientnet_b0.ns_jft_in1k
Weights: /opt/atomgit/.cache/modelscope/hub/models/timm/tf_efficientnet_b0___ns_jft_in1k/model.safetensors
Input shape: [1, 3, 224, 224]
Output shape: [1, 1000]
Top-5 predictions:
class_978: 0.5125
class_976: 0.1176
class_540: 0.0358
class_437: 0.0309
class_980: 0.0205python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.004901 |
| mean_abs_error | 0.001108 |
| relative_error | 0.1622% |
| cosine_similarity | 0.999999 |
| threshold | 1.0% |
| 结果 | PASS |
python benchmark.py| 指标 | 值 |
|---|---|
| 平均延迟 | 7.09 ms |
| 最小延迟 | 7.02 ms |
| 最大延迟 | 7.19 ms |
| P50 | 7.09 ms |
| P90 | 7.19 ms |
| P95 | 7.19 ms |
| 吞吐量 | 141.10 images/sec |
本项目执行的是 Smoke consistency check(同输入同精度验证),非 ImageNet 官方精度评测。CPU 和 NPU 推理结果完全一致,Top-1/Top-5 类别匹配。
参见 screenshots/self_verification.png。
logs/inference.log — 推理结果logs/accuracy.log — 精度验证logs/benchmark.log — 性能基准pretrained=False 创建模型结构,手动加载本地权重#NPU