Skip to content

Commit b146ff5

Browse files
author
Matt Sokoloff
committed
add: ignore existing data
1 parent 2b3c49a commit b146ff5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

labelbox/data/serialization/coco/converter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from labelbox.data.serialization.coco.panoptic_dataset import CocoPanopticDataset
77

88

9-
def create_path_if_not_exists(path: str):
9+
def create_path_if_not_exists(path: str, ignore_existing_data=False):
1010
if not os.path.exists(path):
1111
os.makedirs(path)
12-
elif os.listdir(path):
12+
elif not ignore_existing_data and os.listdir(path):
1313
raise ValueError(f"Directory `{path}`` must be empty.")
1414

1515

@@ -48,7 +48,8 @@ def serialize_instances(labels: LabelCollection,
4848
def serialize_panoptic(labels: LabelCollection,
4949
image_root: str,
5050
mask_root: str,
51-
all_stuff: bool = False) -> Dict[str, Any]:
51+
all_stuff: bool = False,
52+
ignore_existing_data=False) -> Dict[str, Any]:
5253
"""
5354
Convert a Labelbox LabelCollection into an mscoco dataset.
5455
This function will only convert masks, polygons, and rectangles.
@@ -61,11 +62,13 @@ def serialize_panoptic(labels: LabelCollection,
6162
mask_root: Where to save segmentation masks to
6263
all_stuff: If rectangle or polygon annotations are encountered, they will be treated as instances.
6364
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.
6467
Returns:
6568
A dictionary containing labels in the coco panoptic format.
6669
"""
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)
6972
return CocoPanopticDataset.from_common(labels=labels,
7073
image_root=image_root,
7174
mask_root=mask_root,

0 commit comments

Comments
 (0)