stumbledparams commited on
Commit
ba5657b
·
verified ·
1 Parent(s): a2c943a

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Micro-OD.py +120 -0
  2. README.md +23 -0
Micro-OD.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Micro-OD: A few-shot microscopy object detection benchmark."""
2
+
3
+ import json
4
+ import os
5
+
6
+ import datasets
7
+
8
+ _DESCRIPTION = """\
9
+ Micro-OD is a few-shot microscopy object detection benchmark spanning four
10
+ biological imaging domains: BBBC (malaria parasite detection), BCCD (blood
11
+ cell counting), LIVECell (RatC6 live-cell imaging), and NIH-3T3 (mouse
12
+ fibroblast imaging).
13
+
14
+ Two splits are provided:
15
+ - example: 10 images per sub-dataset (40 total) — the few-shot support set.
16
+ - test: 53 images per sub-dataset (212 total) — the evaluation query set.
17
+ """
18
+
19
+ # Sorted alphabetically; used as ClassLabel names.
20
+ ALL_CLASSES = [
21
+ "Gametocyte Cells",
22
+ "Platelets",
23
+ "Polygonal Cells",
24
+ "Red Blood Cells",
25
+ "Ring Cells",
26
+ "Round Cells",
27
+ "Schizont Cells",
28
+ "Spindle Cells",
29
+ "Trophozoite Cells",
30
+ "White Blood Cells",
31
+ ]
32
+
33
+ SUBDATASETS = ["BBBC", "BCCD", "LIVECell", "NIH-3T3"]
34
+
35
+
36
+ class MicroOD(datasets.GeneratorBasedBuilder):
37
+ """Micro-OD dataset loader."""
38
+
39
+ VERSION = datasets.Version("1.0.0")
40
+
41
+ def _info(self):
42
+ return datasets.DatasetInfo(
43
+ description=_DESCRIPTION,
44
+ features=datasets.Features(
45
+ {
46
+ "image": datasets.Image(),
47
+ "image_id": datasets.Value("string"),
48
+ "subdataset": datasets.Value("string"),
49
+ "objects": datasets.Sequence(
50
+ feature={
51
+ # COCO format: [x_min, y_min, width, height]
52
+ "bbox": datasets.Sequence(
53
+ datasets.Value("float32"), length=4
54
+ ),
55
+ "label": datasets.ClassLabel(names=ALL_CLASSES),
56
+ "category": datasets.Value("string"),
57
+ }
58
+ ),
59
+ }
60
+ ),
61
+ )
62
+
63
+ def _split_generators(self, dl_manager):
64
+ data_dir = os.path.dirname(os.path.abspath(__file__))
65
+ return [
66
+ datasets.SplitGenerator(
67
+ name=datasets.splits.NamedSplit("example"),
68
+ gen_kwargs={"split_path": os.path.join(data_dir, "example")},
69
+ ),
70
+ datasets.SplitGenerator(
71
+ name=datasets.Split.TEST,
72
+ gen_kwargs={"split_path": os.path.join(data_dir, "test")},
73
+ ),
74
+ ]
75
+
76
+ def _generate_examples(self, split_path):
77
+ idx = 0
78
+ for subdataset in SUBDATASETS:
79
+ annotation_path = os.path.join(
80
+ split_path, subdataset, "annotation.jsonl"
81
+ )
82
+ image_base = os.path.join(split_path, subdataset)
83
+
84
+ with open(annotation_path, encoding="utf-8") as f:
85
+ for line in f:
86
+ line = line.strip()
87
+ if not line:
88
+ continue
89
+
90
+ entry = json.loads(line)
91
+ image_path = os.path.join(image_base, entry["image_path"])
92
+
93
+ bboxes, labels, categories = [], [], []
94
+ for category, boxes in entry["bbox"].items():
95
+ for box in boxes:
96
+ x_min, y_min = box[0]
97
+ x_max, y_max = box[1]
98
+ # Convert [[x_min,y_min],[x_max,y_max]] → COCO [x,y,w,h]
99
+ bboxes.append(
100
+ [
101
+ float(x_min),
102
+ float(y_min),
103
+ float(x_max - x_min),
104
+ float(y_max - y_min),
105
+ ]
106
+ )
107
+ labels.append(ALL_CLASSES.index(category))
108
+ categories.append(category)
109
+
110
+ yield idx, {
111
+ "image": image_path,
112
+ "image_id": f"{subdataset}/{entry['image_path']}",
113
+ "subdataset": subdataset,
114
+ "objects": {
115
+ "bbox": bboxes,
116
+ "label": labels,
117
+ "category": categories,
118
+ },
119
+ }
120
+ idx += 1
README.md CHANGED
@@ -133,6 +133,29 @@ Annotations are stored as [JSON Lines](https://jsonlines.org/) (`.jsonl`) files
133
  }
134
  ```
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  ## Dataset Statistics
137
 
138
  Detailed per-class statistics are available in `example/stat.txt` and `test/stat.txt`. Summaries are provided below.
 
133
  }
134
  ```
135
 
136
+ ## Usage
137
+
138
+ ```python
139
+ from datasets import load_dataset
140
+
141
+ ds = load_dataset("path/to/Micro-OD")
142
+
143
+ # Access splits
144
+ example_split = ds["example"] # 40 images — few-shot support set
145
+ test_split = ds["test"] # 212 images — evaluation query set
146
+
147
+ # Each row contains:
148
+ # image — PIL image
149
+ # image_id — "<subdataset>/images/<filename>"
150
+ # subdataset — one of: BBBC, BCCD, LIVECell, NIH-3T3
151
+ # objects — dict with keys:
152
+ # bbox : list of [x_min, y_min, width, height] (COCO format, float)
153
+ # label : list of int (index into the 10-class label set)
154
+ # category : list of str (class name)
155
+ ```
156
+
157
+ > **Note on bbox format:** The loading script converts the raw `[[x_min, y_min], [x_max, y_max]]` annotation format into COCO-style `[x_min, y_min, width, height]` float lists. If you consume the `annotation.jsonl` files directly, refer to the [Annotation Format](#annotation-format) section for the raw coordinate convention.
158
+
159
  ## Dataset Statistics
160
 
161
  Detailed per-class statistics are available in `example/stat.txt` and `test/stat.txt`. Summaries are provided below.