OpenVINO-YoloV3
I wrote an English article, here
1.はじめに
私のYoloV3リポジトリへの独自データセットに関する海外エンジニアからのissueが多すぎてやかましいため、この場で検証を兼ねて適当な手順をメモとして残すものです。
Qiita上には素晴らしい手順を整理してみえる方々がたくさんいらっしゃいますので、そちらを参照いただくことをオススメします。
皆さんと私の手順で異なる部分は、 Intel の OpenVINO へストレートに対応させる手順を含むことです。
今更ローカルで学習するなんて旧石器時代みたいなことしてる、とか冷たいことを言わないでください。
Darknetの学習だけにとどまらない環境構築手順になりますので、空の上に出ると逆に面倒きわまりなかっただけです。
完全にメモとして残しますので文章でウダウダと解説いたしません。
Personクラス
だけで簡易トレーニングします。
2.環境
- Ubuntu 16.04 x86_64
- Geforce GTX 1070
- Core i7
- NVIDIA Driver Version: 396.54
- CUDA 9.0
- CuDNN 7.2.1
- VoTT 1.7.2 (楽にアノテーションしたい方は他のツールをオススメします)
- OpenCV 4.0.1-openvino
- Tensorflow GPU v1.12.0
3.独自データセットによる学習環境構築
$ cd ~
$ git clone https://github.com/pjreddie/darknet.git
$ cd darknet
$ nano Makefile
GPU=1
CUDNN=1
OPENCV=1
OPENMP=0
DEBUG=0
$ make
$ cd ~
$ sudo apt install -y snapd
$ wget https://github.com/Microsoft/VoTT/releases/download/v1.7.2/vott-linux.snap
$ sudo snap install --dangerous vott-linux.snap
$ cd ~
$ mkdir vott
# ココでvottフォルダ配下に学習させたい画像をコピーしておく
$ cd ~
$ mv darknet/data darknet/_data
$ cp -r vott/data darknet
$ cp darknet/cfg/yolov3-tiny.cfg darknet/cfg/yolov3-tiny-mine.cfg
$ nano darknet/cfg/yolov3-tiny-mine.cfg
**yolov3-tiny-mine.cfgの修正内容**
filters = (classes +5) * 3
[net]
# Testing
#batch=1
#subdivisions=1
# Training
batch=4
subdivisions=1
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
#filters=(classes+5)*3
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 8
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
#filters=(classes+5)*3
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
$ cd ~/darknet
$ wget https://pjreddie.com/media/files/darknet53.conv.74
$ ./darknet detector train data/obj.data cfg/yolov3-tiny-mine.cfg darknet53.conv.74
/home/b920405/darknet/cfg/yolov3-tiny-mine.cfg
/home/b920405/darknet/data/obj.data
/home/b920405/darknet/data/obj.names
4.Darknet (.weights) -> Tensorflow (.pb) -> OpenVINO (.bin)
$ cd ~
$ git clone https://github.com/PINTO0309/OpenVINO-YoloV3.git
$ cd OpenVINO-YoloV3
$ cp ~/darknet/backup/yolov3-tiny-mine_10000.weights weights
$ echo 'person' > yolov3-tiny-mine.names
$ python3 convert_weights_pb.py \
--class_names yolov3-tiny-mine.names \
--weights_file weights/yolov3-tiny-mine_10000.weights \
--data_format NHWC \
--tiny \
--output_graph pbmodels/frozen_yolov3-tiny-mine.pb
$ sudo python3 /opt/intel/computer_vision_sdk/deployment_tools/model_optimizer/mo_tf.py \
--input_model pbmodels/frozen_yolov3-tiny-mine.pb \
--output_dir lrmodels/tiny-YoloV3/FP32 \
--data_type FP32 \
--batch 1 \
--tensorflow_use_custom_operations_config yolo_v3_tiny_changed.json
$ sudo python3 /opt/intel/computer_vision_sdk/deployment_tools/model_optimizer/mo_tf.py \
--input_model pbmodels/frozen_yolov3-tiny-mine.pb \
--output_dir lrmodels/tiny-YoloV3/FP16 \
--data_type FP16 \
--batch 1 \
--tensorflow_use_custom_operations_config yolo_v3_tiny_changed.json
5.おわりに
おいっ!! ひとつも躓かずに30分で一発成功したやないかい!!
やはり、海外のエンジニアは、アレですな。
Support for local training and OpenVINO of One Class tiny-YoloV3 with a proprietary data set
1.introduction
Simple training with only Person class
.
2.Environment
- Ubuntu 16.04 x86_64
- Geforce GTX 1070
- Core i7
- NVIDIA Driver Version: 396.54
- CUDA 9.0
- CuDNN 7.2.1
- VoTT 1.7.2
- OpenCV 4.0.1-openvino
- Tensorflow GPU v1.12.0
3.Learning environment construction by original data set
$ cd ~
$ git clone https://github.com/pjreddie/darknet.git
$ cd darknet
$ nano Makefile
GPU=1
CUDNN=1
OPENCV=1
OPENMP=0
DEBUG=0
$ make
$ cd ~
$ sudo apt install -y snapd
$ wget https://github.com/Microsoft/VoTT/releases/download/v1.7.2/vott-linux.snap
$ sudo snap install --dangerous vott-linux.snap
$ cd ~
$ mkdir vott
# Copy the image you want to learn under vott folder here
$ cd ~
$ mv darknet/data darknet/_data
$ cp -r vott/data darknet
$ cp darknet/cfg/yolov3-tiny.cfg darknet/cfg/yolov3-tiny-mine.cfg
$ nano darknet/cfg/yolov3-tiny-mine.cfg
**Modification of yolov3-tiny-mine.cfg**
filters = (classes +5) * 3
[net]
# Testing
#batch=1
#subdivisions=1
# Training
batch=4
subdivisions=1
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
#filters=(classes+5)*3
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 8
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
#filters=(classes+5)*3
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
$ cd ~/darknet
$ wget https://pjreddie.com/media/files/darknet53.conv.74
$ ./darknet detector train data/obj.data cfg/yolov3-tiny-mine.cfg darknet53.conv.74
/home/b920405/darknet/cfg/yolov3-tiny-mine.cfg
/home/b920405/darknet/data/obj.data
/home/b920405/darknet/data/obj.names
4.Darknet (.weights) -> Tensorflow (.pb) -> OpenVINO (.bin)
$ cd ~
$ git clone https://github.com/PINTO0309/OpenVINO-YoloV3.git
$ cd OpenVINO-YoloV3
$ cp ~/darknet/backup/yolov3-tiny-mine_10000.weights weights
$ echo 'person' > yolov3-tiny-mine.names
$ python3 convert_weights_pb.py \
--class_names yolov3-tiny-mine.names \
--weights_file weights/yolov3-tiny-mine_10000.weights \
--data_format NHWC \
--tiny \
--output_graph pbmodels/frozen_yolov3-tiny-mine.pb
$ sudo python3 /opt/intel/computer_vision_sdk/deployment_tools/model_optimizer/mo_tf.py \
--input_model pbmodels/frozen_yolov3-tiny-mine.pb \
--output_dir lrmodels/tiny-YoloV3/FP32 \
--data_type FP32 \
--batch 1 \
--tensorflow_use_custom_operations_config yolo_v3_tiny_changed.json
$ sudo python3 /opt/intel/computer_vision_sdk/deployment_tools/model_optimizer/mo_tf.py \
--input_model pbmodels/frozen_yolov3-tiny-mine.pb \
--output_dir lrmodels/tiny-YoloV3/FP16 \
--data_type FP16 \
--batch 1 \
--tensorflow_use_custom_operations_config yolo_v3_tiny_changed.json