Week 7— Object Detection for Blind People

Burakkarademir
bbm406f19
Published in
4 min readJan 12, 2020

Hello everyone, this is our last week. This week I will show you how to train YOLO with your dataset.

Firstly we need darknet. We can download and install it with this command:

git clone https://github.com/pjreddie/darknet
cd darknet
make

Then we need to download the images which belong to the object or person we want to detect. We need to collect all images under the /darknet/data/name_of_folder.

Preparing the Dataset

In order to detect objects with YOLO, we need to determine the bounding box of the person or object we want to recognize in the downloaded images. We are going to use the BBox Label Tool. Let’s clone the Github repo to our own computer and change the file path on line 128 in main.py by specifying the full path to the folder where we downloaded the BBox Label Tool. Also, we may need to change the picture extension. (jpg,jpeg..)

After that, we need to delete the files under the 001 (Examples/001, Images/001, Labels/001). Then we need to copy our images into Images/001. Then run main.py with this command: python main.py

In the Image Dir field, type 001, and then select Load, the images will be loaded from the BBox-Label-Tool / Images / 002 folder.

Then mark the person or object we want to recognize in the picture so that it is enclosed in the smallest frame and move on to the next picture.

After finishing the marking all of the images we will see that a .txt file created with the name of the image file under the BBox-Label-Tool / Labels / 002 folder. In this file, you will see the pixel coordinates of the frame we marked on the picture as follows.

Converting .txt Files into YOLO Format

For converting we are going to use convert.py script.

Let’s edit the convert.py file as follows;

15th line classes = [“002”] (our tag value)
34th line mypath = “/ …. / BBox-Label-Tool / Labels / 002 /” (the folder where the coordinates we tagged BBox Label Tool are saved)
35th line outpath = …./ darknet / data / name_of_folder/ ”(the folder where the new YOLO darknet library is located)
37th line cls = “001”

Then run convert.py with this command: python convert.py. After that, it creates .txt files into …/darknet/data/ataturk_dataset/name_of_folder.

Dividing the Dataset

For dividing the dataset we are going to use process.py. Let change the process.py 7th line (path_data) with ‘data/name_of_folder/’ which includes the .txt files and images. Then run the script : python process.py. After that, it creates train.txt and test.txt files into ‘data/name_of_folder/’.

Preparation of Configuration Files

We need to create obj.data, obj.names, yolo-obj.cfg files under the cfg folder.

obj.data :

classes= 1
train = /…/darknet/data/name_of_folder/train.txt
valid = /…/darknet/data/name_of_folder/test.txt
names = /…/darknet/cfg/ataturk-obj.names
backup = /…/darknet/backup/

obj.names:

Name of our object

Finally, create a copy of the existing yolo-voc.cfg (under darknet/cfg/ file) and change the file name to yolo-obj.cfg.

Update the batch value on line 3 to 64 (you can set it as you like)
Let’s update the value of the subdivision in line 4 to 8 (you can set it according to the number of GPU and CPU processors)
Since our class number is 1 (1 + 5) * 5 = 30 according to the formula (classes + 5) * 5 on line 237, let’s update filters = 30
Since the number of classes in the 244.sale is 1, let’s update it to 1.

We will start our training using ImageNet weights using pre-trained weights.
Let’s download the weight file here.

Training

Start training with this command:

sudo ./darknet detector train cfg/obj.data cfg/ yolo-obj.cfg darknet19_448.conv.23

Where to Stop Training?

When the average error value (avg) is quite low (such as 0.08s) among the results obtained during the training and no longer falls for a certain time, we can stop the training.

Thank you for reading.

See you on another project.

--

--

Burakkarademir
bbm406f19
0 Followers
Writer for

Computer engineering student at Hacettepe University