本项目将 timm/regnetx_160.tv2_in1k 图片分类模型适配到华为昇腾 NPU (Ascend910) 上运行。模型通过 ModelScope 下载本地权重,使用 timm.create_model(pretrained=False) 创建模型结构并加载权重,实现单卡 NPU 推理、CPU-NPU 精度一致性验证与性能基准测试。
| 项目 | 版本 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 对应版本 |
| timm | latest |
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.000935 |
| mean_abs_error | 0.000153 |
| relative_error | 0.0228% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| warmup_runs | 2 |
| benchmark_runs | 10 |
| avg_latency(s) | 0.007576 |
| min_latency(s) | 0.007520 |
| max_latency(s) | 0.007691 |
| p50_latency(s) | 0.007573 |
| p90_latency(s) | 0.007691 |
| p95_latency(s) | 0.007691 |
| images_per_sec | 132.00 |
日志保存在 logs/benchmark.log。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
logs/inference.log — 推理结果logs/accuracy.log — CPU-NPU 精度一致性logs/benchmark.log — 性能基准测试snapshot_download 下载,严禁使用 timm.create_model(..., pretrained=True) 从 HuggingFace 自动下载。#NPU #Ascend #Ascend910 #timm #image-classification