From eaa901ce5624391f7ae7a707ee14a26a6244e3e7 Mon Sep 17 00:00:00 2001 From: Yiheng Wang <68361391+yiheng-wang-nv@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:27:12 +0800 Subject: [PATCH] Fix test load image issue (#8297) Fixes https://github.com/Project-MONAI/MONAI/issues/8274 . ### Description The new test has already tested with the same 24.08 + A100 env. I did some tests but cannot reproduce the original test case error (there are NaN values or significant small/large data). Since only 24.08 base image has the issue (24.10 does not have), I decided to use a different test case for 24.08 and prepared this PR ### 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`. - [ ] 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: Yiheng Wang --- tests/test_load_image.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_load_image.py b/tests/test_load_image.py index dc0af5e97e..498b9972b4 100644 --- a/tests/test_load_image.py +++ b/tests/test_load_image.py @@ -217,7 +217,12 @@ def test_nibabel_reader(self, input_param, filenames, expected_shape): @SkipIfNoModule("kvikio") @parameterized.expand([TEST_CASE_GPU_1, TEST_CASE_GPU_2, TEST_CASE_GPU_3, TEST_CASE_GPU_4]) def test_nibabel_reader_gpu(self, input_param, filenames, expected_shape): - test_image = np.random.rand(128, 128, 128) + if torch.__version__.endswith("nv24.8"): + # related issue: https://github.com/Project-MONAI/MONAI/issues/8274 + # for this version, use randint test case to avoid the issue + test_image = torch.randint(0, 256, (128, 128, 128), dtype=torch.uint8).numpy() + else: + test_image = np.random.rand(128, 128, 128) with tempfile.TemporaryDirectory() as tempdir: for i, name in enumerate(filenames): filenames[i] = os.path.join(tempdir, name)