本项目将 timm/resnet152.a1h_in1k 图片分类模型适配到单卡昇腾 NPU (Ascend910) 上运行。
model.safetensorstimm.create_model(pretrained=False) + snapshot_download 本地权重加载| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| npu-smi | 25.5.2 |
| PyTorch | 2.x |
| torch_npu | 可用 |
| timm | 最新版 |
环境检查日志: logs/env_check.log
python inference.py使用 model_utils.py 中的 load_model() 统一加载模型,通过 timm.data.resolve_model_data_config 自动获取预处理配置,输入图片 assets/test.jpg,在 npu:0 上执行推理。
Top-5 预测结果:
| 排名 | 类别 | 置信度 |
|---|---|---|
| 1 | class_970 | 0.199085 |
| 2 | class_671 | 0.143515 |
| 3 | class_979 | 0.134288 |
| 4 | class_972 | 0.106749 |
| 5 | class_880 | 0.049798 |
完整日志: logs/inference.log
python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.009038 |
| mean_abs_error | 0.001412 |
| relative_error | 0.0158% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
python benchmark.py| 指标 | 数值 |
|---|---|
| Warm-up | 2 runs |
| Formal runs | 10 |
| Avg latency | 16.32 ms |
| Min latency | 14.13 ms |
| Max latency | 31.00 ms |
| P50 latency | 14.68 ms |
| P90 latency | 31.00 ms |
| P95 latency | 31.00 ms |
| Throughput | 61.26 images/sec |
完整日志: logs/benchmark.log
本工程未包含完整 ImageNet 验证集精度评测。上述 Smoke 验证表明 CPU/NPU 数值一致性良好,可作为精度可靠的参考依据。
自验证信息见 screenshots/self_verification.txt 与 screenshots/self_verification.png。
logs/env_check.log - 环境检查logs/stage0.log - 阶段0模型可用性验证logs/inference.log - 推理结果logs/accuracy.log - CPU/NPU一致性对比logs/benchmark.log - 性能基准测试timm.create_model(..., pretrained=False) 创建模型结构,权重通过 modelscope.snapshot_download 下载到本地后加载,不依赖 HuggingFace 自动下载。.bin/.safetensors/.pth/.pt/.ckpt/.onnx 等权重文件。timm.data.resolve_model_data_config 自动获取模型对应的预处理参数,确保与预训练一致。torch.npu.synchronize() 确保计时准确。#NPU #Ascend #timm #resnet #image-classification