2525import numpy as np
2626import tensorflow_datasets .public_api as tfds
2727
28- _URLS = {
28+ _EXTRACT_URLS = {
2929 'train_annotation' : (
3030 'https://dl.fbaipublicfiles.com/LVIS/lvis_v1_train.json.zip'
3131 ),
3434 'https://dl.fbaipublicfiles.com/LVIS/lvis_v1_val.json.zip'
3535 ),
3636 'validation_images' : 'http://images.cocodataset.org/zips/val2017.zip' ,
37- 'test_annotation' : 'https://dl.fbaipublicfiles.com/LVIS/lvis_v1_image_info_test_dev.json.zip' ,
37+ 'test_annotation' : (
38+ 'https://dl.fbaipublicfiles.com/LVIS/lvis_v1_image_info_test_dev.json.zip'
39+ ),
3840 'test_images' : 'http://images.cocodataset.org/zips/test2017.zip' ,
39- # Minival from https://github.com/ashkamath/mdetr/blob/main/.github/lvis.md:
41+ }
42+ _URLS = {
43+ # Minival from
44+ # https://gitlab.com/YuanHuan_Pro/YOLO-World/-/blob/master/docs/data.md:
4045 'minival_annotation' : (
41- 'https://nyu.box.com/shared/static/2yk9x8az9pnlsy2v8gd95yncwn2q7vj6.zip '
46+ 'https://huggingface.co/GLIPModel/GLIP/resolve/main/lvis_v1_minival_inserted_image_name.json '
4247 ),
4348}
4449
7176class Builder (tfds .core .GeneratorBasedBuilder ):
7277 """DatasetBuilder for lvis dataset."""
7378
74- VERSION = tfds .core .Version ('1.3 .0' )
79+ VERSION = tfds .core .Version ('1.4 .0' )
7580 RELEASE_NOTES = {
7681 '1.1.0' : (
7782 'Added fields `neg_category_ids` and `not_exhaustive_category_ids`.'
7883 ),
7984 '1.2.0' : 'Added class names.' ,
8085 '1.3.0' : 'Added minival split.' ,
86+ '1.4.0' : 'Added segmentation masks to the minival split.' ,
8187 }
8288
8389 def _info (self ) -> tfds .core .DatasetInfo :
@@ -116,7 +122,10 @@ def _info(self) -> tfds.core.DatasetInfo:
116122
117123 def _split_generators (self , dl_manager : tfds .download .DownloadManager ):
118124 """Returns SplitGenerators."""
119- paths = dl_manager .download_and_extract (_URLS )
125+ paths = {
126+ ** dl_manager .download_and_extract (_EXTRACT_URLS ),
127+ ** dl_manager .download (_URLS ),
128+ }
120129 image_dirs = [
121130 paths ['train_images' ] / 'train2017' ,
122131 paths ['validation_images' ] / 'val2017' ,
@@ -135,7 +144,7 @@ def _split_generators(self, dl_manager: tfds.download.DownloadManager):
135144 ),
136145 'minival' : self ._generate_examples (
137146 image_dirs ,
138- paths ['minival_annotation' ] / 'lvis_v1_minival.json' ,
147+ paths ['minival_annotation' ],
139148 ),
140149 }
141150
@@ -169,7 +178,7 @@ def _process_example(image_info):
169178 'bbox' : _build_bbox (image_info , * inst ['bbox' ]),
170179 'label' : inst ['category_id' ] - 1 ,
171180 'segmentation' : _build_segmentation_mask (
172- image_info , inst . get ( 'segmentation' , []) # No segs in minival.
181+ image_info , inst [ 'segmentation' ]
173182 ),
174183 })
175184 return image_info ['id' ], example
0 commit comments