Skip to content

Commit

Permalink
MULTICLASS NMS. DATA AUG.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksanjeevan committed Jul 30, 2018
1 parent e8f04cc commit f98d125
Show file tree
Hide file tree
Showing 16 changed files with 538 additions and 302 deletions.
66 changes: 37 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ Original paper and github: [YOLO9000: Better, Faster, Stronger](https://arxiv.or
### Dependancies
---
- [keras](https://github.com/fchollet/keras)
- [tensorflow](https://www.tensorflow.org/)
- [tensorflow 1.9](https://www.tensorflow.org/api_docs/)
- [numpy](http://www.numpy.org/)
- [h5py](http://www.h5py.org/)
- [opencv](https://pypi.org/project/opencv-python/)
- [python3.5](https://www.python.org/)
- [python 3.5](https://www.python.org/)
- [moviepy](https://zulko.github.io/moviepy/) (optional, gifs)
### Simple use
---

0. Clone repository:
```bash
git clone https://github.com/ksanjeevan/dourflow.git
```

1. Download pretrained [model](https://drive.google.com/open?id=1khOgS8VD-paUD8KhjOLOzEXkzaXNAAMq) and place it in **dourflow/**.

2. Predict on an [image](https://images.pexels.com/photos/349758/hummingbird-bird-birds-349758.jpeg?auto=compress&cs=tinysrgb&h=350):

```bash
Expand All @@ -38,13 +45,14 @@ Running `python3 dourflow.py --help`:

```bash
usage: dourflow.py [-h] [-m MODEL] [-c CONF] [-t THRESHOLD] [-w WEIGHT_FILE]
[--gif]
action

dourflow: a keras YOLO V2 implementation.

positional arguments:
action what to do: 'train', 'validate', 'cam' or pass a video, image
file/dir.
action what to do: 'train', 'validate', 'cam' or pass a
video, image file/dir.

optional arguments:
-h, --help show this help message and exit
Expand All @@ -55,7 +63,7 @@ optional arguments:
detection threshold
-w WEIGHT_FILE, --weight_file WEIGHT_FILE
path to weight file

--gif video output stored as gif also

```
#### *action* [positional]
Expand Down Expand Up @@ -151,28 +159,28 @@ Output:

```bash
Batch Processed: 100%|████████████████████████████████████████████| 4282/4282 [01:53<00:00, 37.84it/s]
AP( bus ): 0.806
AP( tvmonitor ): 0.716
AP( motorbike ): 0.666
AP( dog ): 0.811
AP( horse ): 0.574
AP( boat ): 0.618
AP( sofa ): 0.625
AP( sheep ): 0.718
AP( bicycle ): 0.557
AP( cow ): 0.725
AP( pottedplant ): 0.565
AP( train ): 0.907
AP( bird ): 0.813
AP( person ): 0.665
AP( car ): 0.580
AP( cat ): 0.908
AP( bottle ): 0.429
AP( diningtable ): 0.593
AP( chair ): 0.475
AP( aeroplane ): 0.724
AP( train ): 0.907
AP( dog ): 0.899
AP( bird ): 0.814
AP( aeroplane ): 0.810
AP( cow ): 0.810
AP( bus ): 0.806
AP( motorbike ): 0.792
AP( person ): 0.737
AP( sheep ): 0.719
AP( tvmonitor ): 0.718
AP( sofa ): 0.701
AP( bicycle ): 0.683
AP( diningtable ): 0.665
AP( car ): 0.641
AP( boat ): 0.617
AP( horse ): 0.575
AP( pottedplant ): 0.568
AP( chair ): 0.528
AP( bottle ): 0.487
-------------------------------
mAP: 0.674
mAP: 0.719

```

Expand All @@ -198,7 +206,7 @@ Will store the custom bounding box priors wherever the path indicates in the con

Training will create directory **logs/** which will store metrics and checkpoints for all the different training runs.

Model passed is used for [transfer learning](https://en.wikipedia.org/wiki/Transfer_learning) (TRAINING FROM SCRATCH / TRAINING ONLY LAST LAYER SHOULD BE ADDED SOON).
Model passed is used for [transfer learning](https://en.wikipedia.org/wiki/Transfer_learning).

Example:
`python3 dourflow.py train -m models/logo/coco_model.h5 -c confs/config_custom.json`
Expand All @@ -214,16 +222,16 @@ Then, in another terminal tab you can run `tensorboard --logdir=logs/run_X` and

#### To Do

- [ ] cfg parser
- [x] Multiclass NMS
- [x] Anchor generation for custom datasets
- [ ] mAP write up
- [x] Add webcam support
- [ ] Data Augmentation
- [x] Data Augmentation
- [x] TensorBoard metrics

#### Inspired from

- [Darknet](https://github.com/pjreddie/darknet)
- [Darkflow](https://github.com/thtrieu/darkflow)
- [keras-yolo2](https://github.com/experiencor/keras-yolo2)
- [YAD2K](https://github.com/allanzelener/YAD2K)
- [YAD2K](https://github.com/allanzelener/YAD2K)
4 changes: 2 additions & 2 deletions confs/config_coco.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"model" : {
"input_size": 416,
"grid_size": 13,
"true_box_buffer": 30,
"true_box_buffer": 10,
"iou_threshold": 0.5,
"nms_threshold": 0.3
"nms_threshold": 0.4
},
"config_path" : {
"labels": "models/coco/labels_coco.txt",
Expand Down
4 changes: 2 additions & 2 deletions confs/config_voc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"grid_size": 13,
"true_box_buffer": 10,
"iou_threshold": 0.5,
"nms_threshold": 0.3
"nms_threshold": 0.45
},
"config_path" : {
"labels": "models/voc/labels_voc.txt",
Expand All @@ -17,7 +17,7 @@
"annot_folder": "/home/kiran/Documents/DATA/VOC/train/anns",
"batch_size": 16,
"learning_rate": 1e-4,
"num_epochs": 20,
"num_epochs": 50,
"object_scale": 5.0 ,
"no_object_scale": 1.0,
"coord_scale": 1.0,
Expand Down
1 change: 0 additions & 1 deletion kmeans_anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def IoU_dist(x, c):




def exrtract_wh(img):
result = []
pixel_height = img['height']
Expand Down
7 changes: 7 additions & 0 deletions net/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#from . import netarch
#from . import netdecode
#from . import neteval
#from . import netgen
#from . import netloss
#from . import netparams
#from . import utils
20 changes: 13 additions & 7 deletions net/netarch.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""
Set up keras model with Yolo v2 architecture, for both training
and inference.
"""
import tensorflow as tf
import numpy as np
import pickle, argparse, json, os, cv2

from keras.models import Model, load_model
from keras.layers import Reshape, Conv2D, Input, MaxPooling2D, BatchNormalization, Lambda
from keras.layers.advanced_activations import LeakyReLU

from keras.layers.merge import concatenate

import tensorflow as tf
import numpy as np
import pickle, argparse, json, os, cv2

from keras.utils.vis_utils import plot_model

from net.netparams import YoloParams
from net.netdecode import YoloOutProcess
from .netparams import YoloParams
from .netdecode import YoloOutProcess



Expand All @@ -20,6 +23,7 @@ class YoloInferenceModel(object):
def __init__(self, model):
self._yolo_out = YoloOutProcess()
self._inf_model = self._extend_processing(model)
self._model = model

def _extend_processing(self, model):
output = Lambda(self._yolo_out, name='lambda_2')(model.output)
Expand All @@ -40,6 +44,8 @@ def _prepro_single_image(self, image):
def predict(self, image):

image = self._prepro_single_image(image)

#np.save('person.npy', self._model.predict(image))
output = self._inf_model.predict(image)[0]

if output.size == 0:
Expand Down
Loading

0 comments on commit f98d125

Please sign in to comment.