本项目将 timm/vit_base_patch16_224.augreg2_in21k_ft_in1k 图片分类模型适配到单卡昇腾 NPU(Ascend910)上运行。
timm.create_model(pretrained=False) + 本地 safetensors 权重| 项目 | 版本/型号 |
|---|---|
| NPU | Ascend910_9362 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 适配 CANN 8.5.1 |
| timm | latest |
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.020678 |
| mean_abs_error | 0.003952 |
| relative_error | 0.9614% |
| cosine_similarity | 0.999970 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg latency | 5.26 ms |
| min latency | 5.16 ms |
| max latency | 5.51 ms |
| p50 latency | 5.22 ms |
| p90 latency | 5.48 ms |
| p95 latency | 5.50 ms |
| throughput | 190.14 images/sec |
测试条件:batch_size=1, input_shape=[1,3,224,224], NPU 预热 2 次 + 正式 10 次取平均。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
| 日志 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查 |
logs/inference.log | NPU 推理结果 |
logs/accuracy.log | CPU-NPU 精度一致性 |
logs/benchmark.log | NPU 性能基准测试 |
snapshot_download 下载,严禁使用 timm.create_model(..., pretrained=True) 从 HuggingFace 自动下载。timm.data.resolve_model_data_config + create_transform 进行预处理。eval() 模式,关闭 dropout 等随机行为。.bin, .safetensors, .pth 等已加入 .gitignore)。#NPU #Ascend #Ascend910 #timm #ViT #image-classification