mindspore.ops.GridSampler3D

class mindspore.ops.GridSampler3D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=False)[source]

Given an input and a grid, the output is calculated using the input values and pixel positions in the grid. Only volume (5-D) input is supported.

Warning

This is an experimental API that is subject to change or deletion.

Refer to mindspore.ops.grid_sample() for more details.

Parameters
  • interpolation_mode (str, optional) –

    An optional string specifying the interpolation method. The optional values are "bilinear" or "nearest" . Default: "bilinear" .

    • "nearest": Nearest neighbor interpolation. Each output pixel is assigned the value of the nearest input pixel. This method is simple and fast but can result in blocky or pixelated outputs.

    • "bilinear": Bilinear interpolation. Each output pixel is a weighted average of the four nearest input pixels, computed using bilinear interpolation. This method produces smoother results compared to nearest neighbor interpolation.

  • padding_mode (str, optional) –

    An optional string specifying the pad method. The optional values are "zeros" , "border" or "reflection" . Default: "zeros" . When the sampling grid is outside input’s bounds, effects of various padding modes are as follows:

    • "zeros": Pads the input tensor with zeros.

    • "border": Pads the input tensor with the values of the pixels on the border of the tensor.

    • "reflection": Pads the input tensor by reflecting the values of the pixels at the boundary of the tensor.

  • align_corners (bool, optional) – An optional bool specifying alignment method. If set to True , the extrema (-1 and 1) are considered as referring to the center points of the input’s corner pixels. If set to False , they are instead considered as referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic. Default: False .

Inputs:
  • input_x (Tensor) - A 5-D tensor with dtype of float16, float32 or float64 and shape of \((N, C, D_{in}, H_{in}, W_{in})\).

  • grid (Tensor) - A 5-D tensor whose dtype is the same as input_x and whose shape is \((N, D_{out}, H_{out}, W_{out}, 3)\).

Outputs:

A 5-D Tensor whose dtype is the same as input_x and whose shape is \((N, C, D_{out}, H_{out}, W_{out})\).

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> gridsampler = ops.GridSampler3D(interpolation_mode='bilinear', padding_mode='zeros', align_corners=True)
>>> input_x = Tensor(np.arange(32).reshape((2, 2, 2, 2, 2)).astype(np.float32))
>>> grid = Tensor(np.arange(-0.2, 1, 0.1).reshape((2, 2, 1, 1, 3)).astype(np.float32))
>>> output = gridsampler(input_x, grid)
>>> print(output)
[[[[[ 3.3     ]]
   [[ 4.35    ]]]
  [[[11.300001]]
   [[12.349999]]]]
 [[[[21.4     ]]
   [[22.449999]]]
  [[[29.4     ]]
   [[30.449999]]]]]