✏️
BMNNSDK2开发手册
  • BM1684 BMNNSDK2 入门手册
  • 一、BMNNSDK2软件包
    • 1.1 BMNNSDK2 简介
    • 1.2 BMNNSDK2 文档
    • 1.3 基本概念介绍
    • 1.4 获取BMNNSDK2 SDK
    • 1.5 安装BMNNSDK2 SDK
      • 1.5.1 环境配置-Linux
      • 1.5.2 环境配置-Windows
      • 1.5.3 环境配置-SoC
    • 1.6 更新BMNNSDK
    • 1.7 参考样例简介
    • 1.8 BMNNSDK2更新记录
    • 1.9 BMNNSDK2已知问题
  • 二、快速入门
    • 2.1 跑通第一个例子:综述
    • 2.2 跑通第一个例子:模型迁移
    • 2.3 跑通第一个例子:算法迁移
  • 三、网络模型迁移
    • 3.1 模型迁移概述
    • 3.2 FP32 模型生成
      • 3.2.1 编译Caffe模型
      • 3.2.2 编译TensorFlow模型
      • 3.2.3 编译MXNet模型
      • 3.2.4 编译PyTorch模型
      • 3.2.5 编译 Darknet 模型
      • 3.2.6 编译ONNX模型
      • 3.2.7 编译Paddle模型
    • 3.3 INT8 模型生成
      • 3.3.1 准备lmdb数据集
      • 3.3.2 生成FP32 Umodel
      • 3.3.3 生成INT8 Umodel
      • 3.3.4 精度测试
      • 3.3.5 生成INT8 Bmodel
      • 3.3.6 auto_cali一键量化工具
    • 3.4 实例演示
      • 3.4.1 create_lmdb_demo
      • 3.4.2 classify_demo
      • 3.4.3 face_demo
  • 四、算法移植
    • 4.1 算法移植概述
    • 4.2 C/C++编程详解
    • 4.3 Python编程详解
    • 4.4 解码模块
    • 4.5 图形运算加速模块
    • 4.6 模型推理
    • 4.7 实例演示
  • 五、打包和发布
    • 5.1 概述
    • 5.2 PCIE加速卡模式
    • 5.3 SOC模式
  • 附录
由 GitBook 提供支持
在本页
  • 3.4.2.1 测试脚本函数介绍
  • 3.4.2.2 fp32 umodel转换为int8 umodel
  • 3.4.2.3 int8umodel 测试
  • 3.4.2.4 其他测试
  1. 三、网络模型迁移
  2. 3.4 实例演示

3.4.2 classify_demo

classify_demo位于:${BMNNSDK}/examples/calibration/classify_demo

classify_demo主要演示如何将fp32 umodel(resnet18.prototxt、resnet18.fp32umodel)转换为int8 umodel,并验证量化后int8模型的精度;目录下自带lmdb文件和restnet18 fp32 umodel。

3.4.2.1 测试脚本函数介绍

./classify_demo.sh中提供了以下几个函数供参考使用

  • convert_to_int8_demo:将fp32 umodel转化为int8 umodel

  • test_fp32_demo:使用ufw测试fp32 umodel

  • test_int8_demo:使用ufw测试int8 umodel

  • dump_tensor_fp32_demo:保存fp32 umodel的输入输出

  • dump_tensor_int8_demo:保存int8 umodel的输入输出

用户可以根据需要参考./classify_demo.sh文件的函数执行命令,使用source classify_demo.sh可以使能脚本中的函数,以便在命令行中直接使用这些函数:

# 切换工作目录
cd /workspace/examples/calibration/classify_demo
# 使能脚本中函数,这样就可以在命令行中直接使用脚本中的函数了
source classify_demo.sh

3.4.2.2 fp32 umodel转换为int8 umodel

在命令行中执行convert_to_int8_demo,生成int8 umodel:

# 以下为命令行输出
......

I1206 13:23:29.258087   972 cali_core.cpp:1941]
I1206 13:23:29.258093   972 cali_core.cpp:1942] calibration for layer = acc/top-5
I1206 13:23:29.258097   972 cali_core.cpp:1943]  id=83 type:Accuracy ...
I1206 13:23:29.258105   972 cali_core.cpp:2063] Do nothing for Layer 83 of Type Accuracy with no blobs
I1206 13:23:29.258111   972 cali_core.cpp:2072]  intput 0: set_scaleconvertbacktofloat_input_mul =0.189022
I1206 13:23:29.258118   972 cali_core.cpp:2072]  intput 1: set_scaleconvertbacktofloat_input_mul =1.18394
I1206 13:23:29.258123   972 cali_core.cpp:2076]  output 0 set_scaleconvertbacktofloat_output_mul =0.000494048
I1206 13:23:29.258131   972 cali_core.cpp:2079]  forward_with_float = 0
I1206 13:23:29.258137   972 cali_core.cpp:2080]  output_is_float = 0
I1206 13:23:29.258144   972 cali_core.cpp:2081]  is_shape_layer  = 0
I1206 13:23:29.258150   972 cali_core.cpp:2082]  use_max_as_th =0

I1206 13:23:32.369089   972 cali_core.cpp:2268] used time=0 hour:0 min:7 sec
I1206 13:23:32.369168   972 cali_core.cpp:2270] int8 calibration done.
#INFO: Run Example (Resnet18 Fp32ToInt8) Done

转换好的int8 umodel文件将被保存在models目录下:

cd /workspace/examples/calibration/classify_demo
tree
# 以下为命令行输出
#|-- classify_demo.sh
#|-- lmdb
#|   `-- imagenet_s
#|       `-- ilsvrc12_val_lmdb
#|           |-- data.mdb
#|           `-- lock.mdb
#|-- models
#|   |-- resnet18.fp32umodel
#|   |-- resnet18.int8umodel
#|   |-- resnet18.prototxt
#|   |-- resnet18_deploy_fp32_unique_top.prototxt
#|   |-- resnet18_deploy_int8_unique_top.prototxt
#|   |-- resnet18_test_fp32_unique_top.prototxt
#|   `-- resnet18_test_int8_unique_top.prototxt
#`-- ......

3.4.2.3 int8umodel 测试

您也可以命令行中直接执行test_int8_demo,这将同时执行int8 umodel的生成和测试,打印top_k的置信度,输出如下:

# 以下为命令行输出内容
......

I1206 13:30:14.015234  1058 net_cfg.cpp:263] UFW Forward(82): acc/top-1 , Accuracy ...
I1206 13:30:14.015241  1058 accuracy_layer.cpp:101] use un-unique top_k
I1206 13:30:14.015245  1058 accuracy_layer.cpp:115] label:831
I1206 13:30:14.015259  1058 net_cfg.cpp:263] UFW Forward(83): acc/top-5 , Accuracy ...
I1206 13:30:14.015264  1058 accuracy_layer.cpp:101] use un-unique top_k
I1206 13:30:14.015267  1058 accuracy_layer.cpp:115] label:831
I1206 13:30:14.015282  1058 ufw.cpp:292] Batch 9, acc/top-1 = 0
I1206 13:30:14.015305  1058 ufw.cpp:292] Batch 9, acc/top-5 = 1
I1206 13:30:14.015311  1058 ufw.cpp:297] Batch 9 Finished
I1206 13:30:14.015314  1058 ufw.cpp:300] Loss: 0
I1206 13:30:14.015331  1058 ufw.cpp:319] acc/top-5 = 0.9
I1206 13:30:14.015341  1058 ufw.cpp:327] mean score of Accuracy5-acc/top-5 is 0.9
I1206 13:30:14.015354  1058 ufw.cpp:319] acc/top-1 = 0.7
I1206 13:30:14.015358  1058 ufw.cpp:327] mean score of Accuracy1-acc/top-1 is 0.7
use time=0.000000 : 0.000000 : 5.418000
#INFO: Test Resnet-INT8 Done

3.4.2.4 其他测试

您还可以运行脚本中的其他函数,对比验证fp32 umodel以及int8 umodel的精度差异。

上一页3.4.1 create_lmdb_demo下一页3.4.3 face_demo

最后更新于3年前