未验证 提交 b4460eee 编写于 作者: 傅剑寒 提交者: GitHub

remove fluid.layers.affine_grid API (#47851)

上级 b7841a2b
......@@ -177,7 +177,6 @@ __all__ = [
'mul',
'maxout',
'space_to_depth',
'affine_grid',
'affine_channel',
'similarity_focus',
'hash',
......@@ -9693,90 +9692,6 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
return out
def affine_grid(theta, out_shape, name=None):
"""
: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.
Args:
theta (Variable) - A Tensor with shape [N, 2, 3]. It contains a batch of affine transform parameters.
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 :ref:`api_guide_Name`.
Returns:
Variable: 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`.
Raises:
ValueError: If the type of arguments is not supported.
Examples:
.. code-block:: python
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])
"""
helper = LayerHelper('affine_grid')
check_variable_and_dtype(
theta, 'theta', ['float32', 'float64'], 'affine_grid'
)
if not (
isinstance(out_shape, list)
or isinstance(out_shape, tuple)
or isinstance(out_shape, Variable)
):
raise ValueError("The out_shape should be a list, tuple or Variable.")
if not isinstance(theta, Variable):
raise ValueError("The theta should be a Variable.")
out = helper.create_variable_for_type_inference(theta.dtype)
ipts = {'Theta': theta}
attrs = {}
if isinstance(out_shape, Variable):
ipts['OutputShape'] = out_shape
check_variable_and_dtype(
out_shape, 'out_shape', ['int32'], 'affine_grid'
)
else:
attrs['output_shape'] = out_shape
if core.is_compiled_with_rocm():
# ROCM platform do not have MIOPEN kernel for affine_grid
attrs['use_cudnn'] = False
helper.append_op(
type='affine_grid',
inputs=ipts,
outputs={'Output': out},
attrs=None if len(attrs) == 0 else attrs,
)
return out
def pad2d(
input,
paddings=[0, 0, 0, 0],
......
......@@ -52,7 +52,9 @@ class AffineGridTestCase(unittest.TestCase):
theta_var = fluid.data(
"input", self.theta_shape, dtype=self.dtype
)
y_var = fluid.layers.affine_grid(theta_var, self.output_shape)
y_var = paddle.nn.functional.affine_grid(
theta_var, self.output_shape
)
feed_dict = {"input": self.theta}
exe = fluid.Executor(place)
exe.run(start)
......
......@@ -3278,7 +3278,9 @@ class TestBook(LayerTest):
fluid.default_main_program(), fluid.default_startup_program()
):
theta = self._get_data("theta", shape=[2, 3], dtype='float32')
x = fluid.layers.affine_grid(theta, out_shape=[2, 3, 244, 244])
x = paddle.nn.functional.affine_grid(
theta, out_shape=[2, 3, 244, 244]
)
return layers.pool2d(
x, pool_size=[5, 3], pool_stride=[1, 2], pool_padding=(2, 1)
)
......@@ -4175,8 +4177,8 @@ class TestBook(LayerTest):
theta = layers.data(name="theta", shape=[2, 3], dtype="float32")
out_shape = layers.data(name="out_shape", shape=[-1], dtype="int32")
data_0 = layers.affine_grid(theta, out_shape)
data_1 = layers.affine_grid(theta, [5, 3, 28, 28])
data_0 = paddle.nn.functional.affine_grid(theta, out_shape)
data_1 = paddle.nn.functional.affine_grid(theta, [5, 3, 28, 28])
self.assertIsNotNone(data_0)
self.assertIsNotNone(data_1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册