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

Method __call__

monai/transforms/spatial/array.py:3146–3172  ·  view source on GitHub ↗

Args: img: shape must be (num_channels, H, W[, D]). mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). Interpolation mode to calculate output values. Defaults to ``self.mode``. See also: https://pytorch

(
        self, img: torch.Tensor, mode: str | None = None, padding_mode: str | None = None, randomize: bool = True
    )

Source from the content-addressed store, hash-verified

3144 )
3145
3146 def __call__(
3147 self, img: torch.Tensor, mode: str | None = None, padding_mode: str | None = None, randomize: bool = True
3148 ) -> torch.Tensor:
3149 """
3150 Args:
3151 img: shape must be (num_channels, H, W[, D]).
3152 mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
3153 Interpolation mode to calculate output values. Defaults to ``self.mode``.
3154 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
3155 When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used
3156 and the value represents the order of the spline interpolation.
3157 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
3158 padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
3159 Padding mode for outside grid values. Defaults to ``self.padding_mode``.
3160 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
3161 When `mode` is an integer, using numpy/cupy backends, this argument accepts
3162 {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}.
3163 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
3164 randomize: whether to shuffle the random factors using `randomize()`, default to True.
3165 """
3166 if randomize:
3167 if isinstance(img, MetaTensor) and img.pending_operations:
3168 warnings.warn("MetaTensor img has pending operations, transform may return incorrect results.")
3169 self.randomize(img.shape[1:])
3170 if not self._do_transform:
3171 return convert_to_tensor(img, track_meta=get_track_meta()) # type: ignore
3172 return self.grid_distortion(img, distort_steps=self.distort_steps, mode=mode, padding_mode=padding_mode)
3173
3174
3175class GridSplit(Transform, MultiSampleTrait):

Callers

nothing calls this directly

Calls 3

randomizeMethod · 0.95
convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90

Tested by

no test coverage detected