Skip to content

Commit eecae58

Browse files
author
Matt Sokoloff
committed
add ignore flag to coco objects
1 parent b146ff5 commit eecae58

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

labelbox/data/serialization/coco/converter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def create_path_if_not_exists(path: str, ignore_existing_data=False):
1010
if not os.path.exists(path):
1111
os.makedirs(path)
1212
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+
)
1416

1517

1618
def validate_path(path, name):
@@ -28,7 +30,8 @@ class COCOConverter:
2830
"""
2931

3032
def serialize_instances(labels: LabelCollection,
31-
image_root: str) -> Dict[str, Any]:
33+
image_root: str,
34+
ignore_existing_data=False) -> Dict[str, Any]:
3235
"""
3336
Convert a Labelbox LabelCollection into an mscoco dataset.
3437
This function will only convert masks, polygons, and rectangles.
@@ -38,10 +41,12 @@ def serialize_instances(labels: LabelCollection,
3841
Args:
3942
labels: A collection of labels to convert
4043
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.
4146
Returns:
4247
A dictionary containing labels in the coco object format.
4348
"""
44-
create_path_if_not_exists(image_root)
49+
create_path_if_not_exists(image_root, ignore_existing_data)
4550
return CocoInstanceDataset.from_common(labels=labels,
4651
image_root=image_root).dict()
4752

0 commit comments

Comments
 (0)