MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / execute_compose

Function execute_compose

monai/transforms/compose.py:65–138  ·  view source on GitHub ↗

``execute_compose`` provides the implementation that the ``Compose`` class uses to execute a sequence of transforms. As well as being used by Compose, it can be used by subclasses of Compose and by code that doesn't have a Compose instance but needs to execute a sequence of transfor

(
    data: NdarrayOrTensor | Sequence[NdarrayOrTensor] | Mapping[Any, NdarrayOrTensor],
    transforms: Sequence[Any],
    map_items: bool | int = True,
    unpack_items: bool = False,
    start: int = 0,
    end: int | None = None,
    lazy: bool | None = False,
    overrides: dict | None = None,
    threading: bool = False,
    log_stats: bool | str = False,
)

Source from the content-addressed store, hash-verified

63
64
65def execute_compose(
66 data: NdarrayOrTensor | Sequence[NdarrayOrTensor] | Mapping[Any, NdarrayOrTensor],
67 transforms: Sequence[Any],
68 map_items: bool | int = True,
69 unpack_items: bool = False,
70 start: int = 0,
71 end: int | None = None,
72 lazy: bool | None = False,
73 overrides: dict | None = None,
74 threading: bool = False,
75 log_stats: bool | str = False,
76) -> NdarrayOrTensor | Sequence[NdarrayOrTensor] | Mapping[Any, NdarrayOrTensor]:
77 """
78 ``execute_compose`` provides the implementation that the ``Compose`` class uses to execute a sequence
79 of transforms. As well as being used by Compose, it can be used by subclasses of
80 Compose and by code that doesn't have a Compose instance but needs to execute a
81 sequence of transforms is if it were executed by Compose. It should only be used directly
82 when it is not possible to use ``Compose.__call__`` to achieve the same goal.
83 Args:
84 data: a tensor-like object to be transformed
85 transforms: a sequence of transforms to be carried out
86 map_items: controls whether to apply a transformation to each item in `data`. If `data` is a list or tuple,
87 it can behave as follows:
88 - Defaults to True, which is equivalent to `map_items=1`, meaning the transformation will be applied
89 to the first level of items in `data`.
90 - If an integer is provided, it specifies the maximum level of nesting to which the transformation
91 should be recursively applied. This allows treating multi-sample transforms applied after another
92 multi-sample transform while controlling how deep the mapping goes.
93 unpack_items: whether to unpack input `data` with `*` as parameters for the callable function of transform.
94 defaults to `False`.
95 start: the index of the first transform to be executed. If not set, this defaults to 0
96 end: the index after the last transform to be executed. If set, the transform at index-1
97 is the last transform that is executed. If this is not set, it defaults to len(transforms)
98 lazy: whether to enable :ref:`lazy evaluation<lazy_resampling>` for lazy transforms. If False, transforms will be
99 carried out on a transform by transform basis. If True, all lazy transforms will
100 be executed by accumulating changes and resampling as few times as possible.
101 overrides: this optional parameter allows you to specify a dictionary of parameters that should be overridden
102 when executing a pipeline. These each parameter that is compatible with a given transform is then applied
103 to that transform before it is executed. Note that overrides are currently only applied when
104 :ref:`lazy evaluation<lazy_resampling>` is enabled for the pipeline or a given transform. If lazy is False
105 they are ignored. Currently supported args are:
106 {``"mode"``, ``"padding_mode"``, ``"dtype"``, ``"align_corners"``, ``"resample_mode"``, ``device``}.
107 threading: whether executing is happening in a threaded environment. If set, copies are made
108 of transforms that have the ``RandomizedTrait`` interface.
109 log_stats: this optional parameter allows you to specify a logger by name for logging of pipeline execution.
110 Setting this to False disables logging. Setting it to True enables logging to the default loggers.
111 Setting a string overrides the logger name to which logging is performed.
112
113 Returns:
114 A tensorlike, sequence of tensorlikes or dict of tensorlists containing the result of running
115 `data`` through the sequence of ``transforms``.
116 """
117 end_ = len(transforms) if end is None else end
118 if start is None:
119 raise ValueError(f"'start' ({start}) cannot be None")
120 if start < 0:
121 raise ValueError(f"'start' ({start}) cannot be less than 0")
122 if start > end_:

Calls 2

apply_transformFunction · 0.90
apply_pending_transformsFunction · 0.90

Used in the wild real call sites across dependent graphs

searching dependent graphs…