From f0ebe29b52cd31e7c1806403c0fab7f8d76e784d Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 21 Oct 2021 21:50:59 +0100 Subject: [PATCH 1/3] revise docstrings Signed-off-by: Wenqi Li --- monai/transforms/transform.py | 40 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index 3ea2fda136..5dd5094e14 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -40,9 +40,9 @@ def _apply_transform( Otherwise `parameters` is considered as single argument to `transform`. Args: - transform (Callable[..., ReturnType]): a callable to be used to transform `data`. - parameters (Any): parameters for the `transform`. - unpack_parameters (bool, optional): whether to unpack parameters for `transform`. Defaults to False. + transform: a callable to be used to transform `data`. + parameters: parameters for the `transform`. + unpack_parameters: whether to unpack parameters for `transform`. Defaults to False. Returns: ReturnType: The return type of `transform`. @@ -64,11 +64,11 @@ def apply_transform( otherwise transform will be applied once with `data` as the argument. Args: - transform (Callable[..., ReturnType]): a callable to be used to transform `data`. - data (Any): an object to be transformed. - map_items (bool, optional): whether to apply transform to each item in `data`, + transform: a callable to be used to transform `data`. + data: an object to be transformed. + map_items: whether to apply transform to each item in `data`, if `data` is a list or tuple. Defaults to True. - unpack_items (bool, optional): [description]. Defaults to False. + unpack_items: whether to unpack parameters using `*`. Defaults to False. Raises: Exception: When ``transform`` raises an exception. @@ -216,17 +216,15 @@ def __call__(self, data: Any): return an updated version of ``data``. To simplify the input validations, most of the transforms assume that - - ``data`` is a Numpy ndarray, PyTorch Tensor or string + - ``data`` is a Numpy ndarray, PyTorch Tensor or string, - the data shape can be: - #. string data without shape, `LoadImage` transform expects file paths - #. most of the pre-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``, - except that `AddChannel` expects (spatial_dim_1[, spatial_dim_2, ...]) and - `AsChannelFirst` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels) - #. most of the post-processing transforms expect - ``(batch_size, num_channels, spatial_dim_1[, spatial_dim_2, ...])`` + #. string data without shape, `LoadImage` transform expects file paths, + #. most of the pre-/post-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``, + except that, e.g., `AddChannel` expects (spatial_dim_1[, spatial_dim_2, ...]) and + `AsChannelFirst` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels), - - the channel dimension is not omitted even if number of channels is one + - the channel dimension is often not omitted even if number of channels is one. This method can optionally take additional arguments to help execute transformation operation. @@ -323,18 +321,16 @@ def __call__(self, data): To simplify the input validations, this method assumes: - - ``data`` is a Python dictionary + - ``data`` is a Python dictionary, - ``data[key]`` is a Numpy ndarray, PyTorch Tensor or string, where ``key`` is an element of ``self.keys``, the data shape can be: - #. string data without shape, `LoadImaged` transform expects file paths - #. most of the pre-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``, - except that `AddChanneld` expects (spatial_dim_1[, spatial_dim_2, ...]) and + #. string data without shape, `LoadImaged` transform expects file paths, + #. most of the pre-/post-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``, + except that, e.g., `AddChanneld` expects (spatial_dim_1[, spatial_dim_2, ...]) and `AsChannelFirstd` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels) - #. most of the post-processing transforms expect - ``(batch_size, num_channels, spatial_dim_1[, spatial_dim_2, ...])`` - - the channel dimension is not omitted even if number of channels is one + - the channel dimension is often not omitted even if number of channels is one. Raises: NotImplementedError: When the subclass does not override this method. From 87d91f60490eddf1d3c4470e18da36aecf149d67 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Fri, 22 Oct 2021 17:14:14 +0100 Subject: [PATCH 2/3] update based on comments Signed-off-by: Wenqi Li --- monai/transforms/transform.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index 5dd5094e14..61794308f4 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -221,7 +221,7 @@ def __call__(self, data: Any): #. string data without shape, `LoadImage` transform expects file paths, #. most of the pre-/post-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``, - except that, e.g., `AddChannel` expects (spatial_dim_1[, spatial_dim_2, ...]) and + except for example: `AddChannel` expects (spatial_dim_1[, spatial_dim_2, ...]) and `AsChannelFirst` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels), - the channel dimension is often not omitted even if number of channels is one. @@ -327,7 +327,7 @@ def __call__(self, data): #. string data without shape, `LoadImaged` transform expects file paths, #. most of the pre-/post-processing transforms expect: ``(num_channels, spatial_dim_1[, spatial_dim_2, ...])``, - except that, e.g., `AddChanneld` expects (spatial_dim_1[, spatial_dim_2, ...]) and + except for example: `AddChanneld` expects (spatial_dim_1[, spatial_dim_2, ...]) and `AsChannelFirstd` expects (spatial_dim_1[, spatial_dim_2, ...], num_channels) - the channel dimension is often not omitted even if number of channels is one. From f761a8401ebb96d8d2f560ef44951865afabe4e8 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Fri, 22 Oct 2021 17:17:44 +0100 Subject: [PATCH 3/3] fixes windows tests Signed-off-by: Wenqi Li --- tests/test_decollate.py | 2 +- tests/test_inverse_collation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_decollate.py b/tests/test_decollate.py index 9bc3c3b470..f35988e215 100644 --- a/tests/test_decollate.py +++ b/tests/test_decollate.py @@ -120,7 +120,7 @@ def check_match(self, in1, in2): def check_decollate(self, dataset): batch_size = 2 - num_workers = 2 + num_workers = 2 if sys.platform == "linux" else 0 loader = DataLoader(dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers) diff --git a/tests/test_inverse_collation.py b/tests/test_inverse_collation.py index f0a87c2b9d..d04360a95d 100644 --- a/tests/test_inverse_collation.py +++ b/tests/test_inverse_collation.py @@ -106,7 +106,7 @@ def test_collation(self, _, transform, collate_fn, ndim): modified_transform = Compose([transform, ResizeWithPadOrCropd(KEYS, 100), ToTensord(KEYS)]) # num workers = 0 for mac or gpu transforms - num_workers = 0 if sys.platform == "darwin" or torch.cuda.is_available() else 2 + num_workers = 0 if sys.platform != "linux" or torch.cuda.is_available() else 2 dataset = CacheDataset(data, transform=modified_transform, progress=False) loader = DataLoader(dataset, num_workers, batch_size=self.batch_size, collate_fn=collate_fn)