Articles on: Datasets

How to Create a Dataset for Object Detection using the YOLO Labeling Format

The YOLO (You Only Look Once) format is a specific format for annotating object bounding boxes in images for object detection tasks. In this format, each image in the dataset should have a corresponding text file with the same name as the image, containing the bounding box annotations for that image. The text file should have the following format:


YOLO text file format

Where:

<object-class> is an integer representing the class of the object. The class index should start from 0 and increase by 1 for each unique class in the dataset.

<x-center> and <y-center> are the coordinates of the center of the bounding box, normalized by the width and height of the image, respectively. The values should be in the range of [0, 1].

<width> and <height> are the width and height of the bounding box, normalized by the width and height of the image, respectively. The values should be in the range of [0, 1].


Here's an example of a YOLO format annotation file for an image containing two objects, a car and a pedestrian:


Example of YOLO format annotation


This means that there is a car (class 0) with its center at (0.45 x image width, 0.6 x image height), and a width and height of 0.1 x image width and 0.2 x image height, respectively. There is also a pedestrian (class 1) with its center at (0.7 x image width, 0.8 x image height), and a width and height of 0.05 x image width and 0.1 x image height, respectively.

Finally, in order to train the object detection model in Cogniflow, you must create a zip file with two folders: labels and images. The txt files in the labels folder have the YOLO format annotation described above. Additionally, we require a classes.txt file to map each integer class with the corresponding name. Each line in classes.txt contains a class name. For the previous example where 0 is car and 1 is pedestrian the classes.txt file would look like this:


Example of classes.txt


Example of zip file with the required structure

You can use any tool of your choice to help you with the labeling process for an object detection task. If you do not have one, then our recommendation is to use the already deployed version of Label Studio which we provide access directly using your Cogniflow account. You can read this tutorial to learn how to use the integrated version of Label Studio and how to export your labeled dataset (with the structure presented in this article) ready to be used in Cogniflow.

Updated on: 10/02/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!