Sweep & yolov8

I could’nt find a a-z example of how to integrate Sweep with a yolo classifier so I had to stitch a few pieces of code to get something going so I may have missed something.

This is my current train.py code:

import argparse
from ultralytics import YOLO

# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('--dropout', type=float, default=0.2, help='dropout rate')
parser.add_argument('--lr0', type=float, default=0.001, help='learning rate')
parser.add_argument('--scale', type=float, default=0.50, help='scaling the image')
parser.add_argument('--erasing', type=float, default=0.50, help='Erasing part of the image')
parser.add_argument('--epochs', type=int, default=40, help='Epochs count')
parser.add_argument('--batch', type=int, default=16, help='Batch size')
args = parser.parse_args()

data_path = '/home/ubuntu/data-ff/'
model = YOLO('yolov8m-cls')  # build a new model from YAML

results = model.train(data=data_path, epochs=args.epochs, imgsz=640, batch=args.batch, device=0, dropout=args.dropout, lr0=args.lr0, hsv_h=0.0, hsv_s=0.0, hsv_v=0.0, degrees=0.0, translate=0.0, scale=args.scale, erasing=args.erasing)

and my sweep.yaml:

program: train.py

method: bayes

  goal: maximize
  name: mAP50

    distribution: log_uniform_values
    min: 1e-5
    max: 1e-2
    values: [0.0, 0.1, 0.2, 0.3]
    values: [0.1, 0.2, 0.3, 0.4, 0.5]
    values: [0.1, 0.2, 0.3, 0.4, 0.5]
    values: [8, 16, 32]

If I call this with the wand agent command, so I have to also add the add_wandb_callback call in my train.py script or everything is handled by wandb sweep? How does WandB knows where to get the mAP50 to optimize for? I think I am missing something!


Basically, how can I ensure the mAP50 in the following graph is populated?

Hi @pmrcc

We have a documentation for using YOLOv5 with Weights and Biases. Please check it here and see if this could help you with your sweep. There are samples on this guide that might give you some tips and use it for your current experiment.

Let me know if you have questions.

Best Regards,

Hi @paulo-sabile,

We finally managed to fix our issue, the metric had a typo, but it brought up another question: how does Wandb gathers the metrics from the Yolo training? Does it parse the logs ? How can I know which metrics are available?