From fd5eb559b1f8edf767537cae9f2d116e6437e679 Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:46:41 +0100 Subject: [PATCH 1/8] Update image_utils.py --- src/picai_eval/image_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index 3ef85bb..ab62c3c 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -64,12 +64,12 @@ def read_image(path: PathLike): else: assert isinstance(path, str), f"Unexpected path type: {type(path)}. Please provide a Path or str." - if '.npy' in path: + if '.npz' in path: + return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format + elif '.npy' in path: return np.load(path) elif '.nii' in path or '.mha' in path or 'mhd' in path: return sitk.GetArrayFromImage(sitk.ReadImage(path)) - elif '.npz' in path: - return np.load(path)['softmax'].astype('float32')[1] # nnUnet format else: raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.") @@ -85,4 +85,5 @@ def read_label(path: PathLike) -> "npt.NDArray[np.int32]": """Read label, given a filepath""" # read label and ensure correct dtype lbl: "npt.NDArray[np.int32]" = np.array(read_image(path), dtype=np.int32) + lbl[lbl!=1]=0 return lbl From e65ca44fd76ab83710f796c1bc1db8cd815e0b5e Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:29:49 +0100 Subject: [PATCH 2/8] update image_utils.py to work with nnunetv2 --- src/picai_eval/image_utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index ab62c3c..7c6c38b 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -64,12 +64,15 @@ def read_image(path: PathLike): else: assert isinstance(path, str), f"Unexpected path type: {type(path)}. Please provide a Path or str." - if '.npz' in path: - return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format - elif '.npy' in path: + if '.npy' in path: return np.load(path) elif '.nii' in path or '.mha' in path or 'mhd' in path: return sitk.GetArrayFromImage(sitk.ReadImage(path)) + elif '.npz' in path: + try: + return np.load(path)['softmax'].astype('float32')[1] # nnUnet format + except: + return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format else: raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.") From b7ffe035bb3eb7c17d942180b3be0d255b16ec69 Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:47:51 +0100 Subject: [PATCH 3/8] fix coding style issues --- src/picai_eval/image_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index 7c6c38b..4726c1a 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -71,7 +71,7 @@ def read_image(path: PathLike): elif '.npz' in path: try: return np.load(path)['softmax'].astype('float32')[1] # nnUnet format - except: + except Exception as e: return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format else: raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.") @@ -88,5 +88,5 @@ def read_label(path: PathLike) -> "npt.NDArray[np.int32]": """Read label, given a filepath""" # read label and ensure correct dtype lbl: "npt.NDArray[np.int32]" = np.array(read_image(path), dtype=np.int32) - lbl[lbl!=1]=0 + lbl[lbl != 1] = 0 return lbl From 4b402c9aa56634ab79b992ef286b1893c91faf3b Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:02:20 +0100 Subject: [PATCH 4/8] Update image_utils.py --- src/picai_eval/image_utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index 4726c1a..231c67e 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -69,10 +69,10 @@ def read_image(path: PathLike): elif '.nii' in path or '.mha' in path or 'mhd' in path: return sitk.GetArrayFromImage(sitk.ReadImage(path)) elif '.npz' in path: - try: - return np.load(path)['softmax'].astype('float32')[1] # nnUnet format - except Exception as e: - return np.load(path)['probabilities'].astype('float32')[1] # nnUnet format + # read the nnU-Net format + data = np.load(path) + data = data["softmax"] if "softmax" in data else data["probabilities"] + return data.astype("float32")[1] else: raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.") @@ -88,5 +88,4 @@ def read_label(path: PathLike) -> "npt.NDArray[np.int32]": """Read label, given a filepath""" # read label and ensure correct dtype lbl: "npt.NDArray[np.int32]" = np.array(read_image(path), dtype=np.int32) - lbl[lbl != 1] = 0 return lbl From d70ac909fd7c53753dade1717823c734d9081e23 Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:12:06 +0100 Subject: [PATCH 5/8] fix formatting --- src/picai_eval/image_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index 231c67e..f6bc408 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -69,7 +69,7 @@ def read_image(path: PathLike): elif '.nii' in path or '.mha' in path or 'mhd' in path: return sitk.GetArrayFromImage(sitk.ReadImage(path)) elif '.npz' in path: - # read the nnU-Net format + #read the nnU-Net format data = np.load(path) data = data["softmax"] if "softmax" in data else data["probabilities"] return data.astype("float32")[1] From b4518b2d4e3049c2075aae3103086971da974b4a Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:20:24 +0100 Subject: [PATCH 6/8] Update image_utils.py --- src/picai_eval/image_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index f6bc408..3047740 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -69,7 +69,7 @@ def read_image(path: PathLike): elif '.nii' in path or '.mha' in path or 'mhd' in path: return sitk.GetArrayFromImage(sitk.ReadImage(path)) elif '.npz' in path: - #read the nnU-Net format + # read the nnU-Net format data = np.load(path) data = data["softmax"] if "softmax" in data else data["probabilities"] return data.astype("float32")[1] From d7260f16c4adbf475a1f2198cfaefd5ae95c6b76 Mon Sep 17 00:00:00 2001 From: NataliaAlves13 <50765571+NataliaAlves13@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:24:25 +0100 Subject: [PATCH 7/8] Update image_utils.py --- src/picai_eval/image_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/picai_eval/image_utils.py b/src/picai_eval/image_utils.py index 3047740..ccb1e1a 100644 --- a/src/picai_eval/image_utils.py +++ b/src/picai_eval/image_utils.py @@ -72,7 +72,7 @@ def read_image(path: PathLike): # read the nnU-Net format data = np.load(path) data = data["softmax"] if "softmax" in data else data["probabilities"] - return data.astype("float32")[1] + return data.astype("float32")[1] else: raise ValueError(f"Unexpected file path. Supported file formats: .nii(.gz), .mha, .npy and .npz. Got: {path}.") From 1ac6d83f45bb1676154be26ae289229d614b39e8 Mon Sep 17 00:00:00 2001 From: Joeran Bosma Date: Mon, 6 May 2024 12:39:39 +0200 Subject: [PATCH 8/8] Update supported Python versions --- .github/workflows/tests.yml | 2 +- setup.cfg | 4 ++-- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ad20b78..4e30306 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: ['3.7', '3.8', '3.9'] + python-version: ['3.8', '3.11'] steps: - uses: actions/checkout@v2 diff --git a/setup.cfg b/setup.cfg index 42b0698..4199731 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,10 +8,10 @@ platforms = unix, linux, osx, cygwin, win32 classifiers = Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 [options] packages = diff --git a/setup.py b/setup.py index 8ef08d9..04a3bdb 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,7 @@ def run(self): long_description = fh.read() setuptools.setup( - version='1.4.5', # also update version in metrics.py -> version + version='1.4.6', # also update version in metrics.py -> version author_email='Joeran.Bosma@radboudumc.nl', long_description=long_description, long_description_content_type="text/markdown",