本项目将 timm/resnet50.a3_in1k 图片分类模型适配到单卡昇腾 NPU(Ascend910)上运行。
timm.create_model(pretrained=False) + ModelScope 本地权重加载| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
环境检查日志见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.011322 |
| mean_abs_error | 0.002799 |
| relative_error | 0.0328% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_time | 0.0055 s |
| min_time | 0.0054 s |
| max_time | 0.0056 s |
| p50_time | 0.0055 s |
| p90_time | 0.0056 s |
| p95_time | 0.0056 s |
| images_per_sec | 181.79 |
日志保存在 logs/benchmark.log。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 和 screenshots/self_verification.txt。
logs/env_check.log — 环境检查logs/inference.log — 推理输出logs/accuracy.log — 精度一致性验证logs/benchmark.log — 性能基准测试snapshot_download 自动下载到本地缓存,严禁使用 pretrained=True 从 HuggingFace 直接下载。timm.data.resolve_model_data_config + create_transform,与 timm 官方保持一致。本模型默认输入尺寸为 160x160。npu:0 上执行,并使用 torch.npu.synchronize() 确保计时准确。#NPU #Ascend #Ascend910 #timm #ResNet #image-classification