Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of contents

Table of Contents
minLevel1
maxLevel4

Preparation

...

Please refer here for the environment construction procedure.

...

Convert sample model

...

inception_v4

Download sample model.

Code Block
$ 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.Please change the parameter "setting.conf" of the argument according to the model to be converted

Code Block
$ ./tf_conversion.sh setting.conf

mobilenetv2ssd

Download sample model.

Code Block
$ cd /home/cvtool/conversion/tensorflow/mobilenetv2ssd
$ wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_coco_2018_03_29.tar.gz
$ tar -xvzf ssd_mobilenet_v2_coco_2018_03_29.tar.gz
$ mv ssd_mobilenet_v2_coco_2018_03_29/frozen_inference_graph.pb sample/model
$ rm ssd_mobilenet_v2_coco_2018_03_29.tar.gz

Convert the model.

Code Block
$ ./tf_conversion.sh setting_coco20180329.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]

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

...

${OUTPUT_DIR}/${NET_NAME}/

Conversion

...

Note

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

...

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

Code Block
$ cd /home/cvtool/conversion/tensorflow
$ cp -r inception_v4 foo
$ cd foo
  1. Change the parameter of "setting.conf" according to the model to be converted.

  2. Convert the model.

Code Block
$ ./tf_conversion.sh setting.conf

setting.conf

...

Note

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.

Code Block
# Network Name
NET_NAME=inception_v4


# SSD Model or Not (0:not SSD, 1:SSD)
IS_SSD=0

# Path to Directory for (frozen) Protobuf File
PB_DIR=./sample/model

# Path to Directory for DRA Images
DRA_IMAGE_DIR=../../dra_img

# Path to Directory for Output Data
OUTPUT_DIR=./out

# Quantization Mode
#  FIX8  : Fixed-point  8bit
#  FIX16 : Fixed-point 16bit
#  MIX   : FIX8/FIX16 mixed
PARSER_OPTION=MIX

# Input Data Format (0:NHWC, 1:NCHW)
IN_DATA_FORMAT=0

# Input Data Channel
IN_DATA_CHANNEL=3

# Input Data Width
IN_DATA_WIDTH=299

# Input Data Height
IN_DATA_HEIGHT=299

# Input Data Mean Vector
IN_MEAN=127.5,127.5,127.5

# Input Data Scale
# IN_SCALE=1/Scale
IN_SCALE=127.5

# RGB or BGR (0:RGB, 1:BGR)
IS_BGR=1

# Input Nodes Name
IN_NODE=input

# Output Nodes Name
OUT_NODE=InceptionV4/Logits/Predictions

# (Need to Set When IS_SSD=1) Node Name as "priorbox"
PRIORBOX_NODE=Concatenate/concat

#cavalry version
#if not specified -> ""
CAVALRY_VER="2.1.7"

# Unique preprocess
# if use im2bin -> NONE
# if use unique preprocess -> script path
PREPRO=NONE
PREPRO_ARG=""

# Parser Data Format (0:NHWC, 1:NCHW)
PARSER_IN_DATA_FORMAT=1

# Input file data format
IN_DATA_FILEFORMAT=0,0,0,0

# Transpose indices(NONE:without transpose , 0,3,1,2:transpose (EX))
IN_DATA_TRANSPOSE=NONE
  • 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

  • CAVALRY_VER: Version of cavalry to use

  • 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,1,0,4

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

  • NIN_DATA_TRANSPOSE: Specify when performing TRANSPOSE on the input data

Info

CAVALRY_VER is "2.1.7" for ambaCV2X, but please set "2.2.8.2" for ambaCV5X.

Convert sample model

inception_v4

Download sample model.

Code Block
$ 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.

Code Block
$ ./tf_conversion.sh setting.conf

mobilenetv2ssd

Download sample model.

Code Block
$ cd /home/cvtool/conversion/tensorflow/mobilenetv2ssd
$ wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_coco_2018_03_29.tar.gz
$ tar -xvzf ssd_mobilenet_v2_coco_2018_03_29.tar.gz
$ mv ssd_mobilenet_v2_coco_2018_03_29/frozen_inference_graph.pb sample/model
$ rm ssd_mobilenet_v2_coco_2018_03_29.tar.gz

Convert the model.

...