YOLOv8 single class training is used when a detector only needs to identify one target object category, such as helmets, vehicles, defects, tumors, license plates, or a specific animal. A custom one-class dataset normally assigns class ID 0 to every target object and defines only one class name in data.yaml. Ultralytics also provides the single_cls=True training option, which can treat all classes in an existing multi-class dataset as one class during training.
Single-class object detection is different from ordinary binary image classification. YOLOv8 still predicts bounding boxes and object locations; it simply does not need to distinguish between multiple object categories. This can simplify the classification objective, but model quality still depends heavily on dataset diversity, annotation accuracy, negative images, image resolution, and training configuration.
Introduction to YOLOv8 Single Class Training
Many object detection projects do not need dozens of classes. An industrial inspection system may only need to detect cracks, a security system may only need to locate people, and an agricultural detector may only need to identify one type of fruit.
In these situations, training a one-class YOLOv8 model can be simpler than maintaining a multi-class dataset. Every annotated target object belongs to the same category, which means its class ID is always 0.
A typical single-class detection project might look like:
Target object:
helmet
Class ID:
0
Number of classes:
1
YOLOv8 still learns object localization and confidence. The difference is that its classification problem contains only one foreground category.
Single-class training can be performed with a dataset that genuinely contains one class, or by enabling single_cls=True when you want an existing multi-class dataset to be treated as a single detection category. Ultralytics officially exposes single_cls as a training setting for this purpose.
What Is Single Class Training in YOLOv8?
Single class training means training the detector so that every labeled object belongs to one category.
For example, a license-plate detector might contain:
0 = license_plate
Every label therefore begins with:
0
rather than several possible IDs such as 0, 1, 2, or 3.
The detector still learns:
object presence
bounding box location
object size
confidence
but does not need to choose among multiple semantic categories.
Single Class vs Multi-Class Object Detection
A multi-class dataset might contain:
0 = car
1 = truck
2 = bus
3 = motorcycle
The model must determine both:
Where is the object?
and:
Which class is it?
A single-class dataset contains:
0 = vehicle
so all target objects are treated as the same category.
Conceptually:
Multi-Class Detection
Object
↓
Locate Bounding Box
↓
Choose Class
↓
car / truck / bus
versus:
Single-Class Detection
Object
↓
Locate Bounding Box
↓
Assign One Class
The localization problem can still be difficult even when classification is simple.
When Single Class Training Is Useful
Single-class training is useful when only one object category matters to the application.
Common examples include:
- license plate detection,
- helmet detection,
- defect detection,
- face detection,
- pothole detection,
- vehicle detection,
- specific wildlife monitoring,
- medical structure detection.
It can also be useful when a multi-class dataset contains several categories but your application only cares whether an object is present, not exactly which original category it belongs to. In that case, single_cls=True can collapse the dataset classes into one training class.
Prepare a Dataset for Single Class Training
Dataset quality remains one of the most important factors in one-class detection. A simple class structure does not compensate for poor annotations or insufficient diversity.
Your training images should represent the conditions the model will encounter after deployment, including difficult backgrounds, partially visible objects, small targets, different viewing angles, and images containing no target object.
Collect and Annotate Images
Collect images containing the target object under realistic conditions.
For example, a helmet detector should include:
front views
side views
small helmets
large helmets
bright scenes
dark scenes
crowded scenes
partially occluded helmets
different helmet designs
Bounding boxes should tightly surround each target object.
For YOLO detection, each object is represented by a normalized label row in the general format:
class_id x_center y_center width height
Ultralytics uses this standard detection annotation format for custom YOLO datasets.
Assign One Class ID to All Objects
For a genuine single-class dataset, every object should use:
class_id = 0
Example:
0 0.517 0.442 0.216 0.330
If an image contains three target objects:
0 0.221 0.415 0.123 0.215
0 0.507 0.476 0.156 0.284
0 0.782 0.394 0.137 0.244
All three labels use class ID 0.
Do not create class IDs such as:
1
2
3
for different instances of the same object. Class IDs represent semantic categories, not individual objects.
Split Data into Training and Validation Sets
Organize the dataset into training and validation splits.
A common structure is:
dataset/
├── images/
│ ├── train/
│ └── val/
├── labels/
│ ├── train/
│ └── val/
└── data.yaml
The training split is used for optimization, while the validation split measures generalization.
The validation data should contain the same type of real-world variation expected after deployment. Avoid putting nearly identical frames from the same video sequence into both training and validation sets, because this can make metrics look unrealistically strong.
Configure the YOLOv8 Data YAML File
The dataset YAML tells Ultralytics where the images are stored and what the class means.
For a one-class dataset, this file is especially simple.
A typical example is:
path: /datasets/helmet
train: images/train
val: images/val
names:
0: helmet
The important requirement is that the YAML class mapping matches the class IDs used in the label files. Ultralytics detection datasets use YAML configuration to define dataset paths and class names.
Define Train and Validation Paths
Suppose your dataset is stored at:
D:/datasets/helmet/
You can define:
path: D:/datasets/helmet
train: images/train
val: images/val
Ultralytics resolves these paths relative to the dataset root.
The corresponding directories become:
D:/datasets/helmet/images/train
D:/datasets/helmet/images/val
Make sure these folders exist before starting training.
Add the Single Class Name
For one class:
names:
0: helmet
Another example:
names:
0: crack
or:
names:
0: license_plate
Only class ID 0 should appear in labels for a true single-class dataset.
Verify Dataset Labels
Before training, check:
✓ all target objects use class 0
✓ no label uses class 1 or higher
✓ every label matches the correct image
✓ bounding boxes are normalized
✓ class name in YAML matches the target
A label such as:
2 0.50 0.45 0.20 0.30
would be invalid for a dataset that defines only:
0 = helmet
Label errors can produce training failures or incorrect model behavior.
How to Train YOLOv8 on a Single Class
Once the images, labels, and YAML file are ready, a single-class detector can be trained almost exactly like a normal YOLOv8 detector.
If the dataset itself already contains only one class, single_cls=True is usually unnecessary. The one-class names mapping already tells Ultralytics that the dataset contains one category.
The single_cls option becomes especially useful when the source dataset contains multiple class IDs but you want the trainer to treat all of them as one class. Current Ultralytics Train mode documents single_cls=False as the default and describes True as treating all classes in a multi-class dataset as one class.
Train Using the YOLO CLI
For a genuine one-class dataset:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
Because data.yaml contains one class, the model is trained for that target category.
A more complete command could be:
yolo detect train \
model=yolov8s.pt \
data=data.yaml \
epochs=150 \
imgsz=640 \
batch=16
You do not need a separate single-class YOLOv8 checkpoint.
Train Using Python
Using Python:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=100,
imgsz=640,
batch=16
)
This works normally when data.yaml defines one class.
A pretrained YOLOv8 model can therefore be fine-tuned directly for a single target category.
Use the single_cls Training Option
If your original dataset is multi-class but you want every object treated as one class:
yolo detect train model=yolov8n.pt data=data.yaml single_cls=True
Using Python:
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.train(
data="data.yaml",
epochs=100,
single_cls=True
)
Current Ultralytics documentation defines single_cls as treating all classes in a multi-class dataset as a single class during training.
For example:
Original dataset:
0 = car
1 = truck
2 = bus
with:
single_cls=True
becomes conceptually:
all objects
→ one detection class
If your dataset is already genuinely one class, enabling this setting normally adds no important benefit.
Choosing a YOLOv8 Model for Single Class Training
The number of classes does not automatically determine the ideal YOLOv8 model size.
A single target class can still be visually difficult. For example, detecting tiny defects in high-resolution industrial images may require more model capacity than detecting large vehicles in simple scenes.
Choose the model primarily according to object difficulty, dataset size, inference speed requirements, and available hardware.
Small vs Large YOLOv8 Models
Common YOLOv8 detection sizes include:
yolov8n
yolov8s
yolov8m
yolov8l
yolov8x
A smaller model is useful when:
fast inference matters
GPU memory is limited
dataset is relatively simple
edge deployment is required
A larger model may be useful when:
objects are difficult
images contain complex backgrounds
maximum accuracy matters
hardware resources are available
Start with Nano or Small when establishing a baseline before moving to a larger model.
Pretrained Weights vs Training from Scratch
For most one-class datasets, pretrained weights are the better starting point.
For example:
model = YOLO("yolov8n.pt")
allows the model to reuse features learned during pretraining.
Even though the original pretrained model contains many classes, its backbone has learned general visual features such as:
edges
textures
shapes
object boundaries
spatial patterns
These features can transfer to a one-class custom task.
Training from scratch is more appropriate when:
- the dataset is extremely large,
- the domain is very different,
- pretrained weights cannot be used,
- the experiment specifically requires random initialization.
Important Training Settings
Single-class training uses the same major hyperparameters as multi-class YOLOv8 training.
The fact that there is only one class does not eliminate the need to tune epochs, image size, batch size, optimizer behavior, and augmentation.
A strong workflow is to establish a baseline first and then tune only when validation performance indicates a specific weakness.
Epochs and Batch Size
Example:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 batch=16
epochs controls how many times the model passes through the training set.
batch controls how many images are processed together during each optimization step.
A small dataset may begin overfitting before a long training run finishes, so monitor validation performance and use early stopping when appropriate.
Image Size
A common setting is:
imgsz=640
For example:
yolo detect train model=yolov8n.pt data=data.yaml imgsz=640
If the target object is extremely small, a larger image size may preserve more useful detail.
For example:
imgsz=1024
may help small-object detection, but it also increases GPU memory and computation.
Learning Rate and Optimizer
YOLOv8 exposes optimizer-related settings such as:
optimizer
lr0
momentum
weight_decay
For most projects, begin with standard Ultralytics settings rather than immediately changing all optimizer parameters.
If training loss is unstable or convergence is unusually slow, then test controlled adjustments.
Data Augmentation
Augmentation can improve generalization by exposing the model to variation in:
object position
scale
orientation
lighting
background
Useful YOLO augmentation settings may include:
mosaic
mixup
scale
translate
degrees
hsv_h
hsv_s
hsv_v
However, every augmentation should remain realistic for the deployment environment.
For example, aggressive color augmentation may be inappropriate if color itself distinguishes the target object from similar negatives.
Evaluate a Single Class YOLOv8 Model
Single-class evaluation is simpler because there is only one target category, but several metrics still need to be considered.
Do not evaluate the model only by looking at a few successful predictions. Precision, recall, mAP, false positives, and false negatives provide a more reliable picture of performance.
Ultralytics validation mode provides detection metrics including precision, recall, and mAP. It also supports single_cls during validation when all classes should be evaluated as one.
Precision and Recall
Precision measures how many predicted objects are actually correct.
Conceptually:
High precision
→ few false positives
Recall measures how many real target objects are detected.
Conceptually:
High recall
→ few missed objects
A detector can have high precision but low recall if it only predicts the easiest objects.
mAP Performance
For a one-class model, mAP represents performance for that single category rather than an average across many classes.
Useful metrics include:
mAP50
mAP50-95
mAP50 measures average precision at IoU 0.50.
mAP50-95 averages AP across multiple IoU thresholds and is more demanding about localization quality.
False Positives and False Negatives
False positives occur when YOLO detects the target where it does not actually exist.
False negatives occur when the target exists but YOLO misses it.
For single-class applications, these errors can be especially important because there are no other predicted classes to inspect.
For example:
Helmet detector
False positive:
hat detected as helmet
False negative:
small helmet missed
Reviewing these failure cases often reveals what new training data is needed.
How to Improve Single Class Detection Accuracy
One-class training can still be difficult when the target resembles background objects or appears in many visual forms.
The most reliable improvements often come from better dataset design rather than simply increasing epochs.
Increase Dataset Diversity
Collect the target under many conditions.
For example:
different cameras
different backgrounds
different object sizes
different orientations
different lighting
partial occlusion
different distances
If every training image looks almost identical, the model may memorize the training environment rather than learn the general concept.
Add Difficult Negative Images
Negative images contain no target object.
They can be especially useful in single-class detection because they teach the model what not to detect.
Suppose a helmet detector produces false positives on:
hats
balls
round signs
construction equipment
Add images containing these confusing objects without helmet labels.
Conceptually:
Positive image
→ target exists
→ annotate it
Negative image
→ target absent
→ no object annotation
These hard negatives can help reduce false positives.
Improve Annotation Quality
Every target instance should follow the same annotation rules.
Check for:
missing boxes
loose bounding boxes
boxes cutting off objects
incorrect class IDs
duplicate annotations
Inconsistent annotation can be particularly damaging in one-class projects because all detection behavior depends on one target definition.
Tune Training Parameters
Once the dataset is strong, test controlled changes to:
epochs
imgsz
batch
lr0
optimizer
mosaic
close_mosaic
For small targets, image size may be especially important.
For overfitting, augmentation and training duration deserve investigation.
For false positives, difficult negative examples may provide more benefit than simply changing the confidence threshold.
Common Single Class Training Problems
Single-class training removes class competition but does not remove normal detection challenges.
Common problems include false positives on visually similar objects, missed small objects, annotation errors, and overfitting.
Model Detects Similar Objects Incorrectly
Suppose your target is:
helmet
but the model detects:
hat
round container
ball
as helmets.
This usually means the training data does not contain enough examples showing the visual difference between true targets and confusing negatives.
Add hard-negative images containing these objects.
Low Recall for the Target Class
Low recall means the detector misses many real objects.
Possible causes include:
- too few target examples,
- tiny objects,
- low image resolution,
- insufficient training,
- weak annotation consistency,
- excessive confidence threshold.
Analyze missed detections rather than immediately changing the model architecture.
Dataset Class ID Errors
A genuine one-class dataset should normally use only:
0
as its class ID.
If labels contain:
1
2
but the YAML contains only:
names:
0: target
the dataset configuration is inconsistent.
Verify all annotation files before training.
Overfitting on a Small Dataset
A one-class dataset can still overfit badly.
Signs include:
training loss improves
validation performance stops improving
predictions work on training-like images
new images perform poorly
Possible solutions include:
- more data,
- stronger realistic augmentation,
- fewer epochs,
- smaller model,
- pretrained weights,
- early stopping.
FAQs About YOLOv8 Single Class Training
Can YOLOv8 be trained on only one class?
Yes.
A one-class dataset can define:
names:
0: target
and every label can use class ID 0.
YOLOv8 can then be trained using the normal detection training workflow. Ultralytics also provides single_cls=True for treating all classes in an existing multi-class dataset as one class.
What does single_cls mean in YOLOv8?
single_cls is a boolean Ultralytics training setting.
When:
single_cls=True
all classes in a multi-class dataset are treated as one class during training. The current default is False.
For a dataset that already contains only one class, setting it to True is generally unnecessary.
How should labels be formatted for single class training?
For detection, every object should use:
0 x_center y_center width height
For example:
0 0.421 0.550 0.190 0.310
All coordinates should follow the standard normalized YOLO detection format, while 0 identifies the only class.
Do I need to change the YOLOv8 model architecture for one class?
Normally, no.
You can load a standard pretrained YOLOv8 detection checkpoint:
model = YOLO("yolov8n.pt")
and train it using a dataset YAML containing one class.
Ultralytics adapts the detector to the dataset class configuration during custom training, so a separate manually edited architecture is generally unnecessary for a normal one-class project.
Can I use pretrained weights for single class training?
Yes.
Using:
yolov8n.pt
yolov8s.pt
yolov8m.pt
as a starting point is usually beneficial because the pretrained model already contains useful visual features.
The final detector can then be fine-tuned for the single target category.
How many images are needed for one-class YOLOv8 training?
There is no fixed minimum.
The required amount depends on:
object complexity
background variation
target size
camera variation
model size
deployment conditions
A few hundred diverse images may be enough for a narrow controlled problem, while a robust detector for highly variable real-world environments may require thousands or considerably more.
Diversity and annotation quality are often more important than reaching a specific image count.
How can I reduce false positives in single class detection?
Useful approaches include:
add difficult negative images
increase dataset diversity
correct inconsistent labels
include visually similar non-target objects
evaluate confidence thresholds
review false-positive examples
Hard negatives are particularly useful because they directly teach the model that similar-looking objects should not be detected as the target.
Conclusion
YOLOv8 single class training is a straightforward way to create a detector that focuses on one object category.
For a genuine one-class custom dataset, the typical configuration is:
path: /datasets/target
train: images/train
val: images/val
names:
0: target
and each detection label uses:
0 x_center y_center width height
A basic training command is:
yolo detect train model=yolov8n.pt data=data.yaml epochs=100 imgsz=640
If the source dataset contains multiple classes but you want to collapse them into one detection category, current Ultralytics provides:
single_cls=True
for exactly that purpose.
The difference can be summarized as:
True one-class dataset
→ one class in data.yaml
→ all labels use class 0
→ single_cls usually unnecessary
Multi-class dataset treated as one class
→ keep source dataset
→ use single_cls=True
→ all classes trained as one category
Single-class training does not automatically make object detection easy. Localization quality, false positives, difficult negatives, tiny objects, dataset diversity, and annotation consistency remain critical.
For most projects, start with pretrained YOLOv8 weights, build a clean one-class dataset, include challenging negative images, monitor precision and recall, and only tune training parameters after establishing a strong baseline.
I’m Jane Austen, a skilled content writer with the ability to simplify any complex topic. I focus on delivering valuable tips and strategies throughout my articles.