3
4

More than 3 years have passed since last update.

YOLOv3(TensorFlow 2.1)で自分のモデルをトレーニングする

Last updated at Posted at 2020-05-05

目的

自分のモデルをトレーニングして火事を認識できる
1.JPG

事前用意

windowsでYOLOv3(TensorFlow 2.0)で物体検出(CPUバージョン)

windowsのGPUでYOLOv3(TensorFlow 2.1)で物体検出をやってみた!

※CPUのトレーニング速度は遅いのため、GPUでトレーニングする。

training用写真用意

https://pan.baidu.com/s/1G2Qh-V8kyLOq4oDbTwK6HQ
提取码(パスワード):vogw
ファイルは「yolo_tf2\VOCdevkit_fire\VOC2012\JPEGImages」

labelImg.exeでラベル

上記「yolo_tf2\VOCdevkit_fire\VOC2012\Annotations」の資材流用

tools/voc2012.py修正

下記ファイル名はfire_開始しているのため、修正必要
yolov3-tf2\VOCdevkit_fire\VOC2012\ImageSets\Main\
fire_train.txt
fire_val.txt

# 96行目
        FLAGS.data_dir, 'ImageSets', 'Main', 'fire_%s.txt' % FLAGS.split)).read().splitlines()

tfrecordファイル作成(train and val)

python tools/voc2012.py --data_dir ./VOCdevkit_fire/VOC2012 --split train --output_file ./data/voc2012_train_fire.tfrecord --classes ./data/fire_voc2012.names

python tools/voc2012.py --data_dir ./VOCdevkit_fire/VOC2012 --split val --output_file ./data/voc2012_val_fire.tfrecord --classes ./data/fire_voc2012.names

tfrecordファイル作成の確認

(keras_work) C:\temp\yolov3-tf2\data>dir /B *.tfrecord
voc2012_train_fire.tfrecord
voc2012_val_fire.tfrecord

トレーニング

--epochs 20:トレーニング回数

cd..

python train.py --dataset ./data/voc2012_train_fire.tfrecord --val_dataset ./data/voc2012_val_fire.tfrecord --classes ./data/fire_voc2012.names --num_classes 1 --mode fit --transfer darknet --batch_size 4 --epochs 20 --weights ./checkpoints/yolov3.tf --weights_num_classes 80

windows7のGPU使用率確認

GPUでトレーニング時間

20分

自分のモデルの確認

python detect.py --classes ./data/fire_voc2012.names --num_classes 1 --weights ./checkpoints/yolov3_train_19.tf --image ./fire.jpg

--weights ./checkpoints/yolov3_train_19.tf
※自分でトレーニングしたのcheckpointを指定(最大の番号19を指定)

確認結果

I0505 22:21:46.660045  7024 detect.py:35] weights loaded
I0505 22:21:46.662045  7024 detect.py:38] classes loaded
I0505 22:21:47.962119  7024 detect.py:55] time: 1.21506929397583
I0505 22:21:47.963119  7024 detect.py:57] detections:
I0505 22:21:48.174131  7024 detect.py:66] output saved to: ./output.jpg

detections:内容なし?認識できないみたい

output.jpg
output.jpg

認識できない?yolo_score_threshold 指定必要

python detect.py --classes ./data/fire_voc2012.names --num_classes 1 --weights ./checkpoints/yolov3_train_19.tf --image ./fire.jpg --yolo_score_threshold 0.3

output.jpg
output.jpg

3
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4