metadata
task_categories:
- object-detection
language:
- en
Example usage:
from abc import ABC, abstractmethod
from datasets import load_dataset
from PIL import Image
from typing import Iterator
class DatasetInterface(ABC):
@abstractmethod
def get_generator(self) -> Iterator[tuple[Image.Image, list[float], list[float], list[str]]]:
pass
class CocoDataset(DatasetInterface):
def __init__(self):
self.dataset = load_dataset("detection-datasets/coco", split="val", streaming=True)
def get_generator(self) -> Iterator[tuple[Image.Image, list[float], list[float], list[str]]]:
for elem in self.dataset:
image = elem['image'].convert("RGB")
boxes = elem['objects']['bbox']
probs = [1.0] * len(boxes) # max confidence
labels = elem['objects']['category']
yield image, boxes, probs, labels