m0_74196153/volo_d1_384-npu
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

volo_d1_384

模型介绍

volo_d1_384 是基于 VOLO (Vision Outlooker) 架构的图像分类模型,在 ImageNet-1K 数据集上预训练。VOLO 通过引入 Outlooker 注意力机制,有效提升了视觉 Transformer 在细粒度分类任务上的性能。

原始模型地址

  • ModelScope: https://www.modelscope.cn/models/timm/volo_d1_384.sail_in1k
  • HuggingFace: https://huggingface.co/timm/volo_d1_384.sail_in1k

任务类型

图像分类 (Image Classification)

模型框架

  • PyTorch + timm
  • torch_npu (Ascend NPU 适配)

输入格式

  • 图像 (RGB),输入尺寸: 384

输出格式

  • Top-5 分类概率和对应的 ImageNet 类别标签

依赖环境

torch>=2.0.0
torch-npu>=2.1.0
timm>=0.9.0
Pillow>=9.0.0
scipy>=1.7.0
numpy>=1.20.0

NPU 适配说明

本模型已在华为昇腾 Ascend 910 NPU 上完成适配和测试。适配基于 PyTorch + torch_npu 框架,利用 timm 模型库加载预训练权重,通过 model.to("npu") 将模型迁移至 NPU 进行推理。

主要适配步骤:

  1. 使用 timm 加载预训练模型
  2. 将模型转移到 NPU 设备 (model.to(torch.npu.current_device()))
  3. 使用标准数据预处理流水线 (timm 的 resolve_data_config + create_transform)
  4. CPU 和 NPU 分别推理并对比结果

环境准备

# 设置 huggingface 镜像(如果无法访问 huggingface.co)
export HF_ENDPOINT=https://hf-mirror.com

# 安装依赖
pip install -r requirements.txt

推理命令

CPU 推理

python3 inference.py --device cpu --output cpu_result.json

NPU 推理

python3 inference.py --device npu --output npu_result.json

推理结果

CPU 推理结果

排名类别概率
1window screen78.05%
2entertainment center5.05%
3yurt2.72%
4wig1.00%
5slide rule0.20%

CPU 推理耗时: 1.1489s

NPU 推理结果

排名类别概率
1window screen77.83%
2entertainment center5.03%
3yurt2.74%
4wig1.00%
5slide rule0.20%

NPU 推理耗时: 0.2133s

性能对比

指标CPUNPU
推理耗时 (s)1.14890.2133

NPU 推理加速比: 5.39x

CPU/NPU 精度测试方法

  1. 使用相同输入图像在 CPU 和 NPU 上分别运行推理
  2. 提取模型 logits 输出进行数值对比
  3. 计算以下指标:
    • Logits 最大绝对误差 (Max Absolute Error)
    • Logits 余弦相似度 (Cosine Similarity)
    • 概率最大差异 (Max Probability Difference)
    • Top-5 预测一致性

运行精度对比脚本:

python3 compare_cpu_npu.py

CPU/NPU 精度测试结果

详细精度指标

指标数值
Logits 最大绝对误差0.02060699
Logits 平均绝对误差0.00145573
Logits 余弦相似度0.99999666
概率最大差异0.22%
概率平均差异4.87e-06
Top-5 一致数5/5
Top-1 匹配True

Top-5 预测对比

排名CPU 类别CPU 概率NPU 类别NPU 概率匹配
1window screen78.05%window screen77.83%✓
2entertainment center5.05%entertainment center5.03%✓
3yurt2.72%yurt2.74%✓
4wig1.00%wig1.00%✓
5slide rule0.20%slide rule0.20%✓

结论

NPU 与 CPU 推理结果误差 < 1%。 具体数值:

  • 最大概率差异: 0.22%(远小于 1% 阈值)
  • 余弦相似度: 0.99999666(极接近 1.0)
  • Top-5 预测完全一致: 5/5

终端截图

终端截图

部署和推理方法

本模型适用于图像分类任务,可直接在华为昇腾 NPU 上部署推理:

  1. 准备测试图像(支持 JPEG/PNG 格式)
  2. 运行 NPU 推理脚本
  3. 获取 Top-5 分类结果

对于批量推理需求,可将多个图像依次送入模型,并收集分类结果。

模型标签

  • #+NPU
  • #+CV
  • #+图像分类
  • #+昇腾
  • #+PyTorch
  • #+timm
  • #+VOLO