24
24
import json
25
25
import os
26
26
27
- from zipfile import ZipFile
28
-
29
27
from absl import logging
30
28
import tensorflow as tf
31
29
@@ -541,7 +539,22 @@ def _split_generators(self, dl_manager):
541
539
extracted_paths = dl_manager .download_and_extract ({
542
540
key : root_url + url for key , url in urls .items ()
543
541
})
544
-
542
+
543
+ # Extract the panoptic_{}.zip folders containing the png images
544
+ panoptic_image_filename = "panoptic_{}.zip"
545
+ # Extracting panoptic train png images
546
+ panoptic_train_image_path = os .path .join (
547
+ extracted_paths ["panoptic_annotations_trainval2017" ],
548
+ "annotations" ,
549
+ panoptic_image_filename .format ("train2017" )
550
+ )
551
+ # Extracting panoptic val png images
552
+ panoptic_val_image_path = os .path .join (
553
+ extracted_paths ["panoptic_annotations_trainval2017" ],
554
+ "annotations" ,
555
+ panoptic_image_filename .format ("val2017" )
556
+ )
557
+
545
558
return [
546
559
tfds .core .SplitGenerator (
547
560
name = tfds .Split .TRAIN ,
@@ -550,6 +563,7 @@ def _split_generators(self, dl_manager):
550
563
image_dir = extracted_paths ["train_images" ],
551
564
annotation_dir = extracted_paths ["panoptic_annotations_trainval2017" ],
552
565
split_type = "train2017" ,
566
+ panoptic_extracted_images = os .path .join (dl_manager .extract (panoptic_train_image_path ), "panoptic_train2017" ),
553
567
)),
554
568
tfds .core .SplitGenerator (
555
569
name = tfds .Split .VALIDATION ,
@@ -558,11 +572,12 @@ def _split_generators(self, dl_manager):
558
572
image_dir = extracted_paths ["val_images" ],
559
573
annotation_dir = extracted_paths ["panoptic_annotations_trainval2017" ],
560
574
split_type = "val2017" ,
575
+ panoptic_extracted_images = os .path .join (dl_manager .extract (panoptic_val_image_path ), "panoptic_val2017" ),
561
576
)),
562
577
]
563
578
564
579
def _generate_examples (
565
- self , image_dir , annotation_dir , split_type ):
580
+ self , image_dir , annotation_dir , split_type , panoptic_extracted_images ):
566
581
"""Generate examples as dicts.
567
582
568
583
Args:
@@ -609,16 +624,6 @@ def _generate_examples(
609
624
610
625
categories_id2name = {c ["id" ]: c ["name" ] for c in categories }
611
626
612
- # Extract the panoptic_{}.zip folder containing the png images
613
- panoptic_image_filename = "panoptic_{}.zip"
614
- panoptic_image_path = os .path .join (
615
- annotation_dir ,
616
- "annotations" ,
617
- panoptic_image_filename .format (split_type )
618
- )
619
- with ZipFile (panoptic_image_path ) as f :
620
- f .extractall (os .path .join (annotation_dir , "annotations" ))
621
-
622
627
# Iterate over all images
623
628
for image_info in sorted (images , key = lambda x : x ["id" ]):
624
629
# Each instance annotation is a dict:
@@ -654,7 +659,7 @@ def build_bbox(x, y, width, height):
654
659
"image" : os .path .join (image_dir , split_type , image_info ["file_name" ]),
655
660
"image_id" : image_info ["id" ],
656
661
"image/filename" : image_info ["file_name" ],
657
- "panoptic_image" : os .path .join (annotation_dir , "annotations" , "panoptic_{}" . format ( split_type ) , instances ["file_name" ]),
662
+ "panoptic_image" : os .path .join (panoptic_extracted_images , instances ["file_name" ]),
658
663
"panoptic_image/filename" : instances ["file_name" ],
659
664
"objects" : [{
660
665
"area" : instance ["area" ],
0 commit comments