X
Xiaoxy510/google--efficientnet-b0-ascend
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

google--efficientnet-b0 on Ascend NPU

1. 简介

本文档记录 google--efficientnet-b0 在昇腾NPU上的适配与验证结果。

efficientnet-b0 是 Google 提出的高效卷积神经网络,在 ImageNet 上取得了优秀的准确率,同时具有较低的计算成本。

相关资源:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/google/efficientnet-b0
  • 权重下载地址(HuggingFace):https://huggingface.co/google/efficientnet-b0

2. 验证环境

组件版本
python3.10
torch2.5.1
torch-npu2.5.1
transformers5.8.1
timm1.0.27
  • NPU:8 卡(型号 910B3)
  • 操作系统:Linux aarch64

3. 环境准备

3.1 创建Conda环境

conda create -n "google--efficientnet-b0" python=3.10 -y
conda activate "google--efficientnet-b0"

3.2 安装依赖

pip install torch==2.5.1 torchvision torchaudio -f https://download.pytorch.org/whl/torch_npu.html
pip install torch-npu==2.5.1 -f https://download.pytorch.org/whl/torch_npu.html
pip install transformers timm -i https://repo.huaweicloud.com/repository/pypi/simple
pip install decorator psutil attrs cloudpickle tornado ml-dtypes scipy

4. 推理脚本使用

4.1 基本用法

# 默认使用随机测试数据
python inference.py

# 指定图片路径
python inference.py --image-path /path/to/image.jpg

# 指定批处理大小
python inference.py --batch-size 16

4.2 脚本参数说明

参数说明默认值
--model-path, -m模型路径/data/xxy/google--efficientnet-b0
--device, -d运行设备auto
--image-path, -i图片路径随机数据
--batch-size, -b批处理大小8

5. 精度与性能评测

5.1 运行评测

python benchmark.py --log-file log.txt

5.2 评测结果

指标数值
批处理大小8
相对误差0.1372%
精度检查PASS

5.3 性能对比

设备平均延迟吞吐量加速比
CPU2433.65 ms3.29 samples/s-
NPU26.26 ms304.62 samples/s92.67x

6. 文件结构

google--efficientnet-b0-ascend/
├── inference.py              # NPU适配推理脚本
├── benchmark.py             # 精度与性能评测脚本
├── log.txt                  # 评测运行日志
└── README.md                # 本文档

7. 注意事项

  1. 环境隔离:建议为每个模型创建独立的Conda环境
  2. NPU初始化:首次运行需要图编译,后续显著加速
  3. 精度波动:NPU与CPU的少量数值误差(<1%)是正常现象

8. 参考资料

  • timm 官方文档
  • PyTorch NPU 官方文档
  • 昇腾NPU 开发者文档