paddle.fluid.layers.detection. box_clip ( input, im_info, name=None ) [source]

Clip the box into the size given by im_info For each input box, The formula is given as follows:

xmin = max(min(xmin, im_w - 1), 0)
ymin = max(min(ymin, im_h - 1), 0)
xmax = max(min(xmax, im_w - 1), 0)
ymax = max(min(ymax, im_h - 1), 0)

where im_w and im_h are computed from im_info:

im_h = round(height / scale)
im_w = round(weight / scale)
  • input (Variable) – The input Tensor with shape \([N_1, N_2, ..., N_k, 4]\), the last dimension is 4 and data type is float32 or float64.

  • im_info (Variable) – The 2-D Tensor with shape [N, 3] with layout (height, width, scale) representing the information of image. Height and width are the input sizes and scale is the ratio of network input size and original size. The data type is float32 or float64.

  • name (str, optional) – For detailed information, please refer to Name. Usually name is no need to set and None by default.


output(Variable): The clipped tensor with data type float32 or float64. The shape is same as input.

Return type



import paddle.fluid as fluid
import paddle
boxes =
    name='boxes', shape=[None, 8, 4], dtype='float32', lod_level=1)
im_info ='im_info', shape=[-1 ,3])
out = fluid.layers.box_clip(
    input=boxes, im_info=im_info)