g
gyccc/microsoft-swin-small-patch4-window7-224-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

microsoft/swin-small-patch4-window7-224 on Ascend NPU

1. 简介

将 ModelScope 上的 microsoft/swin-small-patch4-window7-224 图片分类模型适配到华为昇腾 NPU (Ascend910B) 上运行。

  • 原始权重地址:https://modelscope.cn/models/microsoft/swin-small-patch4-window7-224
  • 模型架构:SwinForImageClassification
  • 输入尺寸:224x224
  • 输出类别数:1000 (ImageNet-1K)

2. 验证环境

  • 硬件:华为昇腾 910B NPU
  • 操作系统:Linux (aarch64)
  • Python:3.11
  • PyTorch:2.x + torch_npu
  • CANN:8.5.1
  • transformers:4.57.6
  • ModelScope:latest

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU Top-5):

  • Top-1: lakeside, lakeshore (0.6503)
  • Top-2: park bench (0.0193)
  • Top-3: flagpole, flagstaff (0.0163)
  • Top-4: mountain tent (0.0144)
  • Top-5: obelisk (0.0126)

日志保存在 logs/inference.log。

4. 精度验证

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

指标数值
relative_error0.3035%
cosine_similarity0.999997
threshold1.0%
结果PASS
  • CPU Top-1: lakeside, lakeshore
  • NPU Top-1: lakeside, lakeshore
  • Top-1 match: True
  • Top-5 match: True

5. 性能参考

指标数值
Avg latency26.62 ms
Min latency26.14 ms
Max latency27.77 ms
P50 latency26.28 ms
P90 latency27.69 ms
P95 latency27.73 ms
Throughput37.56 images/sec

测试条件:2 次预热 + 10 次正式测量,batch_size=1,单卡 NPU。

6. 精度评测说明

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

7. 自验证截图

自验证截图

8. 日志文件

  • logs/inference.log — NPU 推理结果
  • logs/accuracy.log — CPU-NPU 精度一致性验证
  • logs/benchmark.log — 性能基准测试

9. 注意事项

  • 使用 ModelScope snapshot_download 下载权重,禁止 HuggingFace 自动下载
  • 使用 SwinForImageClassification.from_pretrained 加载预训练权重
  • 推理使用 torch.npu.synchronize() 确保 NPU 计算完成
  • 精度验证使用官方 Ascend 一致性指标:max_abs_error、mean_abs_error、relative_error、cosine_similarity

10. 标签 #NPU