sheeps_/timm-vit_srelpos_small_patch16_224.sw_in1k-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

timm/vit_srelpos_small_patch16_224.sw_in1k on Ascend NPU

1. 简介

本项目将 timm/vit_srelpos_small_patch16_224.sw_in1k 图片分类模型适配到华为昇腾 NPU (Ascend910)。

  • 模型来源: ModelScope / timm
  • 模型类型: ViT (Vision Transformer) with Swin-style relative positional embeddings
  • 输入尺寸: 224x224
  • 分类数: 1000 (ImageNet-1k)
  • 适配方式: timm.create_model(pretrained=False) + ModelScope 本地权重加载
  • 权重格式: Safetensors

2. 验证环境

项目版本/型号
NPUAscend910
CANN8.5.1
PyTorch2.x
torch_npu可用
timm最新版

环境详情见 logs/env_check.log。

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU Top-5):

  • Top-1: whiskey jug (0.4261)
  • Top-2: coffee mug (0.1193)
  • Top-3: mortar (0.0832)
  • Top-4: espresso (0.0347)
  • Top-5: chocolate syrup (0.0253)

日志保存在 logs/inference.log。

4. 精度验证

对单张测试图片进行 CPU 与 NPU 一致性验证:

指标数值
max_abs_error0.017087
mean_abs_error0.002245
relative_error0.3843%
cosine_similarity0.999995
threshold1.0%
结果PASS
  • CPU Top-1: whiskey jug
  • NPU Top-1: whiskey jug
  • CPU Top-5: whiskey jug, coffee mug, mortar, espresso, chocolate syrup
  • NPU Top-5: whiskey jug, coffee mug, mortar, espresso, chocolate syrup
  • Top-1 match: True
  • Top-5 match: True

5. 性能参考

在单卡 Ascend910 NPU 上运行 10 次取平均(Batch size = 1):

指标数值
Avg latency7.517 ms
Min latency7.458 ms
Max latency7.594 ms
P50 latency7.523 ms
P90 latency7.544 ms
P95 latency7.544 ms
Throughput (avg)133.03 images/sec
Throughput (min)131.68 images/sec
Throughput (max)134.09 images/sec

日志保存在 logs/benchmark.log。

6. 精度评测说明

本项目包含单图 smoke consistency 验证,非官方 ImageNet 完整验证集评测。详细指标见第 4 节。

7. 自验证截图

见 screenshots/self_verification.png 和 screenshots/self_verification.txt。

8. 日志文件

  • logs/env_check.log — 环境检查
  • logs/inference.log — 推理输出
  • logs/accuracy.log — CPU-NPU 精度一致性
  • logs/benchmark.log — 性能基准测试

9. 注意事项

  1. 权重通过 ModelScope snapshot_download 下载,严禁使用 timm.create_model(..., pretrained=True) 从 HuggingFace 自动下载。
  2. 运行前请确保 NPU 驱动和 CANN 环境已正确配置。
  3. 首次运行会自动下载模型权重,请确保网络畅通。

10. 标签

#NPU #Ascend #Ascend910 #timm #ViT #image-classification