本项目将 Stefanieliang/cv_vit-base_image-classification_Dailylife-labels_flowers 适配到昇腾 NPU (Ascend910B)。
该模型基于 DeiT-Base ViT 架构,在 flowers14 数据集上微调,用于 14 类花卉图像分类。由于原始模型使用 mmcls/mmpretrain 格式,为避免引入沉重的 mmpretrain 依赖,本项目在 model_utils.py 中实现了纯 PyTorch 的 MMClsVisionTransformer,并通过键名映射完成本地权重加载。
| 项目 | 版本 |
|---|---|
| NPU | Ascend910B (Ascend910_9362) |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.1.0 |
| torch_npu | 2.1.0 |
pip install -r requirements.txt
python inference.py推理结果 (NPU):
Top-1: class_8 (0.0715)
Top-2: class_6 (0.0715)
Top-3: class_1 (0.0715)
Top-4: class_0 (0.0715)
Top-5: class_5 (0.0715)日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.000012 |
| mean_abs_error | 0.000005 |
| relative_error | 0.5946% |
| cosine_similarity | 0.999989 |
| threshold | 1.0% |
| 结果 | PASS |
CPU Top-1 == NPU Top-1: True (class_8) CPU Top-5 == NPU Top-5: True
| 指标 | 数值 |
|---|---|
| avg_latency | 4.81 ms |
| min_latency | 4.71 ms |
| max_latency | 5.03 ms |
| p50_latency | 4.80 ms |
| p90_latency | 5.03 ms |
| throughput | 207.82 images/sec |
日志保存在 logs/benchmark.log。
本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 与 screenshots/self_verification.txt。
logs/env_check.log — NPU 环境检查logs/inference.log — NPU 推理结果logs/accuracy.log — CPU-NPU 精度一致性logs/benchmark.log — NPU 性能基准snapshot_download 下载到本地缓存,运行时会从本地路径加载,不会触发 HuggingFace 自动下载。#NPU #Ascend #Ascend910 #ImageClassification #ViT #DeiT