How to Train a YOLOv5 Model On a Custom Dataset
Published Jan 10, 2026 • 6 min read
SUMMARY

If you have existing YOLOv5 weights you can upload them and run inference through Roboflow's Serverless Hosted API. You can train a custom object detector by labeling in the browser, generating a dataset version, and training in the cloud in under an hour. Train RF-DETR, which fine-tunes fast, runs in real time, and ships under Apache 2.0.

If you set out to train YOLOv5 on a custom dataset, what you actually want is an object detector that works on your own images, without cloning a repo, editing a model config, or babysitting a Colab GPU. This guide gets you there in the browser: label your images, generate a dataset version, and train a model in the cloud.

The model you train is Roboflow's RF-DETR, a real-time detection transformer that fine-tunes fast, reaches state-of-the-art accuracy, and ships under a permissive Apache 2.0 license, so it goes to production without licensing friction.

We use a blood cell detection dataset (BCCD) as the running example, since finding and classifying red blood cells, white blood cells, and platelets is a clean stand-in for any task where you locate many objects in one frame. Swap in your own images at any step, the process is the same.

What Is YOLOv5?

YOLOv5 is a single-stage object detection model released in 2020, built in the PyTorch framework. It became popular because it trained quickly, ran fast, and was straightforward to use compared with the Darknet-based detectors before it.

How YOLOv5 Is Structured

YOLOv5 detects objects in a single forward pass with a CSP-based convolutional backbone, a feature-pyramid neck, and an anchor-based detection head. It ships in a range of sizes, YOLOv5s, m, l, and x, that trade speed for accuracy, and trains at input resolutions like 640x640 or 1280x1280. Training it the traditional way means cloning the repository, editing a YAML model config to set your class count and anchors, and running a training script on a GPU you provision yourself.

Where YOLOv5 Fits Today

YOLOv5 is a useful reference for how modern single-stage detectors are put together, and it is still fast. For a detector you plan to build on and deploy, transformer-based architectures now match or exceed it on accuracy while being simpler to train and ship.

That is why this guide trains RF-DETR. RF-DETR fine-tunes on a custom dataset in a fraction of the time a from-scratch training loop takes, runs in real time, and comes with a clean commercial license and a direct deployment path. You keep the real-time detection goal YOLOv5 was built for, without the repo, the config file, or the GPU setup that make the original hard to reproduce.

Training an object detector on your own images

The goal is a model that puts a labeled box around every object you care about. BCCD is 364 images with roughly 4,900 labels, which is small by deep learning standards. With transfer learning from a COCO-pretrained checkpoint, that is plenty: a few hundred well-labeled images gets you a working detector, no million-image dataset required. Follow the complete steps to train a custom RF-DETR model here. Here's a quick overview:

What you need

A free Roboflow account, some images (yours, or a public dataset), and a browser. To call the model from a script afterward, you also need Python locally. There is no repository to clone, no CUDA to match, and no GPU to rent.

Step 1: Create a project

Sign in, create a new project, set the type to Object Detection, and name your classes. The project is the home for your images, annotations, dataset versions, and trained models.

Step 2: Upload your images

Drag your images in. To skip collection and labeling, you can fork the BCCD dataset, or any of the 200,000-plus datasets on Roboflow Universe, into your workspace already labeled. If you upload your own images, Roboflow reads existing annotations in YOLOv5 PyTorch TXT, COCO, Pascal VOC, and other formats, or leaves them unlabeled for the next step.

Step 3: Annotate your images

Label any unlabeled images in Roboflow Annotate. Auto Label drafts annotations with a foundation model for you to review, and Label Assist pre-draws boxes as you go so you confirm rather than draw each one. Tight, consistent boxes move final accuracy more than any training setting.

Step 4: Generate a dataset version

A version freezes your labeled images together with preprocessing and augmentation, and Roboflow auto-splits them into train, validation, and test sets. Auto-orient and resize are worth applying to almost any dataset. Augmentations such as flips and small rotations expand a small dataset and reduce overfitting, and Roboflow updates every bounding box for you when it transforms an image.

Step 5: Train your model

Open Roboflow Custom Training, choose RF-DETR, and train from the COCO-pretrained checkpoint so the model starts with broad object knowledge and only learns your classes. This is transfer learning, and it is why a few hundred images is enough. Training runs on Roboflow's cloud, so there is nothing to configure, and a small dataset like BCCD usually finishes in under an hour.

Try out RF-DETR in the interactive workflow below.

Step 6: Evaluate your model

When training finishes, Roboflow reports mean average precision (mAP) on the held-out test set, with precision and recall. Read the per-class numbers, not just the overall figure: BCCD skews heavily toward red blood cells, so a model can post a healthy average while missing the rarer platelets. When a class lags, add or relabel examples of it and retrain. Two or three of these passes is what turns a promising model into a production-ready one.

Step 7: Run inference

Serve the trained model through the Serverless Hosted API and call it from a few lines of Python. Install the SDK:

pip install inference-sdk supervision

Then run the model on an image, with your API key supplied through an environment variable:

import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.getenv("ROBOFLOW_API_KEY"),
)

# model_id is "project-name/version", e.g. "your-project/1"
result = client.infer("image.jpg", model_id="your-project/1")

image = cv2.imread("image.jpg")
detections = sv.Detections.from_inference(result)

box_annotator = sv.BoxAnnotator()
label_annotator = sv.LabelAnnotator()
annotated = box_annotator.annotate(scene=image.copy(), detections=detections)
annotated = label_annotator.annotate(scene=annotated, detections=detections)
cv2.imwrite("annotated.png", annotated)

The supervision library handles drawing and post-processing so you are not writing box math by hand.

Step 8: Deploy to production

To run the model where your images are, Roboflow Inference is the open source engine that serves it on the cloud, on-prem, or at the edge on devices like NVIDIA Jetson, using the same model ID. To add application logic without building a service, Roboflow Workflows is a low-code builder for chaining the model with steps like filtering by class, counting, and triggering actions. And if you work with a coding agent, the Roboflow MCP server connects your workspace to tools like Claude Code, Codex, and Cursor over the Model Context Protocol.

Why RF-DETR for Custom Object Detection?

YOLOv5 was built for real-time detection that trains quickly, and it delivered for its era. RF-DETR reaches that goal with an architecture and workflow suited to production today. It fine-tunes fast, so the evaluate-and-retrain loop is quick. It runs in real time, so the model you train for analysis drops straight into a live pipeline. It ships under an Apache 2.0 license, so commercial deployment is unambiguous. And it lives in one platform from labeling to training to deployment, so there is no repo, config file, or separate serving stack to maintain.

Can I still train YOLOv5 in Roboflow?

Training YOLOv5 in Roboflow is deprecated for new projects. YOLOv5 inference is still supported: you can upload your own trained YOLOv5 weights to a Roboflow project and run them through the Serverless Hosted API for object detection or instance segmentation, or self-host with Roboflow Inference. Note that commercial use of YOLOv5 requires a license from its maintainers. Learn more in the YOLOv5 docs.

Train a YOLOv5 Model on a Custom Dataset

You can train a custom object detection model on your own images today, entirely in the browser, and have a deployable model in an afternoon. Create a free Roboflow account and start with your dataset or one from Universe.

YOLOv5 Custom Dataset Training

Cite this Post

Use the following entry to cite this post in your research:

Erik Kokalj. (Jan 10, 2026). How to Train a YOLOv5 Model On a Custom Dataset. Roboflow Blog: https://blog.roboflow.com/how-to-train-yolov5-on-a-custom-dataset/

Stay Connected
Get the Latest in Computer Vision First
Unsubscribe at any time. Review our Privacy Policy.

Written by

Erik Kokalj
Developer Experience @ Roboflow