How to Train YOLOv5 on Custom Objects?
This tutorial is based on the YOLOv5 repository with Google Collab.
This notebook shows training on your own custom objects with
Data Annotation Tools at Roboflow.
Steps Covered in this Tutorial
In this tutorial, we will walk through the steps required to train YOLOv5 on your custom objects. We use a public blood cell detection datasets, which is open source and free to use. You can also use this notebook on your own data.
To train our detector we take the following steps:
- Annotation the unlabeled data using Roboflow
- Install YOLOv5 dependencies
- Download custom YOLOv5 object detection data
- Write our YOLOv5 Training configuration
- Run YOLOv5 training
- Evaluate YOLOv5 performance
- Visualize YOLOv5 training data
- Run YOLOv5 inference on test images
- Export saved YOLOv5 weights for future inference
1- Annotation Data with Roboflow Annotation Platform:
Roboflow provides everything you need to turn images into information. We build all the tools necessary to start using computer vision, even if you’re not a machine learning expert (and to supercharge your pipeline if you are).
- Adding Data
To get started, create an account using your email or GitHub account: https://app.roboflow.com
After reviewing and accepting the terms of service, you’ll land on your project’s homepage,
Click “Create New Project” and then select dataset folder
Once you selected the human-dataset folder into Roboflow, the images and annotations are processed for you to see them
You will be asked to select a train/test split for your images; the default of 70% training, 20% validation,
and 10% testing is usually a safe bet.
2. Annotating Images:
One of the images in the sample dataset is not yet annotated.
You will use Roboflow Annotate to add a box around the unlabeled chess piece in the image.
Annotations are the “answer key” your computer vision model learns from.
3. Preprocessing and Augmentations:
After you’re done annotating, continue to generate a new version of your datasets. This creates a point-in-time snapshot
of your images processed in a particular way (think of it a bit like version control for data).
If you’ve worked with computer vision, you’ll note augmentations are typically performed at the time of training your models.
Augmenting before training has three notable advantages.
First, it improves model reproducibility, easing debugging and performance improvement. For example, your model might quietly perform better on images captured in brighter rooms. By having a copy of the darker augmentations, debugging with inference is far easier.
Second, augmenting first reduces your training time and cost. When training with GPUs, augmentations are CPU-constrained operations. Thus, your GPUs are kept waiting for CPU operations to finish augmentations, increasing your training time and costs. (Saving around 12% training costs in our tests!)
Third, instead of (re)writing your augmentation scripts (or model config files) for each different model you train, you can have a consistent set of augmentations and images to compare across models head-to-head.
4. Exporting Data from Roboflow for Training:
let’s use the “YOLOv5 PyTorch” export format. When you click “Export”, your dataset is zipped, and you are given
several options for using it.
Click the “your dataset” link to download your zipped export to your computer. It contains an export folder with your images
and annotations and a README describing the transformations you provided to your data