Skip to content

Commit 663f4e6

Browse files
baiyfqingqing01
authored andcommitted
Fix bilinear_op Python API (#11117)
* fix conflict * code clean
1 parent 9503dbb commit 663f4e6

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

doc/fluid/api/layers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,10 @@ dice_loss
10031003
.. autofunction:: paddle.fluid.layers.dice_loss
10041004
:noindex:
10051005

1006-
upsampling_bilinear2d
1006+
resize_bilinear
10071007
____
10081008

1009-
.. autofunction:: paddle.fluid.layers.upsampling_bilinear2d
1009+
.. autofunction:: paddle.fluid.layers.resize_bilinear
10101010
:noindex:
10111011

10121012
gather

python/paddle/fluid/layers/nn.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
'label_smooth',
8282
'roi_pool',
8383
'dice_loss',
84-
'upsampling_bilinear2d',
84+
'resize_bilinear',
8585
'gather',
8686
'random_crop',
8787
]
@@ -3929,9 +3929,9 @@ def dice_loss(input, label, epsilon=0.00001):
39293929
return reduce_mean(dice_score)
39303930

39313931

3932-
def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None):
3932+
def resize_bilinear(input, out_shape=None, scale=None, name=None):
39333933
"""
3934-
The mathematical meaning of upsampling_bilinear2d is also called
3934+
The mathematical meaning of resize bilinear layer is
39353935
Bilinear interpolation.
39363936
Bilinear interpolation is an extension of linear interpolation for
39373937
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):
39413941
https://en.wikipedia.org/wiki/Bilinear_interpolation
39423942
39433943
Args:
3944-
input (Variable): The input tensor of bilinear interpolation,
3944+
input (Variable): The input tensor of resize bilinear layer,
39453945
This is a 4-D tensor of the shape
39463946
(num_batches, channels, in_h, in_w).
3947-
out_shape(list|tuple|Variable|None): Output shape of bilinear interpolation
3947+
out_shape(list|tuple|Variable|None): Output shape of resize bilinear
39483948
layer, the shape is (out_h, out_w).
39493949
Default: None
3950-
scale(int|None): The multiplier for the input height or width.
3950+
scale(float|None): The multiplier for the input height or width.
39513951
At least one of out_shape or scale must be set.
39523952
And out_shape has a higher priority than scale.
39533953
Default: None
@@ -3961,7 +3961,7 @@ def upsampling_bilinear2d(input, out_shape=None, scale=None, name=None):
39613961
Examples:
39623962
.. code-block:: python
39633963
3964-
out = fluid.layers.bilinear_interp(input, out_shape=[12, 12])
3964+
out = fluid.layers.resize_bilinear(input, out_shape=[12, 12])
39653965
"""
39663966
if out_shape is None and scale is None:
39673967
raise ValueError("One of out_shape and scale must not be None")
@@ -3975,10 +3975,9 @@ def _is_list_or_turple_(data):
39753975
out_w = 0
39763976
inputs = {"X": input}
39773977
if out_shape is not None:
3978-
if not (_is_list_or_turple_(out_shape) and len(out_shape) == 2) and (
3979-
out_shape is not Variable):
3980-
raise ValueError('out_shape should be a list or tuple ',
3981-
'with length 2, (out_h, out_w).')
3978+
if not (_is_list_or_turple_(out_shape) and
3979+
len(out_shape) == 2) and not isinstance(out_shape, Variable):
3980+
raise ValueError('out_shape should be a list or tuple or variable')
39823981
if _is_list_or_turple_(out_shape):
39833982
out_shape = list(map(int, out_shape))
39843983
out_h = out_shape[0]

python/paddle/fluid/tests/unittests/test_layers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@ def test_roi_pool(self):
369369
self.assertIsNotNone(output)
370370
print(str(program))
371371

372-
def test_upsampling_bilinear2d(self):
372+
def test_resize_bilinear(self):
373373
program = Program()
374374
with program_guard(program):
375375
x = layers.data(name='x', shape=[3, 9, 6], dtype="float32")
376-
output = layers.upsampling_bilinear2d(x, out_shape=[12, 12])
376+
output = layers.resize_bilinear(x, out_shape=[12, 12])
377377
self.assertIsNotNone(output)
378-
output = layers.upsampling_bilinear2d(x, scale=3)
378+
output = layers.resize_bilinear(x, scale=3)
379379
self.assertIsNotNone(output)
380380
print(str(program))
381381

0 commit comments

Comments
 (0)