AI model convert tool: Caffe

 

Preparation


Please refer here for the environment construction procedure.

 

Convert sample model


Change directory.

$ cd /home/cvtool/conversion/caffe

Download sample model.

$ wget https://github.com/shicai/MobileNet-Caffe/raw/master/mobilenet.caffemodel $ mv mobilenet.caffemodel sample/mobilenet_v1/models

Conver the model.

$ ./caffe_conversion.sh setting.conf


The model after conversion is output to the following directory.

  • For ambaCV2X camera

${OUTPUT_DIR}/${NET_NAME}/${PARSER_OPTION}/[model name]

  • For ambaCV5X camera

${OUTPUT_DIR}/${NET_NAME}_ambaCV5X/${PARSER_OPTION}/[model name]

Conversion


  1. Copy /home/cvtool/conversion/caffe .

  1. Change the parameter of "setting.conf" according to the model to be converted.

  2. Convert the model.

setting.conf


From v1.20, parameter "CAVALRY_VER" is removed that existed in setting.conf until v1.19.
If you use setting.conf from v1.19 or earlier, please remove "CAVALRY_VER" from it.

  • NET_NAME: The name of network.

    • Any name can be set.

  • DEPLOY_PROTOTXT: Path to deploy prototxt file

  • MODEL_DIR: Path to directory which includes caffemodel

    • All caffemodels under the converted directory

  • DRA_IMAGE_DIR: Path to directory which includes image files for optimizing quantization

    • Please put the directory image files for training. Recommended number of image files is 100 to 200.

    • Image file format should be the format that are supported by OpenCV (Ex. JPEG, PNG and etc…).

    • Any resolution is supported.

  • OUTPUT_DIR: Path to directory to which the converted data is placed

  • PARSER_OPTION: Quantization mode

    • Select from FIX8/FIX16/MIX (FIX8/FIX16 mixed).

  • IN_DATA_CHANNEL: Number of input image channel for target model

  • N_DATA_WIDTH: Width of input image for target model

  • IN_DATA_HEIGHT: Height of input image for target model

  • IN_MEAN: Normalization parameter (mean) of input image

    • It can be set by numerical value or .binaryproto file

    • Please refrain from using space between “,” as shown below if using numerical value.
      IN_MEAN=127.5,127.5,127.5

    • Please set a path to the file as shown below when setting by .binaryproto file.
      IN_MEAN=./model/mean.binaryproto

  • IN_SCALE: Normalization parameter (scale) of input image

    • Please refrain from using space between “,” and only use “,” to separate values when setting different values for each channel.

  • IS_BGR: Format of input image (RGB or BGR)

  • IN_LAYER: The name of input layer for target network

    • In the converted model, the name of input layer changes to “${IN_LAYER}_0” .
      Therefore, “_0” needs to be added to the name of input layer, when the converted model executes AdamApp.

    • When the following symbols are contained in the name of input layer, conversion may not be successful.
      : | ; , ‘

  • OUT_LAYER: The name of output layer for target network

    • If two or more layers exists, separate layers by “,”.

    • When the following symbols are contained in the name of output layer, conversion may not be successful.
      : | ; , ‘

  • PREPRO: Path of preprocessing script (python script)

    • Refer to “/home/cvtool/ common/prepro.py” for how to create a script.

  • PREPRO_ARG: Argument of preprocessing script (python script)

  • IN_DATA_FILEFORMAT: Input data format

    • examples: uint8->0,0,0,0, float32->1,2,0,7, float16->1,1,0,4)

    • When the value of IN_DATA_FILEFORMAT changes from “0,0,0,0”, setting PREPRO is needed.

  • IN_DATA_TRANSPOSE: Specify when performing TRANSPOSE on the input data


If input layer is not defined in deployed prototxt file, add the layer as shown below.