本项目将 timm/efficientnetv2_rw_s.ra2_in1k 图片分类模型适配到单卡昇腾 NPU(Ascend910)运行。使用 ModelScope snapshot_download 下载权重,通过 timm.create_model(pretrained=False) 创建模型结构并加载本地权重,不依赖 HuggingFace 自动下载。项目包含推理验证、CPU-NPU 精度一致性检查和性能基准测试。
| 组件 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| npu-smi | 25.5.2 |
| PyTorch NPU | available (Ascend910_9362) |
| timm | 1.0.27 |
详细环境信息见 logs/env_check.log。
pip install -r requirements.txt
python inference.py推理脚本会:
modelscope.snapshot_download 自动下载模型权重(首次运行时)timm.create_model(pretrained=False) 创建模型结构model.safetensors 权重npu:0 上执行真实推理logs/inference.log示例输出:
Input shape: [1, 3, 288, 288]
Output shape: [1, 1000]
Top-1: class_469: 0.2678
Top-5: class_469, class_968, class_438, class_622, class_470python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.008019 |
| mean_abs_error | 0.000754 |
| relative_error | 0.0938% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
python benchmark.py| 指标 | 值 |
|---|---|
| Avg latency | 16.313 ms |
| Min latency | 14.295 ms |
| Max latency | 31.068 ms |
| P50 latency | 14.840 ms |
| P90 latency | 16.695 ms |
| P95 latency | 23.882 ms |
| Throughput | 61.30 images/sec |
测试配置:warm-up 2 次,正式测试 10 次,每次前后 torch.npu.synchronize(),输入尺寸 [1, 3, 288, 288]。
本项目未在完整 ImageNet 验证集上跑官方精度,仅提供 CPU-NPU smoke consistency 结果。如需完整精度评测,请使用 ImageNet val 集运行标准 eval 流程。
见 screenshots/self_verification.png 和 screenshots/self_verification.txt。
logs/env_check.log — 环境检查logs/inference.log — 推理输出logs/accuracy.log — 精度一致性logs/benchmark.log — 性能基准logs/paths.txt — 模型路径记录288x288,由 timm.data.resolve_model_data_config 自动解析.bin/.safetensors/.pth 等文件提交到仓库#NPU #Ascend #timm #EfficientNetV2 #image-classification