g
gcw_C8PI9e90/cv_edible_wild_plants_classification-npu
模型介绍文件和版本Pull Requests讨论分析

cv_edible_wild_plants_classification-npu

概述

可食用野生植物分类模型,基于 ViT (Vision Transformer) 架构,适配 Ascend NPU (Ascend910) 进行推理。

  • 原始模型: cubeai/cv_edible_wild_plants_classification
  • 模型架构: ViTForImageClassification
  • 推理设备: CPU / Ascend NPU (Ascend910)
  • 任务类型: 图像分类 (Image Classification)
  • 类别数: 62 种类别

文件说明

文件说明
inference.pyCPU/NPU 推理脚本,支持 --device cpu 或 --device npu
compare_cpu_npu.pyCPU vs NPU 精度对比脚本
requirements.txtPython 依赖
terminal_screenshot.png推理结果终端截图

依赖环境

  • Python 3.11+
  • PyTorch 2.9.0
  • torch_npu 2.9.0.post1 (Ascend NPU)
  • transformers 4.57.6
  • Ascend910 NPU + CANN 25.5.2

环境准备

pip install -r requirements.txt

推理命令

CPU 推理:

python3 inference.py --device cpu

NPU 推理:

python3 inference.py --device npu

推理结果

设备推理耗时Top-1 类别Top-1 置信度
CPU665.72 msAlfalfaN/A
NPU179.24 msAlfalfaN/A

NPU 加速比约为 3.71x。

CPU/NPU 精度测试方法

python3 compare_cpu_npu.py

CPU/NPU 精度测试结果

指标值
CPU 推理时间665.72 ms
NPU 推理时间179.24 ms
NPU 加速比3.71x
Top-1 匹配是
Max Logits Absolute Error0.005633234977722168
Mean Logits Absolute Error0.0014081948902457952
Max Probability Absolute Error2.7894973754882812e-05
Mean Probability Absolute Error8.996926794679894e-07
Cosine Similarity (Logits)0.9999989867210388
L2 Error (Logits)0.00173998496029526
最大概率误差0.0028%

结论:NPU 与 CPU 推理结果误差 < 1%(最大概率误差为 0.0028%),精度符合要求。

精度结论:该模型已完成 Ascend NPU 适配部署,CPU 与 NPU 推理结果一致性验证通过,精度误差低于 1% 要求。

终端截图

推理终端截图

精度结论

基于现有评测数据,CPU 与 NPU 的 余弦相似度 精度误差为 0.0001%,小于 1% 的精度要求。

推理成功证据

本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理:

# NPU 推理
python3 inference.py --device npu

# CPU 推理
python3 inference.py --device cpu

推理完成后会输出推理结果和耗时,表明模型在 NPU 上推理成功。

模型标签

  • #+NPU
  • #+CV
  • #+图像分类
  • #+昇腾
  • #+PyTorch
  • #+ViT
下载使用量0