From ba56a6d029abed931e3d8bcac5f7c91ddd2ccaf2 Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 5 Feb 2025 15:26:32 +0000 Subject: [PATCH 1/8] Move test_image_filter.py --- tests/{ => data}/test_image_rw.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{ => data}/test_image_rw.py (100%) diff --git a/tests/test_image_rw.py b/tests/data/test_image_rw.py similarity index 100% rename from tests/test_image_rw.py rename to tests/data/test_image_rw.py From da29d2f8304a09886e7909f4090464c4aa5a430c Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 19 Feb 2025 09:37:15 +0000 Subject: [PATCH 2/8] Corrects test paths target --- tests/bundle/test_bundle_trt_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bundle/test_bundle_trt_export.py b/tests/bundle/test_bundle_trt_export.py index a7c570438d..5168fcfdb5 100644 --- a/tests/bundle/test_bundle_trt_export.py +++ b/tests/bundle/test_bundle_trt_export.py @@ -70,7 +70,7 @@ def tearDown(self): @parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4]) @unittest.skipUnless(has_torchtrt and has_tensorrt, "Torch-TensorRT is required for conversion!") def test_trt_export(self, convert_precision, input_shape, dynamic_batch): - tests_dir = Path(__file__).resolve().parent + tests_dir = Path(__file__).resolve().parents[1] meta_file = os.path.join(tests_dir, "testing_data", "metadata.json") config_file = os.path.join(tests_dir, "testing_data", "inference.json") with tempfile.TemporaryDirectory() as tempdir: From 93f16dba61f3bcc18dd4ea6cccb3145eda6092db Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 19 Feb 2025 10:25:03 +0000 Subject: [PATCH 3/8] Fix unrelated tests/networks/test_convert_to_onnx.py There was a problem with this test after the else statement was removed, leading to a onnx_model not defined error --- tests/networks/test_convert_to_onnx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/networks/test_convert_to_onnx.py b/tests/networks/test_convert_to_onnx.py index cfc356d5a4..106f15dc9d 100644 --- a/tests/networks/test_convert_to_onnx.py +++ b/tests/networks/test_convert_to_onnx.py @@ -64,7 +64,7 @@ def test_unet(self, device, use_trace, use_ort): rtol=rtol, atol=atol, ) - self.assertTrue(isinstance(onnx_model, onnx.ModelProto)) + self.assertTrue(isinstance(onnx_model, onnx.ModelProto)) @parameterized.expand(TESTS_ORT) @SkipIfBeforePyTorchVersion((1, 12)) From 99dce143ed6b37abefbfe08250e619ab25051055 Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 19 Feb 2025 16:21:10 +0000 Subject: [PATCH 4/8] DCO Remediation Commit for R. Garcia-Dias I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: ba56a6d029abed931e3d8bcac5f7c91ddd2ccaf2 I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: da29d2f8304a09886e7909f4090464c4aa5a430c I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: 93f16dba61f3bcc18dd4ea6cccb3145eda6092db Signed-off-by: R. Garcia-Dias Signed-off-by: R. Garcia-Dias --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e5607ccb02..214fd478ab 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ MONAI is a [PyTorch](https://pytorch.org/)-based, [open-source](https://github.com/Project-MONAI/MONAI/blob/dev/LICENSE) framework for deep learning in healthcare imaging, part of the [PyTorch Ecosystem](https://pytorch.org/ecosystem/). Its ambitions are as follows: + - Developing a community of academic, industrial and clinical researchers collaborating on a common foundation; - Creating state-of-the-art, end-to-end training workflows for healthcare imaging; - Providing researchers with the optimized and standardized way to create and evaluate deep learning models. From 2549bbb1f6ce4011bf9c9604a9b5141c91b93122 Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 19 Feb 2025 17:53:30 +0000 Subject: [PATCH 5/8] Add dict_product utility for test case generation - Introduced a new `dict_product` function to create combinations of input parameters. - Updated test cases to use the new utility for generating shape and input type combinations. - Cleaned up code by removing old nested loops in favor of the new function. --- tests/test_utils.py | 18 +++++++++++++++++- tests/transforms/test_gibbs_noise.py | 8 +++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index c494bb547c..97a3181c44 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -30,9 +30,10 @@ import warnings from contextlib import contextmanager from functools import partial, reduce +from itertools import product from pathlib import Path from subprocess import PIPE, Popen -from typing import Callable +from typing import Callable, Literal from urllib.error import ContentTooShortError, HTTPError import numpy as np @@ -862,6 +863,21 @@ def equal_state_dict(st_1, st_2): if torch.cuda.is_available(): TEST_DEVICES.append([torch.device("cuda")]) + +def dict_product(trailing=False, format: Literal["list", "dict"] = "dict", **items): + keys = items.keys() + values = items.values() + for pvalues in product(*values): + dict_comb = dict(zip(keys, pvalues)) + if format == "dict": + if trailing: + yield [dict_comb] + list(pvalues) + else: + yield dict_comb + else: + yield pvalues + + if __name__ == "__main__": parser = argparse.ArgumentParser(prog="util") parser.add_argument("-c", "--count", default=2, help="max number of gpus") diff --git a/tests/transforms/test_gibbs_noise.py b/tests/transforms/test_gibbs_noise.py index 2aa2a44d10..1f96595a26 100644 --- a/tests/transforms/test_gibbs_noise.py +++ b/tests/transforms/test_gibbs_noise.py @@ -21,14 +21,12 @@ from monai.transforms import GibbsNoise from monai.utils.misc import set_determinism from monai.utils.module import optional_import -from tests.test_utils import TEST_NDARRAYS, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose, dict_product _, has_torch_fft = optional_import("torch.fft", name="fftshift") -TEST_CASES = [] -for shape in ((128, 64), (64, 48, 80)): - for input_type in TEST_NDARRAYS if has_torch_fft else [np.array]: - TEST_CASES.append((shape, input_type)) +params = {"shape": ((128, 64), (64, 48, 80)), "input_type": TEST_NDARRAYS if has_torch_fft else [np.array]} +TEST_CASES = list(dict_product(format="list", **params)) class TestGibbsNoise(unittest.TestCase): From 679ac3c67a1f972e3168ea832902db5aa475d273 Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 19 Feb 2025 16:21:10 +0000 Subject: [PATCH 6/8] DCO Remediation Commit for R. Garcia-Dias I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: ba56a6d029abed931e3d8bcac5f7c91ddd2ccaf2 I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: da29d2f8304a09886e7909f4090464c4aa5a430c I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: 93f16dba61f3bcc18dd4ea6cccb3145eda6092db Signed-off-by: R. Garcia-Dias Signed-off-by: R. Garcia-Dias --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e5607ccb02..214fd478ab 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ MONAI is a [PyTorch](https://pytorch.org/)-based, [open-source](https://github.com/Project-MONAI/MONAI/blob/dev/LICENSE) framework for deep learning in healthcare imaging, part of the [PyTorch Ecosystem](https://pytorch.org/ecosystem/). Its ambitions are as follows: + - Developing a community of academic, industrial and clinical researchers collaborating on a common foundation; - Creating state-of-the-art, end-to-end training workflows for healthcare imaging; - Providing researchers with the optimized and standardized way to create and evaluate deep learning models. From f5ac5345d2bb87b225af66e40bb3c8571d3db5a1 Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Wed, 19 Feb 2025 17:53:30 +0000 Subject: [PATCH 7/8] Add dict_product utility for test case generation - Introduced a new `dict_product` function to create combinations of input parameters. - Updated test cases to use the new utility for generating shape and input type combinations. - Cleaned up code by removing old nested loops in favor of the new function. --- tests/test_utils.py | 18 +++++++++++++++++- tests/transforms/test_gibbs_noise.py | 8 +++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index c494bb547c..97a3181c44 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -30,9 +30,10 @@ import warnings from contextlib import contextmanager from functools import partial, reduce +from itertools import product from pathlib import Path from subprocess import PIPE, Popen -from typing import Callable +from typing import Callable, Literal from urllib.error import ContentTooShortError, HTTPError import numpy as np @@ -862,6 +863,21 @@ def equal_state_dict(st_1, st_2): if torch.cuda.is_available(): TEST_DEVICES.append([torch.device("cuda")]) + +def dict_product(trailing=False, format: Literal["list", "dict"] = "dict", **items): + keys = items.keys() + values = items.values() + for pvalues in product(*values): + dict_comb = dict(zip(keys, pvalues)) + if format == "dict": + if trailing: + yield [dict_comb] + list(pvalues) + else: + yield dict_comb + else: + yield pvalues + + if __name__ == "__main__": parser = argparse.ArgumentParser(prog="util") parser.add_argument("-c", "--count", default=2, help="max number of gpus") diff --git a/tests/transforms/test_gibbs_noise.py b/tests/transforms/test_gibbs_noise.py index 2aa2a44d10..1f96595a26 100644 --- a/tests/transforms/test_gibbs_noise.py +++ b/tests/transforms/test_gibbs_noise.py @@ -21,14 +21,12 @@ from monai.transforms import GibbsNoise from monai.utils.misc import set_determinism from monai.utils.module import optional_import -from tests.test_utils import TEST_NDARRAYS, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose, dict_product _, has_torch_fft = optional_import("torch.fft", name="fftshift") -TEST_CASES = [] -for shape in ((128, 64), (64, 48, 80)): - for input_type in TEST_NDARRAYS if has_torch_fft else [np.array]: - TEST_CASES.append((shape, input_type)) +params = {"shape": ((128, 64), (64, 48, 80)), "input_type": TEST_NDARRAYS if has_torch_fft else [np.array]} +TEST_CASES = list(dict_product(format="list", **params)) class TestGibbsNoise(unittest.TestCase): From cb6578ce522a695e8aa67fd3a4632c2dd8e0e0f6 Mon Sep 17 00:00:00 2001 From: "R. Garcia-Dias" Date: Thu, 20 Feb 2025 10:20:29 +0000 Subject: [PATCH 8/8] DCO Remediation Commit for R. Garcia-Dias I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: 2549bbb1f6ce4011bf9c9604a9b5141c91b93122 I, R. Garcia-Dias , hereby add my Signed-off-by to this commit: f5ac5345d2bb87b225af66e40bb3c8571d3db5a1 Signed-off-by: R. Garcia-Dias --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 214fd478ab..69cd1c657f 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ Its ambitions are as follows: - Creating state-of-the-art, end-to-end training workflows for healthcare imaging; - Providing researchers with the optimized and standardized way to create and evaluate deep learning models. - ## Features + > _Please see [the technical highlights](https://docs.monai.io/en/latest/highlights.html) and [What's New](https://docs.monai.io/en/latest/whatsnew.html) of the milestone releases._ - flexible pre-processing for multi-dimensional medical imaging data;