supervision icon indicating copy to clipboard operation
supervision copied to clipboard

[DetectionDataset] - expand `from_yolo` to include support for OBB (Oriented Bounding Boxes)

Open pedbrgs opened this issue 10 months ago • 18 comments

Description

In supervision-0.18.0, we added initial support for OBB; it's time to extend it to include dataset loading.

Make the necessary changes in sv.DetectionDataset.from_yolo to enable loading OBB datasets from disk in YOLO format. Here you can read more about the YOLO OBB Format. In short, each line of the .txt file should have the following format.

class_index, x1, y1, x2, y2, x3, y3, x4, y4

The sv.OrientedBoxAnnotator expects information about oriented bounding boxes to be stored in the xyxyxyxy field of sv.Detections.data. Ensure that the information loaded from the dataset is stored there.

API

Here's an example of how to use the new API. Roboflow allows for the export of segmentation datasets as OBB. Let's ensure that our support for OBB definitely works with datasets exported from Roboflow.

import random
import roboflow
from roboflow import Roboflow
import supervision as sv

roboflow.login()
rf = Roboflow()

project = rf.workspace("roboflow-jvuqo").project("fashion-assistant")
version = project.version(3)
dataset = version.download("yolov8-obb")

train_ds = sv.DetectionDataset.from_yolo(
    images_directory_path=f"{dataset.location}/train/images",
    annotations_directory_path=f"{dataset.location}/train/labels",
    data_yaml_path=f"{dataset.location}/data.yaml"
)

image_name = random.choice(list(train_ds.images))
image = train_data.images[image_name]
detections = train_data.annotations[image_name]

oriented_box_annotator = sv.OrientedBoxAnnotator()
annotated_frame = oriented_box_annotator.annotate(
    scene=image.copy(),
    detections=detections
)

Additional

  • Note: Please share a Google Colab with minimal code to test the new feature. We know it's additional work, but it will speed up the review process. The reviewer must test each change. Setting up a local environment to do this is time-consuming. Please ensure that Google Colab can be accessed without any issues (make it public). Thank you! 🙏🏻

pedbrgs avatar Apr 05 '24 13:04 pedbrgs