From 05816d5622034c6df3d0f0134c3a26bf0872567d Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:07:45 +0800 Subject: [PATCH 01/14] fix #8186 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/transform.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index 15c2499a73..afd6bf9f84 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -136,8 +136,10 @@ def apply_transform( Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof. """ try: - if isinstance(data, (list, tuple)) and map_items: - return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data] + if not map_items: + return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) + if isinstance(data, (list, tuple)): + return [apply_transform(transform, item, map_items, unpack_items, log_stats, lazy, overrides) for item in data] return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) except Exception as e: # if in debug mode, don't swallow exception so that the breakpoint From c0daf6f7ea63ecbe7a9a5bdecf7f823d3fef71fb Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:10:14 +0800 Subject: [PATCH 02/14] fix #8186 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/transform.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index afd6bf9f84..696586c0f6 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -136,9 +136,7 @@ def apply_transform( Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof. """ try: - if not map_items: - return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) - if isinstance(data, (list, tuple)): + if isinstance(data, (list, tuple)) and map_items: return [apply_transform(transform, item, map_items, unpack_items, log_stats, lazy, overrides) for item in data] return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) except Exception as e: From 2c28c37674d5709e86f7bb1093380cd0ee799be8 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:29:27 +0800 Subject: [PATCH 03/14] allow map_items to be int Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/compose.py | 12 ++++++------ monai/transforms/transform.py | 14 +++++++++++--- tests/test_compose.py | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index 236d3cc4c5..1a02af860d 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -47,7 +47,7 @@ def execute_compose( data: NdarrayOrTensor | Sequence[NdarrayOrTensor] | Mapping[Any, NdarrayOrTensor], transforms: Sequence[Any], - map_items: bool = True, + map_items: bool | int = True, unpack_items: bool = False, start: int = 0, end: int | None = None, @@ -66,7 +66,7 @@ def execute_compose( data: a tensor-like object to be transformed transforms: a sequence of transforms to be carried out map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. + defaults to `True`. If set to an integer, the transform will be applied to that index of the input `data`. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. start: the index of the first transform to be executed. If not set, this defaults to 0 @@ -206,7 +206,7 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform): Args: transforms: sequence of callables. map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. + defaults to `True`. If set to an integer, the transform will be applied to that index of the input `data`. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. @@ -227,7 +227,7 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform): def __init__( self, transforms: Sequence[Callable] | Callable | None = None, - map_items: bool = True, + map_items: bool | int = True, unpack_items: bool = False, log_stats: bool | str = False, lazy: bool | None = False, @@ -238,9 +238,9 @@ def __init__( if transforms is None: transforms = [] - if not isinstance(map_items, bool): + if not isinstance(map_items, (bool, int)): raise ValueError( - f"Argument 'map_items' should be boolean. Got {type(map_items)}." + f"Argument 'map_items' should be boolean or int. Got {type(map_items)}." "Check brackets when passing a sequence of callables." ) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index 696586c0f6..3c70462a5c 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -101,7 +101,7 @@ def _apply_transform( def apply_transform( transform: Callable[..., ReturnType], data: Any, - map_items: bool = True, + map_items: bool | int = True, unpack_items: bool = False, log_stats: bool | str = False, lazy: bool | None = None, @@ -119,6 +119,7 @@ def apply_transform( 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. + it can also be an int, if so, apply the transform to each item in the list `map_items` times. unpack_items: whether to unpack parameters using `*`. Defaults to False. log_stats: log errors when they occur in the processing pipeline. By default, this is set to False, which disables the logger for processing pipeline errors. Setting it to None or True will enable logging to the @@ -136,8 +137,15 @@ def apply_transform( Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof. """ try: - if isinstance(data, (list, tuple)) and map_items: - return [apply_transform(transform, item, map_items, unpack_items, log_stats, lazy, overrides) for item in data] + if isinstance(data, (list, tuple)) and isinstance(map_items, (int, bool)): + # if map_items is an int, apply the transform to each item in the list `map_items` times + if isinstance(map_items, int) and type(map_items) is not bool and map_items > 0: + return [ + apply_transform(transform, item, map_items - 2, unpack_items, log_stats, lazy, overrides) + for item in data + ] + else: + return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data] return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) except Exception as e: # if in debug mode, don't swallow exception so that the breakpoint diff --git a/tests/test_compose.py b/tests/test_compose.py index 3c53ac4a22..e6727c976f 100644 --- a/tests/test_compose.py +++ b/tests/test_compose.py @@ -141,6 +141,20 @@ def b(i, i2): self.assertEqual(mt.Compose(transforms, unpack_items=True)(data), expected) self.assertEqual(execute_compose(data, transforms, unpack_items=True), expected) + def test_list_non_dict_compose_with_unpack_map_2(self): + + def a(i, i2): + return i + "a", i2 + "a2" + + def b(i, i2): + return i + "b", i2 + "b2" + + transforms = [a, b, a, b] + data = [[("", ""), ("", "")], [("t", "t"), ("t", "t")]] + expected = [[("abab", "a2b2a2b2"), ("abab", "a2b2a2b2")], [("tabab", "ta2b2a2b2"), ("tabab", "ta2b2a2b2")]] + self.assertEqual(mt.Compose(transforms, map_items=2, unpack_items=True)(data), expected) + self.assertEqual(execute_compose(data, transforms, map_items=2, unpack_items=True), expected) + def test_list_dict_compose_no_map(self): def a(d): # transform to handle dict data From 92a7625a6779d8dadc566edbf908fe30ef87570a Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:12:42 +0800 Subject: [PATCH 04/14] fix ci Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- 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 3c70462a5c..ea6b335956 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -137,9 +137,9 @@ def apply_transform( Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof. """ try: - if isinstance(data, (list, tuple)) and isinstance(map_items, (int, bool)): + if isinstance(data, (list, tuple)) and (map_items or type(map_items) == int): # if map_items is an int, apply the transform to each item in the list `map_items` times - if isinstance(map_items, int) and type(map_items) is not bool and map_items > 0: + if type(map_items) == int and map_items > 0: return [ apply_transform(transform, item, map_items - 2, unpack_items, log_stats, lazy, overrides) for item in data From b00ed2d90e6cc63c0a336f646f93c1d4768b9681 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:13:46 +0800 Subject: [PATCH 05/14] fix format Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- 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 ea6b335956..54ea015050 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -137,9 +137,9 @@ def apply_transform( Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof. """ try: - if isinstance(data, (list, tuple)) and (map_items or type(map_items) == int): + if isinstance(data, (list, tuple)) and (map_items or type(map_items) is int): # if map_items is an int, apply the transform to each item in the list `map_items` times - if type(map_items) == int and map_items > 0: + if type(map_items) is int and map_items > 0: return [ apply_transform(transform, item, map_items - 2, unpack_items, log_stats, lazy, overrides) for item in data From 6fd7fbce2e4c8dace24f292dc20a668a43c14577 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:39:04 +0800 Subject: [PATCH 06/14] fix mypy Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/compose.py | 8 ++++---- monai/transforms/transform.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index 1a02af860d..e3793fcc51 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -66,7 +66,7 @@ def execute_compose( data: a tensor-like object to be transformed transforms: a sequence of transforms to be carried out map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. If set to an integer, the transform will be applied to that index of the input `data`. + defaults to `True`. If set to an integer, recursively map the items in `data` `map_items` times. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. start: the index of the first transform to be executed. If not set, this defaults to 0 @@ -206,7 +206,7 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform): Args: transforms: sequence of callables. map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. If set to an integer, the transform will be applied to that index of the input `data`. + defaults to `True`. If set to an integer, recursively map the items in `data` `map_items` times. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. @@ -392,7 +392,7 @@ class OneOf(Compose): weights: probabilities corresponding to each callable in transforms. Probabilities are normalized to sum to one. map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. + defaults to `True`. If set to an integer, recursively map the items in `data` `map_items` times. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. @@ -414,7 +414,7 @@ def __init__( self, transforms: Sequence[Callable] | Callable | None = None, weights: Sequence[float] | float | None = None, - map_items: bool = True, + map_items: bool | int = True, unpack_items: bool = False, log_stats: bool | str = False, lazy: bool | None = False, diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index 54ea015050..b1c30aa163 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -106,7 +106,7 @@ def apply_transform( log_stats: bool | str = False, lazy: bool | None = None, overrides: dict | None = None, -) -> list[ReturnType] | ReturnType: +) -> list[Any] | ReturnType: """ Transform `data` with `transform`. @@ -119,7 +119,7 @@ def apply_transform( 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. - it can also be an int, if so, apply the transform to each item in the list `map_items` times. + it can also be an int, if so, recursively map the items in `data` `map_items` times. unpack_items: whether to unpack parameters using `*`. Defaults to False. log_stats: log errors when they occur in the processing pipeline. By default, this is set to False, which disables the logger for processing pipeline errors. Setting it to None or True will enable logging to the From 44066afafd309bb7835699850c73214bb773a027 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 24 Jan 2025 22:14:07 +0800 Subject: [PATCH 07/14] Update monai/transforms/transform.py Co-authored-by: Ben Murray Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/transform.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index b1c30aa163..ad02976006 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -137,15 +137,12 @@ def apply_transform( Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof. """ try: - if isinstance(data, (list, tuple)) and (map_items or type(map_items) is int): - # if map_items is an int, apply the transform to each item in the list `map_items` times - if type(map_items) is int and map_items > 0: - return [ - apply_transform(transform, item, map_items - 2, unpack_items, log_stats, lazy, overrides) - for item in data - ] - else: - return [_apply_transform(transform, item, unpack_items, lazy, overrides, log_stats) for item in data] + map_items_ = int(map_items) if isinstance(map_items, bool) else map_items + if isinstance(data, (list, tuple)) and map_items_ > 0: + return [ + apply_transform(transform, item, map_items - 1, unpack_items, log_stats, lazy, overrides) + for item in data + ] return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) except Exception as e: # if in debug mode, don't swallow exception so that the breakpoint From 83c47295f8fd8cb6b4260a04a853877f0b220aa8 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 24 Jan 2025 22:19:50 +0800 Subject: [PATCH 08/14] address comments Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/transform.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index ad02976006..53c46ee150 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -120,6 +120,13 @@ def apply_transform( map_items: whether to apply transform to each item in `data`, if `data` is a list or tuple. Defaults to True. it can also be an int, if so, recursively map the items in `data` `map_items` times. + map_items: Controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, + it can behave as follows: + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied + to the first level of items in `data`. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. This allows treating multi-sample transforms applied after another + multi-sample transform while controlling how deep the mapping goes. unpack_items: whether to unpack parameters using `*`. Defaults to False. log_stats: log errors when they occur in the processing pipeline. By default, this is set to False, which disables the logger for processing pipeline errors. Setting it to None or True will enable logging to the From 10d89ade385d1dba214502f6b4c82488bdff9b6c Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 24 Jan 2025 22:21:39 +0800 Subject: [PATCH 09/14] enhance docstring Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/compose.py | 27 +++++++++++++++++++++------ monai/transforms/transform.py | 5 +---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index e3793fcc51..e15c4e2045 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -65,8 +65,13 @@ def execute_compose( Args: data: a tensor-like object to be transformed transforms: a sequence of transforms to be carried out - map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. If set to an integer, recursively map the items in `data` `map_items` times. + map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, + it can behave as follows: + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied + to the first level of items in `data`. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. This allows treating multi-sample transforms applied after another + multi-sample transform while controlling how deep the mapping goes. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. start: the index of the first transform to be executed. If not set, this defaults to 0 @@ -205,8 +210,13 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform): Args: transforms: sequence of callables. - map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. If set to an integer, recursively map the items in `data` `map_items` times. + map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, + it can behave as follows: + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied + to the first level of items in `data`. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. This allows treating multi-sample transforms applied after another + multi-sample transform while controlling how deep the mapping goes. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. @@ -391,8 +401,13 @@ class OneOf(Compose): transforms: sequence of callables. weights: probabilities corresponding to each callable in transforms. Probabilities are normalized to sum to one. - map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple. - defaults to `True`. If set to an integer, recursively map the items in `data` `map_items` times. + map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, + it can behave as follows: + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied + to the first level of items in `data`. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. This allows treating multi-sample transforms applied after another + multi-sample transform while controlling how deep the mapping goes. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index 53c46ee150..aa709f20c4 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -117,10 +117,7 @@ def apply_transform( Args: 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. - it can also be an int, if so, recursively map the items in `data` `map_items` times. - map_items: Controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, + map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, it can behave as follows: - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied to the first level of items in `data`. From c3ee2fc6291da9b103858262813534a579388002 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 24 Jan 2025 22:27:20 +0800 Subject: [PATCH 10/14] Update monai/transforms/transform.py Co-authored-by: Ben Murray Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/transforms/transform.py b/monai/transforms/transform.py index aa709f20c4..1a365b8d8e 100644 --- a/monai/transforms/transform.py +++ b/monai/transforms/transform.py @@ -144,7 +144,7 @@ def apply_transform( map_items_ = int(map_items) if isinstance(map_items, bool) else map_items if isinstance(data, (list, tuple)) and map_items_ > 0: return [ - apply_transform(transform, item, map_items - 1, unpack_items, log_stats, lazy, overrides) + apply_transform(transform, item, map_items_ - 1, unpack_items, log_stats, lazy, overrides) for item in data ] return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats) From 92fdb821c9247a7cfb319022529391a295ca919c Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 12 Feb 2025 23:48:18 +0800 Subject: [PATCH 11/14] fix doc Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/compose.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index e15c4e2045..dcc0218397 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -212,11 +212,12 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform): transforms: sequence of callables. map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, it can behave as follows: - - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied - to the first level of items in `data`. - - If an integer is provided, it specifies the maximum level of nesting to which the transformation - should be recursively applied. This allows treating multi-sample transforms applied after another - multi-sample transform while controlling how deep the mapping goes. + + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied + to the first level of items in `data`. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. This allows treating multi-sample transforms applied after another + multi-sample transform while controlling how deep the mapping goes. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. @@ -403,11 +404,12 @@ class OneOf(Compose): Probabilities are normalized to sum to one. map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, it can behave as follows: - - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied - to the first level of items in `data`. - - If an integer is provided, it specifies the maximum level of nesting to which the transformation - should be recursively applied. This allows treating multi-sample transforms applied after another - multi-sample transform while controlling how deep the mapping goes. + + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied + to the first level of items in `data`. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. This allows treating multi-sample transforms applied after another + multi-sample transform while controlling how deep the mapping goes. unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform. defaults to `False`. log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution. From 8de271fdd6040f7ef3aa1f9b3a35266579230102 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2025 15:49:14 +0000 Subject: [PATCH 12/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/transforms/compose.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index dcc0218397..4513e26678 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -404,7 +404,7 @@ class OneOf(Compose): Probabilities are normalized to sum to one. map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, it can behave as follows: - + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied to the first level of items in `data`. - If an integer is provided, it specifies the maximum level of nesting to which the transformation From 24ea51af335bb0cc3c5499314e4394a457f10ad3 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 12 Feb 2025 23:49:20 +0800 Subject: [PATCH 13/14] fix format Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/transforms/compose.py | 2 +- monai/utils/jupyter_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/transforms/compose.py b/monai/transforms/compose.py index dcc0218397..4513e26678 100644 --- a/monai/transforms/compose.py +++ b/monai/transforms/compose.py @@ -404,7 +404,7 @@ class OneOf(Compose): Probabilities are normalized to sum to one. map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple, it can behave as follows: - + - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied to the first level of items in `data`. - If an integer is provided, it specifies the maximum level of nesting to which the transformation diff --git a/monai/utils/jupyter_utils.py b/monai/utils/jupyter_utils.py index c93e93dcb9..b1b43a6767 100644 --- a/monai/utils/jupyter_utils.py +++ b/monai/utils/jupyter_utils.py @@ -234,7 +234,7 @@ def plot_engine_status( def _get_loss_from_output( - output: list[torch.Tensor | dict[str, torch.Tensor]] | dict[str, torch.Tensor] | torch.Tensor, + output: list[torch.Tensor | dict[str, torch.Tensor]] | dict[str, torch.Tensor] | torch.Tensor ) -> torch.Tensor: """Returns a single value from the network output, which is a dict or tensor.""" From d4bc172e4f59cdd2591593c3d6a49cf5e94e59e4 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 12 Feb 2025 23:59:57 +0800 Subject: [PATCH 14/14] fix format Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/utils/jupyter_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/utils/jupyter_utils.py b/monai/utils/jupyter_utils.py index b1b43a6767..c93e93dcb9 100644 --- a/monai/utils/jupyter_utils.py +++ b/monai/utils/jupyter_utils.py @@ -234,7 +234,7 @@ def plot_engine_status( def _get_loss_from_output( - output: list[torch.Tensor | dict[str, torch.Tensor]] | dict[str, torch.Tensor] | torch.Tensor + output: list[torch.Tensor | dict[str, torch.Tensor]] | dict[str, torch.Tensor] | torch.Tensor, ) -> torch.Tensor: """Returns a single value from the network output, which is a dict or tensor."""