Skip to content

Commit

Permalink
add Tiny YOLOv2 model family
Browse files Browse the repository at this point in the history
  • Loading branch information
david8862 committed Nov 13, 2019
1 parent 3f45694 commit 87935ae
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 12 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TF Keras YOLO Modelset
# TF Keras YOLOv3/v2 Modelset

[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)

Expand All @@ -23,6 +23,7 @@ A common YOLOv3/v2 object detection pipeline implement with tf.keras. Including
- [x] Tiny YOLOv3 Lite
- [x] YOLOv2
- [x] YOLOv2 Lite
- [x] Tiny YOLOv2

#### Loss
- [x] Standard YOLOv3 loss
Expand Down Expand Up @@ -59,7 +60,7 @@ A common YOLOv3/v2 object detection pipeline implement with tf.keras. Including
# pip install -r requirements.txt
```

2. Download Darknet/YOLOv2/YOLOv3/YOLOv3-spp/Tiny YOLOv3 weights from [YOLO website](http://pjreddie.com/darknet/yolo/).
2. Download Related Darknet/YOLOv2/YOLOv3 weights from [YOLO website](http://pjreddie.com/darknet/yolo/).
3. Convert the Darknet YOLO model to a Keras model.
4. Run YOLO detection on your image or video, default using Tiny YOLOv3 model.

Expand All @@ -71,12 +72,16 @@ A common YOLOv3/v2 object detection pipeline implement with tf.keras. Including
# wget -O weights/yolov3-spp.weights https://pjreddie.com/media/files/yolov3-spp.weights
# wget -O weights/yolov2.weights http://pjreddie.com/media/files/yolo.weights
# wget -O weights/yolov2-voc.weights http://pjreddie.com/media/files/yolo-voc.weights
# wget -O weights/yolov2-tiny.weights https://pjreddie.com/media/files/yolov2-tiny.weights
# wget -O weights/yolov2-tiny-voc.weights https://pjreddie.com/media/files/yolov2-tiny-voc.weights
# python tools/convert.py cfg/yolov3.cfg weights/yolov3.weights weights/yolov3.h5
# python tools/convert.py cfg/yolov3-tiny.cfg weights/yolov3-tiny.weights weights/yolov3-tiny.h5
# python tools/convert.py cfg/yolov3-spp.cfg weights/yolov3-spp.weights weights/yolov3-spp.h5
# python tools/convert.py cfg/yolov2.cfg weights/yolov2.weights weights/yolov2.h5
# python tools/convert.py cfg/yolov2-voc.cfg weights/yolov2-voc.weights weights/yolov2-voc.h5
# python tools/convert.py cfg/yolov2-tiny.cfg weights/yolov2-tiny.weights weights/yolov2-tiny.h5
# python tools/convert.py cfg/yolov2-tiny-voc.cfg weights/yolov2-tiny-voc.weights weights/yolov2-tiny-voc.h5
# python tools/convert.py cfg/darknet53.cfg weights/darknet53.conv.74.weights weights/darknet53.h5
# python tools/convert.py cfg/darknet19_448_body.cfg weights/darknet19_448.conv.23.weights weights/darknet19.h5
Expand Down
138 changes: 138 additions & 0 deletions cfg/yolov2-tiny-voc.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=2
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
max_batches = 40200
policy=steps
steps=-1,100,20000,30000
scales=.1,10,.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
size=3
stride=1
pad=1
filters=1024
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=125
activation=linear

[region]
anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
bias_match=1
classes=20
coords=4
num=5
softmax=1
jitter=.2
rescore=1

object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1

absolute=1
thresh = .6
random=1
139 changes: 139 additions & 0 deletions cfg/yolov2-tiny.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=2
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
size=3
stride=1
pad=1
filters=512
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=425
activation=linear

[region]
anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
bias_match=1
classes=80
coords=4
num=5
softmax=1
jitter=.2
rescore=0

object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1

absolute=1
thresh = .6
random=1
1 change: 1 addition & 0 deletions configs/yolo2-tiny-voc_anchors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
1 change: 1 addition & 0 deletions configs/yolo2-tiny_anchors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
12 changes: 9 additions & 3 deletions yolo2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam

from yolo2.models.yolo2_darknet import yolo2_body
from yolo2.models.yolo2_mobilenet import yolo2_mobilenet_body, yolo2lite_mobilenet_body
from yolo2.models.yolo2_mobilenetv2 import yolo2_mobilenetv2_body, yolo2lite_mobilenetv2_body
from yolo2.models.yolo2_darknet import yolo2_body, tiny_yolo2_body
from yolo2.models.yolo2_mobilenet import yolo2_mobilenet_body, yolo2lite_mobilenet_body, tiny_yolo2_mobilenet_body, tiny_yolo2lite_mobilenet_body
from yolo2.models.yolo2_mobilenetv2 import yolo2_mobilenetv2_body, yolo2lite_mobilenetv2_body, tiny_yolo2_mobilenetv2_body, tiny_yolo2lite_mobilenetv2_body
from yolo2.models.yolo2_xception import yolo2_xception_body, yolo2lite_xception_body
from yolo2.loss import yolo2_loss
from yolo2.postprocess import batched_yolo2_postprocess
Expand All @@ -32,6 +32,12 @@
'yolo2_mobilenetv2_lite': [yolo2lite_mobilenetv2_body, 155, None],
'yolo2_xception': [yolo2_xception_body, 132, None],
'yolo2_xception_lite': [yolo2lite_xception_body, 132, None],

'tiny_yolo2_darknet': [tiny_yolo2_body, 0, None],
'tiny_yolo2_mobilenet': [tiny_yolo2_mobilenet_body, 87, None],
'tiny_yolo2_mobilenet_lite': [tiny_yolo2lite_mobilenet_body, 87, None],
'tiny_yolo2_mobilenetv2': [tiny_yolo2_mobilenetv2_body, 155, None],
'tiny_yolo2_mobilenetv2_lite': [tiny_yolo2lite_mobilenetv2_body, 155, None],
}


Expand Down
Loading

0 comments on commit 87935ae

Please sign in to comment.