本项目将 timm/res2net50_26w_4s.in1k 图片分类模型适配到华为昇腾 NPU (Ascend910),包含完整的推理验证、CPU-NPU 精度一致性检查与性能基准测试。
timm.create_model(pretrained=False) + ModelScope snapshot_download 本地权重加载| 组件 | 版本/信息 |
|---|---|
| NPU | Ascend910 |
| npu-smi | 25.5.2 |
| PyTorch | 可用 |
| torch_npu | 可用 |
详见 logs/env_check.log。
pip install -r requirements.txt
python inference.py关键实现: 使用 model_utils.py 统一加载模型,禁止 HuggingFace 自动下载,权重通过 ModelScope 本地加载。
推理输出示例:
Model: timm/res2net50_26w_4s.in1k
Input shape: torch.Size([1, 3, 224, 224])
Output shape: torch.Size([1, 1000])
Top-5 predictions:
1. class_973: 0.6941
2. class_109: 0.0292
3. class_991: 0.0114
4. class_108: 0.0109
5. class_76: 0.0073python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.004905 |
| mean_abs_error | 0.000677 |
| relative_error | 0.1234% |
| cosine_similarity | 0.999999 |
| threshold | 1.0% |
| 结果 | PASS |
python benchmark.py| 指标 | 数值 |
|---|---|
| Avg latency | 9.47 ms |
| Min latency | 9.31 ms |
| Max latency | 9.85 ms |
| P50 latency | 9.41 ms |
| P90 latency | 9.73 ms |
| P95 latency | 9.79 ms |
| Throughput | 105.57 images/sec |
测试配置:batch_size=1,预热 2 轮,正式 10 轮。
本项目提供 CPU-NPU smoke 一致性检查脚本 eval_accuracy.py,验证 NPU 推理结果与 CPU 对齐。详细日志见 logs/accuracy.log。
见 screenshots/self_verification.png 与 screenshots/self_verification.txt。
logs/env_check.log — 环境检查logs/inference.log — 推理结果logs/accuracy.log — 精度一致性logs/benchmark.log — 性能基准snapshot_download 自动下载到本地缓存,不会提交到仓库。timm.create_model(..., pretrained=True) 触发 HuggingFace 自动下载。#NPU #Ascend #ImageClassification #timm