w
gcw_uQ09W7jl/apple-mobilevit-x-small-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

apple/mobilevit-x-small on Ascend NPU

1. 简介

本项目将 ModelScope apple/mobilevit-x-small 图像分类模型适配到华为昇腾 NPU (Ascend910)。模型通过 ModelScope 下载权重,使用 transformers 库的 AutoModelForImageClassification 进行本地加载,并在单卡 NPU 上完成推理验证、CPU-NPU 精度一致性检查和性能基准测试。

  • 模型架构: MobileViTForImageClassification
  • 参数量: 2.32M
  • 任务类型: 图像分类 (ImageNet-1k, 1000 类)
  • 输入尺寸: 288 (resize) -> 256 (center crop)

2. 验证环境

项目版本/信息
NPUAscend910
CANN8.5.1
PyTorch2.x
torch_npu适配 CANN 8.5.1
transformers最新版

完整环境信息见 logs/env_check.log。

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU):

=== NPU Inference Result ===
Input image: assets/test.jpg
Logits shape: torch.Size([1, 1000])
Logits sample (first 10): [4.1390, 0.2492, 1.0306, 1.3025, 1.6823, 1.7179, 1.0253, 1.5865, 2.3747, 3.4093]

Top-5 predictions:
  1. class_958: 0.2071
  2. class_984: 0.1256
  3. class_595: 0.1200
  4. class_856: 0.0260
  5. class_730: 0.0184

日志保存在 logs/inference.log。

4. 精度验证

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

指标数值
max_abs_error0.013688
mean_abs_error0.006430
relative_error0.4342%
cosine_similarity0.999996
threshold1.0%
结果PASS

5. 性能参考

单张图片 batch=1 在 Ascend910 上的推理性能:

指标数值
avg_latency_ms8.406
min_latency_ms8.362
max_latency_ms8.477
p50_latency_ms8.396
p90_latency_ms8.457
p95_latency_ms8.467
throughput_img/s118.96

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 snapshot_download 自动下载,首次运行需要联网。
  2. 脚本使用 local_files_only=True 加载本地权重,不触发 HuggingFace 自动下载。
  3. 测试图片为真实下载图片,可直接用于验证。

10. 标签

#NPU #Ascend #Ascend910 #MobileViT #ImageClassification