1.下载并编译ncnn
git clone https://github.com/Tencent/ncnn
cd ncnn
mkdir build && cd build
cmake …
make -j
make install
编译完成后在ncnn/build/tools 目录下,生成 caffe2ncnn和ncnn2mem可执行文件,caffe2ncnn将caffe模型生成ncnn 模型,ncnn2mem对模型加密
2.旧版caffe model转新版caffe model
~/caffe/build/tools/upgrade_net_proto_text deploy.prototxt deploy_new.prototxt
~/caffe/build/tools/upgrade_net_proto_binary mobilenet.caffemodel mobilenet_new.caffemodel
ncnn只支持转换新版的caffe模型,新版caffe框架中自带转换的工具。
3.新版caffe模型转ncnn模型
(1) ./caffe2ncnn deploy_new.prototxt mobilenet_new.caffemodel mobilenet.param mobilenet.bin
(2) ./ncnn2mem mobilenet.param mobilenet.bin mobilenet.id.h mobilenet.mem.h
4.ncnn读取模型,ncnn对加密和非加密两种文件的读取方式不一样
// 加载非加密的ncnn模型
ncnn::Net net;
net.load_param(“mobilenet.param”);
net.load_model(“mobilenet.bin”);
// 加载加密的ncnn模型
ncnn::Net net;
net.load_param_bin(“mobilenet.param.bin”);
net.load_model(“mobilenet.bin”);