weixin_72661020/Birds-Classifier-EfficientNetB2
模型介绍文件和版本Pull Requests讨论分析

Birds-Classifier-EfficientNetB2

1. 简介

本文档记录 cubeai/Birds-Classifier-EfficientNetB2 在昇腾 NPU(Ascend910)环境的快速部署与验证结果。

EfficientNetForImageClassification 图像分类模型,基于 HuggingFace transformers 框架,支持一键加载推理。该模型在 EfficientNetB2 基础上 Fine-tuned,支持 525 种鸟类分类。

相关获取地址:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/cubeai/Birds-Classifier-EfficientNetB2
  • 权重下载地址(HuggingFace):https://huggingface.co/cubeai/Birds-Classifier-EfficientNetB2

参考文档:

  • https://huggingface.co/docs/transformers/en/model_doc/auto#transformers.AutoModelForImageClassification

2. 验证环境

组件版本
torch2.5.1
torch_npu2.5.1
transformers>=4.48.0
CANN8.5.RC1
  • NPU:Ascend910(单卡)
  • 输入尺寸:3x260x260
  • 类别数:525
  • 推理框架:PyTorch + transformers

3. 快速部署

3.1 环境准备

pip install transformers torch torchvision pillow

3.2 推理代码

import torch
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image

device = torch.device("npu:0" if torch.npu.is_available() else "cpu")

processor = AutoImageProcessor.from_pretrained("cubeai/Birds-Classifier-EfficientNetB2")
model = AutoModelForImageClassification.from_pretrained("cubeai/Birds-Classifier-EfficientNetB2")
model = model.to(device).eval()

image = Image.new("RGB", (260, 260), (128, 128, 128))
inputs = processor(images=image, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()}

with torch.no_grad():
    outputs = model(**inputs)
pred = outputs.logits.argmax(-1).item()
print(f"Predicted class: {pred}")

4. Smoke 验证

python3 inference.py

验证结果:

  • 模型成功加载到 npu:0
  • 输出预测类别(整数索引,对应 525 种鸟类之一)
  • 推理过程无报错

5. 性能参考

测试条件:FP32 / batch=1 / warmup=5 / timed=50 runs,Ascend910 单卡。

指标数值
平均推理时间10.00 ms
测试次数50

6. 精度评测

NPU 与 CPU 输出对比,使用 4 张纯色测试图(RGB 255/0、0/255/0、0/0/255、128/128/128),比较 logits 一致性。

指标数值
Top-1 一致性4/4 (100%)
Top-5 一致性4/4 (100%)
最大 logits 相对误差0.05 %
平均 KL 散度0.000000
结论PASS

7. 注意事项

  • AutoImageProcessor 会自动匹配模型配置中的 image_size(260x260),无需手动设置
  • 该模型为鸟类分类 Fine-tuned 模型,输出 525 类,标签为英文鸟类名称
  • 权重格式为 safetensors(32.5MB),transformers 自动支持
  • NPU 推理结果与 CPU 在 Top-1/Top-5 完全一致,最大 logits 相对误差 < 1%(判定阈值)
下载使用量0