6
6
from labelbox .data .serialization .coco .panoptic_dataset import CocoPanopticDataset
7
7
8
8
9
- def create_path_if_not_exists (path : str ):
9
+ def create_path_if_not_exists (path : str , ignore_existing_data = False ):
10
10
if not os .path .exists (path ):
11
11
os .makedirs (path )
12
- elif os .listdir (path ):
12
+ elif not ignore_existing_data and os .listdir (path ):
13
13
raise ValueError (f"Directory `{ path } `` must be empty." )
14
14
15
15
@@ -48,7 +48,8 @@ def serialize_instances(labels: LabelCollection,
48
48
def serialize_panoptic (labels : LabelCollection ,
49
49
image_root : str ,
50
50
mask_root : str ,
51
- all_stuff : bool = False ) -> Dict [str , Any ]:
51
+ all_stuff : bool = False ,
52
+ ignore_existing_data = False ) -> Dict [str , Any ]:
52
53
"""
53
54
Convert a Labelbox LabelCollection into an mscoco dataset.
54
55
This function will only convert masks, polygons, and rectangles.
@@ -61,11 +62,13 @@ def serialize_panoptic(labels: LabelCollection,
61
62
mask_root: Where to save segmentation masks to
62
63
all_stuff: If rectangle or polygon annotations are encountered, they will be treated as instances.
63
64
To convert them to stuff class set `all_stuff=True`.
65
+ ignore_existing_data: Whether or not to raise an exception if images already exist.
66
+ This exists only to support detectons panoptic fpn model which requires two mscoco payloads for the same images.
64
67
Returns:
65
68
A dictionary containing labels in the coco panoptic format.
66
69
"""
67
- create_path_if_not_exists (image_root )
68
- create_path_if_not_exists (mask_root )
70
+ create_path_if_not_exists (image_root , ignore_existing_data )
71
+ create_path_if_not_exists (mask_root , ignore_existing_data )
69
72
return CocoPanopticDataset .from_common (labels = labels ,
70
73
image_root = image_root ,
71
74
mask_root = mask_root ,
0 commit comments