mindspore.ops.AffineGrid

View Source On Gitee
class mindspore.ops.AffineGrid(align_corners=False)[source]

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

Warning

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

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

Parameters

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 .

Inputs:
  • 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.

  • output_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.

Outputs:

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.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> affinegrid = ops.AffineGrid(align_corners=False)
>>> theta = Tensor([[[0.8, 0.5, 0],[-0.5, 0.8, 0]]], mindspore.float32)
>>> out_size = (1, 3, 2, 3)
>>> output = affinegrid(theta, out_size)
>>> 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]]]]