Caffe turn NCNN model transformation

caffe2ncnn

First, the preparatory work

Install opencv

Installation protobuf

Download the source code and compile ncnn

git clone https://github.com/Tencent/ncnn

cd CbnA

mkdir build && cd build

cmake ..

make -j4

make install

Second, specific operation

(1), if an older version of Caffe models, need to convert to the new model in Caffe Caffe environment;

 ~/caffe/build/tools/upgrade_net_proto_text deploy.prototxt new_deplpy.prototxt

 ~/caffe/build/tools/upgrade_net_proto_binary bvlc_alexnet.caffemodel new_bvlc_alexnet.caffemodel

 After the execution, you can generate a new version of Cafffe model;

(2), NCNN compile the source code, compiled successfully, it will generate a build folder in the source code;

(3), the terminal enters ncnn / build / tools under / caffe directory, you will find a caffe2ncnn of an executable file.

(4), execute the following command: (caffe file names and file names generated ncnn needs its own set)

./caffe2ncnn new_deploy.prototxt new.caffemodel demo.param demo.bin

After the execution is complete, you can see the generated param and bin files in ncnn / build / tools / caffe.

Third, the transformation model validation

Verify ideas:

1, and ncnn caffe same pretreatment, so that consistent results, such as specifying the image size, the channel conversion to HWC CHW, mean subtraction, normalization processing operations;

2, input a picture, use Resnet50 Caffe model runs, the outcome;

The next into the caffe / build / examples resnet50 executable file, enter the picture, and the probability index to obtain the predicted value of the results

3. Similarly, the input with the pictures, use Resnet50 NCNN model runs, the outcome;

The results of the executable file under execution resnet enter ncnn / build / examples file, enter the picture, and the probability index to obtain the predicted value of

4, two obtained results are compared to see if substantially the same. If the result is substantially the same, the model conversion was successful; if the result is a big gap between the model conversion failed.

Guess you like

Origin www.cnblogs.com/wanggangtao/p/11314010.html