mindspore.ops.affine_grid

mindspore.ops.affine_grid(theta, size, align_corners=False)[source]

Returns a 2D or 3D flow field (sampling grid) based on theta, a batch of affine matrices.

Parameters
  • theta (Tensor) – The input tensor of flow field whose dtype is float16, float32. Input batch of affine matrices with shape \((N, 2, 3)\) for 2D grid or \((N, 3, 4)\) for 3D grid.

  • size (tuple[int]) – The target output image size. The value of target output with format \((N, C, H, W)\) for 2D grid or \((N, C, D, H, W)\) for 3D grid.

  • align_corners (bool, optional) – Geometrically, each pixel of input is viewed as a squqre instead of dot. If True , consider extremum -1 and 1 referring to the centers of the pixels rather than pixel corners. The default value is False , extremum -1 and 1 refer to the corners of the pixels, so that sampling is irrelevant to resolution of the image. Default: False .

Returns

Tensor, a tensor whose data type is same as 'theta', and the shape is \((N, H, W, 2)\) for 2D grid or \((N, D, H, W, 3)\) for 3D grid.

Raises
  • TypeError – If theta is not a Tensor or size is not a tuple.

  • ValueError – If the shape of theta is not \((N, 2, 3)\) or \((N, 3, 4)\).

  • ValueError – If the size of size is not 4 or 5.

  • ValueError – If the shape of theta is \((N, 2, 3)\), the size of size is not 4; If the shape of theta is \((N, 3, 4)\), the size of size is not 5.

  • ValueError – If the size[0] is not equal to the shape[0] of theta.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor
>>> from mindspore import ops
>>> theta = Tensor([[[0.8, 0.5, 0],[-0.5, 0.8, 0]]], mindspore.float32)
>>> out_size = (1, 3, 2, 3)
>>> output = ops.affine_grid(theta, out_size, False)
>>> print(output)
[[[[-0.78333336 -0.06666666]
[-0.25       -0.4       ]
[ 0.28333336 -0.73333335]]
[[-0.28333336  0.73333335]
[ 0.25        0.4       ]
[ 0.78333336  0.06666666]]]]