paddle.fluid.layers.nn. resize_linear ( input, out_shape=None, scale=None, name=None, actual_shape=None, align_corners=True, align_mode=1, data_format='NCW' ) [source]

This op resizes the input by performing linear interpolation based on given output shape which specified by actual_shape, out_shape and scale in priority order.

Warning: the parameter actual_shape will be deprecated in the future and only use out_shape instead.

Align_corners and align_mode are optional parameters,the calculation method of interpolation can be selected by them.


For scale:

    if align_corners = True && out_size > 1 :

      scale_factor = (in_size-1.0)/(out_size-1.0)


      scale_factor = float(in_size/out_size)

Linear interpolation:

      align_corners = False , align_mode = 0

      input : (N,C,W_in)
      output: (N,C,W_out) where:

      W_out = (W_{in}+0.5) * scale_{factor} - 0.5


      input : (N,C,W_in)
      output: (N,C,W_out) where:
      W_out = W_{in} * scale_{factor}
  • input (Variable) – 3-D Tensor(NCW), its data type is float32, float64, or uint8, its data format is specified by data_format.

  • out_shape (list|tuple|Variable|None) – Output shape of resize linear layer, the shape is (out_w,). Default: None. If a list, each element can be an integer or a Tensor Variable with shape: [1]. If a Tensor Variable, its dimension size should be 1.

  • scale (float|Variable|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.

  • actual_shape (Variable) – An optional input to specify output shape dynamically. If provided, image resize according to this given shape rather than out_shape and scale specifying shape. That is to say actual_shape has the highest priority. It is recommended to use out_shape if you want to specify output shape dynamically, because actual_shape will be deprecated. When using actual_shape to specify output shape, one of out_shape and scale should also be set, otherwise errors would be occurred in graph constructing stage. Default: None

  • align_corners (bool) – an optional bool. Defaults to True. If True, the centers of 4 corner pixels of the input and output tensors are aligned, preserving the values at the corner pixels, If False, are not aligned

  • align_mode (bool) – (int, default ‘1’), optional for bilinear interpolation, can be ‘0’ for src_idx = scale*(dst_indx+0.5)-0.5 , can be ‘1’ for src_idx = scale*dst_index

  • data_format (str, optional) – Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from: “NCW”, “NWC”. The default is “NCW”. When it is “NCW”, the data is stored in the order of: [batch_size, input_channels, input_width].

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name


3-D tensor(NCW or NWC).

Return type



#declarative mode
import paddle.fluid as fluid
import numpy as np
input ="input", shape=[None,3,100])

output = fluid.layers.resize_linear(input=input,out_shape=[50,])

place = fluid.CPUPlace()
exe = fluid.Executor(place)

input_data = np.random.rand(1,3,100).astype("float32")

output_data =,


# (1, 3, 50)

#imperative mode
import paddle.fluid.dygraph as dg

with dg.guard(place) as g:
    input = dg.to_variable(input_data)
    output = fluid.layers.resize_linear(input=input, out_shape=[50,])

    # [1L, 3L, 50L]