w
gcw_uQ09W7jl/google-vit-large-patch16-224-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

google/vit-large-patch16-224 on Ascend NPU

1. 简介

本项目将 google/vit-large-patch16-224 图像分类模型适配到华为昇腾 NPU (Ascend910) 上运行。

  • 模型类型: Vision Transformer (ViT) 图像分类
  • 输入: 224x224 RGB 图像
  • 输出: 1000 类 ImageNet 分类 logits
  • 权重加载: ModelScope snapshot_download + 本地 pytorch_model.bin 加载
  • 适配方式: transformers.AutoModelForImageClassification + AutoConfig

2. 验证环境

项目版本/型号
NPUAscend910
CANN8.5.1
PyTorch2.x
torch_npu适配 CANN 8.5.1

环境检查日志: logs/env_check.log

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU):

=== Top-5 Predictions ===
1. class_idx= 985, prob=0.978861
2. class_idx= 883, prob=0.004505
3. class_idx= 968, prob=0.000758
4. class_idx= 738, prob=0.000354
5. class_idx= 504, prob=0.000316
  • 输入 shape: [1, 3, 224, 224]
  • 输出 logits shape: [1, 1000]

日志保存在 logs/inference.log。

4. 精度验证

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

指标数值
max_abs_error0.042520
mean_abs_error0.006184
relative_error0.7396%
cosine_similarity0.999978
threshold1.0%
结果PASS
python eval_accuracy.py

5. 性能参考

运行环境: Ascend910, batch=1, 输入 [1, 3, 224, 224]

指标数值
avg_latency11.63 ms
min_latency11.19 ms
max_latency11.83 ms
p50_latency11.66 ms
p90_latency11.83 ms
p95_latency11.83 ms
throughput85.97 samples/sec
python benchmark.py

日志保存在 logs/benchmark.log。

6. 精度评测说明

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

7. 自验证截图

见 screenshots/self_verification.txt 与 screenshots/self_verification.png。

8. 日志文件

  • logs/env_check.log — 环境检查
  • logs/inference.log — NPU 推理输出
  • logs/accuracy.log — CPU-NPU 精度对比
  • logs/benchmark.log — 性能基准测试

9. 注意事项

  1. 权重通过 ModelScope 自动下载,首次运行需要联网。
  2. 请勿将权重文件(*.bin, *.safetensors 等)提交到 Git 仓库,已配置 .gitignore。
  3. 本项目仅验证单卡 NPU 推理,未测试多卡并行。

10. 标签

#NPU #Ascend #Ascend910 #ViT #ImageClassification