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

Class Invertd

monai/transforms/post/dictionary.py:772–940  ·  view source on GitHub ↗

Utility transform to invert the previously applied transforms. Taking the ``transform`` previously applied on ``orig_keys``, this ``Invertd`` will apply the inverse of it to the data stored at ``keys``. ``Invertd``'s output will also include a copy of the metadata dictionary (

Source from the content-addressed store, hash-verified

770
771
772class Invertd(MapTransform):
773 """
774 Utility transform to invert the previously applied transforms.
775
776 Taking the ``transform`` previously applied on ``orig_keys``, this ``Invertd`` will apply the inverse of it
777 to the data stored at ``keys``.
778
779 ``Invertd``'s output will also include a copy of the metadata
780 dictionary (originally from ``orig_meta_keys`` or the metadata of ``orig_keys``),
781 with the relevant fields inverted and stored at ``meta_keys``.
782
783 A typical usage is to apply the inverse of the preprocessing (``transform=preprocessings``) on
784 input ``orig_keys=image`` to the model predictions ``keys=pred``.
785
786 A detailed usage example is available in the tutorial:
787 https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/torch/unet_inference_dict.py
788
789 Note:
790
791 - The output of the inverted data and metadata will be stored at ``keys`` and ``meta_keys`` respectively.
792 - To correctly invert the transforms, the information of the previously applied transforms should be
793 available at ``{orig_keys}_transforms``, and the original metadata at ``orig_meta_keys``.
794 (``meta_key_postfix`` is an optional string to conveniently construct "meta_keys" and/or "orig_meta_keys".)
795 see also: :py:class:`monai.transforms.TraceableTransform`.
796 - The transform will not change the content in ``orig_keys`` and ``orig_meta_key``.
797 These keys are only used to represent the data status of ``key`` before inverting.
798
799 """
800
801 def __init__(
802 self,
803 keys: KeysCollection,
804 transform: InvertibleTransform,
805 orig_keys: KeysCollection | None = None,
806 meta_keys: KeysCollection | None = None,
807 orig_meta_keys: KeysCollection | None = None,
808 meta_key_postfix: str = DEFAULT_POST_FIX,
809 nearest_interp: bool | Sequence[bool] = True,
810 to_tensor: bool | Sequence[bool] = True,
811 device: str | torch.device | Sequence[str | torch.device] | None = None,
812 post_func: Callable | Sequence[Callable] | None = None,
813 allow_missing_keys: bool = False,
814 ) -> None:
815 """
816 Args:
817 keys: the key of expected data in the dict, the inverse of ``transforms`` will be applied on it in-place.
818 It also can be a list of keys, will apply the inverse transform respectively.
819 transform: the transform applied to ``orig_key``, its inverse will be applied on ``key``.
820 orig_keys: the key of the original input data in the dict. These keys default to `self.keys` if not set.
821 the transform trace information of ``transforms`` should be stored at ``{orig_keys}_transforms``.
822 It can also be a list of keys, each matches the ``keys``.
823 meta_keys: The key to output the inverted metadata dictionary.
824 The metadata is a dictionary optionally containing: filename, original_shape.
825 It can be a sequence of strings, maps to ``keys``.
826 If None, will try to create a metadata dict with the default key: `{key}_{meta_key_postfix}`.
827 orig_meta_keys: the key of the metadata of original input data.
828 The metadata is a dictionary optionally containing: filename, original_shape.
829 It can be a sequence of strings, maps to the `keys`.

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…