81
81
'label_smooth' ,
82
82
'roi_pool' ,
83
83
'dice_loss' ,
84
- 'bilinear_interp ' ,
84
+ 'upsampling_bilinear2d ' ,
85
85
]
86
86
87
87
@@ -3917,8 +3917,10 @@ def dice_loss(input, label, epsilon=0.00001):
3917
3917
return reduce_mean (dice_score )
3918
3918
3919
3919
3920
- def bilinear_interp (input , out_h , out_w , name = None ):
3920
+ def upsampling_bilinear2d (input , out_shape = None , scale = None , name = None ):
3921
3921
"""
3922
+ The mathematical meaning of upsampling_bilinear2d is also called
3923
+ Bilinear interpolation.
3922
3924
Bilinear interpolation is an extension of linear interpolation for
3923
3925
interpolating functions of two variables (e.g. H-direction and
3924
3926
W-direction in this layer) on a rectilinear 2D grid.
@@ -3930,8 +3932,13 @@ def bilinear_interp(input, out_h, out_w, name=None):
3930
3932
input (Variable): The input tensor of bilinear interpolation,
3931
3933
This is a 4-D tensor of the shape
3932
3934
(num_batches, channels, in_h, in_w).
3933
- out_h (int): output height of bilinear interpolation layer.
3934
- out_w (int): output width of bilinear interpolation layer.
3935
+ out_shape(list|tuple|None): Output shape of bilinear interpolation
3936
+ layer, the shape is (out_h, out_w).
3937
+ Default: None
3938
+ scale(int|None): The multiplier for the input height or width.
3939
+ At least one of out_shape or scale must be set.
3940
+ And out_shape has a higher priority than scale.
3941
+ Default: None
3935
3942
name(str|None): A name for this layer(optional). If set None, the layer
3936
3943
will be named automatically.
3937
3944
@@ -3942,10 +3949,27 @@ def bilinear_interp(input, out_h, out_w, name=None):
3942
3949
Examples:
3943
3950
.. code-block:: python
3944
3951
3945
- out = fluid.layers.bilinear_interp(input, out_h= 12, out_w=12 )
3952
+ out = fluid.layers.bilinear_interp(input, out_shape=[ 12, 12] )
3946
3953
"""
3954
+ if out_shape is None and scale is None :
3955
+ raise ValueError ("One of out_shape and scale must not be None" )
3947
3956
helper = LayerHelper ('bilinear_interp' , ** locals ())
3948
3957
dtype = helper .input_dtype ()
3958
+
3959
+ def _is_list_or_turple_ (data ):
3960
+ return (isinstance (data , list ) or isinstance (data , tuple ))
3961
+
3962
+ if out_shape is not None :
3963
+ if not (_is_list_or_turple_ (out_shape ) and len (out_shape ) == 2 ):
3964
+ raise ValueError ('out_shape should be a list or tuple ' ,
3965
+ 'with length 2, (out_h, out_w).' )
3966
+ out_shape = list (map (int , out_shape ))
3967
+ out_h = out_shape [0 ]
3968
+ out_w = out_shape [1 ]
3969
+ else :
3970
+ out_h = int (input .shape [2 ] * scale )
3971
+ out_w = int (input .shape [3 ] * scale )
3972
+
3949
3973
out = helper .create_tmp_variable (dtype )
3950
3974
helper .append_op (
3951
3975
type = "bilinear_interp" ,
0 commit comments