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

brain_model-npu

概述

脑瘤图像检测模型,基于 ViT (Vision Transformer) 架构,适配 Ascend NPU (Ascend910) 进行推理。

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

文件说明

文件说明
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 置信度
CPU647.7 msglioma_tumorN/A
NPU180.45 msglioma_tumorN/A

NPU 加速比约为 3.59x。

CPU/NPU 精度测试方法

python3 compare_cpu_npu.py

CPU/NPU 精度测试结果

指标值
CPU 推理时间647.7 ms
NPU 推理时间180.45 ms
NPU 加速比3.59x
Top-1 匹配是
Max Logits Absolute Error0.0015469789505004883
Mean Logits Absolute Error0.0010141273960471153
Max Probability Absolute Error0.00035347044467926025
Mean Probability Absolute Error0.00022509321570396423
Cosine Similarity (Logits)0.9999924898147583
L2 Error (Logits)0.0011680604657158256
最大概率误差0.0353%

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

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

终端截图

推理终端截图

精度结论

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

推理成功证据

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

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

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

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

模型标签

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