本工程将 ModelScope 上的 timm/inception_v4.tf_in1k 图片分类模型适配为可在单卡昇腾 NPU(Ascend910B)上运行的提交工程。
timm/inception_v4.tf_in1ktimm.create_model(pretrained=False) 创建模型结构,通过 ModelScope snapshot_download 下载本地权重并加载NPU: Ascend910_9362
npu-smi: 25.5.2
PyTorch: with torch_npu support
Python: 3.11详见 logs/env_check.log。
安装依赖:
pip install -r requirements.txt运行单图推理:
python inference.py推理流程:
model_utils.load_model() 通过 ModelScope 下载权重并加载到 timm 模型timm.data.resolve_model_data_config + create_transform 进行预处理npu:0Model: timm/inception_v4.tf_in1k
Model dir: /opt/atomgit/.cache/modelscope/hub/models/timm/inception_v4___tf_in1k
Weights: /opt/atomgit/.cache/modelscope/hub/models/timm/inception_v4___tf_in1k/model.safetensors
Missing keys: 0
Unexpected keys: 0
Input shape: [1, 3, 299, 299]
Output shape: [1, 1000]
Top-5 predictions:
1. class_912: 0.445134
2. class_718: 0.065991
3. class_839: 0.054934
4. class_821: 0.048072
5. class_743: 0.034755python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.008008 |
| mean_abs_error | 0.000979 |
| relative_error | 0.1363% |
| cosine_similarity | 0.999999 |
| threshold | 1.0% |
| 结果 | PASS |
运行性能基准测试:
python benchmark.py结果摘要(batch=1,输入 3x299x299):
本工程提供 smoke consistency 验证脚本 eval_accuracy.py,对比同一输入在 CPU 与 NPU 上的输出一致性。官方 ImageNet-1k 精度需用户在完整验证集上自行运行。
见 screenshots/self_verification.txt 与 screenshots/self_verification.png。
| 文件 | 内容 |
|---|---|
logs/env_check.log | NPU 环境信息 |
logs/inference.log | 单图推理结果 |
logs/accuracy.log | CPU/NPU 一致性对比 |
logs/benchmark.log | 性能基准测试结果 |
snapshot_download 自动下载到本地缓存,不随本工程提交。timm.create_model(..., pretrained=True),避免 HuggingFace 直连下载。assets/test.jpg 为随机测试图片,仅用于验证推理流程。#NPU