4747def execute_compose (
4848 data : NdarrayOrTensor | Sequence [NdarrayOrTensor ] | Mapping [Any , NdarrayOrTensor ],
4949 transforms : Sequence [Any ],
50- map_items : bool = True ,
50+ map_items : bool | int = True ,
5151 unpack_items : bool = False ,
5252 start : int = 0 ,
5353 end : int | None = None ,
@@ -65,8 +65,13 @@ def execute_compose(
6565 Args:
6666 data: a tensor-like object to be transformed
6767 transforms: a sequence of transforms to be carried out
68- map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple.
69- defaults to `True`.
68+ map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple,
69+ it can behave as follows:
70+ - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied
71+ to the first level of items in `data`.
72+ - If an integer is provided, it specifies the maximum level of nesting to which the transformation
73+ should be recursively applied. This allows treating multi-sample transforms applied after another
74+ multi-sample transform while controlling how deep the mapping goes.
7075 unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
7176 defaults to `False`.
7277 start: the index of the first transform to be executed. If not set, this defaults to 0
@@ -205,8 +210,14 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform):
205210
206211 Args:
207212 transforms: sequence of callables.
208- map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple.
209- defaults to `True`.
213+ map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple,
214+ it can behave as follows:
215+
216+ - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied
217+ to the first level of items in `data`.
218+ - If an integer is provided, it specifies the maximum level of nesting to which the transformation
219+ should be recursively applied. This allows treating multi-sample transforms applied after another
220+ multi-sample transform while controlling how deep the mapping goes.
210221 unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
211222 defaults to `False`.
212223 log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution.
@@ -227,7 +238,7 @@ class Compose(Randomizable, InvertibleTransform, LazyTransform):
227238 def __init__ (
228239 self ,
229240 transforms : Sequence [Callable ] | Callable | None = None ,
230- map_items : bool = True ,
241+ map_items : bool | int = True ,
231242 unpack_items : bool = False ,
232243 log_stats : bool | str = False ,
233244 lazy : bool | None = False ,
@@ -238,9 +249,9 @@ def __init__(
238249 if transforms is None :
239250 transforms = []
240251
241- if not isinstance (map_items , bool ):
252+ if not isinstance (map_items , ( bool , int ) ):
242253 raise ValueError (
243- f"Argument 'map_items' should be boolean. Got { type (map_items )} ."
254+ f"Argument 'map_items' should be boolean or int . Got { type (map_items )} ."
244255 "Check brackets when passing a sequence of callables."
245256 )
246257
@@ -391,8 +402,14 @@ class OneOf(Compose):
391402 transforms: sequence of callables.
392403 weights: probabilities corresponding to each callable in transforms.
393404 Probabilities are normalized to sum to one.
394- map_items: whether to apply transform to each item in the input `data` if `data` is a list or tuple.
395- defaults to `True`.
405+ map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple,
406+ it can behave as follows:
407+
408+ - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied
409+ to the first level of items in `data`.
410+ - If an integer is provided, it specifies the maximum level of nesting to which the transformation
411+ should be recursively applied. This allows treating multi-sample transforms applied after another
412+ multi-sample transform while controlling how deep the mapping goes.
396413 unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
397414 defaults to `False`.
398415 log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution.
@@ -414,7 +431,7 @@ def __init__(
414431 self ,
415432 transforms : Sequence [Callable ] | Callable | None = None ,
416433 weights : Sequence [float ] | float | None = None ,
417- map_items : bool = True ,
434+ map_items : bool | int = True ,
418435 unpack_items : bool = False ,
419436 log_stats : bool | str = False ,
420437 lazy : bool | None = False ,
0 commit comments