w
gcw_uQ09W7jl/google-efficientnet-b4-NPU
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

google/efficientnet-b4 on Ascend NPU

1. 简介

本项目将 HuggingFace google/efficientnet-b4 图像分类模型适配到华为昇腾 NPU (Ascend910)。模型通过 ModelScope 下载权重,使用 transformers 库的 AutoModelForImageClassification 进行本地加载,并在单卡 NPU 上完成推理验证、CPU-NPU 精度一致性检查和性能基准测试。

  • 模型架构: EfficientNetForImageClassification
  • 参数量: 19.34M
  • 任务类型: 图像分类 (ImageNet-1k, 1000 类)
  • 输入尺寸: 380x380

2. 验证环境

项目版本/信息
NPUAscend910
CANN8.5.1
PyTorch2.x
torch_npu适配 CANN 8.5.1
transformers最新版

完整环境信息见 logs/env_check.log。

3. 推理运行

pip install -r requirements.txt
python inference.py

推理结果 (NPU):

=== NPU Inference Result ===
Input image: assets/test.jpg
Logits shape: torch.Size([1, 1000])
Logits sample (first 10): [-0.4476, -0.5143, -0.0919, -0.2052, -0.1999, -0.2789, -0.1137, -0.1936, -0.4504, 0.0855]

Top-5 predictions:
  1. class_405: 0.0048
  2. class_21: 0.0040
  3. class_701: 0.0040
  4. class_657: 0.0038
  5. class_895: 0.0038

日志保存在 logs/inference.log。

4. 精度验证

对单张测试输入进行 CPU 与 NPU 一致性验证:

指标数值
max_abs_error0.004179
mean_abs_error0.000734
relative_error0.1887%
cosine_similarity0.999999
threshold1.0%
结果PASS

5. 性能参考

单张图片 batch=1 在 Ascend910 上的推理性能:

指标数值
avg_latency_ms15.376
min_latency_ms15.270
max_latency_ms15.497
p50_latency_ms15.363
p90_latency_ms15.463
p95_latency_ms15.480
throughput_img/s65.04

6. 精度评测说明

本项目包含单输入 smoke consistency 验证,非官方完整验证集评测。详细指标见第 4 节。

7. 自验证截图

见 screenshots/self_verification.txt 和 screenshots/self_verification.png。

8. 日志文件

  • logs/env_check.log — 环境检查
  • logs/inference.log — NPU 推理输出
  • logs/accuracy.log — CPU-NPU 精度一致性
  • logs/benchmark.log — 性能基准测试

9. 注意事项

  1. 权重通过 ModelScope snapshot_download 自动下载,首次运行需要联网。
  2. 脚本使用 local_files_only=True 加载本地权重,不触发 HuggingFace 自动下载。
  3. 测试图片为占位图(网络不可用),实际使用时替换为真实图片即可。

10. 标签

#NPU #Ascend #Ascend910 #EfficientNet #ImageClassification