将 timm 预训练模型 vit_base_patch16_clip_224.openai_ft_in12k_in1k(基于 CLIP/OpenAI 预训练的 ViT-Base,Patch16,224x224,经 ImageNet-12K + ImageNet-1K 微调)适配到单卡昇腾 NPU(Ascend910)上运行。
snapshot_downloadtimm.create_model(pretrained=False) + 本地 safetensors 权重pip install -r requirements.txt
python inference.py推理输出示例(单张测试图片):
Input shape: [1, 3, 224, 224]
Output shape: [1, 1000]
Top-1: class_466 (0.1612)
Top-2: class_565 (0.1095)
Top-3: class_547 (0.0429)
Top-4: class_829 (0.0421)
Top-5: class_718 (0.0335)对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.029879 |
| mean_abs_error | 0.004917 |
| relative_error | 0.5616% |
| cosine_similarity | 0.999986 |
| threshold | 1.0% |
| 结果 | PASS |
CPU Top-1: class_466
NPU Top-1: class_466
Top-1 match: True
CPU Top-5: class_466, class_565, class_547, class_829, class_718
NPU Top-5: class_466, class_565, class_547, class_829, class_718
Top-5 match: True
| 指标 | 数值 |
|---|---|
| avg latency | 8.16 ms |
| min latency | 5.16 ms |
| max latency | 33.44 ms |
| p50 latency | 5.25 ms |
| p90 latency | 8.46 ms |
| p95 latency | 20.95 ms |
| throughput | 122.49 images/sec |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
详见 screenshots/self_verification.png。
logs/inference.log — 推理输出日志logs/accuracy.log — CPU-NPU 精度一致性验证日志logs/benchmark.log — 性能基准测试日志logs/paths.txt — 模型路径信息timm.create_model(pretrained=False) 创建模型结构,通过 ModelScope snapshot_download 下载权重并本地加载.safetensors、.bin 等)#NPU