✏️
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 提供支持
在本页
  1. 三、网络模型迁移
  2. 3.2 FP32 模型生成

3.2.7 编译Paddle模型

BMPADDLE是针对Paddle Paddle的模型编译器,可以将模型文件(inference.pdmodel,inference.pdiparams)编译成 BMRuntime 所需的文件。而且在编译的同时,可选择将每一个操作的NPU模型计算结果和CPU的计算结果进行对比,保证正确性。

  • 命令行形式:

python3 -m bmpaddle [--model=<path>] \ 
                    [--input_names=<string>] \ 
                    [--shapes=<string>] \ 
                    [--descs=<string>] \ 
                    [--output_names=<string>] \
                    [--net_name=<name>] \ 
                    [--opt=<value>] \ 
                    [--dyn=<bool>] \ 
                    [--outdir=<path>] \ 
                    [--target=<name>] \ 
                    [--cmp=<bool>] \ 
                    [--mode=<string>] \ 
                    [--enable_profile=<bool>] \ 
                    [--list_ops]

参数介绍:

args

type

Description

model

string

Necessary.paddlepaddle model directory

input_names

string

Necessary.Set name of all network inputs one by one in sequence. Format “name1,name2,name3”

shapes

string

Necessary. Shapes of all inputs, default use the shape in prototxt, format [[x,x,x,x],[x,x],…], these correspond to inputs one by one in sequence

descs

string

Optional. Descriptions of inputs, format "[serial number, data type, lower bound, upper bound]", e.g., "[0, uint8, 0, 256]", default "[x, float, 0, 1]"

output_names

string

Necessary. Set name of all network outputs one by one in sequence. Format “name1,name2,name3”

net_name

string

Necessary. Name of the network

opt

int

Optional. Optimization level. Option: 0, 1, 2, default 1.

dyn

bool

Optional. Use dynamic compilation, default false.

outdir

string

Necessary. Output directory

target

string

Necessary. Option: BM1682, BM1684; default: BM1682

cmp

bool

Optional.Check result during compilation. Default: true

mode

string

Optional. Set bmpaddle mode. Option: compile, GenUmodel,summary, show, check. Default: compile.

enable_profile

bool

Optional. Enable profile log. Default: false

list_ops

Optional. List supported ops.

  • Python模式:

import bmpaddle
## compile fp32 model
bmpaddle.compile(
    model = "/path/to/model(directory)", ## Necessary
    outdir = "xxx", ## Necessary
    target = "BM1684", ## Necessary
    shapes = [[x,x,x,x],[x,x,x]], ## Necessary
    net_name = "name", ## Necessary
    input_names=["name1","name2"], ## Necessary, when .h5 use None
    output_names=["out_name1","out_name2"], ## Necessary, when .h5 use None
    opt = 2, ## optional, if not set, default equal to 1
    dyn = False, ## optional, if not set, default equal to False
    cmp = True, ## optional, if not set, default equal to True
    enable_profile = True ## optional, if not set, default equal to False
    )

注意:

  • --model 参数指定到模型所在文件夹那一级,但要特别注意,PaddlePaddle模型有2种:组合式(combined model)和非复合式(uncombined model);组合式就是model + 权重,__model__文件夹下有很多文件,每一个文件是一层,这种模型名称必须用__model__;如果是非组合式,一定要把模型名称修改为*.pdmodel和*.pdiparams

  • shapes和descs中的变量顺序、名称要和实际模型一致,不能写错

  • 对于模型中带nms操作的,并且cmp==true时descs参数必填;对于int32类型,范围不能填重复的值,比如608*608的输入,要填608,609,但生效的就是608;对于float类型,则没有这个限制;对于不填的输入,其取值范围默认都是0-1。

若成功,输出的 log 最后会看到以下信息:

######################################
# Store bmodel of BMCompiler.
######################################

成功后,将在指定的文件夹中生成一个compilation.bmodel的文件,该文件则是转换成功的 bmodel,用户可以重命名。

上一页3.2.6 编译ONNX模型下一页3.3 INT8 模型生成

最后更新于3年前