From d06f00455ec2a6f6617b11aacaa54a1e621d97ab Mon Sep 17 00:00:00 2001 From: myron Date: Tue, 21 Mar 2023 20:06:01 -0700 Subject: [PATCH 1/2] ensure invertible Signed-off-by: myron --- .../hecktor22/hecktor_crop_neck_region.py | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py b/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py index b0405805bb..70866c5b56 100644 --- a/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py +++ b/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py @@ -50,7 +50,9 @@ def __call__(self, data): box_start, box_end = self.extract_roi(im_pet=im_pet, box_size=box_size) - if "label" in d and "label" in self.keys: + use_label = 'label' in d and 'label' in self.keys and (d['image'].shape[1:]==d['label'].shape[1:]) + + if use_label: # if label mask is available, let's check if the cropped region includes all foreground before_sum = d["label"].sum().item() after_sum = ( @@ -61,29 +63,22 @@ def __call__(self, data): if before_sum != after_sum: warnings.warn( "WARNING, H&N crop could be incorrect!!! ", - before_sum, - after_sum, - "image:", - d["image"].shape, - "pet:", - d["image2"].shape, - "label:", - d["label"].shape, - "updated box_size", - box_size, - "box_start", - box_start, - "box_end:", - box_end, - "filename", - filename, + before_sum, after_sum, + "image:", d["image"].shape, + "pet:", d["image2"].shape, + "label:", d["label"].shape, + "updated box_size", box_size, + "box_start", box_start, + "box_end:", box_end, + "filename", filename ) d[self.start_coord_key] = box_start d[self.end_coord_key] = box_end for key, m in self.key_iterator(d, self.mode): - self.push_transform(d, key, extra_info={"box_start": box_start, "box_end": box_end}) + if key=="label" and not use_label: + continue d[key] = self.cropper.crop_pad(img=d[key], box_start=box_start, box_end=box_end, mode=m) return d From a1fcf5b4bf408ca831f7638fc435c53d2328c47f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 03:08:17 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../hecktor22/hecktor_crop_neck_region.py | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py b/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py index 70866c5b56..3adf6e1d07 100644 --- a/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py +++ b/auto3dseg/tasks/hecktor22/hecktor_crop_neck_region.py @@ -50,7 +50,7 @@ def __call__(self, data): box_start, box_end = self.extract_roi(im_pet=im_pet, box_size=box_size) - use_label = 'label' in d and 'label' in self.keys and (d['image'].shape[1:]==d['label'].shape[1:]) + use_label = "label" in d and "label" in self.keys and (d["image"].shape[1:] == d["label"].shape[1:]) if use_label: # if label mask is available, let's check if the cropped region includes all foreground @@ -63,21 +63,29 @@ def __call__(self, data): if before_sum != after_sum: warnings.warn( "WARNING, H&N crop could be incorrect!!! ", - before_sum, after_sum, - "image:", d["image"].shape, - "pet:", d["image2"].shape, - "label:", d["label"].shape, - "updated box_size", box_size, - "box_start", box_start, - "box_end:", box_end, - "filename", filename + before_sum, + after_sum, + "image:", + d["image"].shape, + "pet:", + d["image2"].shape, + "label:", + d["label"].shape, + "updated box_size", + box_size, + "box_start", + box_start, + "box_end:", + box_end, + "filename", + filename, ) d[self.start_coord_key] = box_start d[self.end_coord_key] = box_end for key, m in self.key_iterator(d, self.mode): - if key=="label" and not use_label: + if key == "label" and not use_label: continue d[key] = self.cropper.crop_pad(img=d[key], box_start=box_start, box_end=box_end, mode=m)