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

...

Convert the model.

Please change the parameter "setting.conf" of the argument according to the model to be converted.

Code Block
$ cd /home/cvtool/conversion/tensorflow
$ ./tf_conversion.sh setting.conf

変換後のモデルは以下のディレクトリに出力されます。The model after conversion is output to the following directory.

${OUTPUT_DIR}/${NET_NAME}/${PARSER_OPTION}/[モデル名]

SSDを使用するモデルの場合、以下のディレクトリにもう一つバイナリが出力されます。

SSDを使用するモデルは、2つのバイナリファイルをアプリケーションで使用します。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}/

Note

The model of tensorflow v2.xのモデルは事前にtfliteに変換が必要です。x needs to be converted to tflite in advance.

Setting.

...

conf

...

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:SSDを使用するモデルの場合、1を指定SSD: Set 1, if target model uses SSD

  • PB_DIR:(freeze処理済みの)pbファイルが格納されたディレクトリ

    ディレクトリ下の全てのモデルに対して、変換処理を実行します。

    : Path to directory which includes frozen .pb files

    • All .pb files under the directory are converted.

  • IMAGE_DIR:量子化の最適化処理で使用する、画像ファイルが格納されたディレクトリ

    • 学習に使った画像を格納してください。100~200枚が推奨枚数です。

    • 画像フォーマットはJPEGやPNGなど、OpenCVで対応しているものです。

    • 任意サイズの画像を使用可能です。

  • OUTPUT_DIR:変換後のデータ出力先ディレクトリ

  • PARSER_OPTION:量子化モード

    : Path to directory which includes image files for optimizing quantization

    • Please put the directory image files for training. Recommende 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 which converted data will be put

  • PARSER_OPTION: Quantization mode

    • Select from FIX8/FIX16/MIX (FIX8/FIX16混合)から選択します。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

    • In case of setting by numerical value, do not put space between “,” as following.
      IN_MEAN=127.5,127.5,127.5

  • IN_SCALE:入力画像の正規化パラメータ(スケール)

    チャネルごとに異なる設定値にする場合は、”,”で値を区切ってください。”,”の間には空白を入れないようにしてください。

    : Normalization parameter (scale) of input image

    • In case of setting different value for each channel, split values by “,”. Do not put space between “,”.

  • IS_BGR:入力画像のフォーマット(RGB or BGR): Format of input image (RGB or BGR)

  • IN_NODE:ネットワークの入力ノード名: The name of input node for target network

  • OUT_NODE:ネットワークの出力ノード名

    複数指定する場合は”,”で区切ってください。

    : The name of output node for target network

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

  • PRIORBOX_NODE:”priorbox”に相当するノード: Node equivalent to “priorbox”

    • Need to set when IS_SSD=1の時に、設定が必要です。1

  • CAVALRY_VER:使用するcavalryバージョン: Version of cavalry to use

  • PREPRO:前処理スクリプトパス: Path of preprocessing script (python script)

    • スクリプトの作り方は“Refer to “/home/cvtool/ common/prepro.py”を参照してください。py” for how to create a script

  • PREPRO_ARG:前処理スクリプトの引数: Argument of preprocessing script (python script)

  • PARSER_IN_DATA_FORMAT:モデルの入力データフォーマット(tfparser実行時: Format of input data for target model (when tfparser run) (NHWC or NCHW)

  • IN_DATA_FILEFORMAT:入力データのフォーマット

    例:uint8-> 0

    : Input data format

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

    • NWhen the value of IN_DATA_FILEFORMAT を”0changes from “0,0,0,0”から変更した場合はPREPROの設定が必要になります。,0”, setting PREPRO is needed.

  • N_DATA_TRANSPOSE:入力データに対してTRANSPOSE を行う場合指定する

...

  • TRANSPOSE: Specify when performing TRANSPOSE on the input data

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.

Code Block
$ ./tf_conversion.sh setting_coco20180329.conf

...