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

Method __init__

monai/transforms/post/dictionary.py:801–860  ·  view source on GitHub ↗

Args: keys: the key of expected data in the dict, the inverse of ``transforms`` will be applied on it in-place. It also can be a list of keys, will apply the inverse transform respectively. transform: the transform applied to ``orig_key``, its inverse

(
        self,
        keys: KeysCollection,
        transform: InvertibleTransform,
        orig_keys: KeysCollection | None = None,
        meta_keys: KeysCollection | None = None,
        orig_meta_keys: KeysCollection | None = None,
        meta_key_postfix: str = DEFAULT_POST_FIX,
        nearest_interp: bool | Sequence[bool] = True,
        to_tensor: bool | Sequence[bool] = True,
        device: str | torch.device | Sequence[str | torch.device] | None = None,
        post_func: Callable | Sequence[Callable] | None = None,
        allow_missing_keys: bool = False,
    )

Source from the content-addressed store, hash-verified

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`.
830 If None, will try to create a metadata dict with the default key: `{orig_key}_{meta_key_postfix}`.
831 This metadata dict will also be included in the inverted dict, stored in `meta_keys`.
832 meta_key_postfix: if `orig_meta_keys` is None, use `{orig_key}_{meta_key_postfix}` to fetch the
833 metadata from dict, if `meta_keys` is None, use `{key}_{meta_key_postfix}`. Default: ``"meta_dict"``.
834 nearest_interp: whether to use `nearest` interpolation mode when inverting the spatial transforms,
835 default to `True`. If `False`, use the same interpolation mode as the original transform.
836 It also can be a list of bool, each matches to the `keys` data.
837 to_tensor: whether to convert the inverted data into PyTorch Tensor first, default to `True`.
838 It also can be a list of bool, each matches to the `keys` data.
839 device: if converted to Tensor, move the inverted results to target device before `post_func`,
840 default to None, it also can be a list of string or `torch.device`, each matches to the `keys` data.
841 post_func: post processing for the inverted data, should be a callable function.
842 It also can be a list of callable, each matches to the `keys` data.
843 allow_missing_keys: don't raise exception if key is missing.
844
845 """
846 super().__init__(keys, allow_missing_keys)
847 if not isinstance(transform, InvertibleTransform):
848 raise ValueError("transform is not invertible, can't invert transform for the data.")
849 self.transform = transform
850 self.orig_keys = ensure_tuple_rep(orig_keys, len(self.keys)) if orig_keys is not None else self.keys
851 self.meta_keys = ensure_tuple_rep(None, len(self.keys)) if meta_keys is None else ensure_tuple(meta_keys)
852 if len(self.keys) != len(self.meta_keys):
853 raise ValueError("meta_keys should have the same length as keys.")
854 self.orig_meta_keys = ensure_tuple_rep(orig_meta_keys, len(self.keys))
855 self.meta_key_postfix = ensure_tuple_rep(meta_key_postfix, len(self.keys))
856 self.nearest_interp = ensure_tuple_rep(nearest_interp, len(self.keys))
857 self.to_tensor = ensure_tuple_rep(to_tensor, len(self.keys))
858 self.device = ensure_tuple_rep(device, len(self.keys))

Callers 15

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 3

ensure_tuple_repFunction · 0.90
ensure_tupleFunction · 0.90
ToTensorClass · 0.90

Tested by

no test coverage detected