✏️
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.5 编译 Darknet 模型

BMNETD 是针对 Darknet 的模型编译器,可将某网络的 weight 和 cfg 编译成 BMRuntime 所需要 的文件 (目前只支持 yolo)。而且在编译的同时,支持每一层的 NPU 模型计算结果都会和 CPU 的计算结果进行对 比,保证正确性。

bmnetd的使用例程参见${BMNNSDK}/examples/nntc/bmnetd。

Darknet模型转换注意事项

cfg 文件中batch/subvision 要大于转换脚本中设置的输入shape的batch size。

  • 命令行形式:

/path/to/bmnetd [--model=<path>] \
                [--weight=<path>] \
                [--shapes=<string>] \ 
                [--net_name=<name>] \ 
                [--opt=<value>] \ 
                [--dyn=<bool>] \ 
                [--outdir=<path>] \ 
                [--target=<name>] \ 
                [--cmp=<bool>] \ 
                [--mode=<string>] \ 
                [--enable_profile=<bool>]

参数介绍:

args
type
Description

model

string

Necessary. Darknet cfg path

weights

string

Necessary.Darknet weight path

shapes

string

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

net_name

string

Optional. Name of the network, default use cfg path

opt

int

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

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 bmnetc mode. Option: compile, GenUmodel. Default: compile.

enable_profile

bool

Optional. Enable profile log. Default: fals

log_dir

string

Optional. Specify the log directory Default: “”

v

string

Optional.Set log verbose level. Default: 0 (0: FATAL, 1: ERROR, 2: WARNING, 3: INFO, 4: DEBUG).

dump_ref

bool

Optional.Enable dump input&output ref data when compile without compare. Default: false.

  • Python模式:

import bmnetd
## compile fp32 model
bmnetd.compile(
    model = "/path/to/cfg", ## Necessary
    weight = "/path/to/weight", ## Necessary
    outdir = "xxx", ## Necessary
    target = "BM1684", ## Necessary
    net_name = "name", ## optional, if not set, default use the path of cfg
    shapes = [[x,x,x,x], [x,x,x]], ## optional, if not set, default use shape in weights
    opt = 2, ## optional, if not set, default equal to 2
    dyn = False, ## optional, if not set, default equal to False
    cmp = True, ## optional, if not set, default equal to True
    enable_profile = False ## optional, if not set, default equal to False
)

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

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

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

上一页3.2.4 编译PyTorch模型下一页3.2.6 编译ONNX模型

最后更新于2年前