g
gyccc/microsoft-resnet-18-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

microsoft/resnet-18 on Ascend NPU

1. 简介

将 ModelScope 上的 microsoft/resnet-18 图片分类模型适配到华为昇腾 NPU (Ascend910B) 上运行。

  • 原始权重地址:https://modelscope.cn/models/microsoft/resnet-18
  • 模型架构:ResNetForImageClassification
  • 输入尺寸:224x224
  • 输出类别数:1000 (ImageNet-1K)

2. 验证环境

  • 硬件:华为昇腾 910B NPU
  • 操作系统:Linux (aarch64)
  • Python:3.11
  • PyTorch:2.x + torch_npu
  • CANN:8.5.1
  • transformers:4.57.6
  • ModelScope:latest

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU Top-5):

  • Top-1: geyser (0.3984)
  • Top-2: volcano (0.0706)
  • Top-3: ski (0.0246)
  • Top-4: airship, dirigible (0.0241)
  • Top-5: alp (0.0222)

日志保存在 logs/inference.log。

4. 精度验证

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

指标数值
relative_error0.1703%
cosine_similarity0.999999
threshold1.0%
结果PASS
  • CPU Top-1: geyser
  • NPU Top-1: geyser
  • Top-1 match: True
  • Top-5 match: True

5. 性能参考

指标数值
Avg latency2.88 ms
Min latency2.81 ms
Max latency2.91 ms
P50 latency2.88 ms
P90 latency2.91 ms
P95 latency2.91 ms
Throughput347.47 images/sec

测试条件:2 次预热 + 10 次正式测量,batch_size=1,单卡 NPU。

6. 精度评测说明

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

7. 自验证截图

自验证截图

8. 日志文件

  • logs/inference.log — NPU 推理结果
  • logs/accuracy.log — CPU-NPU 精度一致性验证
  • logs/benchmark.log — 性能基准测试

9. 注意事项

  • 使用 ModelScope snapshot_download 下载权重,禁止 HuggingFace 自动下载
  • 使用 ResNetForImageClassification.from_pretrained 加载预训练权重
  • 推理使用 torch.npu.synchronize() 确保 NPU 计算完成
  • 精度验证使用官方 Ascend 一致性指标:max_abs_error、mean_abs_error、relative_error、cosine_similarity

10. 标签 #NPU