Skip to content

Commit

Permalink
add fail_on_labelbox_project_export_error argument to skip labelbox e…
Browse files Browse the repository at this point in the history
…xport failures
  • Loading branch information
tyesayan committed Dec 3, 2024
1 parent 9ae0cb5 commit 6ee3bbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions deeplake/integrations/labelbox/labelbox_.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def converter_for_video_project_with_id(
lb_api_key,
group_mapping=None,
fail_on_error=False,
fail_on_labelbox_project_export_error=False,
):
"""
Creates a converter for Labelbox video project to a Deeplake dataset format based on annotation types.
Expand All @@ -26,6 +27,7 @@ def converter_for_video_project_with_id(
lb_api_key (str): Labelbox API key for authentication.
group_mapping (dict, optional): A dictionary mapping annotation kinds (labelbox_kind) to the desired tensor group name (tensor_name). This mapping determines whether annotations of the same kind should be grouped into the same tensor or kept separate.
fail_on_error (bool, optional): Whether to raise an exception if data validation fails. Defaults to False.
fail_on_labelbox_project_export_error (bool, optional): Whether to raise an exception if Labelbox project export fails. Defaults to False.
Returns:
labelbox_type_converter or None: Returns a labelbox_type_converter if successful, None if no data is found.
Expand All @@ -51,7 +53,7 @@ def converter_for_video_project_with_id(
- Supports Video ontology from labelbox.
- The function first validates the project data before setting up converters.
"""
project_json = labelbox_get_project_json_with_id_(client, project_id, fail_on_error)
project_json = labelbox_get_project_json_with_id_(client, project_id, fail_on_labelbox_project_export_error)

Check warning on line 56 in deeplake/integrations/labelbox/labelbox_.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_.py#L56

Added line #L56 was not covered by tests

if len(project_json) == 0:
print("no data")
Expand Down Expand Up @@ -253,6 +255,7 @@ def create_dataset_from_video_annotation_project_with_custom_data_filler(
fail_on_error=False,
url_presigner=None,
video_generator_batch_size=100,
fail_on_labelbox_project_export_error=False,
):
"""
Creates a Deeplake dataset from an existing Labelbox video annotation project using custom data processing.
Expand All @@ -276,6 +279,8 @@ def create_dataset_from_video_annotation_project_with_custom_data_filler(
overwrite (bool, optional): Whether to overwrite existing dataset. Defaults to False
fail_on_error (bool, optional): Whether to raise an exception if data validation fails. Defaults to False
url_presigner (callable, optional): Function that takes a URL and returns a pre-signed URL and headers (str, dict). Default will use labelbox access token to access the data. Is useful when used cloud storage integrations.
video_generator_batch_size (int, optional): Number of frames to process in each batch. Defaults to 100
fail_on_labelbox_project_export_error (bool, optional): Whether to raise an exception if Labelbox project export fails. Defaults to False
Returns:
Dataset: Created Deeplake dataset containing processed video frames and Labelbox metadata.
Expand All @@ -293,7 +298,7 @@ def create_dataset_from_video_annotation_project_with_custom_data_filler(
)
data_filler["create_tensors"](ds)

Check warning on line 299 in deeplake/integrations/labelbox/labelbox_.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_.py#L299

Added line #L299 was not covered by tests

proj = labelbox_get_project_json_with_id_(lb_client, project_id, fail_on_error)
proj = labelbox_get_project_json_with_id_(lb_client, project_id, fail_on_labelbox_project_export_error)
if len(proj) == 0:
print("no data")
return ds

Check warning on line 304 in deeplake/integrations/labelbox/labelbox_.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_.py#L301-L304

Added lines #L301 - L304 were not covered by tests
Expand Down Expand Up @@ -344,6 +349,7 @@ def create_dataset_from_video_annotation_project(
fail_on_error=False,
url_presigner=None,
video_generator_batch_size=100,
fail_on_labelbox_project_export_error=False,
):
"""
See create_dataset_from_video_annotation_project_with_custom_data_filler for complete documentation.
Expand All @@ -368,4 +374,5 @@ def create_dataset_from_video_annotation_project(
fail_on_error=fail_on_error,
url_presigner=url_presigner,
video_generator_batch_size=video_generator_batch_size,
fail_on_labelbox_project_export_error=fail_on_labelbox_project_export_error,
)
14 changes: 10 additions & 4 deletions deeplake/integrations/labelbox/labelbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,16 @@ def error_stream_handler(error):
raise Exception(f"Error during export: {error}")
print(f"Error during export: {error}")

Check warning on line 173 in deeplake/integrations/labelbox/labelbox_utils.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_utils.py#L170-L173

Added lines #L170 - L173 were not covered by tests

if export_task.has_errors():
export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(
stream_handler=error_stream_handler
)

try:
if export_task.has_errors():
export_task.get_buffered_stream(stream_type=lb.StreamType.ERRORS).start(

Check warning on line 178 in deeplake/integrations/labelbox/labelbox_utils.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_utils.py#L176-L178

Added lines #L176 - L178 were not covered by tests
stream_handler=error_stream_handler
)
except Exception as e:
if fail_on_error:
raise e
print(f"Error during export: {e}")

Check warning on line 184 in deeplake/integrations/labelbox/labelbox_utils.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_utils.py#L181-L184

Added lines #L181 - L184 were not covered by tests

if export_task.has_result():
export_json = export_task.get_buffered_stream(

Check warning on line 187 in deeplake/integrations/labelbox/labelbox_utils.py

View check run for this annotation

Codecov / codecov/patch

deeplake/integrations/labelbox/labelbox_utils.py#L186-L187

Added lines #L186 - L187 were not covered by tests
Expand Down

0 comments on commit 6ee3bbe

Please sign in to comment.