本项目将 timm/vit_tiny_patch16_224.augreg_in21k 适配到单卡昇腾 NPU(Ascend910)上运行,支持图片分类推理。
timm.create_model(pretrained=False) 创建模型并加载本地权重| 项目 | 版本/信息 |
|---|---|
| NPU | Ascend910_9362 |
| npu-smi | 25.5.2 |
| Python | 3.11.14 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 已安装 |
| timm | 1.0.27 |
| modelscope | 已安装 |
NPU 状态(npu-smi info 摘要):
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.036743 |
| mean_abs_error | 0.006481 |
| relative_error | 0.0541% |
| cosine_similarity | 1.000000 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg latency | 5.225 ms |
| min latency | 5.191 ms |
| max latency | 5.266 ms |
| p50 latency | 5.220 ms |
| p90 latency | 5.249 ms |
| p95 latency | 5.249 ms |
| 吞吐量 | 191.37 images/sec |
测试条件:warm-up 2 次,正式运行 10 次,单卡 npu:0,batch_size=1,输入 224x224。
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png 与 screenshots/self_verification.txt。
| 日志 | 说明 |
|---|---|
logs/env_check.log | NPU 环境检查 |
logs/inference.log | NPU 推理输出 |
logs/accuracy.log | CPU-NPU 精度一致性 |
logs/benchmark.log | 性能基准测试 |
snapshot_download 下载,运行时自动缓存到本地,无需手动放置。timm.create_model(..., pretrained=True) 触发 HuggingFace 自动下载。.safetensors/.bin/.pth 等)已加入 .gitignore,不会提交到仓库。#NPU #Ascend #Ascend910 #timm #ViT #image-classification