From 663f4e6168ef9852991dc1ccfea462307d19a5d0 Mon Sep 17 00:00:00 2001 From: baiyf Date: Fri, 1 Jun 2018 19:30:59 +0800 Subject: [PATCH] Fix bilinear_op Python API (#11117) * fix conflict * code clean --- doc/fluid/api/layers.rst | 4 ++-- python/paddle/fluid/layers/nn.py | 21 +++++++++---------- .../fluid/tests/unittests/test_layers.py | 6 +++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/doc/fluid/api/layers.rst b/doc/fluid/api/layers.rst index dbb99d3c0..5329adaa1 100644 --- a/doc/fluid/api/layers.rst +++ b/doc/fluid/api/layers.rst @@ -1003,10 +1003,10 @@ dice_loss .. autofunction:: paddle.fluid.layers.dice_loss :noindex: -upsampling_bilinear2d +resize_bilinear ____ -.. autofunction:: paddle.fluid.layers.upsampling_bilinear2d +.. autofunction:: paddle.fluid.layers.resize_bilinear :noindex: gather diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 56f5c6b4b..bd6ed0f30 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -81,7 +81,7 @@ __all__ = [ 'label_smooth', 'roi_pool', 'dice_loss', - 'upsampling_bilinear2d', + 'resize_bilinear', 'gather', 'random_crop', ] @@ -3929,9 +3929,9 @@ def dice_loss(input, label, epsilon=0.00001): return reduce_mean(dice_score) -def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None): +def resize_bilinear(input, out_shape=None, scale=None, name=None): """ - The mathematical meaning of upsampling_bilinear2d is also called + The mathematical meaning of resize bilinear layer is Bilinear interpolation. Bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables (e.g. H-direction and @@ -3941,13 +3941,13 @@ def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None): https://en.wikipedia.org/wiki/Bilinear_interpolation Args: - input (Variable): The input tensor of bilinear interpolation, + input (Variable): The input tensor of resize bilinear layer, This is a 4-D tensor of the shape (num_batches, channels, in_h, in_w). - out_shape(list|tuple|Variable|None): Output shape of bilinear interpolation + out_shape(list|tuple|Variable|None): Output shape of resize bilinear layer, the shape is (out_h, out_w). Default: None - scale(int|None): The multiplier for the input height or width. + scale(float|None): The multiplier for the input height or width. At least one of out_shape or scale must be set. And out_shape has a higher priority than scale. Default: None @@ -3961,7 +3961,7 @@ def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None): Examples: .. code-block:: python - out = fluid.layers.bilinear_interp(input, out_shape=[12, 12]) + out = fluid.layers.resize_bilinear(input, out_shape=[12, 12]) """ if out_shape is None and scale is None: raise ValueError("One of out_shape and scale must not be None") @@ -3975,10 +3975,9 @@ def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None): out_w = 0 inputs = {"X": input} if out_shape is not None: - if not (_is_list_or_turple_(out_shape) and len(out_shape) == 2) and ( - out_shape is not Variable): - raise ValueError('out_shape should be a list or tuple ', - 'with length 2, (out_h, out_w).') + if not (_is_list_or_turple_(out_shape) and + len(out_shape) == 2) and not isinstance(out_shape, Variable): + raise ValueError('out_shape should be a list or tuple or variable') if _is_list_or_turple_(out_shape): out_shape = list(map(int, out_shape)) out_h = out_shape[0] diff --git a/python/paddle/fluid/tests/unittests/test_layers.py b/python/paddle/fluid/tests/unittests/test_layers.py index 60dc1f83f..ca08fd7fc 100644 --- a/python/paddle/fluid/tests/unittests/test_layers.py +++ b/python/paddle/fluid/tests/unittests/test_layers.py @@ -369,13 +369,13 @@ class TestBook(unittest.TestCase): self.assertIsNotNone(output) print(str(program)) - def test_upsampling_bilinear2d(self): + def test_resize_bilinear(self): program = Program() with program_guard(program): x = layers.data(name='x', shape=[3, 9, 6], dtype="float32") - output = layers.upsampling_bilinear2d(x, out_shape=[12, 12]) + output = layers.resize_bilinear(x, out_shape=[12, 12]) self.assertIsNotNone(output) - output = layers.upsampling_bilinear2d(x, scale=3) + output = layers.resize_bilinear(x, scale=3) self.assertIsNotNone(output) print(str(program)) -- GitLab