Skip to content

Commit 93e56bc

Browse files
committed
Handle images without annotations
1 parent 83b03bf commit 93e56bc

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

backend/kangas/integrations/comet.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ def export_to_comet(path, name, options):
173173
asset_id, asset_type, asset_data, asset_metadata, asset_thumbnail = row
174174
metadata = json.loads(asset_metadata)
175175
## Only send what comet can accept:
176-
for layer_index, annotation_layer in enumerate(metadata["annotations"]):
177-
for index, annotation in reversed(
178-
list(enumerate(annotation_layer["data"][:]))
179-
):
180-
if get_annnotation_type(annotation) not in ["points", "boxes"]:
181-
del metadata["annotations"][layer_index]["data"][index]
176+
if "annotations" in metadata:
177+
for layer_index, annotation_layer in enumerate(metadata["annotations"]):
178+
for index, annotation in reversed(
179+
list(enumerate(annotation_layer["data"][:]))
180+
):
181+
if get_annnotation_type(annotation) not in ["points", "boxes"]:
182+
del metadata["annotations"][layer_index]["data"][index]
182183
if asset_data:
183184
if isinstance(asset_data, str):
184185
if asset_data.startswith("{"):
@@ -202,10 +203,12 @@ def export_to_comet(path, name, options):
202203
else:
203204
step = 0
204205

206+
annotations = metadata["annotations"] if "annotations" in metadata else None
207+
205208
asset_results = experiment.log_image(
206209
binary_io,
207210
name=file_name,
208-
annotations=metadata["annotations"],
211+
annotations=annotations,
209212
step=step,
210213
)
211214
# For consistenency:

0 commit comments

Comments
 (0)