From b6b70ad5fe5fa168d4d44d122b433ad1aaf1959c Mon Sep 17 00:00:00 2001 From: Robert Boscacci Date: Thu, 29 Sep 2022 13:43:41 -0400 Subject: [PATCH] Make COCO exports remember original img resolutions (#1142) * Make COCO exports remember original img resolutions * black formatting --- icevision/data/convert_records_to_coco_style.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/icevision/data/convert_records_to_coco_style.py b/icevision/data/convert_records_to_coco_style.py index 2c68224d2..d2836c358 100644 --- a/icevision/data/convert_records_to_coco_style.py +++ b/icevision/data/convert_records_to_coco_style.py @@ -132,6 +132,14 @@ def export_batch_inferences_as_coco_annotations( ) coco_style_preds = convert_preds_to_coco_style(preds) + imgs_array = [PIL.Image.open(Path(fname)) for fname in img_files] + + sizes = [{"x": img._size[0], "y": img._size[1]} for img in imgs_array] + + for idx, image in enumerate(coco_style_preds["images"]): + coco_style_preds["images"][idx]["width"] = sizes[idx]["x"] + coco_style_preds["images"][idx]["height"] = sizes[idx]["y"] + finalized_pseudo_labels = {**addl_info, **coco_style_preds} # Serialize