sueszli commited on
Commit
b8d48b5
1 Parent(s): cf0b223

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +27 -1
README.md CHANGED
@@ -3,4 +3,30 @@ task_categories:
3
  - object-detection
4
  language:
5
  - en
6
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  - object-detection
4
  language:
5
  - en
6
+ ---
7
+
8
+ Example usage:
9
+
10
+ ```python
11
+ from abc import ABC, abstractmethod
12
+ from datasets import load_dataset
13
+ from PIL import Image
14
+ from typing import Iterator
15
+
16
+ class DatasetInterface(ABC):
17
+ @abstractmethod
18
+ def get_generator(self) -> Iterator[tuple[Image.Image, list[float], list[float], list[str]]]:
19
+ pass
20
+
21
+ class CocoDataset(DatasetInterface):
22
+ def __init__(self):
23
+ self.dataset = load_dataset("detection-datasets/coco", split="val", streaming=True)
24
+
25
+ def get_generator(self) -> Iterator[tuple[Image.Image, list[float], list[float], list[str]]]:
26
+ for elem in self.dataset:
27
+ image = elem['image'].convert("RGB")
28
+ boxes = elem['objects']['bbox']
29
+ probs = [1.0] * len(boxes) # max confidence
30
+ labels = elem['objects']['category']
31
+ yield image, boxes, probs, labels
32
+ ```