将 timm 库的 ResNet-34 图片分类模型适配为可在单卡昇腾 NPU(Ascend910B)上运行的提交工程。
timm/resnet34.a1_in1ktimm.create_model(pretrained=False) + ModelScope snapshot_download 本地权重| 项目 | 值 |
|---|---|
| NPU | Ascend910B |
| npu-smi | OK |
| torch | 2.x |
| torch_npu | 已安装 |
| timm | 已安装 |
| modelscope | 已安装 |
| Python | 3.x |
# 安装依赖
pip install -r requirements.txt
# 单图推理
python inference.py输出示例:
Output shape: torch.Size([1, 1000])
Device: npu:0
Top-5 Predictions:
1. class_979 (0.9791)
2. class_975 (0.0057)
3. class_970 (0.0022)
4. class_972 (0.0012)
5. class_150 (0.0010)python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.005223 |
| mean_abs_error | 0.001312 |
| relative_error | 0.0125% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
python benchmark.py| 指标 | 值 |
|---|---|
| avg latency | 3.99 ms |
| min latency | 3.94 ms |
| max latency | 4.05 ms |
| p50 | 3.99 ms |
| p90 | 4.05 ms |
| p95 | 4.05 ms |
| throughput | 250.58 images/sec |
本项目仅做 smoke consistency check(同输入同精度 CPU vs NPU 对比),非官方精度评测。
见 screenshots/self_verification.png
logs/
├── env_check.log # NPU 环境检查
├── inference.log # 推理结果
├── accuracy.log # CPU vs NPU 一致性验证
├── benchmark.log # 性能基准
└── paths.txt # 模型路径信息timm.create_model(pretrained=True),避免 HuggingFace 自动下载snapshot_download 获取权重,timm.create_model(pretrained=False) 加载结构#NPU