diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 3f5b0bcd7ba8d34069e819b9053e82cdff8ebc2b..d66a5b083a32df50ae28e5c2df309f8662211d53 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -7806,7 +7806,6 @@ def grid_sampler(x, grid, name=None): out = fluid.layers.grid_sampler(x=x, grid=grid) """ helper = LayerHelper("grid_sampler", **locals()) - dtype = helper.input_dtype() if not isinstance(x, Variable): return ValueError("The x should be a Variable") @@ -7814,10 +7813,10 @@ def grid_sampler(x, grid, name=None): if not isinstance(grid, Variable): return ValueError("The grid should be a Variable") - out = helper.create_variable_for_type_inference(dtype) + out = helper.create_variable_for_type_inference(x.dtype) ipts = {'X': x, 'Grid': grid} - helper.append_op(type='grid_sampler', inputs=ipts, outputs={'Output', out}) + helper.append_op(type='grid_sampler', inputs=ipts, outputs={'Output': out}) return out diff --git a/python/paddle/fluid/tests/unittests/test_layers.py b/python/paddle/fluid/tests/unittests/test_layers.py index f85beee9be528431c1b30424bf6bbd2fb0d26b4c..c4ecc2c2c2563fcad09821453ee73e41f81407d5 100644 --- a/python/paddle/fluid/tests/unittests/test_layers.py +++ b/python/paddle/fluid/tests/unittests/test_layers.py @@ -868,12 +868,12 @@ class TestBook(unittest.TestCase): def test_grid_sampler(self): program = Program() with program_guard(program): - x = layers.data(name='x', shape=[2, 3, 5, 7], dtype='float32') - grid = layers.data(name='grid', shape=[2, 5, 7, 2], dtype='float32') + x = layers.data(name='x', shape=[3, 5, 7], dtype='float32') + grid = layers.data(name='grid', shape=[5, 7, 2], dtype='float32') out = layers.grid_sampler(x, grid) self.assertIsNotNone(out) print(str(program)) - + def test_affine_grid(self): program = Program() with program_guard(program):