box_decoder_and_assign

paddle.fluid.layers.box_decoder_and_assign(prior_box, prior_box_var, target_box, box_score, box_clip, name=None)[source]

Bounding Box Coder.

Decode the target bounding box with the prior_box information.

The Decoding schema is described below:

$$ ox = (pw \times pxv \times tx + px) - \frac{tw}{2} $$ $$ oy = (ph \times pyv \times ty + py) - \frac{th}{2} $$ $$ ow = \exp (pwv \times tw) \times pw + \frac{tw}{2} $$ $$ oh = \exp (phv \times th) \times ph + \frac{th}{2} $$

where tx, ty, tw, th denote the target box’s center coordinates, width and height respectively. Similarly, px, py, pw, ph denote the prior_box’s (anchor) center coordinates, width and height. pxv, pyv, pwv, phv denote the variance of the prior_box and ox, oy, ow, oh denote the decoded coordinates, width and height in decode_box.

decode_box is obtained after box decode, then assigning schema is described below:

For each prior_box, use the best non-background class’s decoded values to update the prior_box locations and get output_assign_box. So, the shape of output_assign_box is the same as PriorBox.

Parameters
  • prior_box (Variable) – (Tensor, default Tensor<float>) Box list PriorBox is a 2-D Tensor with shape [N, 4] which holds N boxes and each box is represented as [xmin, ymin, xmax, ymax], [xmin, ymin] is the left top coordinate of the anchor box, if the input is image feature map, they are close to the origin of the coordinate system. [xmax, ymax] is the right bottom coordinate of the anchor box

  • prior_box_var (Variable) – (Tensor, default Tensor<float>, optional) PriorBoxVar is a 2-D Tensor with shape [N, 4] which holds N group of variance. PriorBoxVar will set all elements to 1 by default

  • target_box (Variable) – (LoDTensor or Tensor) This input can be a 2-D LoDTensor with shape [N, classnum*4]. It holds N targets for N boxes

  • box_score (Variable) – (LoDTensor or Tensor) This input can be a 2-D LoDTensor with shape [N, classnum], each box is represented as [classnum] which is the classification probabilities

  • box_clip (FLOAT) – (float, default 4.135, np.log(1000. / 16.)) clip box to prevent overflowing

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

Returns

decode_box(Variable): (LoDTensor or Tensor) the output tensor of op with shape [N, classnum * 4] representing the result of N target boxes decoded with M Prior boxes and variances for each class

output_assign_box(Variable): (LoDTensor or Tensor) the output tensor of op with shape [N, 4] representing the result of N target boxes decoded with M Prior boxes and variances with the best non-background class by BoxScore

Return type

Tuple

Examples

import paddle.fluid as fluid
pb = fluid.data(
    name='prior_box', shape=[None, 4], dtype='float32')
pbv = fluid.data(
    name='prior_box_var', shape=[4], dtype='float32')
loc = fluid.data(
    name='target_box', shape=[None, 4*81], dtype='float32')
scores = fluid.data(
    name='scores', shape=[None, 81], dtype='float32')
decoded_box, output_assign_box = fluid.layers.box_decoder_and_assign(
    pb, pbv, loc, scores, 4.135)