Skip to content

Commit

Permalink
Safdar Khan
Browse files Browse the repository at this point in the history
  • Loading branch information
msafdarkhan committed May 16, 2019
1 parent 8089734 commit bfca0ad
Show file tree
Hide file tree
Showing 535 changed files with 13,259 additions and 0 deletions.
43 changes: 43 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
COPYRIGHT

All contributions by François Chollet:
Copyright (c) 2015 - 2018, François Chollet.
All rights reserved.

All contributions by Google:
Copyright (c) 2015 - 2018, Google, Inc.
All rights reserved.

All contributions by Microsoft:
Copyright (c) 2017 - 2018, Microsoft, Inc.
All rights reserved.

All other contributions:
Copyright (c) 2015 - 2018, the respective contributors.
All rights reserved.

Each contributor holds copyright over their respective contributions.
The project versioning (Git) records all such contribution source information.

LICENSE

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# [How to train an object detection model easy for free](https://www.dlology.com/blog/how-to-train-an-object-detection-model-easy-for-free/) | DLology Blog



## How to Run

Easy way: run [this Colab Notebook](https://colab.research.google.com/github/Tony607/object_detection_demo/blob/master/tensorflow_object_detection_training_colab.ipynb).

Alternatively, if you want to use your images instead of ones comes with this repo.

Require [Python 3.5+](https://www.python.org/ftp/python/3.6.4/python-3.6.4.exe) installed.
### Fork and clone this repository to your local machine.
```
https://github.com/Tony607/object_detection_demo
```
### Install required libraries
`pip3 install -r requirements.txt`


### Step 1: Annotate some images
- Save some photos with your custom object(s), ideally with `jpg` extension to `./data/raw` directory. (If your objects are simple like ones come with this repo, 20 images can be enough.)
- Resize those photo to uniformed size. e.g. `(800, 600)` with
```
python resize_images.py --raw-dir ./data/raw --save-dir ./data/images --ext jpg --target-size "(800, 600)"
```
Resized images locate in `./data/images/`
- Train/test split those files into two directories, `./data/images/train` and `./data/images/test`

- Annotate resized images with [labelImg](https://tzutalin.github.io/labelImg/), generate `xml` files inside `./data/images/train` and `./data/images/test` folders.

*Tips: use shortcuts (`w`: draw box, `d`: next file, `a`: previous file, etc.) to accelerate the annotation.*

- Commit and push your annotated images and xml files (`./data/images/train` and `./data/images/test`) to your forked repository.


### Step 2: Open [Colab notebook](https://colab.research.google.com/github/Tony607/object_detection_demo/blob/master/tensorflow_object_detection_training_colab.ipynb)
- Replace the repository's url to yours and run it.


## How to run inference on frozen TensorFlow graph

Requirements:
- `frozen_inference_graph.pb` Frozen TensorFlow object detection model downloaded from Colab after training.
- `label_map.pbtxt` File used to map correct name for predicted class index downloaded from Colab after training.

You can also opt to download my [copy](https://github.com/Tony607/object_detection_demo/releases/download/V0.1/checkpoint.zip) of those files from the GitHub Release page.


Run the following Jupyter notebook locally.
```
local_inference_test.ipynb
```
# [How to run TensorFlow object detection model faster with Intel Graphics](https://www.dlology.com/blog/how-to-run-tensorflow-object-detection-model-faster-with-intel-graphics/) | DLology Blog

## How to deploy the trained custom object detection model with OpenVINO

Requirements:
- Frozen TensorFlow object detection model. i.e. `frozen_inference_graph.pb` downloaded from Colab after training.
- The modified pipeline config file used for training. Also downloaded from Colab after training.

You can also opt to download my [copy](https://github.com/Tony607/object_detection_demo/releases/download/V0.1/checkpoint.zip) of those files from the GitHub Release page.

Run the following Jupyter notebook locally and follow the instructions in side.
```
deploy/openvino_convert_tf_object_detection.ipynb
```
## Run the benchmark

Examples

Benchmark SSD mobileNet V2 on GPU with FP16 quantized weights.
```
cd ./deploy
python openvino_inference_benchmark.py\
--model-dir ./models/ssd_mobilenet_v2_custom_trained/FP16\
--device GPU\
--data-type FP16\
--img ../test/15.jpg
```
TensorFlow benchmark on cpu
```
python local_inference_test.py\
--model ./models/frozen_inference_graph.pb\
--img ./test/15.jpg\
--cpu
```
Binary file added data/images/test/IMG_20180914_152212_376.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20180914_152212_376.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20180914_152212_376.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20180914_152212_376.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1150</width>
<height>960</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>492</xmin>
<ymin>125</ymin>
<xmax>622</xmax>
<ymax>290</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181023_182007_096.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181023_182007_096.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181023_182007_096.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181023_182007_096.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>1080</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>376</xmin>
<ymin>278</ymin>
<xmax>425</xmax>
<ymax>334</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181104_015628_569.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181104_015628_569.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181104_015628_569.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181104_015628_569.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>343</xmin>
<ymin>277</ymin>
<xmax>967</xmax>
<ymax>1028</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181107_004101_167.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181107_004101_167.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181107_004101_167.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181107_004101_167.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>594</xmin>
<ymin>842</ymin>
<xmax>874</xmax>
<ymax>1202</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181110_073826_071.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181110_073826_071.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181110_073826_071.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181110_073826_071.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>223</xmin>
<ymin>795</ymin>
<xmax>543</xmax>
<ymax>1184</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181110_131436_227.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181110_131436_227.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181110_131436_227.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181110_131436_227.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>380</xmin>
<ymin>391</ymin>
<xmax>683</xmax>
<ymax>726</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181110_131518_192.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181110_131518_192.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181110_131518_192.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181110_131518_192.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>440</xmin>
<ymin>306</ymin>
<xmax>583</xmax>
<ymax>471</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181110_131831_491.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181110_131831_491.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181110_131831_491.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181110_131831_491.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>405</xmin>
<ymin>153</ymin>
<xmax>589</xmax>
<ymax>362</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181111_034327_127.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/test/IMG_20181111_034327_127.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<annotation>
<folder>Instagram</folder>
<filename>IMG_20181111_034327_127.jpg</filename>
<path>E:\Blind Vision Shirt\my data\Instagram\IMG_20181111_034327_127.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1080</width>
<height>2076</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bilal</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>214</xmin>
<ymin>275</ymin>
<xmax>576</xmax>
<ymax>786</ymax>
</bndbox>
</object>
</annotation>
Binary file added data/images/test/IMG_20181113_005955_104.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bfca0ad

Please sign in to comment.