File size: 901 Bytes
cf0b223 b8d48b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
---
task_categories:
- object-detection
language:
- en
---
Example usage:
```python
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
``` |