本项目将 timm/mobilenetv3_small_100.lamb_in1k 图片分类模型适配为可在单卡昇腾 NPU(Ascend910B)上运行的工程。
| 项目 | 版本 |
|---|---|
| NPU 型号 | Ascend910B4 |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| torchvision | 0.24.0 |
| transformers | 4.57.6 |
| timm | 1.0.27 |
| modelscope | 1.35.3 |
| safetensors | 0.7.0 |
| PIL | 12.2.0 |
| numpy | 1.26.4 |
pip install -r requirements.txt# 单图推理
python inference.py
# CPU vs NPU 一致性验证
python eval_accuracy.py
# 性能基准测试
python benchmark.pylogs/inference.log — 推理结果logs/prediction.txt — Top-5 预测摘要logs/accuracy.log — CPU/NPU 一致性对比logs/benchmark.log — 性能基准结果logs/env_check.log — 环境检查torch.npu.is_available(): True| 排名 | 类别 | 置信度 |
|---|---|---|
| 1 | class_978 | 0.308937 |
| 2 | class_980 | 0.105722 |
| 3 | class_976 | 0.072114 |
| 4 | class_974 | 0.055114 |
| 5 | class_979 | 0.040098 |
注:该模型未提供 id2label 映射文件,使用 class_x 作为占位标签。
| 指标 | 数值 |
|---|---|
| Warmup | 2 次 |
| 正式测试 | 10 次 |
| avg | 66.943 ms |
| min | 34.090 ms |
| max | 119.253 ms |
| p50 | 59.309 ms |
| p90 | 103.468 ms |
| p95 | 111.361 ms |
| images/sec | 14.94 |
本项目执行 CPU vs NPU Smoke 一致性验证(非官方 ImageNet 数据集精度)。
| 指标 | 数值 |
|---|---|
| max_abs_diff (logits) | 0.01232910 |
| mean_abs_diff (logits) | 0.00414845 |
| prob_max_diff | 0.00111027 |
| Top-1 match | True (CPU=978, NPU=978) |
| Top-5 match | True |
| CPU Top-5 | [978, 980, 976, 974, 979] |
| NPU Top-5 | [978, 980, 976, 974, 979] |
见 screenshots/self_verification.png 和 screenshots/self_verification.txt。
logs/
├── accuracy.log # CPU/NPU 一致性验证结果
├── accuracy_stdout.log # eval_accuracy.py 标准输出
├── benchmark.log # 性能基准测试结果
├── benchmark_stdout.log # benchmark.py 标准输出
├── env_check.log # 环境检查信息
├── inference.log # 推理结果
├── inference_stdout.log # inference.py 标准输出
├── model_check.log # 阶段 -1/0 模型检查
└── prediction.txt # Top-5 预测摘要pretrained=True:模型结构通过 timm.create_model(pretrained=False) 创建,权重从 ModelScope 本地目录加载,未触发 HuggingFace Hub 下载。timm.data.resolve_model_data_config + create_transform 完成官方预处理,未使用 torchvision 默认 transform。class_x 占位。picsum.photos 下载的随机图片,用于 smoke 验证,非 ImageNet 标准测试集。fusion_result.json 和 kernel_meta/ 目录,并加入 .gitignore。#NPU #Ascend #MobileNetV3 #ImageClassification #timm #ModelScope