目次
Table of Contents | ||||
---|---|---|---|---|
|
環境構築
環境構築手順はこちらをご参照ください。
モデルを変換する
モデル変換を行います。
...
Preparation
...
Please refer here for the environment construction procedure.
Convert sample model
...
Change directory.
Code Block |
---|
$ cd /home/cvtool/conversion/caffe |
Download sample model.
Code Block |
---|
$ wget https://github.com/shicai/MobileNet-Caffe/raw/master/mobilenet.caffemodel $ mv mobilenet.caffemodel sample/mobilenet_v1/models |
Conver the model.
Code Block |
---|
$ ./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
...
Copy
/home/cvtool/conversion/caffe
.
Code Block |
---|
$ cd /home/cvtool/conversion
$ cp -r caffe foo
$ cd foo |
Change the parameter of "setting.conf" according to the model to be converted.
Convert the model.
Code Block |
---|
$ ./caffe_conversion.sh setting.conf |
setting.conf
...
Note |
---|
From v1.20, parameter "CAVALRY_VER" is removed that existed in setting.conf until v1.19. |
Code Block |
---|
# Network Name NET_NAME=mobilenetv1 # Path to Deploy Prototxt DEPLOY_PROTOTXT=./sample/mobilenet_v1/mobilenet_deploy.prototxt # Path to Directory for (Deploy) Caffe Models MODEL_DIR=./sample/mobilenet_v1/models # 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=FIX8 # Input Data Format (0:NHWC, 1:NCHW) IN_DATA_FORMAT=1 # Input Data Channel IN_DATA_CHANNEL=3 # Input Data Width IN_DATA_WIDTH=224 # Input Data Height IN_DATA_HEIGHT=224 # Input Data Mean Vector or Name of .binaryproto IN_MEAN=103.94,116.78,123.68 # Input Data Scale # IN_SCALE=1/Scale IN_SCALE=58.823529411 # RGB or BGR (0:RGB, 1:BGR) IS_BGR=1 # Input Layer Name IN_LAYER=data # Output Layers Name OUT_LAYER=mbox_loc,mbox_conf_flatten #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="" # 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.
DEPLOY_PROTOTXT:deploy用prototxtファイルへのパス: Path to deploy prototxt file
MODEL_DIR:caffemodelが格納されたディレクトリ
ディレクトリ下の全てのモデルに対して、変換処理を実行します。: Path to directory which includes caffemodel
All caffemodels under the converted directory
DRA_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. 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混合)から選択します。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:入力画像の正規化パラメータ(平均値)
数値またはbinaryprotoファイルでの設定が可能です。
数値で設定する場合には、以下のように”,”の間に空白を入れないようにしてください。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.5binaryprotoファイルで設定する場合には、以下のようにファイルへのパスを設定してください。Please set a path to the file as shown below when setting by .binaryproto file.
IN_MEAN=./model/mean.binaryprotoIN_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:入力画像のフォーマット(RGB or 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:ネットワークの出力レイヤ名
複数指定する場合は”,”で区切ってください
CAVALRY_VER:使用するcavalryバージョン
PREPRO:前処理スクリプトパス(python)
スクリプトの作り方は“: 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”を参照してください。.py” for how to create a script.
PREPRO_ARG:前処理スクリプトの引数: Argument of preprocessing script (python script)
IN_DATA_FILEFORMAT:入力データのフォーマット
例:uint8-> 0: Input data format
examples: uint8->0,0,0,0, float32-> 1>1,2,0,7, float16-> 1>1,1,0,4)
NWhen the value of IN_DATA_FILEFORMAT を”0changes from “0,0,0,0”から変更した場合はPREPROの設定が必要になります
,0”, setting PREPRO is needed.
IN_DATA_TRANSPOSE:入力データに対してTRANSPOSE を行う場合指定する
: Normalization parameter (mean) of input image
deploy用のprototxtでinputレイヤが定義されていない場合は、以下のようにレイヤを追加してください。
...
サンプルモデルの変換
サンプルモデルをダウンロードします。
Code Block |
---|
$ wget https://github.com/shicai/MobileNet-Caffe/blob/master/mobilenet.caffemodel
$ mv mobilenet.caffemodel sample/mobilenet_v1/models |
モデル変換を実行します。
...
: Specify when performing TRANSPOSE on the input data
If input layer is not defined in deployed prototxt file, add the layer as shown below.
...