From d98f348118b121e5f44fdf87c008851edbf68504 Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Dias Date: Thu, 20 Feb 2025 14:11:20 +0000 Subject: [PATCH] Solves path problem in test_bundle_trt_export.py (#8357) Fixes #8354 ### Description Fixes path on test that is only run on special conditions. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: R. Garcia-Dias Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- README.md | 3 ++- tests/bundle/test_bundle_trt_export.py | 2 +- tests/networks/test_convert_to_onnx.py | 2 +- tests/test_utils.py | 18 +++++++++++++++++- tests/transforms/test_gibbs_noise.py | 8 +++----- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e5607ccb02..69cd1c657f 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,13 @@ 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. - ## 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; 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: 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)) 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):