sheeps_/timm-tiny_vit_21m_224.dist_in22k_ft_in1k-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

timm/tiny_vit_21m_224.dist_in22k_ft_in1k 在昇腾 NPU 上的部署

1. 简介

本项目将 timm/tiny_vit_21m_224.dist_in22k_ft_in1k 图像分类模型适配到华为昇腾 NPU(Ascend910)。

使用 ModelScope 的 snapshot_download 功能下载权重,通过 timm.create_model(pretrained=False) 加载本地权重,并借助 torch_npu 将模型迁移至 npu:0 设备执行推理。项目包含推理验证、CPU 与 NPU 精度一致性检查以及性能基准测试。

2. 验证环境

项目版本/型号
NPUAscend910
CANN8.5.1
PyTorch[LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL2.9.0+cpu
torch_npu[LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL2.9.0.post1+gitee7ba04
timm[LOG_WARNING] can not create directory, directory: /home/atomgit/ascend/log, possible reason: No such file or directory.path string is NULLpath string is NULL1.0.27

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU Top-5):

  • Top-5 预测结果 (NPU):
    • Top-1: class_970 (0.103296)
    • Top-2: class_975 (0.062706)
    • Top-3: class_671 (0.054681)
    • Top-4: class_979 (0.032301)
    • Top-5: class_972 (0.026633)

日志保存在 logs/inference.log。

4. 精度验证

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

指标数值
max_abs_error0.013995
mean_abs_error0.003792
relative_error0.4300%
cosine_similarity0.999992
threshold1.0%
结果PASS
  • CPU Top-1: class_970
  • NPU Top-1: class_970
  • CPU Top-5: class_970, class_975, class_671, class_979, class_972
  • NPU Top-5: class_970, class_975, class_671, class_979, class_972
  • Top-1 匹配: True
  • Top-5 匹配: True

5. 性能参考

在单卡 Ascend910 NPU 上的性能表现:

指标数值
avg latency8.126 ms
throughput123.07 images/sec

详细指标见 logs/benchmark.log。

6. 精度评测说明

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

7. 自验证截图

见 screenshots/self_verification.png。

8. 日志文件

  • logs/inference.log — 推理输出
  • logs/accuracy.log — 精度一致性验证
  • logs/benchmark.log — 性能基准测试
  • logs/env_check.log — 环境检查

9. 注意事项

  1. 模型权重通过 ModelScope 自动下载,无需手动准备。
  2. 推理时使用 pretrained=False,从本地 safetensors 文件加载权重。
  3. 预处理使用 timm.data.resolve_model_data_config + create_transform,自动匹配模型配置。

10. 标签

#NPU #Ascend #Ascend910 #timm #TinyViT #image-classification