g
gyccc/timm-resnet18.a1_in1k-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

timm/resnet18.a1_in1k on Ascend NPU

1. 简介

将 HuggingFace / ModelScope 上的图片分类模型 timm/resnet18.a1_in1k(ResNet18,ImageNet-1k 预训练)适配为可在单卡昇腾 Ascend910B NPU 上运行的提交工程。

  • 模型:timm/resnet18.a1_in1k
  • 任务类型:图片分类(ImageNet-1k,1000 类)
  • 权重来源:ModelScope snapshot_download 本地权重(pretrained=False + 本地加载,禁用 HuggingFace 自动下载)
  • 推理设备:npu:0(Ascend910B)
  • 输入尺寸:224×224,输出 [1, 1000]

2. 验证环境

项值
NPU 设备Ascend910(Ascend910_9362)
NPU 驱动npu-smi 25.5.5
PyTorch2.9.0
torch_npu2.9.0.post1
timm1.0.28
modelscope1.36.3
Python3.11.14

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU Top-5):

  • Top-1: coral reef (0.9536)
  • Top-2: brain coral (0.0321)
  • Top-3: coral fungus (0.0010)
  • Top-4: sea anemone, anemone (0.0009)
  • Top-5: velvet (0.0007)

日志保存在 logs/inference.log。

4. 精度验证

对单张测试图片进行 CPU 与 NPU 一致性验证:

指标数值
max_abs_error0.006659
mean_abs_error0.001702
relative_error0.0172%
cosine_similarity1.000000
threshold1.0%
结果PASS
  • CPU Top-1: coral reef
  • NPU Top-1: coral reef
  • CPU Top-5: coral reef, brain coral, coral fungus, sea anemone, anemone, velvet
  • NPU Top-5: coral reef, brain coral, coral fungus, sea anemone, anemone, velvet
  • Top-1 match: True
  • Top-5 match: True

5. 性能参考

NPU 单卡基准(输入 1×3×224×224,预热 2 次 + 正式 10 次):

指标数值
avg_latency_ms2.3118
min_latency_ms2.2886
max_latency_ms2.3464
p50_latency_ms2.3075
p90_latency_ms2.3313
p95_latency_ms2.3313
images_per_sec432.57

日志保存在 logs/benchmark.log。

6. 精度评测说明

本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。

7. 自验证截图

见 screenshots/self_verification.png。

8. 日志文件

文件说明
logs/inference.logNPU 推理 Top-5 结果
logs/accuracy.logCPU-NPU 精度一致性验证
logs/benchmark.logNPU 性能基准
logs/env_check.logNPU 环境检查

9. 注意事项

  • 权重通过 ModelScope snapshot_download 下载并本地加载,timm.create_model(..., pretrained=False),不依赖 HuggingFace 自动下载。
  • *.bin / *.safetensors 等权重文件不随仓库提交(见 .gitignore)。
  • 适配仅覆盖单卡 NPU 推理,不使用 vLLM、TP/EP/DP、文本生成、检测、分割、OCR、多模态。

10. 标签 #NPU