Train a Model

YOLO-World, introduced in the research paper “YOLO-World: Real-Time Open-Vocabulary Object Detection”, shows a significant advancement in the field of open-vocabulary object detection by demonstrating that lightweight detectors, such as those from the YOLO series, can achieve strong open-vocabulary performance. This is particularly noteworthy for real-world applications where efficiency and speed are crucial, like edge applications.

Ultralytics YOLOv8 is a convolutional neural network that supports realtime object detection, instance segmentation, and other tasks. It can be deployed to a variety of edge devices.

In this guide, we show how to train a computer vision model without labelling using these two models.

Use YOLO-World to train a YOLOv8 Object Detection model

Autodistill allows you to use state-of-the-art foundation models that know a lot about a variety of objects to label data for your project. You can then train a new model with your labeled data. This whole process uses around a dozen lines of code.

To learn more about how autodistill works, read our overview guide or watch our YouTube tutorial.

In this guide, we will show you how to use

YOLO-World

to train a

YOLOv8

model.



To use

YOLO-World
to train a
YOLOv8
model, we will:

1. Install autodistill
2. Create a dataset
3. Find a prompt to label images in the dataset
4. Label our data with autodistill
5. Train a new
YOLOv8
model

Let's get started!

Autodistill allows you to use state-of-the-art foundation models that know a lot about a variety of objects to label data for your project. You can then train a new model with your labeled data. This whole process uses around a dozen lines of code.

To learn more about how autodistill works, read our overview guide or watch our YouTube tutorial.

In this guide, we will show you how to label data with

YOLO-World

.



To label data with

YOLO-World
, we will:

1. Install autodistill
2. Create a dataset
3. Find a prompt to label images in the dataset
4. Label our data with autodistill


Let's get started!

Step #1: Install Dependencies

First, install the following packages:

pip install autodistill autodistill-yolov8 autodistill-yolo-world supervision

Step #2: Create a Dataset

Before you can label a dataset, you need a dataset with which to work.

Roboflow has a few resources that can help you create a dataset for your project:

You can use any folder of images you have on your local machine with Autodistill, too.

Step #3: Label Images with YOLO-World

Autodistill has two model types:

  1. A Base Model, which automatically labels your data, and;
  2. A Target Model, which trains on your labeled data.

To label your dataset with a Base Model, you need to provide prompt(s) that are relevant to the classes you want to label.

Replace "example" below with the prompt you want to use. Replace "class" with the name of the class you want the prompt results to be saved as in your dataset. Also, replace the IMAGE_NAME with an image from your dataset.

The code cell below loads the base model with your prompt on the provided image, then visualizes the results.

You may need to experiment with a few prompts.


from autodistill_yolo_world import YOLOWorldModel
from autodistill.detection import CaptionOntology
from autodistill.utils.plot import plot

# define an ontology to map class names to our YOLO-World prompt
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
# then, load the model
base_model = YOLOWorldModel(
    ontology=CaptionOntology(
        {
            "person": "person",
            "a forklift": "forklift"
        }
    )
)

# predict on an image
result = base_model.predict("image.jpeg", confidence=0.1)

plot(
    image=cv2.imread("./image.jpeg"),
    classes=base_model.ontology.classes(),
    detections=result
)

# label a folder of images
base_model.label("./context_images", extension=".jpeg")

Step #4: Label Data

To start labeling your images with

YOLO-World

, run the following lines of code:

base_model.label(input_folder="./images", output_folder="./dataset")

Step #5: Train a YOLOv8 Model

To train a

YOLOv8

model using your newly-labeled dataset, run the following code:


from autodistill_yolov8 import YOLOv8

target_model = YOLOv8("yolov8n.pt")
target_model.train("./dataset/data.yaml", epochs=200)

# run inference on the new model
pred = target_model.predict("./dataset/valid/your-image.jpg", confidence=0.5)

print(pred)

After running this cell, you will have model weights that you can use to run inference on your new model.

Step #5: Upload Model to Roboflow (Optional)

You can deploy your trained model to Roboflow. By deploying your model to Roboflow, you can run inference on our infinitely-scalable API. As your inference demands grow, our you will continue to see high levels of performance thanks to autoscaling infrastructure that is always on.

Roboflow offers:

Fully managed, infinitely-scalable APIs for deployed models

SDKs for common deployment targets (NVIDIA Jetson, Luxonis OAK, Docker, and more)

SOC II Type 1 Compliant

Trusted by 250,000+ developers

To deploy your model to Roboflow, run the following code:


import roboflow

PROJECT_ID = ""
DATASET_VERSION = 1

roboflow.login()

rf = roboflow.Roboflow()

project = rf.workspace().project(PROJECT_ID)
project.version(DATASET_VERSION).deploy(model_type="yolov8", model_path=f"./runs/detect/train/")

Deploy your model with Roboflow

Through Roboflow, you can deploy your model to a range of targets. Below, we have listed devices to which you can deploy your model using Roboflow SDKs.

No items found.

Explore More Models for Auto-Labeling

Base models are models you can use to automatically label data. Below are more base models you can use with Autodistill to label data.

Explore More Models for Training

Target models are models you can train with custom data. Below are more target models you can use with Autodistill.

Used by Over 16,000 companies
cardinal healthUSGIntel logoRivian logoMedtronic logoColumn logo