affine_grid

paddle.fluid.layers.nn. affine_grid ( theta, out_shape, name=None ) [source]
Alias_main

paddle.nn.functional.affine_grid :alias: paddle.nn.functional.affine_grid,paddle.nn.functional.vision.affine_grid :old_api: paddle.fluid.layers.affine_grid

It generates a grid of (x,y) coordinates using the parameters of the affine transformation that correspond to a set of points where the input feature map should be sampled to produce the transformed output feature map.

Parameters
  • theta (Variable) – The data type can be float32 or float64.

  • out_shape (Variable | list | tuple) – The shape of target output with format [batch_size, channel, height, width]. out_shape can be a Tensor or a list or tuple. The data type must be int32.

  • name (str|None) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A Tensor with shape [batch_size, H, W, 2] while ‘H’ and ‘W’ are the height and width of feature map in affine transformation. The data type is the same as theta.

Return type

Variable

Raises

ValueError – If the type of arguments is not supported.

Examples

import paddle.fluid as fluid
import numpy as np
place = fluid.CPUPlace()
theta = fluid.data(name="x", shape=[None, 2, 3], dtype="float32")
out_shape = fluid.data(name="y", shape=[4], dtype="int32")
grid_0 = fluid.layers.affine_grid(theta, out_shape)
grid_1 = fluid.layers.affine_grid(theta, [5, 3, 28, 28])
batch_size=2
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
output= exe.run(feed={"x": np.random.rand(batch_size,2,3).astype("float32"),
                      "y": np.array([5, 3, 28, 28]).astype("int32")},
                      fetch_list=[grid_0.name, grid_1.name])
print(output[0])
print(output[1])