MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / Compose

Class Compose

monai/transforms/compose.py:141–421  ·  view source on GitHub ↗

``Compose`` provides the ability to chain a series of callables together in a sequential manner. Each transform in the sequence must take a single argument and return a single value. ``Compose`` can be used in two ways: #. With a series of transforms that accept and return a s

Source from the content-addressed store, hash-verified

139
140
141class Compose(Randomizable, InvertibleTransform, LazyTransform):
142 """
143 ``Compose`` provides the ability to chain a series of callables together in
144 a sequential manner. Each transform in the sequence must take a single
145 argument and return a single value.
146
147 ``Compose`` can be used in two ways:
148
149 #. With a series of transforms that accept and return a single
150 ndarray / tensor / tensor-like parameter.
151 #. With a series of transforms that accept and return a dictionary that
152 contains one or more parameters. Such transforms must have pass-through
153 semantics that unused values in the dictionary must be copied to the return
154 dictionary. It is required that the dictionary is copied between input
155 and output of each transform.
156
157 If some transform takes a data item dictionary as input, and returns a
158 sequence of data items in the transform chain, all following transforms
159 will be applied to each item of this list if `map_items` is `True` (the
160 default). If `map_items` is `False`, the returned sequence is passed whole
161 to the next callable in the chain.
162
163 For example:
164
165 A `Compose([transformA, transformB, transformC],
166 map_items=True)(data_dict)` could achieve the following patch-based
167 transformation on the `data_dict` input:
168
169 #. transformA normalizes the intensity of 'img' field in the `data_dict`.
170 #. transformB crops out image patches from the 'img' and 'seg' of
171 `data_dict`, and return a list of three patch samples::
172
173 {'img': 3x100x100 data, 'seg': 1x100x100 data, 'shape': (100, 100)}
174 applying transformB
175 ---------->
176 [{'img': 3x20x20 data, 'seg': 1x20x20 data, 'shape': (20, 20)},
177 {'img': 3x20x20 data, 'seg': 1x20x20 data, 'shape': (20, 20)},
178 {'img': 3x20x20 data, 'seg': 1x20x20 data, 'shape': (20, 20)},]
179
180 #. transformC then randomly rotates or flips 'img' and 'seg' of
181 each dictionary item in the list returned by transformB.
182
183 The composed transforms will be set the same global random seed if user called
184 `set_determinism()`.
185
186 When using the pass-through dictionary operation, you can make use of
187 :class:`monai.transforms.adaptors.adaptor` to wrap transforms that don't conform
188 to the requirements. This approach allows you to use transforms from
189 otherwise incompatible libraries with minimal additional work.
190
191 Note:
192
193 In many cases, Compose is not the best way to create pre-processing
194 pipelines. Pre-processing is often not a strictly sequential series of
195 operations, and much of the complexity arises when a not-sequential
196 set of functions must be called as if it were a sequence.
197
198 Example: images and labels

Callers 15

__init__Method · 0.90
_default_transformsFunction · 0.90
__init__Method · 0.90
_get_all_case_statsMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
allow_missing_keys_modeFunction · 0.90
get_dataFunction · 0.90
gaussian_occlusionMethod · 0.90
initializeMethod · 0.90
initializeMethod · 0.90
pad_test_combine_opsMethod · 0.90

Calls

no outgoing calls

Tested by 15

run_training_testFunction · 0.72
test_warn_non_randomMethod · 0.72
test_train_timingMethod · 0.72
run_testMethod · 0.72
run_training_testFunction · 0.72
run_inference_testFunction · 0.72
run_training_testFunction · 0.72
run_inference_testFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…