本项目将 ModelScope 上的 timm/swinv2_tiny_window8_256.ms_in1k 图片分类模型适配到单卡昇腾 NPU(Ascend910)。
ModelScope snapshot_download 下载权重,timm.create_model(pretrained=False) 创建模型结构并加载本地权重npu:0)| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 25.5.2 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 与 CANN 配套 |
| timm | 1.0.27 |
| modelscope | 1.35.3 |
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
python inference.py输出示例:
Top-5 predictions:
1. class_977 0.004667
2. class_794 0.003645
3. class_554 0.003239
4. class_549 0.003237
5. class_844 0.003054对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.005473 |
| mean_abs_error | 0.001047 |
| relative_error | 0.3436% |
| cosine_similarity | 0.999995 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| runs | 10 |
| avg_latency_ms | 13.223 |
| min_latency_ms | 12.651 |
| max_latency_ms | 13.544 |
| p50_latency_ms | 13.332 |
| p90_latency_ms | 13.544 |
| p95_latency_ms | 13.544 |
| images_per_sec | 75.63 |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
| 日志 | 路径 |
|---|---|
| 环境检查 | logs/env_check.log |
| 推理日志 | logs/inference.log |
| 精度验证 | logs/accuracy.log |
| 性能测试 | logs/benchmark.log |
snapshot_download 自动下载到本地缓存,首次运行需联网。timm.create_model(..., pretrained=True),避免触发 HuggingFace 直连下载。source /usr/local/Ascend/ascend-toolkit/set_env.sh 加载 CANN 环境。.bin/.safetensors/.pth 等已加入 .gitignore)。#NPU #Ascend #Ascend910 #timm #SwinV2 #image-classification