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

Function _apply_transform

monai/transforms/transform.py:46–98  ·  view source on GitHub ↗

Perform a transform 'transform' on 'data', according to the other parameters specified. If `data` is a tuple and `unpack_parameters` is True, each parameter of `data` is unpacked as arguments to `transform`. Otherwise `data` is considered as single argument to `transform`. If 'laz

(
    transform: Callable[..., ReturnType],
    data: Any,
    unpack_parameters: bool = False,
    lazy: bool | None = False,
    overrides: dict | None = None,
    logger_name: bool | str = False,
)

Source from the content-addressed store, hash-verified

44
45
46def _apply_transform(
47 transform: Callable[..., ReturnType],
48 data: Any,
49 unpack_parameters: bool = False,
50 lazy: bool | None = False,
51 overrides: dict | None = None,
52 logger_name: bool | str = False,
53) -> ReturnType:
54 """
55 Perform a transform 'transform' on 'data', according to the other parameters specified.
56
57 If `data` is a tuple and `unpack_parameters` is True, each parameter of `data` is unpacked
58 as arguments to `transform`. Otherwise `data` is considered as single argument to `transform`.
59
60 If 'lazy' is True, this method first checks whether it can execute this method lazily. If it
61 can't, it will ensure that all pending lazy transforms on 'data' are applied before applying
62 this 'transform' to it. If 'lazy' is True, and 'overrides' are provided, those overrides will
63 be applied to the pending operations on 'data'. See ``Compose`` for more details on lazy
64 resampling, which is an experimental feature for 1.2.
65
66 Please note, this class is function is designed to be called by ``apply_transform``.
67 In general, you should not need to make specific use of it unless you are implementing
68 pipeline execution mechanisms.
69
70 Args:
71 transform: a callable to be used to transform `data`.
72 data: the tensorlike or dictionary of tensorlikes to be executed on
73 unpack_parameters: whether to unpack parameters for `transform`. Defaults to False.
74 lazy: whether to enable lazy evaluation for lazy transforms. If False, transforms will be
75 carried out on a transform by transform basis. If True, all lazy transforms will
76 be executed by accumulating changes and resampling as few times as possible.
77 See the :ref:`Lazy Resampling topic<lazy_resampling> for more information about lazy resampling.
78 overrides: this optional parameter allows you to specify a dictionary of parameters that should be overridden
79 when executing a pipeline. These each parameter that is compatible with a given transform is then applied
80 to that transform before it is executed. Note that overrides are currently only applied when
81 :ref:`Lazy Resampling<lazy_resampling>` is enabled for the pipeline or a given transform. If lazy is False
82 they are ignored. Currently supported args are:
83 {``"mode"``, ``"padding_mode"``, ``"dtype"``, ``"align_corners"``, ``"resample_mode"``, ``device``}.
84 logger_name: this optional parameter allows you to specify a logger by name for logging of pipeline execution.
85 Setting this to False disables logging. Setting it to True enables logging to the default loggers.
86 Setting a string overrides the logger name to which logging is performed.
87
88 Returns:
89 ReturnType: The return type of `transform`.
90 """
91 from monai.transforms.lazy.functional import apply_pending_transforms_in_order
92
93 data = apply_pending_transforms_in_order(transform, data, lazy, overrides, logger_name)
94
95 if isinstance(data, tuple) and unpack_parameters:
96 return transform(*data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(*data)
97
98 return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data)
99
100
101def apply_transform(

Callers 1

apply_transformFunction · 0.85

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…