本项目将 ModelScope 上的 timm/tf_efficientnetv2_m.in21k_ft_in1k 图片分类模型适配到单卡昇腾 NPU(Ascend910)。
ModelScope snapshot_download 下载权重,timm.create_model(pretrained=False) 创建模型结构并加载本地权重npu:0)| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 25.5.2 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 与 CANN 配套 |
| timm | 1.0.27 |
| modelscope | 1.35.3 |
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
python inference.py输出示例:
Top-5 predictions:
1. class_111 0.127165
2. class_534 0.033293
3. class_128 0.027699
4. class_813 0.021150
5. class_556 0.019315对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.002347 |
| mean_abs_error | 0.000503 |
| relative_error | 0.0548% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| runs | 10 |
| avg_latency_ms | 21.365 |
| min_latency_ms | 20.916 |
| max_latency_ms | 22.059 |
| p50_latency_ms | 21.156 |
| p90_latency_ms | 22.059 |
| p95_latency_ms | 22.059 |
| images_per_sec | 46.81 |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
| 日志 | 路径 |
|---|---|
| 环境检查 | logs/env_check.log |
| 推理日志 | logs/inference.log |
| 精度验证 | logs/accuracy.log |
| 性能测试 | logs/benchmark.log |
snapshot_download 自动下载到本地缓存,首次运行需联网。timm.create_model(..., pretrained=True),避免触发 HuggingFace 直连下载。source /usr/local/Ascend/ascend-toolkit/set_env.sh 加载 CANN 环境。.bin/.safetensors/.pth 等已加入 .gitignore)。#NPU #Ascend #Ascend910 #timm #EfficientNetV2 #image-classification