本项目将 timm/tf_efficientnetv2_m.in1k 图片分类模型适配到华为昇腾 NPU(Ascend910)上运行。使用 ModelScope snapshot_download 下载模型权重,通过 timm.create_model(pretrained=False) 创建模型结构并加载本地权重,在单卡 NPU 上完成推理验证、精度一致性检查和性能基准测试。
| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| npu-smi | 25.5.2 |
| Python | 3.11 |
| PyTorch | 2.x |
| torch-npu | 适配版本 |
| timm | latest |
| modelscope | latest |
pip install -r requirements.txt
python inference.py推理使用单卡 npu:0,输入 shape 为 [1, 3, 384, 384],输出 shape 为 [1, 1000]。
Top-5 预测结果示例:
| 排名 | 类别 | 概率 |
|---|---|---|
| 1 | class_111 | 0.001552 |
| 2 | class_644 | 0.001328 |
| 3 | class_78 | 0.001271 |
| 4 | class_980 | 0.001251 |
| 5 | class_103 | 0.001241 |
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.000313 |
| mean_abs_error | 0.000088 |
| relative_error | 0.1388% |
| cosine_similarity | 0.999999 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg latency | 21.990 ms |
| min latency | 21.554 ms |
| max latency | 22.714 ms |
| p50 latency | 21.933 ms |
| p90 latency | 22.714 ms |
| p95 latency | 22.714 ms |
| Throughput | 45.48 images/sec |
测试配置:warmup 2 次,正式测试 10 次,单卡 npu:0,batch_size=1,输入 [1, 3, 384, 384]。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 与 screenshots/self_verification.txt。
| 日志 | 说明 |
|---|---|
logs/env_check.log | NPU 环境信息 |
logs/inference.log | 推理结果日志 |
logs/accuracy.log | CPU-NPU 精度一致性日志 |
logs/benchmark.log | 性能基准测试日志 |
modelscope 自动下载或手动放置。snapshot_download 从 ModelScope 下载权重到本地缓存目录。timm.create_model(..., pretrained=True) 触发 HuggingFace 直连下载。#NPU #Ascend #Ascend910 #Huawei #timm #EfficientNetV2