3.2.1 编译Caffe模型
BMNETC是针对Caffe的模型编译器,可将某网络的caffemodel和prototxt编译成BMRuntime所需要的文件。而且在编译的同时,支持将每一层的NPU模型计算结果与CPU的计算结果进行比对,保证正确性。
bmnetc的使用例程参见${BMNNSDK}/examples/nntc/bmnetc。
命令行形式:
/path/to/bmnetc [--model=<path>] \
[--weight=<path>] \
[--shapes=<string>] \
[--net_name=<name>] \
[--opt=<value>] \
[--dyn=<bool>] \
[--outdir=<path>] \
[--target=<name>] \
[--cmp=<bool>] \
[--mode=<string>] \
[--enable_profile=<bool>] \
[--show_args] \
[--list_ops]args
type
Description
model
string
Necessary. Caffe prototxt path
weight
string
Necessary. caffemodel(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 the name in prototxt
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: false
show_args
Optional. Display arguments passed to bmnetc compiler.
list_ops
Optional. List bmnetc supported ops.
以sdk中的SSD模型编译float32 bmodel为例,先执行cd /workspace/examples/SSD_object/model/进入SSD模型示例,若该目录下不存在SSD模型文件,则运行:
脚本gen_bmodel.sh中的主要内容如下:
执行完脚本后正常的输出结果如下:
编译生成的模型存放在如下目录:
至此生成bmodel。执行如下命令,检测模型的精度回归:
正常结束后提示如下:
当有“+++ The network[VGG_VOC0712_SSD_300x300_deploy] stage[0] cmp success +++”的提示,则模型编译流程正确,与原生模型的精度一致。
python形式:
bmnetc若成功,输出的 log 最后会看到以下信息:
bmnetc成功后,将在指定的文件夹中生成一个compilation.bmodel的文件,该文件则是转换成功的 bmodel,用户可以重命名。
最后更新于