MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / __call__

Method __call__

monai/transforms/spatial/array.py:2059–2176  ·  view source on GitHub ↗

Args: img: shape must be (num_channels, H, W[, D]). grid: shape must be (3, H, W) for 2D or (4, H, W, D) for 3D. if ``norm_coords`` is True, the grid values must be in `[-(size-1)/2, (size-1)/2]`. if ``USE_COMPILED=True`` and ``norm_co

(
        self,
        img: torch.Tensor,
        grid: torch.Tensor | None = None,
        mode: str | int | None = None,
        padding_mode: str | None = None,
        dtype: DtypeLike = None,
        align_corners: bool | None = None,
    )

Source from the content-addressed store, hash-verified

2057 self.dtype = dtype
2058
2059 def __call__(
2060 self,
2061 img: torch.Tensor,
2062 grid: torch.Tensor | None = None,
2063 mode: str | int | None = None,
2064 padding_mode: str | None = None,
2065 dtype: DtypeLike = None,
2066 align_corners: bool | None = None,
2067 ) -> torch.Tensor:
2068 """
2069 Args:
2070 img: shape must be (num_channels, H, W[, D]).
2071 grid: shape must be (3, H, W) for 2D or (4, H, W, D) for 3D.
2072 if ``norm_coords`` is True, the grid values must be in `[-(size-1)/2, (size-1)/2]`.
2073 if ``USE_COMPILED=True`` and ``norm_coords=False``, grid values must be in `[0, size-1]`.
2074 if ``USE_COMPILED=False`` and ``norm_coords=False``, grid values must be in `[-1, 1]`.
2075 mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
2076 Interpolation mode to calculate output values. Defaults to ``self.mode``.
2077 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2078 When `USE_COMPILED` is `True`, this argument uses
2079 ``"nearest"``, ``"bilinear"``, ``"bicubic"`` to indicate 0, 1, 3 order interpolations.
2080 See also: https://monai.readthedocs.io/en/stable/networks.html#grid-pull (experimental).
2081 When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used
2082 and the value represents the order of the spline interpolation.
2083 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
2084 padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
2085 Padding mode for outside grid values. Defaults to ``self.padding_mode``.
2086 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2087 When `USE_COMPILED` is `True`, this argument uses an integer to represent the padding mode.
2088 See also: https://monai.readthedocs.io/en/stable/networks.html#grid-pull (experimental).
2089 When `mode` is an integer, using numpy/cupy backends, this argument accepts
2090 {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}.
2091 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
2092 dtype: data type for resampling computation. Defaults to ``self.dtype``.
2093 To be compatible with other modules, the output data type is always `float32`.
2094 align_corners: Defaults to ``self.align_corners``.
2095 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
2096
2097 See also:
2098 :py:const:`monai.config.USE_COMPILED`
2099 """
2100 img = convert_to_tensor(img, track_meta=get_track_meta())
2101 if grid is None:
2102 return img
2103
2104 _device = img.device if isinstance(img, torch.Tensor) else self.device
2105 _dtype = dtype or self.dtype or img.dtype
2106 _align_corners = self.align_corners if align_corners is None else align_corners
2107 img_t, *_ = convert_data_type(img, torch.Tensor, dtype=_dtype, device=_device)
2108 sr = min(len(img_t.peek_pending_shape() if isinstance(img_t, MetaTensor) else img_t.shape[1:]), 3)
2109 _use_compiled = USE_COMPILED and not _compiled_unsupported(img_t.device)
2110 backend, _interp_mode, _padding_mode, _ = resolves_modes(
2111 self.mode if mode is None else mode,
2112 self.padding_mode if padding_mode is None else padding_mode,
2113 backend=None,
2114 use_compiled=_use_compiled,
2115 )
2116

Callers

nothing calls this directly

Calls 12

convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
convert_data_typeFunction · 0.90
_compiled_unsupportedFunction · 0.90
resolves_modesFunction · 0.90
convert_to_dst_typeFunction · 0.90
moveaxisFunction · 0.90
grid_pullFunction · 0.90
minFunction · 0.85
maxFunction · 0.85
peek_pending_shapeMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected