Object Detection on Custom Dataset with Faster R-CNN
📌 Creating Anaconda Environment and Requirements
📌 Directories
After cloning this repo, upload from within the requirements.txt file.
Step 1
Download the Tensorflow model file from the link below. We will do the work in this directory. Upload this repo as .zip and unzipped into the directory where you will be working.
NOTE 📝 Change the name of the file you unzipped to models.
Step 2
Move the model in the repo, the file faster_rcnn_inception_v2_coco_2018_01_28 to the models/research/object_detection directory.
NOTE 📝 To find the missing files in the object_detection directory, move the missing files models/research/object_detection like in the object_detection.rar
Step 3
📣 Way 1: Specify pythonpathi in system environment variables. And create new system variable
📣 Way 2: Set environment in Command Prompt with command below.
Adım 4
Run the following commands in the model/research directory.
Move the setup.py file under the model/research folder. Then run the following commands in models/research directory to run the setup.py file we moved.
📌 Dataset Preparing
Your dataset must be in PASCAL VOC [1] format and each image must have its own tag file (with an .xml extension).
Step 1
Move the data you will use as test and train folders to models/research/object_detection/images directory.
Step 2
Run the code below in models/research/object_detection directory. In the images folder, test_labels.csv and train_labels.csv csv files will be created. You can check.
Step 3
Type your classes in the generate_tfrecord.py file as below.
Run the code below in models/research/object_detection directory.
Step 4 : Creating labelmap.pbtxt
- The first thing to do in this step is to move files faster_rcnn_inception_v2_pets.config, graph.pbtxt into models/research/object_detection/training directory.
- Then a file named labelmap.pbtxt should be created in models/research/object_detection/training directory.
⚠️ The extension of the labelmap file must be .pbtxt.
- Type your classes and ids in the labelmap.pbtxt file as below:
NOTE 📝 id = return values, name = name of your class in generate_tfrecord.py
NOTE 📝 Before the training models/research/object_detection/training folder must contain faster_rcnn_inception_v2_pets.config, graph.pbtxt, labelmap.pbtxt
Step 5
Change lines in faster_rcnn_inception_v2_pets.config as below in models/research/object_detection/training directory.
- Line 9: # write your class count
- Line 106: Write your fine_tune_checkpoint
- Line 123: Write your input path of train.record path.
- Line 125: Write your label map path.
- Line 130: Write the count of your test images in models/research/images/test folder.
- Line 135: Write your input path of test.record path.
- Line 137: Write your label map path.
📌Training
⚠️ Before the training models/research/object_detection/inference_graph folder must be empty.
For starting to train, run the command below in models/research/object_detection directory.
It will show like the following image.
📌Testing
Inference Graph
⚠️ Write the number of the last model.ckpt model created in the inference_graph directory in the XXXX part of the command.
Example: The number of my model, which was formed after the training I did, was “0” as follows.
Test Image
Step 1
Write the IDLE to your command and you will see screen like in the follow.
Step 2
Choose File/Open… from the left corner of the idle. Selec the Object_detection_image.py file in directory models/research/object_detection from the screen that opens.
Step 3
There are two options here. You can set the path of the test folder in the object_detection_image.py file, or you can move the image you want to test to the models/research / object_detection directory.
İpucu 🗝️ Here, the operations are carried out by moving the desired image to the test models / research / object_detection directory.
Write the number of classes the object detector can identify.
Step 4
Press F5 to Run Module.
NOTE 📝 If there is a problem with the displaying Accuracy metric, you have to set up according to right version of Tensorflow Model file.
Referanslar
[1] M. Everingham, L. Van Gool, C. K. I. Williams, J. Winn, and A. Zisserman, “The PASCAL Visual Object Classes Challenge 2007 (VOC2007) Results,” 2007.
You can reach the github codes from the link below;
You can reach the Turkish version of the article from the link below;