Using Ultralytics YOLO11 for new object detection

By ihsumlee , 18 March 2026
content

Below is a clear beginner-friendly workflow for teaching how to use Ultralytics YOLO11 for new object detection: data preparation, training, validation, and inference. Ultralytics supports YOLO11 through the same ultralyticspackage and uses the standard train / val / predict workflow. 

1. What you should learn first

you should understand the full pipeline:

  1. Collect images

  2. Annotate bounding boxes

  3. Organize the dataset in YOLO format

  4. Create a dataset YAML file

  5. Train a YOLO11 detection model

  6. Validate the trained model

  7. Run detection on new images/videos

  8. Inspect errors and improve the dataset

This matches the standard Ultralytics object detection workflow. 


2. Install the environment

Ultralytics recommends installing the package with pip:

pip install -U ultralytics

This installs the current stable ultralytics package used for YOLO11 training and inference. 

You can test installation with:

yolo version

or in Python:

from ultralytics import YOLO
print("Ultralytics imported successfully")

The Ultralytics docs support both CLI and Python API usage. 


3. Prepare training data

For object detection, each image needs:

  • the image file itself

  • one .txt label file with the same base filename

  • each row in the label file = one object

Ultralytics detection datasets use YOLO text labels in this form:

class_id x_center y_center width height

These values are normalized to the image size, meaning they are between 0 and 1. The dataset is usually split into trainand val sets, and optionally test. 

Recommended folder structure

my_dataset/
├── images/
│   ├── train/
│   │   ├── img001.jpg
│   │   ├── img002.jpg
│   ├── val/
│   │   ├── img101.jpg
│   │   ├── img102.jpg
│   └── test/
│       ├── img201.jpg
├── labels/
│   ├── train/
│   │   ├── img001.txt
│   │   ├── img002.txt
│   ├── val/
│   │   ├── img101.txt
│   │   ├── img102.txt
│   └── test/
│       ├── img201.txt
└── data.yaml

This train/val organization is the standard approach used by Ultralytics for custom object detection datasets. 

Example label file

If an image contains two objects:

0 0.520 0.410 0.300 0.220
1 0.180 0.670 0.120 0.200

That means:

  • object 1 belongs to class 0

  • object 2 belongs to class 1


4. Annotate the images

You can use any annotation tool that exports YOLO detection format, such as LabelImg, CVAT, or Roboflow. The key point is that the final output must match the YOLO label format and the class IDs must match the class list in data.yaml. This requirement follows the Ultralytics dataset format for detection. 

Good annotation rules

Please do:

  • draw tight boxes

  • label objects consistently

  • include different backgrounds, scales, and lighting

  • avoid missing objects

  • avoid wrong class names

  • keep train and val distributions similar

These are practical best practices; validation quality depends heavily on annotation quality and dataset coverage. Ultralytics also emphasizes augmentation and robust data diversity during training. 


5. Create

data.yaml

Example:

path: /path/to/my_dataset
train: images/train
val: images/val
test: images/test

names:
  0: bottle
  1: cup
  2: phone

This YAML tells Ultralytics where the dataset is and what class names correspond to each class ID. Custom datasets are passed through the data argument during training and validation. 


6. Choose a YOLO11 model

YOLO11 detection models follow names like:

  • yolo11n.pt → nano

  • yolo11s.pt → small

  • yolo11m.pt → medium

  • yolo11l.pt → large

  • yolo11x.pt → extra large

YOLO11 is supported in Ultralytics, and the examples for object detection use yolo11n.pt as a typical starting point. yolo11n.pt or yolo11s.pt is usually best because training is faster and hardware requirements are lower. 


7. Train the model

CLI version

yolo detect train model=yolo11n.pt data=/path/to/my_dataset/data.yaml epochs=100 imgsz=640 batch=16

Python version

from ultralytics import YOLO

model = YOLO("yolo11n.pt")
model.train(
    data="/path/to/my_dataset/data.yaml",
    epochs=100,
    imgsz=640,
    batch=16
)

Ultralytics documents training through both CLI and Python, and training mode is the standard mode for fitting a model to your custom dataset. 

Parameters you should know

  • model: pretrained YOLO11 weights

  • data: path to data.yaml

  • epochs: number of training rounds

  • imgsz: input image size

  • batch: batch size

These are standard training arguments in the Ultralytics configuration system. 

Beginner recommendation

  • start with yolo11n.pt

  • use imgsz=640

  • train with epochs=50 to 100

  • use a small clean dataset first

  • later increase data diversity


8. Where the results are saved

Ultralytics saves training outputs under a runs directory by default, including weights and plots. The best model is typically stored as:

runs/detect/train/weights/best.pt

This follows the standard Ultralytics training workflow and output structure. 


9. Validate the model

Validation measures how well the model performs on unseen validation data. Ultralytics validation mode reports metrics such as mAP50, mAP50-95, precision, and recall. 

CLI

yolo detect val model=runs/detect/train/weights/best.pt data=/path/to/my_dataset/data.yaml

Python

from ultralytics import YOLO

model = YOLO("runs/detect/train/weights/best.pt")
metrics = model.val(data="/path/to/my_dataset/data.yaml")
print(metrics.box.map)      # mAP50-95
print(metrics.box.map50)    # mAP50

Ultralytics explicitly documents model.val() and the returned box metrics for detection models. 

  • Precision: when the model predicts an object, how often it is correct

  • Recall: how many real objects the model successfully finds

  • mAP50: easier benchmark using IoU 0.50

  • mAP50-95: stricter and more comprehensive benchmark


10. Use the model for detection

After training, you can run prediction on new images, folders, videos, webcams, and streams. Ultralytics predict mode is designed for these inference tasks. 

CLI: detect on one image

yolo detect predict model=runs/detect/train/weights/best.pt source=/path/to/test.jpg

CLI: detect on a folder

yolo detect predict model=runs/detect/train/weights/best.pt source=/path/to/test_images/

CLI: detect on a video

yolo detect predict model=runs/detect/train/weights/best.pt source=/path/to/test_video.mp4

Python example

from ultralytics import YOLO

model = YOLO("runs/detect/train/weights/best.pt")
results = model.predict(source="/path/to/test.jpg", save=True, conf=0.25)

for r in results:
    print(r.boxes)

Ultralytics documents predict mode and Python inference through model.predict(...). 


11. A simple full teaching script

This is a good minimal example:

from ultralytics import YOLO

# 1. Load pretrained YOLO11 model
model = YOLO("yolo11n.pt")

# 2. Train on custom dataset
model.train(
    data="data.yaml",
    epochs=50,
    imgsz=640,
    batch=16
)

# 3. Validate the best model
best_model = YOLO("runs/detect/train/weights/best.pt")
metrics = best_model.val(data="data.yaml")
print("mAP50-95:", metrics.box.map)
print("mAP50:", metrics.box.map50)

# 4. Run prediction
best_model.predict(
    source="test.jpg",
    save=True,
    conf=0.25
)

This matches the documented train → val → predict pattern in the Ultralytics Python API. 


12. Common mistakes you make

A. Wrong label format

The label must be:

class_id x_center y_center width height

and values should be normalized. Wrong formatting will break training or degrade results. 

B. Class IDs do not match

data.yaml

If data.yaml says:

names:
  0: bottle
  1: cup

then class 0 must always mean bottle and class 1 must always mean cup.

C. Missing label files

Every training image that contains objects should have a matching label file.

D. Poor train/val split

Do not put nearly identical images into both train and val, or validation will look artificially good.

E. Too little diversity

If all images look the same, the model may fail in real scenes. Data diversity and augmentation matter for generalization. 


13. Suggested learning order

A very practical learning plan is:

Lesson 1: What is object detection?

Explain:

  • class label

  • bounding box

  • confidence

  • train / val / test

Lesson 2: Data annotation

 Labelling 20–50 images in YOLO format.

Lesson 3: Dataset structure

  • images/train, images/val

  • labels/train, labels/val

  • data.yaml

Lesson 4: Training

Run:

yolo detect train model=yolo11n.pt data=data.yaml epochs=50 imgsz=640

Lesson 5: Validation

Run:

yolo detect val model=runs/detect/train/weights/best.pt data=data.yaml

Lesson 6: Prediction

Run:

yolo detect predict model=runs/detect/train/weights/best.pt source=test.jpg

Lesson 7: Error analysis

  • false positives

  • missed objects

  • confusing classes

  • bad annotations

This aligns well with the documented Ultralytics workflow and performance evaluation process. 


14. Best beginner settings

For a first object detection project, a safe starting point is:

yolo detect train model=yolo11n.pt data=data.yaml epochs=50 imgsz=640 batch=8

Reason:

  • yolo11n.pt is lightweight

  • 640 is a common image size

  • smaller batch is easier on limited GPU memory

Model size choice is a practical tradeoff between speed and accuracy within the YOLO11 family. 


15. One-sentence summary

You can remember this:

Prepare labeled data → write data.yaml → train with YOLO11 → validate with mAP/precision/recall → use best.pt for detection on new images or videos. 

 

Tags