srishti-kaushik commited on
Commit
a7739e9
·
verified ·
1 Parent(s): d10b814

Rewrite card: minimal front page, sample grid, docs split out

Browse files
README.md CHANGED
@@ -71,244 +71,38 @@ configs:
71
  data_files: data/image_info/unlabeled2017/*.parquet
72
  ---
73
 
74
- # MS COCO 2017 — Complete
75
 
76
- Every split and every annotation family of [COCO 2017](https://cocodataset.org),
77
- converted to Parquet, verified image-by-image, and split into configs you can
78
- download one at a time.
79
 
80
- Most COCO mirrors on the Hub carry only `train2017` + `val2017` detection boxes.
81
- This one is the whole release: all four image splits, all five annotation
82
- families, both mask families, and the original JSONs kept alongside for
83
- `pycocotools`.
84
-
85
- ## What's here
86
-
87
- | Piece | Images | Annotations | Size |
88
- |---|---|---|---|
89
- | `images_train2017` | 118,287 | — | 19.2 GB |
90
- | `images_val2017` | 5,000 | — | 0.8 GB |
91
- | `images_test2017` | 40,670 | — | 6.3 GB |
92
- | `images_unlabeled2017` | 123,403 | — | 19.0 GB |
93
- | `instances_train2017` / `_val2017` | 118,287 / 5,000 | 860,001 / 36,781 boxes+masks, 80 classes | 113 / 6 MB |
94
- | `captions_train2017` / `_val2017` | 118,287 / 5,000 | 591,753 / 25,014 captions | 15 / 1 MB |
95
- | `person_keypoints_train2017` / `_val2017` | 118,287 / 5,000 | 262,465 / 11,004 people, 17 keypoints | 54 / 3 MB |
96
- | `stuff_train2017` / `_val2017` | 118,287 / 5,000 | 747,458 / 32,801 regions, 92 classes | 489 / 22 MB |
97
- | `panoptic_train2017` / `_val2017` | 118,287 / 5,000 | 1,329,984 / 56,728 segments, 133 classes | 22 / 2 MB |
98
- | `panoptic_masks_train2017` / `_val2017` | 118,287 / 5,000 | PNG id-maps | 0.80 / 0.03 GB |
99
- | `stuff_pixelmaps_train2017` / `_val2017` | 118,287 / 5,000 | PNG label-maps | 0.53 / 0.02 GB |
100
- | `image_info_test2017` / `test-dev2017` / `unlabeled2017` | 40,670 / 20,288 / 123,403 | metadata only | < 5 MB |
101
-
102
- ## Design: images and labels are separate
103
-
104
- Image bytes live in `images_*` configs and **nowhere else**. Every annotation
105
- config is keyed by `image_id` and carries no pixels, so pulling all of COCO's
106
- detection labels costs ~120 MB rather than 19 GB. Join when you need both.
107
 
108
  ```python
109
  from datasets import load_dataset
110
 
111
- # labels only -- seconds, not hours
112
  ann = load_dataset("srishti-kaushik/COCO-2017", "instances_val2017", split="train")
113
- print(ann[0]["objects"][0])
114
- # {'id': 1768, 'category_id': 1, 'category_name': 'person', 'supercategory': 'person',
115
- # 'bbox': [473.07, 395.93, 38.65, 28.67], 'area': 702.1, 'iscrowd': 0,
116
- # 'segmentation': {'format': 'polygon', 'polygons': [[510.66, 423.01, ...]],
117
- # 'counts': None, 'counts_str': None, 'size': None}}
118
 
119
- # pixels when you actually want them
120
  img = load_dataset("srishti-kaushik/COCO-2017", "images_val2017", split="train")
121
- img[0]["image"] # PIL.Image
122
-
123
- # stream instead of downloading
124
- s = load_dataset("srishti-kaushik/COCO-2017", "images_train2017", split="train", streaming=True)
125
- next(iter(s))["image"]
126
- ```
127
-
128
- Joining labels onto images:
129
 
130
- ```python
131
- by_id = {r["image_id"]: r for r in ann}
132
- for row in img:
133
- objects = by_id[row["image_id"]]["objects"]
134
  ```
135
 
136
- ## Downloading just one piece
137
-
138
- ```bash
139
- # only val images + val detection labels (~0.8 GB)
140
- hf download srishti-kaushik/COCO-2017 --repo-type dataset \
141
- --include "data/images/val2017/*" "data/instances/val2017/*"
142
-
143
- # only the panoptic stack, no train JPEGs
144
- hf download srishti-kaushik/COCO-2017 --repo-type dataset \
145
- --include "data/panoptic/*" "data/panoptic_masks/*"
146
-
147
- # the original JSONs, for pycocotools
148
- hf download srishti-kaushik/COCO-2017 --repo-type dataset --include "raw/annotations/*"
149
- ```
150
-
151
- ## Schemas
152
-
153
- **`images_*`** — `image_id` (int64), `file_name`, `width`, `height`, `license`,
154
- `flickr_url`, `coco_url`, `date_captured`, `image` (Image).
155
 
156
- **`instances_*`, `stuff_*`** — the image metadata above, plus `objects`, a list of
157
- `{id, category_id, category_name, supercategory, bbox, area, iscrowd, segmentation}`.
158
- `bbox` is COCO's `[x, y, width, height]` in pixels; `segmentation` is a typed
159
- struct described [below](#segmentation-is-typed-not-a-json-string).
160
 
161
- **`person_keypoints_*`** — as above, plus `num_keypoints` and `keypoints`
162
- (flat `[x1, y1, v1, ...]`, 17 triplets, `v` = 0 unlabeled / 1 labeled-occluded / 2 visible).
163
-
164
- **`captions_*`** — image metadata plus `captions`, a list of `{id, caption}`.
165
-
166
- **`panoptic_*`** — image metadata, `panoptic_file_name` (the matching PNG in
167
- `panoptic_masks_*`), and `objects`: `{id, category_id, category_name, supercategory,
168
- isthing, bbox, area, iscrowd}`.
169
-
170
- **`panoptic_masks_*`, `stuff_pixelmaps_*`** — `image_id`, `file_name`, `mask` (Image).
171
-
172
- **Licence table** — `data/licenses.parquet` (`id`, `name`, `url`) resolves the
173
- `license` id carried by every image row.
174
-
175
- **Category tables** live in `data/categories/<family>_<split>.parquet`
176
- (`id`, `name`, `supercategory`, `isthing`, `color`, `keypoints`, `skeleton`) so a
177
- label map never requires parsing a multi-GB JSON.
178
-
179
- ### `segmentation` is typed, not a JSON string
180
-
181
- COCO overloads this one field with three incompatible shapes. Rather than dump
182
- them into a string that every consumer has to `json.loads`, they are kept as a
183
- struct with a `format` discriminator:
184
-
185
- | `format` | populated field | used by |
186
- |---|---|---|
187
- | `polygon` | `polygons` — `list<list<float64>>`, each `[x, y, x, y, ...]` | ordinary instances |
188
- | `rle_uncompressed` | `counts` — `list<int64>`, plus `size` `[h, w]` | `iscrowd=1` annotations |
189
- | `rle_compressed` | `counts_str` — `string`, plus `size` `[h, w]` | all of `stuff_*` |
190
-
191
- Unused fields are null, so the column stays queryable — you can filter crowds with
192
- `segmentation.format == 'rle_uncompressed'` without decoding anything.
193
-
194
- ```python
195
- from pycocotools import mask as mask_utils
196
-
197
- def to_mask(obj, height, width):
198
- s = obj["segmentation"]
199
- if s["format"] == "polygon":
200
- rle = mask_utils.merge(mask_utils.frPyObjects(s["polygons"], height, width))
201
- elif s["format"] == "rle_uncompressed":
202
- rle = mask_utils.frPyObjects({"counts": s["counts"], "size": s["size"]}, *s["size"])
203
- else:
204
- rle = {"counts": s["counts_str"].encode(), "size": s["size"]}
205
- return mask_utils.decode(rle)
206
- ```
207
 
208
- The original overloaded form is one step away if you need it:
209
-
210
- ```python
211
- def to_coco_segmentation(s):
212
- if s["format"] == "polygon":
213
- return s["polygons"]
214
- counts = s["counts"] if s["format"] == "rle_uncompressed" else s["counts_str"]
215
- return {"counts": counts, "size": s["size"]}
216
- ```
217
-
218
- ### Panoptic PNG encoding
219
-
220
- Panoptic masks keep the official byte-exact encoding: segment id =
221
- `R + 256*G + 256²*B`.
222
-
223
- ```python
224
- import numpy as np
225
- a = np.array(row["mask"]).astype(np.uint32)
226
- ids = a[:, :, 0] + 256 * a[:, :, 1] + 256**2 * a[:, :, 2]
227
- ```
228
-
229
- ## Verification
230
-
231
- Every claim below was checked against the source data, not assumed:
232
-
233
- - **Image bytes are byte-identical to the official release.** All 287,360 JPEGs were
234
- SHA-256 compared against the original files after conversion — 0 differences. The
235
- same check passed for all 246,574 panoptic and stuff mask PNGs.
236
- - **Every JPEG was fully decoded** (not merely header-checked), and each image's real
237
- pixel dimensions were compared against the dimensions declared in the JSON:
238
- **0 corrupt files, 0 dimension mismatches.**
239
- - **The annotation conversion is lossless.** Every annotation was reconstructed from
240
- Parquet back into its original COCO JSON shape and compared field by field against
241
- the source — 2,555,472 annotations plus 1,386,712 panoptic segments, including every
242
- `segmentation` in all three of its formats. 0 mismatches.
243
- - Image and annotation counts match the official release exactly across all 13 JSONs,
244
- and every `file_name` referenced by any annotation resolves to a real image.
245
- - Category tables match the source categories for all five families.
246
- - `image` and `mask` columns were confirmed to decode as PIL images through
247
- `datasets`, and reconstructed segmentations were confirmed to decode through
248
- `pycocotools`.
249
-
250
- The build and verification scripts are in `scripts/` if you want to re-run any of it.
251
-
252
- ### Gotcha: panoptic segment ids are per-image
253
-
254
- `objects.id` in `panoptic_*` is the segment's colour code in the matching PNG, and is
255
- unique **within an image only** — ids repeat across images (val2017 has 56,728 segments
256
- but only 51,462 distinct ids). Key on `(image_id, id)`, never on `id` alone. Annotation
257
- ids in `instances_*`, `captions_*`, `person_keypoints_*` and `stuff_*` *are* globally
258
- unique.
259
-
260
- ## Original files
261
-
262
- `raw/annotations/` holds the unmodified official JSONs, byte-for-byte, for code
263
- that expects to feed a path straight to `pycocotools.coco.COCO`. The Parquet
264
- configs are derived from exactly these files.
265
-
266
- ## Licensing and attribution
267
-
268
- This repository redistributes the publicly released COCO 2017 dataset. It is a
269
- mirror: no content has been altered, and no rights beyond the original terms are
270
- claimed or granted.
271
-
272
- - **Annotations** are released by the COCO Consortium under
273
- [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) and are redistributed
274
- here under that licence, with attribution to the original authors below.
275
- - **Images** remain the property of their respective Flickr photographers. They
276
- are not owned by the COCO Consortium and are not relicensed here; their use is
277
- governed by the [COCO Terms of Use](https://cocodataset.org/#termsofuse) and the
278
- licence attached to each image, recorded in the `license` field of every
279
- `images_*` row and resolvable through `data/licenses.parquet`. Note that several
280
- of these are Creative Commons **NonCommercial** licences, so the image set is not
281
- uniformly free for commercial use — check the per-image `license` id.
282
-
283
- The repository-level licence tag reflects the annotations, which are the part
284
- being licensed. Please observe the image terms above when using the pixels.
285
-
286
- Rights holders may open a discussion on this repository to request removal of any
287
- image.
288
-
289
- ## Citation
290
-
291
- ```bibtex
292
- @inproceedings{lin2014microsoft,
293
- title={Microsoft {COCO}: Common Objects in Context},
294
- author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James
295
- and Perona, Pietro and Ramanan, Deva and Doll{\'a}r, Piotr and Zitnick, C Lawrence},
296
- booktitle={ECCV},
297
- year={2014}
298
- }
299
-
300
- @inproceedings{caesar2018cocostuff,
301
- title={{COCO-Stuff}: Thing and Stuff Classes in Context},
302
- author={Caesar, Holger and Uijlings, Jasper and Ferrari, Vittorio},
303
- booktitle={CVPR},
304
- year={2018}
305
- }
306
-
307
- @inproceedings{kirillov2019panoptic,
308
- title={Panoptic Segmentation},
309
- author={Kirillov, Alexander and He, Kaiming and Girshick, Ross and
310
- Rother, Carsten and Doll{\'a}r, Piotr},
311
- booktitle={CVPR},
312
- year={2019}
313
- }
314
- ```
 
71
  data_files: data/image_info/unlabeled2017/*.parquet
72
  ---
73
 
74
+ # MS COCO 2017
75
 
76
+ The complete COCO 2017 release — all four image splits and every annotation family — in Parquet.
 
 
77
 
78
+ ![Samples from val2017 with instance annotations](https://huggingface.co/datasets/srishti-kaushik/COCO-2017/resolve/main/assets/preview.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  ```python
81
  from datasets import load_dataset
82
 
83
+ # annotations only (~6 MB) -- no image bytes
84
  ann = load_dataset("srishti-kaushik/COCO-2017", "instances_val2017", split="train")
 
 
 
 
 
85
 
86
+ # images
87
  img = load_dataset("srishti-kaushik/COCO-2017", "images_val2017", split="train")
88
+ img[0]["image"] # PIL.Image
 
 
 
 
 
 
 
89
 
90
+ # stream, instead of downloading 19 GB
91
+ train = load_dataset("srishti-kaushik/COCO-2017", "images_train2017",
92
+ split="train", streaming=True)
 
93
  ```
94
 
95
+ Images and labels are separate configs, so you download only what you need:
96
+ `images_{train2017,val2017,test2017,unlabeled2017}`, `instances_*`, `captions_*`,
97
+ `person_keypoints_*`, `stuff_*`, `panoptic_*`, `panoptic_masks_*`,
98
+ `stuff_pixelmaps_*`, `image_info_*`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ ## Documentation
 
 
 
101
 
102
+ - [Structure and schemas](docs/STRUCTURE.md) — every config, field types, joining labels to images, selective download
103
+ - [Verification](docs/VERIFICATION.md) — how this copy was checked against the official release
104
+ - [Licensing and citation](docs/LICENSING.md)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
+ Annotations are CC BY 4.0 (COCO Consortium). Images remain under their original
107
+ Flickr licences and the [COCO Terms of Use](https://cocodataset.org/#termsofuse) —
108
+ see [licensing](docs/LICENSING.md).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/preview.png ADDED

Git LFS Details

  • SHA256: 21f066a831a4392e14fe66e3fd2bd09c2fea7f3ef1bced50201ce272fea2d051
  • Pointer size: 132 Bytes
  • Size of remote file: 1.96 MB
docs/LICENSING.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Licensing, attribution and citation
2
+
3
+ This repository redistributes the publicly released COCO 2017 dataset. It is a
4
+ mirror: no content has been altered, and no rights beyond the original terms are
5
+ claimed or granted.
6
+
7
+ ## Annotations
8
+
9
+ Released by the COCO Consortium under
10
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) and redistributed here
11
+ under that licence, with attribution to the original authors (see citation below).
12
+ The repository-level licence tag reflects the annotations, which are the part being
13
+ licensed.
14
+
15
+ ## Images
16
+
17
+ The images remain the property of their respective Flickr photographers. They are
18
+ not owned by the COCO Consortium and are not relicensed here. Their use is governed
19
+ by the [COCO Terms of Use](https://cocodataset.org/#termsofuse) and by the licence
20
+ attached to each individual image.
21
+
22
+ Each image's licence id is recorded in the `license` field of every `images_*` row
23
+ and resolves through `data/licenses.parquet`:
24
+
25
+ | id | Licence |
26
+ |---|---|
27
+ | 1 | Attribution-NonCommercial-ShareAlike |
28
+ | 2 | Attribution-NonCommercial |
29
+ | 3 | Attribution-NonCommercial-NoDerivs |
30
+ | 4 | Attribution |
31
+ | 5 | Attribution-ShareAlike |
32
+ | 6 | Attribution-NoDerivs |
33
+ | 7 | No known copyright restrictions |
34
+ | 8 | United States Government Work |
35
+
36
+ Several of these are **NonCommercial** licences, so the image set is not uniformly
37
+ free for commercial use. Check the per-image `license` id before relying on it.
38
+
39
+ Rights holders may open a discussion on this repository to request removal of any
40
+ image.
41
+
42
+ ## Citation
43
+
44
+ ```bibtex
45
+ @inproceedings{lin2014microsoft,
46
+ title={Microsoft {COCO}: Common Objects in Context},
47
+ author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James
48
+ and Perona, Pietro and Ramanan, Deva and Doll{\'a}r, Piotr and Zitnick, C Lawrence},
49
+ booktitle={ECCV},
50
+ year={2014}
51
+ }
52
+
53
+ @inproceedings{caesar2018cocostuff,
54
+ title={{COCO-Stuff}: Thing and Stuff Classes in Context},
55
+ author={Caesar, Holger and Uijlings, Jasper and Ferrari, Vittorio},
56
+ booktitle={CVPR},
57
+ year={2018}
58
+ }
59
+
60
+ @inproceedings{kirillov2019panoptic,
61
+ title={Panoptic Segmentation},
62
+ author={Kirillov, Alexander and He, Kaiming and Girshick, Ross and
63
+ Rother, Carsten and Doll{\'a}r, Piotr},
64
+ booktitle={CVPR},
65
+ year={2019}
66
+ }
67
+ ```
docs/STRUCTURE.md ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Structure and schemas
2
+
3
+ ## Design
4
+
5
+ Image bytes live in the `images_*` configs and nowhere else. Every annotation config
6
+ is keyed by `image_id` and carries no pixels, so the full detection label set is
7
+ ~120 MB rather than 19 GB. Join the two when you need both.
8
+
9
+ ## Configs
10
+
11
+ | Config | Rows | Contents | Size |
12
+ |---|---|---|---|
13
+ | `images_train2017` | 118,287 | JPEGs | 19.2 GB |
14
+ | `images_val2017` | 5,000 | JPEGs | 0.8 GB |
15
+ | `images_test2017` | 40,670 | JPEGs | 6.6 GB |
16
+ | `images_unlabeled2017` | 123,403 | JPEGs | 20.0 GB |
17
+ | `instances_train2017` / `_val2017` | 118,287 / 5,000 | 860,001 / 36,781 boxes + masks, 80 classes | 113 / 6 MB |
18
+ | `captions_train2017` / `_val2017` | 118,287 / 5,000 | 591,753 / 25,014 captions | 15 / 1 MB |
19
+ | `person_keypoints_train2017` / `_val2017` | 118,287 / 5,000 | 262,465 / 11,004 people, 17 keypoints | 54 / 3 MB |
20
+ | `stuff_train2017` / `_val2017` | 118,287 / 5,000 | 747,458 / 32,801 regions, 92 classes | 489 / 22 MB |
21
+ | `panoptic_train2017` / `_val2017` | 118,287 / 5,000 | 1,329,984 / 56,728 segments, 133 classes | 22 / 2 MB |
22
+ | `panoptic_masks_train2017` / `_val2017` | 118,287 / 5,000 | PNG id-maps | 0.80 / 0.03 GB |
23
+ | `stuff_pixelmaps_train2017` / `_val2017` | 118,287 / 5,000 | PNG label-maps | 0.53 / 0.02 GB |
24
+ | `image_info_test2017` / `test-dev2017` / `unlabeled2017` | 40,670 / 20,288 / 123,403 | metadata only | < 5 MB |
25
+
26
+ Supporting tables, not exposed as configs:
27
+
28
+ - `data/categories/<family>_<split>.parquet` — `id`, `name`, `supercategory`, `isthing`,
29
+ `color`, `keypoints`, `skeleton`. Label maps without parsing a multi-GB JSON.
30
+ - `data/licenses.parquet` — `id`, `name`, `url`, resolving the `license` id on every image row.
31
+ - `raw/annotations/` — the unmodified official JSONs, for `pycocotools.coco.COCO`.
32
+ - `scripts/` — the build and verification scripts used to produce this repo.
33
+
34
+ ## Schemas
35
+
36
+ **`images_*`** — `image_id` (int64), `file_name`, `width`, `height`, `license`,
37
+ `flickr_url`, `coco_url`, `date_captured`, `image` (Image).
38
+
39
+ **`instances_*`, `stuff_*`** — the image fields above, plus `objects`: a list of
40
+ `{id, category_id, category_name, supercategory, bbox, area, iscrowd, segmentation}`.
41
+ `bbox` is COCO's `[x, y, width, height]` in pixels.
42
+
43
+ **`person_keypoints_*`** — as above, plus `num_keypoints` and `keypoints`
44
+ (flat `[x1, y1, v1, ...]`, 17 triplets; `v` = 0 unlabeled / 1 labeled-occluded / 2 visible).
45
+
46
+ **`captions_*`** — image fields plus `captions`: a list of `{id, caption}`.
47
+
48
+ **`panoptic_*`** — image fields, `panoptic_file_name` (the matching PNG in
49
+ `panoptic_masks_*`), and `objects`:
50
+ `{id, category_id, category_name, supercategory, isthing, bbox, area, iscrowd}`.
51
+
52
+ **`panoptic_masks_*`, `stuff_pixelmaps_*`** — `image_id`, `file_name`, `mask` (Image).
53
+
54
+ ## Joining labels to images
55
+
56
+ ```python
57
+ from datasets import load_dataset
58
+
59
+ R = "srishti-kaushik/COCO-2017"
60
+ img = load_dataset(R, "images_val2017", split="train")
61
+ ann = load_dataset(R, "instances_val2017", split="train")
62
+
63
+ by_id = {r["image_id"]: r["objects"] for r in ann}
64
+ for row in img:
65
+ objects = by_id[row["image_id"]]
66
+ ```
67
+
68
+ ## Selective download
69
+
70
+ ```bash
71
+ # val images + val detection labels (~0.8 GB)
72
+ hf download srishti-kaushik/COCO-2017 --repo-type dataset \
73
+ --include "data/images/val2017/*" "data/instances/val2017/*"
74
+
75
+ # the panoptic stack, without the train JPEGs
76
+ hf download srishti-kaushik/COCO-2017 --repo-type dataset \
77
+ --include "data/panoptic/*" "data/panoptic_masks/*"
78
+
79
+ # the original JSONs, for pycocotools
80
+ hf download srishti-kaushik/COCO-2017 --repo-type dataset --include "raw/annotations/*"
81
+ ```
82
+
83
+ ## `segmentation` is typed, not a JSON string
84
+
85
+ COCO overloads this field with three incompatible shapes. Rather than store a string
86
+ that every consumer has to `json.loads`, it is a struct with a `format` discriminator:
87
+
88
+ | `format` | populated fields | used by |
89
+ |---|---|---|
90
+ | `polygon` | `polygons` — `list<list<float64>>`, each `[x, y, x, y, ...]` | ordinary instances |
91
+ | `rle_uncompressed` | `counts` — `list<int64>`, and `size` `[h, w]` | `iscrowd=1` annotations |
92
+ | `rle_compressed` | `counts_str` — `string`, and `size` `[h, w]` | all of `stuff_*` |
93
+
94
+ Unused fields are null, so the column stays queryable — you can select crowd
95
+ annotations with `segmentation.format == 'rle_uncompressed'` without decoding anything.
96
+
97
+ Decoding to a binary mask:
98
+
99
+ ```python
100
+ from pycocotools import mask as mask_utils
101
+
102
+ def to_mask(obj, height, width):
103
+ s = obj["segmentation"]
104
+ if s["format"] == "polygon":
105
+ rle = mask_utils.merge(mask_utils.frPyObjects(s["polygons"], height, width))
106
+ elif s["format"] == "rle_uncompressed":
107
+ rle = mask_utils.frPyObjects({"counts": s["counts"], "size": s["size"]}, *s["size"])
108
+ else:
109
+ rle = {"counts": s["counts_str"].encode(), "size": s["size"]}
110
+ return mask_utils.decode(rle)
111
+ ```
112
+
113
+ Recovering COCO's original overloaded form:
114
+
115
+ ```python
116
+ def to_coco_segmentation(s):
117
+ if s["format"] == "polygon":
118
+ return s["polygons"]
119
+ counts = s["counts"] if s["format"] == "rle_uncompressed" else s["counts_str"]
120
+ return {"counts": counts, "size": s["size"]}
121
+ ```
122
+
123
+ ## Panoptic PNG encoding
124
+
125
+ Panoptic masks keep the official byte-exact encoding: segment id = `R + 256*G + 256²*B`.
126
+
127
+ ```python
128
+ import numpy as np
129
+
130
+ a = np.array(row["mask"]).astype(np.uint32)
131
+ ids = a[:, :, 0] + 256 * a[:, :, 1] + 256**2 * a[:, :, 2]
132
+ ```
133
+
134
+ ## Note: panoptic segment ids are per-image
135
+
136
+ `objects.id` in `panoptic_*` is the segment's colour code in the matching PNG and is
137
+ unique **within an image only** — ids repeat across images (val2017 has 56,728 segments
138
+ but 51,462 distinct ids). Key on `(image_id, id)`, never `id` alone. Annotation ids in
139
+ `instances_*`, `captions_*`, `person_keypoints_*` and `stuff_*` are globally unique.
docs/VERIFICATION.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Verification
2
+
3
+ This copy was checked against the official COCO 2017 release rather than assumed
4
+ correct. Every check below passed.
5
+
6
+ ## Image and mask integrity
7
+
8
+ | Check | Result |
9
+ |---|---|
10
+ | JPEG bytes SHA-256 identical to the official files | 287,360 / 287,360 |
11
+ | Mask PNG bytes SHA-256 identical to the official files | 246,574 / 246,574 |
12
+ | JPEGs fully decoded (not header-checked) | 287,360, 0 corrupt |
13
+ | Decoded pixel dimensions vs. dimensions declared in the JSON | 0 mismatches |
14
+ | Row count per split vs. files on disk | exact for all splits |
15
+
16
+ Image counts match the official release: 118,287 train / 5,000 val / 40,670 test /
17
+ 123,403 unlabeled.
18
+
19
+ ## Annotation conversion is lossless
20
+
21
+ Every annotation was reconstructed from Parquet back into its original COCO JSON
22
+ shape and compared field by field against the source file.
23
+
24
+ | Family | Annotations compared | Mismatches |
25
+ |---|---|---|
26
+ | `instances` | 896,782 | 0 |
27
+ | `captions` | 616,767 | 0 |
28
+ | `person_keypoints` | 273,469 | 0 |
29
+ | `stuff` | 780,259 | 0 |
30
+ | `panoptic` | 1,386,712 segments | 0 |
31
+
32
+ This covers `bbox`, `area`, `category_id`, `iscrowd`, `keypoints`, `num_keypoints`,
33
+ `caption`, and every `segmentation` in all three of its formats, plus per-image
34
+ metadata (`file_name`, `width`, `height`, `license`, `coco_url`, `flickr_url`,
35
+ `date_captured`) and the category tables for all five families.
36
+
37
+ ## Round-trip behaviour
38
+
39
+ - `image` and `mask` columns decode as PIL images through `datasets`.
40
+ - Reconstructed segmentations decode through `pycocotools` (2,000 sampled, 100%).
41
+ - Annotation `image_id`s and image `image_id`s cover each other exactly, in both
42
+ directions, for every split.
43
+ - Every `panoptic_file_name` resolves to a mask present in `panoptic_masks_*`.
44
+
45
+ ## Reproducing
46
+
47
+ The scripts that built and checked this repo are in `scripts/`:
48
+
49
+ ```bash
50
+ python scripts/build_annotations.py # JSONs -> annotation configs
51
+ python scripts/build_images.py # JPEGs -> image configs
52
+ python scripts/build_masks.py # PNGs -> mask configs
53
+ python scripts/verify_release.py # full verification (byte + round-trip)
54
+ python scripts/validate.py # counts, joins, feature decoding
55
+ ```
56
+
57
+ `verify_release.py` accepts `images`, `masks`, `annotations`, `features` or `all`.
58
+ It compares against a local copy of the official release; paths are set at the top
59
+ of each script.
scripts/make_preview.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Render the sample grid shown on the dataset card.
3
+
4
+ Picks a spread of val2017 images, draws instance boxes with class labels, and
5
+ tiles them into one PNG. Deterministic: same images every run.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import io
11
+ from pathlib import Path
12
+
13
+ import pyarrow.parquet as pq
14
+ from PIL import Image, ImageDraw, ImageFont
15
+
16
+ BUILD = Path("/workspace/workspace_sri/coco_hf/build")
17
+ OUT = BUILD / "assets"
18
+
19
+ COLS, ROWS = 4, 3
20
+ CELL_W, CELL_H = 420, 300
21
+ PAD = 8
22
+ BG = (255, 255, 255)
23
+
24
+ # a readable, colour-blind-friendly cycle for boxes
25
+ PALETTE = [
26
+ (230, 74, 87), (46, 154, 214), (247, 173, 46), (86, 186, 122),
27
+ (155, 106, 214), (232, 122, 178), (95, 194, 196), (198, 142, 82),
28
+ ]
29
+
30
+
31
+ def _font(size: int):
32
+ for p in ("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
33
+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"):
34
+ if Path(p).exists():
35
+ return ImageFont.truetype(p, size)
36
+ return ImageFont.load_default()
37
+
38
+
39
+ def build() -> Path:
40
+ imgs = pq.read_table(BUILD / "data/images/val2017", columns=["image_id", "image"]).to_pylist()
41
+ anns = {r["image_id"]: r for r in pq.read_table(BUILD / "data/instances/val2017").to_pylist()}
42
+
43
+ # prefer images with a handful of objects: busy enough to look like COCO,
44
+ # sparse enough that the boxes stay readable at thumbnail size
45
+ good = [r for r in imgs if 3 <= len(anns.get(r["image_id"], {}).get("objects", [])) <= 8]
46
+ good.sort(key=lambda r: r["image_id"])
47
+ picks = good[:: max(1, len(good) // (COLS * ROWS))][: COLS * ROWS]
48
+
49
+ sheet = Image.new("RGB", (COLS * CELL_W + (COLS + 1) * PAD,
50
+ ROWS * CELL_H + (ROWS + 1) * PAD), BG)
51
+ font = _font(13)
52
+
53
+ for i, rec in enumerate(picks):
54
+ im = Image.open(io.BytesIO(rec["image"]["bytes"])).convert("RGB")
55
+ objects = anns[rec["image_id"]]["objects"]
56
+
57
+ scale = min(CELL_W / im.width, CELL_H / im.height)
58
+ nw, nh = int(im.width * scale), int(im.height * scale)
59
+ im = im.resize((nw, nh), Image.LANCZOS)
60
+ d = ImageDraw.Draw(im)
61
+
62
+ for j, o in enumerate(objects):
63
+ x, y, w, h = (v * scale for v in o["bbox"])
64
+ colour = PALETTE[j % len(PALETTE)]
65
+ d.rectangle([x, y, x + w, y + h], outline=colour, width=3)
66
+ label = o["category_name"]
67
+ tw = d.textlength(label, font=font)
68
+ # keep the tag inside the frame, or it gets clipped at the tile edge
69
+ tx = min(max(0.0, x), nw - tw - 8)
70
+ ty = max(0.0, y - 16)
71
+ d.rectangle([tx, ty, tx + tw + 8, ty + 16], fill=colour)
72
+ d.text((tx + 4, ty + 2), label, fill=(255, 255, 255), font=font)
73
+
74
+ cx = PAD + (i % COLS) * (CELL_W + PAD) + (CELL_W - nw) // 2
75
+ cy = PAD + (i // COLS) * (CELL_H + PAD) + (CELL_H - nh) // 2
76
+ sheet.paste(im, (cx, cy))
77
+
78
+ OUT.mkdir(parents=True, exist_ok=True)
79
+ dst = OUT / "preview.png"
80
+ sheet.save(dst, optimize=True)
81
+ print(f"{dst} {sheet.size} {dst.stat().st_size/1e6:.2f} MB ({len(picks)} images)")
82
+ return dst
83
+
84
+
85
+ if __name__ == "__main__":
86
+ build()