将 timm 库中的 CAFormer-M36 图片分类模型适配为可在单卡昇腾 NPU(Ascend910B)上运行的提交工程。
timm/caformer_m36.sail_in22k_ft_in1k_384snapshot_download,通过 timm.create_model(pretrained=False) 加载本地权重| 项目 | 值 |
|---|---|
| NPU | Ascend910B (Ascend910_9362) |
| PyTorch | 2.x |
| torch_npu | 已安装 |
| timm | 已安装 |
| modelscope | 已安装 |
| Python | 3.x |
cd timm-caformer_m36.sail_in22k_ft_in1k_384-NPU
pip install -r requirements.txt
python inference.py推理输出示例(随机测试图片):
Top-5 predictions:
class_975: 0.390609
class_978: 0.148572
class_460: 0.106211
class_976: 0.085261
class_972: 0.025693python eval_accuracy.py对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.002898 |
| mean_abs_error | 0.000497 |
| relative_error | 0.0517% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 值 |
|---|---|
| Input | 1x3x384x384 |
| Avg Latency | 18.50 ms |
| Min Latency | 17.87 ms |
| Max Latency | 19.31 ms |
| P50 | 18.24 ms |
| P90 | 19.31 ms |
| P95 | 19.31 ms |
| Throughput | 54.05 images/sec |
| 预热次数 | 2 |
| 正式迭代 | 10 |
参见 screenshots/self_verification.png 和 screenshots/self_verification.txt
| 文件 | 说明 |
|---|---|
logs/inference.log | NPU 推理日志 |
logs/accuracy.log | CPU vs NPU 精度一致性日志 |
logs/benchmark.log | 性能基准测试日志 |
logs/env_check.log | NPU 环境检查日志 |
snapshot_download 下载权重,不使用 HuggingFace 直连timm.create_model(pretrained=False) 创建模型结构,手动加载本地权重.safetensors, .bin)不提交到 Git 仓库timm.data.resolve_model_data_config 自动获取预处理配置本工程已通过 Ascend NPU 适配验证,可提交。