From b2f183123eec112dcdd245bd048d37c85abca6af Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Fri, 19 Apr 2024 12:39:33 -0400 Subject: [PATCH 1/4] `data_iterators.py`: Remove `[0]` to properly unpack indexed data This fixes a bug introduced in https://github.com/MIC-DKFZ/nnUNet/commit/d87fa5b84e138c536d1f5c2dba7be92856893554. `[0]` refers specifically to `files = self._data[idx][0]`. By combining the indexes into a single link, the previous commit needed to remove the `[0]` index. --- nnunetv2/inference/data_iterators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nnunetv2/inference/data_iterators.py b/nnunetv2/inference/data_iterators.py index 068905d9f..f71c73a2f 100644 --- a/nnunetv2/inference/data_iterators.py +++ b/nnunetv2/inference/data_iterators.py @@ -146,7 +146,7 @@ def __init__(self, list_of_lists: List[List[str]], def generate_train_batch(self): idx = self.get_indices()[0] - files, seg_prev_stage, ofile = self._data[idx][0] + files, seg_prev_stage, ofile = self._data[idx] # if we have a segmentation from the previous stage we have to process it together with the images so that we # can crop it appropriately (if needed). Otherwise it would just be resized to the shape of the data after # preprocessing and then there might be misalignments @@ -190,7 +190,7 @@ def __init__(self, list_of_images: List[np.ndarray], def generate_train_batch(self): idx = self.get_indices()[0] - image, seg_prev_stage, props, ofname = self._data[idx][0] + image, seg_prev_stage, props, ofname = self._data[idx] # if we have a segmentation from the previous stage we have to process it together with the images so that we # can crop it appropriately (if needed). Otherwise it would just be resized to the shape of the data after # preprocessing and then there might be misalignments From d30dcb92e86373ec596f53d7167f1f0e3f27e7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=CC=8Caxans=CC=8Co=20S=CC=8Cukur=20Sabzale=CC=82?= Date: Sun, 21 Apr 2024 14:37:43 +0600 Subject: [PATCH 2/4] Added missing import --- nnunetv2/preprocessing/preprocessors/default_preprocessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nnunetv2/preprocessing/preprocessors/default_preprocessor.py b/nnunetv2/preprocessing/preprocessors/default_preprocessor.py index df42ac993..7e0068b9d 100644 --- a/nnunetv2/preprocessing/preprocessors/default_preprocessor.py +++ b/nnunetv2/preprocessing/preprocessors/default_preprocessor.py @@ -14,7 +14,7 @@ import multiprocessing import shutil from time import sleep -from typing import Tuple +from typing import Tuple, Union import numpy as np from batchgenerators.utilities.file_and_folder_operations import * From 65bad9df96e399efd53805c7739a8e05144be5f4 Mon Sep 17 00:00:00 2001 From: Fabian Isensee Date: Thu, 25 Apr 2024 11:14:08 +0200 Subject: [PATCH 3/4] 2.4.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d00c8f7f0..e0a1bfeef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nnunetv2" -version = "2.4.1" +version = "2.4.2" requires-python = ">=3.9" description = "nnU-Net is a framework for out-of-the box image segmentation." readme = "readme.md" From f14188b2fd6d9815f1d85f7205d5fb21cec14af4 Mon Sep 17 00:00:00 2001 From: Fabian Isensee Date: Thu, 25 Apr 2024 14:06:20 +0200 Subject: [PATCH 4/4] improve speed of ConvertSegmentationToRegionsTransform --- .../region_based_training.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/nnunetv2/training/data_augmentation/custom_transforms/region_based_training.py b/nnunetv2/training/data_augmentation/custom_transforms/region_based_training.py index 52d2fc0a3..93e8f5edb 100644 --- a/nnunetv2/training/data_augmentation/custom_transforms/region_based_training.py +++ b/nnunetv2/training/data_augmentation/custom_transforms/region_based_training.py @@ -22,17 +22,13 @@ def __init__(self, regions: Union[List, Tuple], def __call__(self, **data_dict): seg = data_dict.get(self.seg_key) - num_regions = len(self.regions) if seg is not None: - seg_shp = seg.shape - output_shape = list(seg_shp) - output_shape[1] = num_regions - region_output = np.zeros(output_shape, dtype=seg.dtype) - for b in range(seg_shp[0]): - for region_id, region_source_labels in enumerate(self.regions): - if not isinstance(region_source_labels, (list, tuple)): - region_source_labels = (region_source_labels, ) - for label_value in region_source_labels: - region_output[b, region_id][seg[b, self.seg_channel] == label_value] = 1 - data_dict[self.output_key] = region_output + b, c, *shape = seg.shape + region_output = np.zeros((b, len(self.regions), *shape), dtype=bool) + for region_id, region_labels in enumerate(self.regions): + if not isinstance(region_labels, (list, tuple)): + region_labels = (region_labels, ) + for label_value in region_labels: + region_output[:, region_id] |= (seg[:, self.seg_channel] == label_value) + data_dict[self.output_key] = region_output.astype(np.uint8, copy=False) return data_dict