47
47
def execute_compose (
48
48
data : NdarrayOrTensor | Sequence [NdarrayOrTensor ] | Mapping [Any , NdarrayOrTensor ],
49
49
transforms : Sequence [Any ],
50
- map_items : bool = True ,
50
+ map_items : bool | int = True ,
51
51
unpack_items : bool = False ,
52
52
start : int = 0 ,
53
53
end : int | None = None ,
@@ -65,8 +65,13 @@ def execute_compose(
65
65
Args:
66
66
data: a tensor-like object to be transformed
67
67
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.
70
75
unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
71
76
defaults to `False`.
72
77
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):
205
210
206
211
Args:
207
212
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.
210
221
unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
211
222
defaults to `False`.
212
223
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):
227
238
def __init__ (
228
239
self ,
229
240
transforms : Sequence [Callable ] | Callable | None = None ,
230
- map_items : bool = True ,
241
+ map_items : bool | int = True ,
231
242
unpack_items : bool = False ,
232
243
log_stats : bool | str = False ,
233
244
lazy : bool | None = False ,
@@ -238,9 +249,9 @@ def __init__(
238
249
if transforms is None :
239
250
transforms = []
240
251
241
- if not isinstance (map_items , bool ):
252
+ if not isinstance (map_items , ( bool , int ) ):
242
253
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 )} ."
244
255
"Check brackets when passing a sequence of callables."
245
256
)
246
257
@@ -391,8 +402,14 @@ class OneOf(Compose):
391
402
transforms: sequence of callables.
392
403
weights: probabilities corresponding to each callable in transforms.
393
404
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.
396
413
unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
397
414
defaults to `False`.
398
415
log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution.
@@ -414,7 +431,7 @@ def __init__(
414
431
self ,
415
432
transforms : Sequence [Callable ] | Callable | None = None ,
416
433
weights : Sequence [float ] | float | None = None ,
417
- map_items : bool = True ,
434
+ map_items : bool | int = True ,
418
435
unpack_items : bool = False ,
419
436
log_stats : bool | str = False ,
420
437
lazy : bool | None = False ,
0 commit comments