本项目将 timm/mobilenetv4_conv_large.e500_r256_in1k 图片分类模型适配到华为昇腾 NPU (Ascend910)。
使用 ModelScope 下载本地权重,通过 timm.create_model(pretrained=False) 加载,实现 NPU 真实推理、CPU-NPU 精度一致性验证及性能基准测试。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
| timm | latest |
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.005696 |
| mean_abs_error | 0.000468 |
| relative_error | 0.0122% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 11.361 |
| min_latency_ms | 11.223 |
| max_latency_ms | 11.550 |
| p50_latency_ms | 11.361 |
| p90_latency_ms | 11.454 |
| p95_latency_ms | 11.454 |
| images_per_sec | 88.02 |
测试配置:batch=1,输入尺寸 3x256x256,预热 2 次,正式测试 10 次取平均。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
| 文件 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查 |
logs/inference.log | NPU 推理输出 |
logs/accuracy.log | CPU-NPU 精度一致性 |
logs/benchmark.log | NPU 性能基准测试 |
timm.create_model(..., pretrained=True),权重必须通过 ModelScope snapshot_download 本地加载。.gitignore 中排除)。r256 决定),非标准 224x224。#NPU #Ascend #Ascend910 #timm #MobileNetV4 #ImageClassification