Skip to content

Extreme memory usage loading OBB dataset #1762

Open
@patel-zeel

Description

@patel-zeel

Search before asking

  • I have searched the Supervision issues and found no similar bug report.

Bug

I tried loading the DOTAv1 dataset processed by Ultralytics from this URL: https://github.com/ultralytics/assets/releases/download/v0.0.0/DOTAv1.zip with sv.DetectionDataset.from_yolo but it was unsuccessful on Google colab. When I loaded a subset of 100 instances on our compute server, it consumed nearly 36 GB of memory. Free Google colab instance comes with ~12 GB memory only so it was bound to fail there.

I investigated further and found the following reason for the extreme memory usage:

  1. _with_mask function is called at the following position and it sets with_masks argument to True for OBB.
    with_masks = _with_mask(lines=lines)
  2. with_masks argument is then passed to the following function with other arguments:
    def yolo_annotations_to_detections(
    lines: List[str],
    resolution_wh: Tuple[int, int],
    with_masks: bool,
    is_obb: bool = False,
    ) -> Detections:
  3. Due to the effect of the with_masks argument, the following lines are executed:
    mask = _polygons_to_masks(polygons=polygons, resolution_wh=resolution_wh)
    return Detections(class_id=class_id, xyxy=xyxy, data=data, mask=mask)
  4. The 2D shape of the mask is the same as the (w, h) resolution of the image. If an image has N detections, the mask shape is (N, w, h), which is not space-friendly.

The size of the mask is the main reason for extreme storage usage.

Environment

Google colab:

  • Supervision: 0.25.1
  • Python: 3.10.12
  • Ubuntu: 22.04

Minimal Reproducible Example

Colab to reproduce the results.

Additional

I have not taken a deeper look, but a naive solution could be to generate masks only when needed and then discard them for efficient memory usage.

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions