From af2b393416b826a9eab0b5d5e7bd5e00c0daf052 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 23 Mar 2022 18:39:02 +0000 Subject: [PATCH 1/6] fixes docstrings Signed-off-by: Wenqi Li --- docs/source/transforms.rst | 42 +++++++++++++++++++++++++++++++++++--- tests/test_module_list.py | 13 ++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docs/source/transforms.rst b/docs/source/transforms.rst index a8d04efaa5..8fc832a253 100644 --- a/docs/source/transforms.rst +++ b/docs/source/transforms.rst @@ -543,8 +543,8 @@ Post-processing :members: :special-members: __call__ -`Prob NMS` -"""""""""" +`ProbNMS` +""""""""" .. autoclass:: ProbNMS :members: @@ -563,6 +563,12 @@ Spatial :members: :special-members: __call__ +`ResampleToMatch` +""""""""""""""""" +.. autoclass:: ResampleToMatch + :members: + :special-members: __call__ + `Spacing` """"""""" .. image:: https://github.com/Project-MONAI/DocImages/raw/main/transforms/Spacing.png @@ -827,7 +833,6 @@ Utility :members: :special-members: __call__ - `Transpose` """"""""""" .. autoclass:: Transpose @@ -852,6 +857,7 @@ Utility :members: :special-members: __call__ + `Lambda` """""""" .. autoclass:: Lambda @@ -1401,6 +1407,12 @@ Post-processing (Dict) :members: :special-members: __call__ +`ProbNMSd` +"""""""""" +.. autoclass:: ProbNMSd + :members: + :special-members: __call__ + Spatial (Dict) ^^^^^^^^^^^^^^ @@ -1410,6 +1422,12 @@ Spatial (Dict) :members: :special-members: __call__ +`ResampleToMatchd` +"""""""""""""""""" +.. autoclass:: ResampleToMatchd + :members: + :special-members: __call__ + `Spacingd` """""""""" .. image:: https://github.com/Project-MONAI/DocImages/raw/main/transforms/Spacingd.png @@ -1656,6 +1674,12 @@ Utility (Dict) :members: :special-members: __call__ +`ToPILd` +"""""""" +.. autoclass:: ToPILd + :members: + :special-members: __call__ + `DeleteItemsd` """""""""""""" .. autoclass:: DeleteItemsd @@ -1668,6 +1692,12 @@ Utility (Dict) :members: :special-members: __call__ +`Transposed` +"""""""""""" +.. autoclass:: Transposed + :members: + :special-members: __call__ + `SqueezeDimd` """"""""""""" .. autoclass:: SqueezeDimd @@ -1710,6 +1740,12 @@ Utility (Dict) :members: :special-members: __call__ +`RemoveRepeatedChanneld` +"""""""""""""""""""""""" +.. autoclass:: RemoveRepeatedChanneld + :members: + :special-members: __call__ + `LabelToMaskd` """""""""""""" .. autoclass:: LabelToMaskd diff --git a/tests/test_module_list.py b/tests/test_module_list.py index ea520c59f3..f58bb3afc3 100644 --- a/tests/test_module_list.py +++ b/tests/test_module_list.py @@ -12,6 +12,7 @@ import glob import inspect import os +import pathlib import unittest import monai @@ -37,6 +38,8 @@ def test_public_api(self): def test_transform_api(self): """monai subclasses of MapTransforms must have alias names ending with 'd', 'D', 'Dict'""" to_exclude = {"MapTransform"} # except for these transforms + to_exclude_docs = {"Decollate", "Ensemble", "Invert", "SaveClassification", "RandTorchVision"} + to_exclude_docs.update({"DeleteItems", "SelectItems", "CopyItems", "ConcatItems"}) xforms = { name: obj for name, obj in monai.transforms.__dict__.items() @@ -44,10 +47,20 @@ def test_transform_api(self): } names = sorted(x for x in xforms if x not in to_exclude) remained = set(names) + doc_file = os.path.join(pathlib.Path(__file__).parent.parent, "docs", "source", "transforms.rst") + with open(doc_file) as f: + contents = f.readlines() + contents = "".join(contents) + for n in names: if not n.endswith("d"): continue basename = n[:-1] # Transformd basename is Transform + for docname in (f"{basename}", f"{basename}d"): + if docname in to_exclude_docs: + continue + if f"`{docname}`" not in contents: + self.assertTrue(False, f"please add {docname} to docs/source/transforms.rst") for postfix in ("D", "d", "Dict"): remained.remove(f"{basename}{postfix}") self.assertFalse(remained) From a88d3f45c0bfa7fb52d7fb8f9b194ee4615b1d10 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 23 Mar 2022 19:33:52 +0000 Subject: [PATCH 2/6] update based on comments Signed-off-by: Wenqi Li --- tests/test_module_list.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/test_module_list.py b/tests/test_module_list.py index f58bb3afc3..2b83b5f82f 100644 --- a/tests/test_module_list.py +++ b/tests/test_module_list.py @@ -48,21 +48,19 @@ def test_transform_api(self): names = sorted(x for x in xforms if x not in to_exclude) remained = set(names) doc_file = os.path.join(pathlib.Path(__file__).parent.parent, "docs", "source", "transforms.rst") - with open(doc_file) as f: - contents = f.readlines() - contents = "".join(contents) - + contents = pathlib.Path(doc_file).read_text() if os.path.exists(doc_file) else None for n in names: if not n.endswith("d"): continue - basename = n[:-1] # Transformd basename is Transform - for docname in (f"{basename}", f"{basename}d"): - if docname in to_exclude_docs: - continue - if f"`{docname}`" not in contents: - self.assertTrue(False, f"please add {docname} to docs/source/transforms.rst") - for postfix in ("D", "d", "Dict"): - remained.remove(f"{basename}{postfix}") + with self.subTest(n=n): + basename = n[:-1] # Transformd basename is Transform + for docname in (f"{basename}", f"{basename}d"): + if docname in to_exclude_docs: + continue + if contents is not None and f"`{docname}`" not in contents: + self.assertTrue(False, f"please add `{docname}` to docs/source/transforms.rst") + for postfix in ("D", "d", "Dict"): + remained.remove(f"{basename}{postfix}") self.assertFalse(remained) From 9ce3ab433a60a341cfe657622a9f63ae09dc437d Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 23 Mar 2022 19:57:44 +0000 Subject: [PATCH 3/6] fixes types Signed-off-by: Wenqi Li --- tests/test_module_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_module_list.py b/tests/test_module_list.py index 2b83b5f82f..74c0ca2d76 100644 --- a/tests/test_module_list.py +++ b/tests/test_module_list.py @@ -57,7 +57,7 @@ def test_transform_api(self): for docname in (f"{basename}", f"{basename}d"): if docname in to_exclude_docs: continue - if contents is not None and f"`{docname}`" not in contents: + if (contents is not None) and f"`{docname}`" not in contents: # type: ignore self.assertTrue(False, f"please add `{docname}` to docs/source/transforms.rst") for postfix in ("D", "d", "Dict"): remained.remove(f"{basename}{postfix}") From 9e0d3b2e470a4c7318045a55adf7a58418a9f05d Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 23 Mar 2022 09:55:11 +0000 Subject: [PATCH 4/6] fixes integration tests Signed-off-by: Wenqi Li --- tests/test_integration_workers.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_integration_workers.py b/tests/test_integration_workers.py index 1f12f81712..9fa2beb3fb 100644 --- a/tests/test_integration_workers.py +++ b/tests/test_integration_workers.py @@ -16,7 +16,7 @@ from monai.data import DataLoader from monai.utils import set_determinism -from tests.utils import DistTestCase, TimedCall, skip_if_no_cuda, skip_if_quick +from tests.utils import DistTestCase, SkipIfBeforePyTorchVersion, TimedCall, skip_if_no_cuda, skip_if_quick def run_loading_test(num_workers=50, device="cuda:0" if torch.cuda.is_available() else "cpu", pw=False): @@ -38,15 +38,19 @@ def run_loading_test(num_workers=50, device="cuda:0" if torch.cuda.is_available( @skip_if_quick @skip_if_no_cuda +@SkipIfBeforePyTorchVersion((1, 9)) class IntegrationLoading(DistTestCase): def tearDown(self): set_determinism(seed=None) @TimedCall(seconds=5000, skip_timing=not torch.cuda.is_available(), daemon=False) def test_timing(self): - for pw, expected in zip((False, True), ((6966, 7714), (6966, 4112))): + expected = None + for pw in (False, True): result = run_loading_test(pw=pw) - np.testing.assert_allclose(result, expected) + if expected is None: + expected = result + np.testing.assert_allclose(result, expected) # test for deterministic in two settings if __name__ == "__main__": From 3414c2b9ee21d9bc1e1cd18b92a71e9a223bffdb Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 23 Mar 2022 12:16:11 +0000 Subject: [PATCH 5/6] update integration tests Signed-off-by: Wenqi Li --- tests/test_integration_workers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_integration_workers.py b/tests/test_integration_workers.py index 9fa2beb3fb..21515d1f82 100644 --- a/tests/test_integration_workers.py +++ b/tests/test_integration_workers.py @@ -49,8 +49,8 @@ def test_timing(self): for pw in (False, True): result = run_loading_test(pw=pw) if expected is None: - expected = result - np.testing.assert_allclose(result, expected) # test for deterministic in two settings + expected = result[0] + np.testing.assert_allclose(result[0], expected) # test for deterministic first epoch in two settings if __name__ == "__main__": From 8acc6233f6e4cf8de0ebc5cfe622636b7d2e67a1 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 23 Mar 2022 20:03:14 +0000 Subject: [PATCH 6/6] fixes pylint Signed-off-by: Wenqi Li --- tests/test_module_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_module_list.py b/tests/test_module_list.py index 74c0ca2d76..83c6979f30 100644 --- a/tests/test_module_list.py +++ b/tests/test_module_list.py @@ -57,7 +57,7 @@ def test_transform_api(self): for docname in (f"{basename}", f"{basename}d"): if docname in to_exclude_docs: continue - if (contents is not None) and f"`{docname}`" not in contents: # type: ignore + if (contents is not None) and f"`{docname}`" not in f"{contents}": self.assertTrue(False, f"please add `{docname}` to docs/source/transforms.rst") for postfix in ("D", "d", "Dict"): remained.remove(f"{basename}{postfix}")