✏️
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.6 编译ONNX模型

BMNETO 是针对 ONNX 的模型编译器,可以把 ONNX 格式的 model 经过图编译优化后,转换成 BMRuntime 所需的文件。在编译模型的同时,可选择将每一个操作的 NPU 模型计算结果和 CPU 的计算结果进行对比, 保证正确性。

  • 命令行形式:

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

参数介绍:

args

type

Description

model

string

Necessary.ONNX model (.onnx) path

input_names

string

Optional.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

outdir

string

Necessary. Output directory

target

string

Necessary. Option: BM1682, BM1684; default: BM1682

net_name

string

Optional. Name of the network, default use the name in onnx path

opt

int

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

dyn

bool

Optional. Use dynamic compilation, default false.

cmp

bool

Optional.Check result during compilation. Default: true

mode

string

Optional. Set bmnetc mode. Option: compile, GenUmodel. Default: compile.

descs

string

Optional. Describe data type and value range of some input in format: "[ index, data format, lower bound, upper bound ]", where data format could be fp32, int64. For example, "[0, int64, 0, 100]", meaning input of index 0 has data type as int64 and values in [0, 100). If no description of some input given, the data type will be fp32 as default and uniformly distributed in 0 ~ 1.

enable_profile

bool

Optional. Enable profile log. Default: false

output_names

string

Optional. Set name of all network outputs one by one in sequence. Format "name1,name2,name2"

list_ops

Optional. List supported ops.

  • Python模式:

import bmneto
## compile fp32 model
bmneto.compile(
    model = "/path/to/.pth", ## Necessary
    outdir = "xxx", ## Necessary
    target = "BM1684", ## Necessary
    shapes = [[x,x,x,x], [x,x,x]], ## Necessary
    net_name = "name", ## Necessary
    input_names = ['name0','name1'] ## Necessary
    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
    descs = [[0, int, 0, 128]] ## optional, if not set, default equal to [[x, float, 0,
,→ 1]]
    output_names = ['oname0','oname1'] ## optional, if not set, default equal to graph␣ ,→output names
)

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

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

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

上一页3.2.5 编译 Darknet 模型下一页3.2.7 编译Paddle模型

最后更新于2年前