Skip to content

Commit

Permalink
Logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Aug 12, 2024
1 parent ab77f0f commit 06e929a
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions project-dataset/src/ui/output_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
from collections import defaultdict

import supervisely as sly
import yaml
Expand Down Expand Up @@ -117,13 +118,36 @@ def apply_model_ds(src_project, dst_project, inference_settings, res_project_met
# upload_annotations
try:
sly.logger.debug(f"Uploading {len(dst_anns)} annotations...")
g.api.annotation.upload_anns(
[image_info.id for image_info in dst_image_infos], dst_anns
)
pbar.update(len(dst_anns))
# Group dst_image_infos and dst_anns by image_info.dataset_id
# where key is dataset_id and value is tuple of lists of image_infos and anns
dst_image_infos_by_ds = defaultdict(lambda: ([], []))
for dst_image_info, dst_ann in zip(dst_image_infos, dst_anns):
dst_image_infos_by_ds[dst_image_info.dataset_id][0].append(
dst_image_info
)
dst_image_infos_by_ds[dst_image_info.dataset_id][1].append(dst_ann)
sly.logger.debug(f"Grouped {len(dst_anns)} annotations by dataset_id.")

for dst_dataset_id, (
dst_image_infos,
dst_anns,
) in dst_image_infos_by_ds.items():
g.api.annotation.upload_anns(
[image_info.id for image_info in dst_image_infos], dst_anns
)
pbar.update(len(dst_anns))
sly.logger.debug(
f"Uploaded {len(dst_anns)} annotations successfully to dataset_id: {dst_dataset_id}."
)
# g.api.annotation.upload_anns(
# [image_info.id for image_info in dst_image_infos], dst_anns
# )
# pbar.update(len(dst_anns))
sly.logger.debug(f"Uploaded {len(dst_anns)} annotations successfully.")
except Exception as e:
sly.logger.warning(f"There was an error while uploading annotations: {repr(e)}.")
sly.logger.warning(
f"There was an error while uploading annotations: {repr(e)}."
)
for img_info, ann in zip(dst_image_infos, dst_anns):
try:
g.api.annotation.upload_ann(img_info.id, ann)
Expand Down

0 comments on commit 06e929a

Please sign in to comment.