@@ -10,7 +10,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
12
elif not ignore_existing_data and os .listdir (path ):
13
- raise ValueError (f"Directory `{ path } `` must be empty." )
13
+ raise ValueError (
14
+ f"Directory `{ path } `` must be empty. Or set `ignore_existing_data=True`"
15
+ )
14
16
15
17
16
18
def validate_path (path , name ):
@@ -28,7 +30,8 @@ class COCOConverter:
28
30
"""
29
31
30
32
def serialize_instances (labels : LabelCollection ,
31
- image_root : str ) -> Dict [str , Any ]:
33
+ image_root : str ,
34
+ ignore_existing_data = False ) -> Dict [str , Any ]:
32
35
"""
33
36
Convert a Labelbox LabelCollection into an mscoco dataset.
34
37
This function will only convert masks, polygons, and rectangles.
@@ -38,10 +41,12 @@ def serialize_instances(labels: LabelCollection,
38
41
Args:
39
42
labels: A collection of labels to convert
40
43
image_root: Where to save images to
44
+ ignore_existing_data: Whether or not to raise an exception if images already exist.
45
+ This exists only to support detectons panoptic fpn model which requires two mscoco payloads for the same images.
41
46
Returns:
42
47
A dictionary containing labels in the coco object format.
43
48
"""
44
- create_path_if_not_exists (image_root )
49
+ create_path_if_not_exists (image_root , ignore_existing_data )
45
50
return CocoInstanceDataset .from_common (labels = labels ,
46
51
image_root = image_root ).dict ()
47
52
0 commit comments