Skip to content

Commit

Permalink
Handle images without annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Jan 16, 2024
1 parent 83b03bf commit 93e56bc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions backend/kangas/integrations/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ def export_to_comet(path, name, options):
asset_id, asset_type, asset_data, asset_metadata, asset_thumbnail = row
metadata = json.loads(asset_metadata)
## Only send what comet can accept:
for layer_index, annotation_layer in enumerate(metadata["annotations"]):
for index, annotation in reversed(
list(enumerate(annotation_layer["data"][:]))
):
if get_annnotation_type(annotation) not in ["points", "boxes"]:
del metadata["annotations"][layer_index]["data"][index]
if "annotations" in metadata:
for layer_index, annotation_layer in enumerate(metadata["annotations"]):
for index, annotation in reversed(
list(enumerate(annotation_layer["data"][:]))
):
if get_annnotation_type(annotation) not in ["points", "boxes"]:
del metadata["annotations"][layer_index]["data"][index]
if asset_data:
if isinstance(asset_data, str):
if asset_data.startswith("{"):
Expand All @@ -202,10 +203,12 @@ def export_to_comet(path, name, options):
else:
step = 0

annotations = metadata["annotations"] if "annotations" in metadata else None

asset_results = experiment.log_image(
binary_io,
name=file_name,
annotations=metadata["annotations"],
annotations=annotations,
step=step,
)
# For consistenency:
Expand Down

0 comments on commit 93e56bc

Please sign in to comment.