本项目将 google/vit-large-patch16-224 图像分类模型适配到华为昇腾 NPU (Ascend910) 上运行。
snapshot_download + 本地 pytorch_model.bin 加载transformers.AutoModelForImageClassification + AutoConfig| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
环境检查日志: logs/env_check.log
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[1, 3, 224, 224][1, 1000]日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.042520 |
| mean_abs_error | 0.006184 |
| relative_error | 0.7396% |
| cosine_similarity | 0.999978 |
| threshold | 1.0% |
| 结果 | PASS |
python eval_accuracy.py运行环境: Ascend910, batch=1, 输入 [1, 3, 224, 224]
| 指标 | 数值 |
|---|---|
| avg_latency | 11.63 ms |
| min_latency | 11.19 ms |
| max_latency | 11.83 ms |
| p50_latency | 11.66 ms |
| p90_latency | 11.83 ms |
| p95_latency | 11.83 ms |
| throughput | 85.97 samples/sec |
python benchmark.py日志保存在 logs/benchmark.log。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.txt 与 screenshots/self_verification.png。
logs/env_check.log — 环境检查logs/inference.log — NPU 推理输出logs/accuracy.log — CPU-NPU 精度对比logs/benchmark.log — 性能基准测试*.bin, *.safetensors 等)提交到 Git 仓库,已配置 .gitignore。#NPU #Ascend #Ascend910 #ViT #ImageClassification