From 3808231601265aed98d70de4218fc845e185959d Mon Sep 17 00:00:00 2001 From: Fabian Isensee Date: Sat, 20 Apr 2024 19:32:47 +0200 Subject: [PATCH] remove unused imports, ensure data is float32, astype w/o copy --- .../preprocessors/default_preprocessor.py | 12 ++++++------ .../preprocessing/resampling/default_resampling.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nnunetv2/preprocessing/preprocessors/default_preprocessor.py b/nnunetv2/preprocessing/preprocessors/default_preprocessor.py index 708f345af..df42ac993 100644 --- a/nnunetv2/preprocessing/preprocessors/default_preprocessor.py +++ b/nnunetv2/preprocessing/preprocessors/default_preprocessor.py @@ -14,20 +14,20 @@ import multiprocessing import shutil from time import sleep -from typing import Union, Tuple +from typing import Tuple -import nnunetv2 import numpy as np from batchgenerators.utilities.file_and_folder_operations import * +from tqdm import tqdm + +import nnunetv2 from nnunetv2.paths import nnUNet_preprocessed, nnUNet_raw from nnunetv2.preprocessing.cropping.cropping import crop_to_nonzero from nnunetv2.preprocessing.resampling.default_resampling import compute_new_shape from nnunetv2.utilities.dataset_name_id_conversion import maybe_convert_to_dataset_name from nnunetv2.utilities.find_class_by_name import recursive_find_python_class from nnunetv2.utilities.plans_handling.plans_handler import PlansManager, ConfigurationManager -from nnunetv2.utilities.utils import get_identifiers_from_splitted_dataset_folder, \ - create_lists_from_splitted_dataset_folder, get_filenames_of_train_images_and_targets -from tqdm import tqdm +from nnunetv2.utilities.utils import get_filenames_of_train_images_and_targets class DefaultPreprocessor(object): @@ -41,7 +41,7 @@ def run_case_npy(self, data: np.ndarray, seg: Union[np.ndarray, None], propertie plans_manager: PlansManager, configuration_manager: ConfigurationManager, dataset_json: Union[dict, str]): # let's not mess up the inputs! - data = np.copy(data) + data = data.astype(np.float32) # this creates a copy if seg is not None: assert data.shape[1:] == seg.shape[1:], "Shape mismatch between image and segmentation. Please fix your dataset and make use of the --verify_dataset_integrity flag to ensure everything is correct" seg = np.copy(seg) diff --git a/nnunetv2/preprocessing/resampling/default_resampling.py b/nnunetv2/preprocessing/resampling/default_resampling.py index a2fb132fb..a733fe565 100644 --- a/nnunetv2/preprocessing/resampling/default_resampling.py +++ b/nnunetv2/preprocessing/resampling/default_resampling.py @@ -151,7 +151,7 @@ def resample_data_or_seg(data: np.ndarray, new_shape: Union[Tuple[float, ...], L dtype_out = data.dtype reshaped_final = np.zeros((data.shape[0], *new_shape), dtype=dtype_out) if np.any(shape != new_shape): - data = data.astype(float) + data = data.astype(float, copy=False) if do_separate_z: # print("separate z, order in z is", order_z, "order inplane is", order) assert len(axis) == 1, "only one anisotropic axis supported"