From 56581cf5763b8ec7fd5cc89e72d7a8c70cd1313b Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Fri, 11 Jun 2021 12:03:13 +0800 Subject: [PATCH] [DLMED] enhance doc-string of Invertd Signed-off-by: Nic Ma --- monai/transforms/post/dictionary.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/monai/transforms/post/dictionary.py b/monai/transforms/post/dictionary.py index 16e21a9881..cb02d4d4e6 100644 --- a/monai/transforms/post/dictionary.py +++ b/monai/transforms/post/dictionary.py @@ -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 @@ -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__(