Skip to content

train error. #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added Media1.mp4
Binary file not shown.
62 changes: 17 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,33 @@
# YOLOv2 in Keras and Applications
# Helmet Detection using YOLOv2 in Keras

This repo contains the implementation of YOLOv2 in Keras with Tensorflow backend. It supports training YOLOv2 network with various backends such as MobileNet and InceptionV3. Links to demo applications are shown below. Check out https://experiencor.github.io/yolo_demo/demo.html for a Raccoon Detector demo run entirely in brower with DeepLearn.js and MobileNet backend (it somehow breaks in Window). Source code of this demo is located at https://git.io/vF7vG.
This repo contains the implementation of YOLOv2 in Keras with Tensorflow backend. It supports training YOLOv2 network with various backends such as MobileNet and InceptionV3.

## Todo list:
- [x] Warmup training
- [x] Raccoon detection, Self-driving car, and Kangaroo detection
- [x] SqueezeNet, MobileNet, InceptionV3, and ResNet50 backends
- [x] Support python 2.7 and 3.6
- [ ] Multiple-GPU training
- [ ] Multiscale training
- [ ] mAP Evaluation

## Some example applications (click for videos):
## My application:

### Raccon detection
<a href="https://www.youtube.com/watch?v=aibuvj2-zxA" rel="some text"><p align="center"><img src="https://i.imgur.com/6okeDjz.jpg" height="300"></p></a>
### Helmet detection
![Helmet and people wearing helmets](./helmet_detection.gif "Helmet Detection")

Dataset => https://github.com/experiencor/raccoon_dataset

### Kangaroo detection
<a href="https://youtu.be/vjmFzEP1qZw?t=34" rel="some text"><p align="center"><img src="https://i.imgur.com/v606VZX.jpg" height="300"></p></a>

Dataset => https://github.com/experiencor/kangaroo

### Self-driving Car
<a href="https://www.youtube.com/watch?v=oYCaILZxEWM" rel="some text"><p align="center"><img src="https://i.imgur.com/kEc9ptL.jpg" height="300"></p></a>

Dataset => http://cocodataset.org/#detections-challenge2017

### Red blod cell detection
<a href="https://www.youtube.com/watch?v=oYCaILZxEWM" rel="some text"><p align="center"><img src="https://i.imgur.com/1vmIJKL.jpg" height="300"></p></a>

Dataset => https://github.com/cosmicad/dataset

### Hand detection
<a href="https://www.youtube.com/watch?v=p3-3kN_fIz0" rel="some text"><p align="center"><img src="https://i.imgur.com/75imQQz.jpg" height="300"></p></a>

Dataset => http://cvrr.ucsd.edu/vivachallenge/index.php/hands/hand-detection/

## Usage for python code

### 0. Requirement

python 2.7
python 2.7 or 3.x

keras >= 2.0.8

imgaug

### 1. Data preparation
Download the Raccoon dataset from from https://github.com/experiencor/raccoon_dataset.

#### Dataset Collection
The dataset containing images of people wearing helmets and people without helmets were collected mostly from google search. Some images have people applauding, those were collected from [Stanford 40 Action Dataset](http://vision.stanford.edu/Datasets/40actions.html).

#### Annotations
Annotaion of each image was done in Pascal VOC format using the awesome lightweight annotation tool [LabelImg](https://github.com/tzutalin/labelImg) for object-detection

#### Organizing the dataset
Organize the dataset into 4 folders:

+ train_image_folder <= the folder that contains the train images.
Expand All @@ -73,12 +50,12 @@ The configuration file is a json file, which looks like this:
"input_size": 416,
"anchors": [0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828],
"max_box_per_image": 10,
"labels": ["raccoon"]
"labels": ["helmet", "person with helmet", "person without helmet"]
},

"train": {
"train_image_folder": "/home/andy/data/raccoon_dataset/images/",
"train_annot_folder": "/home/andy/data/raccoon_dataset/anns/",
"train_image_folder": "/train_image_folder/",
"train_annot_folder": "/train_annot_folder/",

"train_times": 10, # the number of time to cycle through the training set, useful for small datasets
"pretrained_weights": "", # specify the path of the pretrained weights, but it's fine to start from scratch
Expand Down Expand Up @@ -109,15 +86,10 @@ The model section defines the type of the model to construct as well as other pa

Download pretrained weights for backend (tiny yolo, full yolo, squeezenet, mobilenet, and inceptionV3) at:

https://1drv.ms/f/s!ApLdDEW3ut5fec2OzK4S4RpT-SU
https://drive.google.com/file/d/1gpOX-lfvyP70Pi2G77RIGzCBMHqO5Gic/view?usp=sharing

**These weights must be put in the root folder of the repository. They are the pretrained weights for the backend only and will be loaded during model creation. The code does not work without these weights.**

The link to the pretrained weights for the whole model (both frontend and backend) of the raccoon detector can be downloaded at:

https://1drv.ms/f/s!ApLdDEW3ut5feoZAEUwmSMYdPlY

These weights can be used as the pretrained weights for any one class object detectors.

### 3. Generate anchors for your dataset (optional)

Expand Down
20 changes: 10 additions & 10 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
"model" : {
"backend": "Full Yolo",
"input_size": 416,
"anchors": [0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828],
"anchors": [1.57,1.77, 2.80,8.62, 3.60,3.36, 5.51,10.50, 9.22,11.30],
"max_box_per_image": 10,
"labels": ["kangaroo"]
"labels": ["helmet","person with helmet","person without helmet"]
},

"train": {
"train_image_folder": "/home/andy/data/kangaroo/images/",
"train_annot_folder": "/home/andy/data/kangaroo/annots/",
"train_image_folder": "train_image_folder\\",
"train_annot_folder": "train_annot_folder\\",

"train_times": 8,
"pretrained_weights": "full_yolo_kangaroo3.h5",
"batch_size": 16,
"train_times": 10,
"pretrained_weights": "",
"batch_size": 2,
"learning_rate": 1e-4,
"nb_epochs": 1,
"warmup_epochs": 3,
"nb_epochs": 50,
"warmup_epochs": 0,

"object_scale": 5.0 ,
"no_object_scale": 1.0,
"coord_scale": 1.0,
"class_scale": 1.0,

"saved_weights_name": "full_yolo_kangaroo.h5",
"saved_weights_name": "full_yolo_helmet_and_person.h5",
"debug": true
},

Expand Down
Binary file added helmet_detection.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tensorflow-gpu==1.3
tensorflow-gpu==1.4
keras==2.0.8
imgaug
opencv-python
h5py
tqdm
26 changes: 26 additions & 0 deletions train_annot_folder/applauding_001.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_001.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_001.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>300</width>
<height>400</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>30</xmin>
<ymin>57</ymin>
<xmax>250</xmax>
<ymax>322</ymax>
</bndbox>
</object>
</annotation>
38 changes: 38 additions & 0 deletions train_annot_folder/applauding_002.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_002.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_002.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>421</width>
<height>300</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>6</xmin>
<ymin>49</ymin>
<xmax>161</xmax>
<ymax>231</ymax>
</bndbox>
</object>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>205</xmin>
<ymin>16</ymin>
<xmax>420</xmax>
<ymax>277</ymax>
</bndbox>
</object>
</annotation>
26 changes: 26 additions & 0 deletions train_annot_folder/applauding_003.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_003.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_003.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>466</width>
<height>300</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>271</xmin>
<ymin>86</ymin>
<xmax>435</xmax>
<ymax>292</ymax>
</bndbox>
</object>
</annotation>
26 changes: 26 additions & 0 deletions train_annot_folder/applauding_004.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_004.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_004.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>300</width>
<height>417</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>1</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>66</xmin>
<ymin>19</ymin>
<xmax>246</xmax>
<ymax>417</ymax>
</bndbox>
</object>
</annotation>
26 changes: 26 additions & 0 deletions train_annot_folder/applauding_005.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_005.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_005.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>300</width>
<height>451</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>1</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>91</xmin>
<ymin>60</ymin>
<xmax>224</xmax>
<ymax>451</ymax>
</bndbox>
</object>
</annotation>
26 changes: 26 additions & 0 deletions train_annot_folder/applauding_007.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_007.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_007.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>410</width>
<height>400</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>159</xmin>
<ymin>15</ymin>
<xmax>396</xmax>
<ymax>302</ymax>
</bndbox>
</object>
</annotation>
26 changes: 26 additions & 0 deletions train_annot_folder/applauding_008.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>non_workers</folder>
<filename>applauding_008.jpg</filename>
<path>D:\Workspace\YOLO_annotation\dataset_images\non_workers\applauding_008.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>450</width>
<height>300</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>person without helmet</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>211</xmin>
<ymin>28</ymin>
<xmax>314</xmax>
<ymax>232</ymax>
</bndbox>
</object>
</annotation>
Loading