YOLOv3 is one of the most popular real-time object detectors in Computer Vision. If you heard something more popular, I would like to hear it.
In my previous tutorials, I showed you, how to simply use YOLO v3 object detection with the TensorFlow 2.x application and how to train Mnist custom object detection. At the end of the tutorial I promised, that I will show you how to train custom object detection. It was a challenging task, but I found a way to do that. However, before training a custom object detector, we must know where we may get a custom dataset or how we should label it, so in this tutorial, I will show you where you could get labeled dataset, how to prepare it for training, and finally how to train it!
In this step-by-step tutorial, I will start with a simple case of how to train a 7-class object detector (we could use this method to get a dataset for every detector you may use). Therefore, I will build a Vehicle registration plate, Traffic sign, Traffic light, Car, Bus, Truck, and Person object detector.
As with any deep learning task, the first most important task is to prepare the training dataset. Dataset is the fuel that runs any deep learning model.
Same as in my past tutorials, I will use images from Google’s OpenImagesV6 dataset, publicly available online. It is a very big dataset with more than 600 different categories of an object. The dataset contains the bounding box, segmentation, or relationship annotations for these objects. As a whole, the dataset is more than 600GB of size, but we will download the images and classes only needed for our custom detector.
So, we have a link to this large dataset, but it’s not explained how we should download images and labels we need, should we download them one by one? No, there is an amazing OIDv4 ToolKit from GitHub with a full explanation of how to use it.
This toolkit really makes our life easier when we want to train a custom object detection model with popular objects and when we don’t know where to get labeled images. This toolkit allows downloading images from OID v6 seamlessly. The installation is easy and clearly explained in the readme file. The toolkit is loaded with a variety of options. For example, the OIDv4 Toolkit allows us to download almost any particular class of interest from the given database. You can explore this dataset and you can check if there is a class you need for custom detection.
The toolkit can be downloaded from link I mentioned above or cloned by the following command:
git clone ``[https://github.com/pythonlessons/OIDv4_ToolKit.git](https://github.com/pythonlessons/OIDv4_ToolKit.git)
If you installed requirements from my original project, you can skip the following step, otherwise, the first thing you should do is install necessary packages:
pip install -r OIDv4_ToolKit/requirements.txt
At first start, you will be asked to download class-descriptions-boxable.csv (contains the name of all 600+ classes with their corresponding ‘LabelName’), test-annotations-bbox.csv and train-annotations-bbox.csv (the file contains one bounding box (bbox for short) coordinates for one image, and it also has this bbox’s Label Name and current image’s ID from the validation set of OIDv6) files to OID/csv_folder directory.
First, we should check if the database has an appropriate image class we need? Usually, I go to OIDv6 page -> click on explore and in a search tab try to find my needed class. In my example, I will search for “Vehicle registration plate”, “Traffic sign”, “Traffic light”, “Car”, “Bus”, “Truck”, and “Person”. To download all of them I simply can use OIDv4_ToolKit. First, open OIDv4_ToolKit directory: cd OIDv4_ToolKit
, and from there open terminal. In terminal write following command:
python main.py downloader --classes 'Vehicle registration plate' 'Traffic sign' 'Traffic light' Car Bus Truck Person --type_csv train --limit 2000
With this command, I will download 2000 training images for each class, and place them in the train folder. As I mentioned before if you are using this for the first time, this will first download train-annotations-bbox.csv CSV file and download the requested images from the specified class.
After it finished downloading training dataset, do the same for test dataset:
python main.py downloader --classes 'Vehicle registration plate' 'Traffic sign' 'Traffic light' Car Bus Truck Person --type_csv test --limit 200
After downloading the test and train dataset, folders structure should look following:
TensorFlow-2.x-YOLOv3
│ ...
│ train.py
│ detection_custom.py
│ ...
└─── OIDv4_ToolKit
│
└─── OID
│
└─── csv_folder
│ │
│ └─── class-descriptions-boxable.csv
│ │
│ └─── test-annotations-bbox.csv
│ │
│ └─── train-annotations-bbox.csv
│
└─── OID
│
└─── Dataset
│
└─── train
│ │
│ └─── Bus, Car, Person, ...
│
└─── test
│
└─── Bus, Car, Person, ...
#computer-science #yolo #deep learning