/
AI model convert tool: Tensorflow

AI model convert tool: Tensorflow

Preparation


Please refer here for the environment construction procedure.

Please note that the following environment settings must be performed every time the CV Tool container is started.

  • For ambaCV2X camera

$ cd /home/cvtool $ source setup_env.sh
  • For ambaCV5X camera

$ cd /home/cvtool $ source setup_env.sh ipro-ambaCV5X

 

Convert sample model


You can understand the flow of the conversion process by converting a sample model. If you are converting a model that you have developed, you can skip this step.

inception_v4

Download sample model.

$ cd /home/cvtool/conversion/tensorflow/inception_v4 $ wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/model_zoo/upload_20180427/inception_v4_2018_04_27.tgz $ tar -xvf inception_v4_2018_04_27.tgz $ mv inception_v4.pb sample/model $ rm inception_v4_2018_04_27.tgz

Convert the model.

 

mobilenetv2ssd

Download sample model.

Convert the model.



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]

 

For models that use SSD, another binary is output to the following directory.

Models with SSD use two binary files in the application.

${OUTPUT_DIR}/${NET_NAME}/

 

Convert user AI model


The model of tensorflow v2.x needs to be converted to tflite in advance.

  1. Copy either sample model directory under /home/cvtool/conversion/tensorflow .

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

  2. Locate user AI model into /sample/model/.

  3. Convert the model.

If an error occurs, please check the environment settings (source setup_env.sh) below. You will need to do this every time you restart your computer.

Install AI model convert tool - Technology Partner FAQ (En) - Confluence

 

setting.conf


  • NET_NAME: The name of network

    • Any name can be set.

  • IS_SSD: Set 1, if target model uses SSD

  • PB_DIR: Path to directory which includes frozen .pb files

    • All .pb files under the directory are converted.

  • IMAGE_DIR: Path to directory that includes image files for optimizing quantization

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

    • Available image file format is what OpenCV can handle, for example, JPEG, PNG and so on.

    • Any resolution is available.

  • 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_FORMAT: Format of input data for target model (NHWC or NCHW)

  • 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

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

  • 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_NODE: The name of input node for target network

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

  • OUT_NODE: The name of output node for target network

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

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

  • PRIORBOX_NODE: Node equivalent to “priorbox”

    • Need to set when IS_SSD=1

  • 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)

  • PARSER_IN_DATA_FORMAT: Format of input data for target model (when tfparser run) (NHWC or NCHW)

  • 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

 

Related content

AI model convert tool: Caffe
AI model convert tool: Caffe
More like this
AI model convert tool: ONNX(PyTorch)
AI model convert tool: ONNX(PyTorch)
More like this
Date and time are not shown on the retrieved image.
Date and time are not shown on the retrieved image.
Read with this
AIモデル変換ツール:Tensorflow編
AIモデル変換ツール:Tensorflow編
More like this
AI model conversion
AI model conversion
Read with this
AIモデル変換ツール:Caffe編
AIモデル変換ツール:Caffe編
More like this