m0_74196153/tinynet_d-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

TinyNet D - 昇腾 NPU 适配

1. 模型简介

TinyNet D 是 TinyNet 系列中的轻量图像分类模型,在 TinyNet E 的基础上增加了网络容量。TinyNet D 是 TinyNet 家族中的较小变体(e < d < c < b < a),适合资源受限的边缘设备场景。

原始模型地址:

  • ModelScope: https://www.modelscope.cn/models/timm/tinynet_d.in1k
  • HuggingFace: https://huggingface.co/timm/tinynet_d.in1k

任务类型: 图像分类(Image Classification)

模型框架: PyTorch + timm

输入格式: 图像 (RGB, 152×152)

输出格式: 分类 logits (1000 类 ImageNet)

2. 依赖环境

组件版本
Python3.10+
PyTorch2.0+
torch_npu2.0+ (Ascend NPU)
timm0.9.0+
torchvision0.15.0+
Pillow9.0.0+
modelscope1.0.0+

3. NPU 适配说明

TinyNet D 使用 timm 库加载 PyTorch 模型权重,在昇腾 NPU 上可直接使用 torch_npu 进行推理。通过 model.to('npu:0') 将模型迁移到昇腾 NPU,无需修改模型代码。

4. 环境准备

pip install torch torch_npu timm torchvision Pillow numpy modelscope safetensors

5. 推理命令

CPU 推理

python inference.py --model tinynet_d --device cpu

NPU 推理

python inference.py --model tinynet_d --device npu

CPU vs NPU 精度对比

python compare_cpu_npu.py --model tinynet_d

6. 推理结果

指标CPUNPU
平均推理耗时14.11 ms4.36 ms
加速比1x3.24x

Top-5 分类结果

排名CPU 类别CPU 概率NPU 类别NPU 概率
15390.1889735390.189434
27350.1259117350.125847
35330.1038825330.103841
44110.0993084110.098729
54430.0330274430.032826

7. 精度测试结果

指标数值
余弦相似度 (Cosine Similarity)0.99999845
最大绝对误差 (Max Abs Error)0.00885701
平均绝对误差 (Mean Abs Error)0.00178377
均方根误差 (RMSE)0.00228609
平均相对误差 (Relative Error)0.7784%
Top-1 一致✓ 是 (类别 539)
Top-5 重叠数5/5

结论:NPU 与 CPU 推理结果误差 < 1%(余弦相似度 > 0.99999,Top-1/5 完全一致),精度验证通过。

8. 性能测试

指标CPUNPU
设备Intel XeonAscend 910
推理耗时 (5 次平均)14.11 ms4.36 ms
加速比1x3.24x
输入尺寸3×152×1523×152×152
batch size11

9. 模型标签

  • #+NPU
  • #+CV
  • #+昇腾
  • #+图像分类
  • #+TinyNet
  • #+timm