本项目将 timm/mobilenetv3_small_050.lamb_in1k 图像分类模型适配到华为昇腾 NPU (Ascend910) 上运行。模型通过 ModelScope snapshot_download 下载权重,使用 timm 库创建模型结构并加载本地权重,在 NPU 上完成单图推理、CPU-NPU 精度一致性验证与性能基准测试。
pip install -r requirements.txt
python inference.py推理结果 (NPU):
Model: timm/mobilenetv3_small_050.lamb_in1k
Weights: /opt/atomgit/.cache/modelscope/hub/models/timm/mobilenetv3_small_050___lamb_in1k/model.safetensors
Missing keys: 0, Unexpected keys: 0
Input shape: (1, 3, 224, 224)
Output shape: (1, 1000)
Top-5 predictions (NPU):
1. class=972, prob=0.372148
2. class=979, prob=0.045396
3. class=663, prob=0.038370
4. class=820, prob=0.030488
5. class=888, prob=0.025310日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.082224 |
| mean_abs_error | 0.017429 |
| relative_error | 0.8450% |
| cosine_similarity | 0.999959 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 6.9201 |
| min_latency_ms | 5.1982 |
| max_latency_ms | 21.1295 |
| p50_latency_ms | 5.3571 |
| p90_latency_ms | 21.1295 |
| p95_latency_ms | 21.1295 |
| throughput_img/s | 144.51 |
测试条件:batch=1,10 次运行,输入尺寸 224x224,NPU 预热 2 次。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 与 screenshots/self_verification.txt。
logs/inference.log — 推理输出logs/accuracy.log — CPU-NPU 精度一致性检查结果logs/benchmark.log — 性能基准测试结果logs/env_check.log — NPU 环境检查logs/paths.txt — 模型下载路径记录ModelScope snapshot_download 自动下载到本地缓存,推理脚本从本地加载,不触发 HuggingFace 自动下载。torch_npu 可正常导入。#NPU