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

Function engine_apply_transform

monai/engines/utils.py:325–350  ·  view source on GitHub ↗

Apply transform on `batch` and `output`. If `batch` and `output` are dictionaries, temporarily combine them for the transform, otherwise, apply the transform for `output` data only.

(batch: Any, output: Any, transform: Callable[..., dict])

Source from the content-addressed store, hash-verified

323
324
325def engine_apply_transform(batch: Any, output: Any, transform: Callable[..., dict]) -> tuple[Any, Any]:
326 """
327 Apply transform on `batch` and `output`.
328 If `batch` and `output` are dictionaries, temporarily combine them for the transform,
329 otherwise, apply the transform for `output` data only.
330
331 """
332 if isinstance(batch, dict) and isinstance(output, dict):
333 data = dict(batch)
334 data.update(output)
335 transformed_data = apply_transform(transform, data)
336
337 if not isinstance(transformed_data, dict):
338 raise AssertionError("With a dict supplied to apply_transform a single dict return is expected.")
339
340 for k, v in transformed_data.items():
341 # split the output data of post transforms into `output` and `batch`,
342 # `batch` should be read-only, so save the generated key-value into `output`
343 if k in output or k not in batch:
344 output[k] = v
345 else:
346 batch[k] = v
347 else:
348 output = apply_transform(transform, output)
349
350 return batch, output
351
352
353def default_metric_cmp_fn(current_metric: float, prev_best: float) -> bool:

Callers 2

__call__Method · 0.90
_run_postprocessingMethod · 0.85

Calls 2

apply_transformFunction · 0.90
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…