将 timm/tf_efficientnet_b2.ns_jft_in1k 图片分类模型适配到华为昇腾 NPU(Ascend910)。使用 ModelScope snapshot_download 下载权重,timm.create_model(pretrained=False) 加载本地权重,包含推理验证、CPU-NPU 精度一致性检查和性能基准测试。
# 安装依赖
pip install -r requirements.txt
# 运行推理
python inference.py
# 查看日志
cat logs/inference.logTop-5 预测结果:
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.009065 |
| mean_abs_error | 0.001171 |
| relative_error | 0.1886% |
| cosine_similarity | 0.999999 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg | 10.25 ms |
| min | 9.98 ms |
| max | 10.56 ms |
| p50 | 10.25 ms |
| p90 | 10.51 ms |
| p95 | 10.54 ms |
| throughput | 97.56 images/sec |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
详见 screenshots/self_verification.png
logs/inference.log — 推理输出logs/accuracy.log — 精度验证logs/benchmark.log — 性能基准#NPU #Ascend #image-classification #EfficientNet #timm