本项目将 timm/tresnet_l.miil_in1k 图片分类模型适配到单卡昇腾 NPU (Ascend910)。
timm.create_model(pretrained=False) + ModelScope 本地权重加载| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
| timm | latest |
NPU 状态 (npu-smi info):
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.003569 |
| mean_abs_error | 0.000694 |
| relative_error | 0.0573% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
基于单卡 NPU、batch_size=1、输入尺寸 224x224 的基准测试(10 次正式迭代,2 次预热):
| 指标 | 数值 |
|---|---|
| avg latency | 0.014042 s |
| min latency | 0.013608 s |
| max latency | 0.014249 s |
| p50 latency | 0.014133 s |
| p90 latency | 0.014249 s |
| p95 latency | 0.014249 s |
| 吞吐量 | 71.22 images/sec |
日志保存在 logs/benchmark.log。
本项目包含单图 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 — 性能基准测试日志pretrained=False 并通过 modelscope.snapshot_download 加载本地权重,避免 HuggingFace 自动下载。.gitignore 已排除 *.bin, *.safetensors, *.pth, *.pt, *.ckpt, *.onnx 等权重文件。assets/test.jpg 为在线下载的随机测试图,用于 smoke test。timm.data.resolve_model_data_config + create_transform 获取模型专属预处理参数,无需手写 Normalize。#NPU #Ascend #Ascend910 #timm #image-classification