# Sweep & yolov8

**URL:** <https://community.wandb.ai/t/sweep-yolov8/7177>\
**Category:** W&B Help\
**Created:** [July 10, 2024, 3:39pm UTC](https://community.wandb.ai/t/sweep-yolov8/7177 "2024-07-10T15:39:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmrcc](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@pmrcc](https://community.wandb.ai/u/pmrcc)\
**Post date:** [July 10, 2024, 3:39pm UTC](https://community.wandb.ai/t/sweep-yolov8/7177/1 "2024-07-10T15:39:12Z")

</div>

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:

```auto

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:

```auto
program: train.py

method: bayes

metric:
  goal: maximize
  name: mAP50

parameters:
  lr0:
    distribution: log_uniform_values
    min: 1e-5
    max: 1e-2
  dropout:
    values: [0.0, 0.1, 0.2, 0.3]
  scale:
    values: [0.1, 0.2, 0.3, 0.4, 0.5]
  erasing:
    values: [0.1, 0.2, 0.3, 0.4, 0.5]
  batch:
    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!

Thanks!

---

<div class="post-metadata">

**Author:** ![pmrcc](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@pmrcc](https://community.wandb.ai/u/pmrcc)\
**Post date:** [July 10, 2024, 6:29pm UTC](https://community.wandb.ai/t/sweep-yolov8/7177/2 "2024-07-10T18:29:47Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/6/68d26fd323edfc48f2d0f593a1adb8267b833088.png)

---

<div class="post-metadata">

**Author:** ![paulo-sabile](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@paulo-sabile](https://community.wandb.ai/u/paulo-sabile)\
**Post date:** [July 15, 2024, 2:31am UTC](https://community.wandb.ai/t/sweep-yolov8/7177/3 "2024-07-15T02:31:00Z")

</div>

Hi @pmrcc

We have a documentation for using YOLOv5 with Weights and Biases. Please check it [here](https://docs.wandb.ai/guides/integrations/yolov5) 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,  
Paulo

---

<div class="post-metadata">

**Author:** ![pmrcc](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@pmrcc](https://community.wandb.ai/u/pmrcc)\
**Post date:** [July 15, 2024, 1:15pm UTC](https://community.wandb.ai/t/sweep-yolov8/7177/4 "2024-07-15T13:15:21Z")

</div>

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?

Thanks.

---

<div class="post-metadata">

**Author:** ![paulo-sabile](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@paulo-sabile](https://community.wandb.ai/u/paulo-sabile)\
**Post date:** [July 17, 2024, 1:59am UTC](https://community.wandb.ai/t/sweep-yolov8/7177/5 "2024-07-17T01:59:05Z")

</div>

Hi @pmrcc Good day! You may check this collab notebook here that provides a sample on how to train and debug YOLOv5 Models with Weights & Biases. There’s also a youtube video on this page that can show you the workflow. If in case you may not be able to find the answer you are looking for here, let us know and we will review it! Thank you!

---

<div class="post-metadata">

**Author:** ![paulo-sabile](https://avatars.discourse-cdn.com/v4/letter/p/f14d63/32.png) [@paulo-sabile](https://community.wandb.ai/u/paulo-sabile)\
**Post date:** [July 23, 2024, 9:40am UTC](https://community.wandb.ai/t/sweep-yolov8/7177/6 "2024-07-23T09:40:15Z")

</div>

Hi @pmrcc , since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!
