Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion monai/transforms/post/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,17 @@ def __call__(self, data: Mapping[Hashable, Union[np.ndarray, torch.Tensor]]):
class Invertd(MapTransform):
"""
Utility transform to automatically invert the previously applied transforms.
When applying pre-transforms on a orig_key(like: `image`, `label`, etc.), we record the context
information of applied transforms in a dictionary in the input data dictionary with the key
"{orig_key}_transforms". This post transform will extract the transform context information of `orig_keys`
then invert the transforms(got from this context information) on the `keys` data.
Typical usage is to invert the pre-transforms(applied on input `image`) on the model `pred` data.

The output of the inverted data and metadata will be stored at `keys` and `meta_keys` respectively.
To correctly invert the transforms, the information of the previously applied transforms should be
available at `orig_keys`, and the original metadata at `orig_meta_keys`.
(`meta_key_postfix` is an optional string to conveniently construct "meta_keys" and/or "orig_meta_keys".)

Typical usage is to invert the pre-transforms (applied on input `image`) on the model `pred` data.
A detailed usage example is available in the tutorial:
https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/torch/unet_inference_dict.py

Expand All @@ -432,6 +436,10 @@ class Invertd(MapTransform):
thus some following post transforms may not support a list of Tensor, and users can leverage the
`post_func` arg for basic processing logic.

This transform needs to extract the context information of applied transforms and the meta data
dictionary from the input data dictionary, then use some numpy arrays in them to computes the inverse
logic, so please don't move `data["{orig_key}_transforms"]` and `data["{orig_meta_key}"]` to GPU device.

"""

def __init__(
Expand Down