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
for 2D grid or for 3D grid.size (tuple[int]) – The target output image size. The value of target output with format
for 2D grid or 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 isFalse
, 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
for 2D grid or 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
or .ValueError – If the size of size is not 4 or 5.
ValueError – If the shape of theta is
, the size of size is not 4; If the shape of theta is , 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]]]]