本项目将 timm 仓库中的 vit_base_patch32_clip_224.openai_ft_in1k 模型适配到华为昇腾 NPU (Ascend910) 上运行。该模型是一个基于 CLIP 权重初始化的 ViT-B/32 视觉Transformer,在 ImageNet-1k 上微调,输出 1000 类分类 logits。
适配方式:
snapshot_download 下载本地权重timm.create_model(pretrained=False) 创建模型并加载本地权重timm.data.resolve_model_data_config + create_transform 进行预处理npu:0) 推理验证| 项目 | 版本 |
|---|---|
| NPU | Ascend910 |
| CANN | 8.5.1 |
| PyTorch | 2.x |
| torch_npu | 对应版本 |
| timm | latest |
pip install -r requirements.txt
python inference.py推理结果 (NPU Top-5):
日志保存在 logs/inference.log。
对单张测试图片进行 CPU 与 NPU 一致性验证:
| 指标 | 数值 |
|---|---|
| max_abs_error | 0.012312 |
| mean_abs_error | 0.002170 |
| relative_error | 0.3167% |
| cosine_similarity | 0.999996 |
| threshold | 1.0% |
| 结果 | PASS |
| 指标 | 数值 |
|---|---|
| avg_latency_ms | 5.808 |
| min_latency_ms | 5.786 |
| max_latency_ms | 5.913 |
| p50_latency_ms | 5.795 |
| p90_latency_ms | 5.913 |
| p95_latency_ms | 5.913 |
| images_per_sec | 172.18 |
本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。
见 screenshots/self_verification.png。
logs/inference.log - NPU 推理日志logs/accuracy.log - CPU-NPU 精度一致性验证日志logs/benchmark.log - NPU 性能基准测试日志logs/stage0.log - 模型可用性检查日志pretrained=True 从 HuggingFace 自动下载#NPU #Ascend #Ascend910 #timm #ViT #image-classification