Turkish translation of this tutorial is located in the lang folder. If you would like to add new translation for this guide.You can request.
You can train your own object detection classifier on Windows 10,8 and 7. This repository written with TensorFlow 1.5.0 version. If you try with newer version of TensorFlow and different tensorflow models version, you can receive too many errors.
Also i published a YouTube video for this tutorial.
Video Link: https://www.youtube.com/watch?v=ZuG-k__yFrc
Statement
You can use TensorFlow (GPU) instead of TensorFlow (CPU) changing "pip install --ignore-installed --upgrade tensorflow==1.5.0" to "pip install --ignore-installed --upgrade tensorflow-gpu==1.5.0" and you need to install CUDA and cuDNN.
If you use GPU for training,you should have Nvidia GPU for trainig object detection classifier with TensorFlow. Also your graphic card should meet minimum requirements. TensorFlow required minimum 3.5 Compute Capability for training own object detection classifier. Compute Capability List For Each Graphic Card
If your graphic card is medium level, it take about 3 hours. And here is a table of compatible CUDA versions with TensorFlow.
Steps
1.Install Anaconda First of all we should download Anaconda that is a free and open-source distribution of the Python for package management.
You can follow steps from video.
2.Create TensorFlow directory If you don't want to train another version of TensorFlow, you can download this repository directly from here. And continue from third step.
2.1. Create folder in C:/ that named "tensorflow1". This directory will include our models,object_detection and training folder. We will work in "tensorflow1" directory.
2.2. Download TensorFlow models repository from above links. We use TensorFlow 1.5 version in this guide.
You can use your phone to take images. But they should be less then 200KB and their resolution should be less then 720x1280. After you take images you should copy %20 of them to "C:\tensorflow1\models\research\object_detection\images\test\" folder and %80 of them to "C:\tensorflow1\models\research\object_detection\images\train\" folder. Finally care to variety of pictures in folders.
In this step we should download "LabelImg" tool to label images from here.
6. Generate training record
First we should convert images xml data to csv. To do this:
(tensorflow1) C:\tensorflow1\models\research\object_detection>python xml_to_csv.py After that, edit generate_tfrecord.py with a text editor. Change label map with your own label map.
# TO-DO replace this with label map def class_text_to_int(row_label): if row_label == '200TL': return 1 elif row_label == '5TL': return 2 else: None
After that edit "C:\tensorflow1\models\research\object_detection\training\faster_rcnn_inception_v2_pets.config" file with a text editor to configure training.
a. Line 9 - Change num_classes to the number of objects you want to detect.For example; cat,dog,bird and person "num_classes:4"
e. Line 132 - Change num_examples to the number of images you have in the "C:\tensorflow1\models\research\object_detection\images\test" folder: num_examples: 89
f. Save your file and exit.
8. Run the train.py
If you use a newer version of TensorFlow ,train.py file is located in C:\tensorflow1\models\research\object_detection\legacy" folder. You can copy it to object_detection folder.
Let's run train.py! Run the following command from "C:\tensorflow1\models\research\object_detection" folder:
When training is completed,we generate inference graph file(.pb).Change "XXXX" with your highest number in your "C:\tensorflow1\models\research\object_detection\training" folder. Please run the following command to generate file from "C:\tensorflow1\models\research\object_detection" folder:
Generated file is located in "C:\tensorflow1\models\research\object_detection\inference_graph" folder.
10. Using own object detection classifier
If you want to detect with webcam run "Object_detection_webcam.py" that is located in "C:\tensorflow1\models\research\object_detection" folder.Before running "Object_detection_webcam.py" file ,edit "NUM_CLASSES = 2" section. Finally run following command: