Labeling data correctly is crucial for training an accurate object detection model with YOLOv5. A well-annotated dataset ensures that your model learns to detect objects effectively, ultimately improving performance during inference. This guide will walk you through the process of labeling images for YOLOv5, from selecting the right tool to organizing your data properly.
1. Understanding YOLOv5 Annotation Format
YOLOv5 uses a simple text-based annotation format where each image has a corresponding .txt file. Each line in this file represents an object in the image with the following values:
- Class index: The integer index representing the detected object’s class.
- Normalized x-center: Center x-coordinate of the bounding box, scaled between 0 and 1.
- Normalized y-center: Center y-coordinate of the bounding box, scaled between 0 and 1.
- Normalized width: Bounding box width, scaled between 0 and 1.
- Normalized height: Bounding box height, scaled between 0 and 1.
For example, if an object of class “car” (index 0) has a bounding box centered at (0.5, 0.5) with a width of 0.4 and height of 0.3, the annotation would look like:
0 0.5 0.5 0.4 0.3
2. Choosing the Right Labeling Tool
There are several annotation tools available that support YOLOv5 format. Below are a few popular options:
- LabelImg: A simple and widely used annotation tool with support for YOLO format.
- Roboflow: A cloud-based annotation platform that allows team collaboration.
- CVAT (Computer Vision Annotation Tool): Provides advanced annotation features such as video support.
- LabelMe: Browser-based annotation tool with easy-to-use interface.
Depending on your project size and team collaboration needs, you can choose a tool that best suits your workflow.

3. Installing and Using LabelImg
If you are looking for a quick way to annotate images, LabelImg is a great choice. Follow these steps to set up and use LabelImg:
- Install LabelImg: You can install it using Python with the following command:
- Launch LabelImg: Run the tool by executing:
- Open Image Directory: Load the folder containing the images you want to annotate.
- Start Annotation: Draw bounding boxes around desired objects and assign the correct class labels.
- Save Annotations: Ensure to save in YOLO format (.txt files will be created).
pip install labelImg
labelImg
LabelImg automatically saves annotations with the same filename as the corresponding image but with a .txt extension.
4. Structuring Your Dataset
Once annotation is complete, it’s essential to organize your dataset properly for training with YOLOv5. A typical dataset structure looks like this:
dataset/
├── images/
│ ├── train/
│ ├── val/
│ ├── test/
├── labels/
│ ├── train/
│ ├── val/
│ ├── test/
Each image should have a corresponding label file inside the labels directory.

5. Validating Annotations
Before training YOLOv5, it’s crucial to verify that labels are correctly assigned. You can use the following methods:
- Check a few labeled files manually – Open the .txt files and ensure they match the objects in the image.
- Use Roboflow – Roboflow allows you to visualize annotations online before training.
- Run a quick test with YOLOv5 – Use `train.py` in YOLOv5 to detect potential labeling errors.
6. Importing Your Dataset into YOLOv5
Once you have labeled and structured your dataset, you need to prepare a data.yaml file that provides information about your dataset. Here’s an example configuration:
train: /path/to/dataset/images/train
val: /path/to/dataset/images/val
nc: 3
names: ['person', 'car', 'bike']
Make sure to update this file according to your dataset and ensure all paths are correct before starting training.
Conclusion
Proper labeling and dataset preparation play a crucial role in building an effective object detection model. By following these steps, you can ensure your YOLOv5 model will learn from accurately annotated data, leading to higher detection accuracy and better performance.
