Skip to content

Commit

Permalink
remove unused imports, ensure data is float32, astype w/o copy
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianIsensee committed Apr 20, 2024
1 parent 45a4be1 commit 3808231
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions nnunetv2/preprocessing/preprocessors/default_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
import multiprocessing
import shutil
from time import sleep
from typing import Union, Tuple

This comment has been minimized.

Copy link
@shukkkur

shukkkur Apr 21, 2024

Contributor

Union is not an unused import.
Removing it raises NameError error on line 42 and others
PR #2117

This comment has been minimized.

Copy link
@FabianIsensee

FabianIsensee Apr 22, 2024

Author Member

Jup, I am not sure how that happened. I let pycharm clean up unused imports and forgot to double check. Will take care of this as soon as I am back form my travels

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):
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nnunetv2/preprocessing/resampling/default_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3808231

Please sign in to comment.