Skip to content

Computer Vision

Training a Custom YOLO Model: From Labeling to Deployment

A practical walkthrough of training a custom YOLO object detection model: collecting and labeling data, dataset format, training, reading the metrics, and deploying to production.

VisionColab TeamSoftware engineering & AI 5 min read
Object detection pipeline from labelled images to a trained model detecting objects

In shortTo train a custom YOLO object detector, collect images that match real conditions, label every object of interest with bounding boxes in YOLO format, describe the dataset in a small YAML file, fine-tune a pretrained model, check precision, recall and mAP on a held-out set, then export the model for the hardware it will run on. Data quality decides most of the result.

YOLO (“You Only Look Once”) models are popular for real-time object detection because they are fast, accurate and well supported. This guide follows the workflow our team uses on real computer vision projects, with official recommendations from the Ultralytics documentation.

Step 1: Define exactly what to detect

Write down each class and a rule for what counts as one instance. “Scratch” is too vague; “any visible scratch longer than 2 mm on the front panel” can be labeled consistently. Unclear class definitions are the most common reason for disappointing accuracy, because different labellers draw different boxes.

Step 2: Collect the right images

  • Use the same cameras, angles and lighting you will use in production.
  • Include variety: different times of day, backgrounds, object sizes and partial occlusion.
  • Include rare cases deliberately. If a defect appears once in a thousand items, you need a plan to capture enough examples.
  • Add background images with no objects, which help reduce false positives.

How much data? Ultralytics’ tips for best training results recommend at least 1,500 images and 10,000 labeled instances per class for strong production results, and about 0 to 10% background images. A proof of concept can start much smaller to test feasibility, but expect accuracy to improve as the dataset grows.

Step 3: Label the data

The Ultralytics guidance is clear: every instance of every class in every image must be labeled. Partial labeling teaches the model that unlabelled objects are background.

YOLO uses one text file per image. Each line describes one object: the class number, then the box center, width and height, all normalized to values between 0 and 1.

# labels/train/panel_0001.txt
# class  x_center  y_center  width  height
0 0.512 0.430 0.120 0.085
1 0.250 0.700 0.060 0.040

Labeling is often the slowest step. Modern tools can speed it up with AI-assisted annotation: a segmentation model such as Meta’s Segment Anything proposes outlines, and a person corrects them. Whatever tool you use, have a second person review a sample of labels for consistency.

Step 4: Organize the dataset

Split images into training and validation sets, typically around 80/20, making sure similar images such as consecutive video frames do not end up on both sides. Then describe the dataset in a YAML file:

# defects.yaml
path: datasets/defects
train: images/train
val: images/val
names:
  0: scratch
  1: dent

Images go in images/train and images/val, with matching label files in labels/train and labels/val.

Step 5: Train from pretrained weights

Start from a model pretrained on a large dataset rather than from scratch. It converges faster and usually performs better. With the Ultralytics Python package, a training run looks like this:

pip install ultralytics
yolo detect train data=defects.yaml model=yolo11n.pt epochs=100 imgsz=640

Check the Ultralytics documentation for the latest recommended model versions. Ultralytics advises training first with default settings to set a baseline before tuning anything. Smaller models (such as “n” or “s” sizes) are faster; larger ones are more accurate but need more computing power.

Step 6: Read the results correctly

MetricWhat it tells youWhen it matters most
PrecisionOf the objects the model detected, how many were realWhen false alarms are costly
RecallOf the real objects, how many the model foundWhen missing an object is costly, such as safety defects
mAP50Average precision with a lenient box-overlap thresholdQuick overall check
mAP50-95Average precision across stricter overlap thresholdsWhen exact box placement matters, such as measurement

Numbers alone are not enough. Look at the images the model gets wrong. Patterns in the errors, such as missed small objects or confusion in poor lighting, tell you what data to collect next.

Step 7: Improve with data, not just settings

  • Add more examples of the cases the model gets wrong.
  • Fix inconsistent or missing labels.
  • Increase image size if small objects are missed.
  • Try a larger model if speed allows.

Step 8: Deploy and monitor

Export the trained model to a format suited to your hardware, for example ONNX for general use or TensorRT for NVIDIA devices:

yolo export model=runs/detect/train/weights/best.pt format=onnx

Then test speed and accuracy on the real device, connect detections to your business system, and monitor performance on live data. Cameras move, lighting changes and products are updated, so plan to collect new examples and retrain periodically.

From detection to tracking and analysis

Detection is often only the first step. Adding object tracking lets you follow each object across video frames, count movements and measure behavior over time. VisionColab co-founder Mahmood Yousaf built EthoGrid, an open-source research tool that combines YOLO detection, tracking and automated statistical analysis to turn hours of laboratory video into research-ready data. The same pipeline approach applies to traffic, retail and manufacturing video.

Frequently asked questions

Do I need a GPU to train YOLO?

Training is far faster on a GPU. Cloud GPU instances or notebook services work well if you do not have local hardware. Small models can run inference on a CPU.

Can I start with fewer images than the recommendation?

Yes, for a proof of concept. A few hundred well-labeled, representative images can show whether the task is feasible. Production systems need more data, especially for rare cases.

Should I use YOLO or a cloud vision API?

Cloud APIs work for common objects. A custom YOLO model is better when your objects or defects are specific to your business, when you need to run on local hardware, or when you want control over cost and data. See What Is Computer Vision? for more on choosing an approach.

Work with a computer vision team

VisionColab builds custom detection, tracking and video analysis systems. See our computer vision services and AI development, or book a free consultation to discuss your use case.

Written by the VisionColab team

VisionColab designs and builds AI, web, mobile and cloud software for businesses. Our guides explain the decisions, costs and trade-offs involved in planning a software project.

Have a project in mind?

Share your goals and constraints. We will suggest a realistic scope and the right technology approach.