Skip to main content

YOLOv8


Ultralytics' YOLOv8 is a top modeling repository for object detection, segmentation, and classification. Get the most out of YOLOv8 with ClearML:

  • Track every YOLOv8 training run in ClearML
  • Remotely train and monitor your YOLOv8 training runs using ClearML Agent
  • Turn your newly trained YOLOv8 model into an API with just a few commands using ClearML Serving

Setup

  1. Install the clearml python package:

    pip install clearml
  2. To keep track of your experiments and/or data, ClearML needs to communicate to a server. You have 2 server options:

  3. Connect the ClearML SDK to the server by creating credentials (go to the top right in the UI to Settings > Workspace > Create new credentials), then execute the command below and follow the instructions:

    clearml-init

That's it! Now, whenever you train a model using YOLOv8, the run will be captured and tracked by ClearML – no additional code necessary.

Training YOLOv8 with ClearML

To enable ClearML experiment tracking, simply install the clearml pip package in your execution environment.

pip install clearml>=1.2.0

This will enable integration with the YOLOv8 training script. In every training run from now on, the ClearML experiment manager will capture:

  • Source code and uncommitted changes
  • Installed packages
  • Hyperparameters
  • Model files (use --save-period n to save a checkpoint every n epochs)
  • Console output
  • Scalars (e.g. mAP_0.5, mAP_0.5:0.95, precision, recall, losses)
  • General information such as machine details, runtime, creation date etc.
  • All produced plots such as label correlogram and confusion matrix
  • Mosaic per epoch
  • Validation images per epoch
  • And more

All of this is captured into a ClearML Task: a task with your training script's name created in a YOLOv8 ClearML project. To change the task's name or project, pass the name and project arguments in one of the following ways:

  • Via the SDK:

    from ultralytics import YOLO

    # Initialize YOLO object, load/create YOLOv8 model
    model = YOLO()

    # Run MODE mode using the custom arguments ARGS
    model.MODE(name="<new_task_name>", project="<new_project_name>")
  • Via the yolo CLI:

    yolo TASK MODE project=new_project name=new_task_name
project names

ClearML uses / as a delimiter for subprojects: using example/sample as a name will create the sample task within the example project.

You can see all the captured data in the task's page of the ClearML WebApp. Additionally, you can view all of your YOLOv8 runs tracked by ClearML in the Experiments Table. Add custom columns to the table, such as mAP values, so you can easily sort and see what is the best performing model. You can also select multiple experiments and directly compare them.

Remote Execution

ClearML logs all the information required to reproduce an experiment on a different machine (installed packages, uncommitted changes etc.). The ClearML Agent listens to designated queues and when a task is enqueued, the agent pulls it, recreates its execution environment, and runs it, reporting its scalars, plots, etc. to the experiment manager.

Deploy a ClearML Agent onto any machine (e.g. a cloud VM, a local GPU machine, your own laptop) by simply running the following command on it:

clearml-agent daemon --queue <queues_to_listen_to> [--docker]

Use the ClearML Autoscalers to help you manage cloud workloads in the cloud of your choice (AWS, GCP, Azure) and automatically deploy ClearML agents: the autoscaler automatically spins up and shuts down instances as needed, according to a resource budget that you set.

Cloning, Editing, and Enqueuing

ClearML logs all the information required to reproduce an experiment, but you may also want to change a few parameters and task details when you re-run an experiment, which you can do through ClearML's UI.

In order to be able to override parameters via the UI, you have to run your code to create a ClearML Task, which will log all the execution parameters before using the YOLO model. When ClearML re-runs the task remotely, ClearML will override these parameters before YOLO comes into play.

For example:

from clearml import Task
from ultralytics import YOLO

# Create a ClearML Task
task = Task.init(
project_name="my project",
task_name="my yolo task"
)

# Load a model
model_variant = "yolov8n"
# Log "model_variant" parameter to task
task.set_parameter("model_variant", model_variant)

# Load the YOLOv8 model
model = YOLO(f'{model_variant}.pt')

# Put all YOLOv8 arguments in a dictionary and pass it to ClearML
# When the arguments are later changed in UI, they will be overridden here!
args = dict(data="coco128.yaml", epochs=16)
task.connect(args)

# Train the model
# If running remotely, the arguments may be overridden by ClearML if they were changed in the UI
results = model.train(**args)
tip

Notice that in the script above only the data and epochs args are passed to ClearML, so only their values can be overridden via the UI. You can add all of YOLO's default parameters to the parameter dictionary, so you'll be able to override any of them through the UI.

Use the UI to edit task details, then execute the task with the new configuration on a remote machine:

  • Clone the experiment
  • Edit the hyperparameters and/or other details
  • Enqueue the task

The ClearML Agent executing the task will use the new values to override any hard coded values.

Cloning, editing, enqueuing gif