本项目将 timm/tf_efficientnetv2_m.in21k_ft_in1k 图像分类模型适配到华为昇腾 NPU (Ascend910)。
模型基于 PyTorch 实现,通过 timm 库加载,使用 ModelScope snapshot_download 下载权重并本地加载,支持在单卡 NPU 上完成推理、精度一致性验证和性能基准测试。
| 项目 | 版本/信息 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
| timm | latest |
| modelscope | latest |
详细环境信息见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理结果 (NPU):
=== NPU Inference Result ===
Model: timm/tf_efficientnetv2_m.in21k_ft_in1k
Input shape: [1, 3, 384, 384]
Output shape: [1, 1000]
Output dtype: torch.float32
Top-5 predictions:
1. class_idx=979, prob=0.865997
2. class_idx=980, prob=0.029974
3. class_idx=975, prob=0.007894
4. class_idx=972, prob=0.003608
5. class_idx=973, prob=0.003454
Raw logits (first 10):
[0.37995484471321106, -0.15465034544467926, -0.9324793219566345, -0.023927170783281326, -0.7763705253601074, 1.3367199897766113, -0.07686387747526169, -1.1545323133468628, -0.6389279365539551, 0.6060746312141418]日志保存在 logs/inference.log。
对单张测试输入进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.001379 |
| mean_abs_error | 0.000320 |
| relative_error | 0.0472% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| Device | npu:0 |
| Input shape | [1, 3, 384, 384] |
| avg latency | 22.347 ms |
| min latency | 21.799 ms |
| max latency | 22.919 ms |
| p50 latency | 22.271 ms |
| p90 latency | 22.911 ms |
| p95 latency | 22.915 ms |
| throughput | 44.75 samples/sec |
本项目包含单输入 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 — 性能基准测试snapshot_download 下载,首次运行会自动缓存到本地npu:0,如需更改请修改 inference.py 中的 .to("npu:0")https://picsum.photos/400/300,如无法访问会生成占位图#NPU #Ascend #Ascend910 #timm #EfficientNetV2