@templatedoc()
def box_coder(prior_box, prior_box_var, target_box, code_type='encode_center_size', box_normalized=True, name=None, axis=0):
    '\n\t:alias_main: paddle.nn.functional.box_coder\n\t:alias: paddle.nn.functional.box_coder,paddle.nn.functional.vision.box_coder\n\t:old_api: paddle.fluid.layers.box_coder\n\n    **Box Coder Layer**\n\n    Encode/Decode the target bounding box with the priorbox information.\n    \n    The Encoding schema described below:\n\n    .. math::\n\n        ox = (tx - px) / pw / pxv\n\n        oy = (ty - py) / ph / pyv\n\n        ow = \\log(\x07bs(tw / pw)) / pwv \n\n        oh = \\log(\x07bs(th / ph)) / phv \n\n    The Decoding schema described below:\n    \n    .. math::\n  \n        ox = (pw * pxv * tx * + px) - tw / 2\n\n        oy = (ph * pyv * ty * + py) - th / 2\n\n        ow = \\exp(pwv * tw) * pw + tw / 2\n\n        oh = \\exp(phv * th) * ph + th / 2   \n\n    where `tx`, `ty`, `tw`, `th` denote the target box\'s center coordinates, \n    width and height respectively. Similarly, `px`, `py`, `pw`, `ph` denote \n    the priorbox\'s (anchor) center coordinates, width and height. `pxv`, \n    `pyv`, `pwv`, `phv` denote the variance of the priorbox and `ox`, `oy`, \n    `ow`, `oh` denote the encoded/decoded coordinates, width and height. \n\n    During Box Decoding, two modes for broadcast are supported. Say target \n    box has shape [N, M, 4], and the shape of prior box can be [N, 4] or \n    [M, 4]. Then prior box will broadcast to target box along the \n    assigned axis. \n\n    Args:\n        prior_box(Variable): Box list prior_box is a 2-D Tensor with shape \n            [M, 4] holds M boxes and data type is float32 or float64. Each box\n            is represented as [xmin, ymin, xmax, ymax], [xmin, ymin] is the \n            left top coordinate of the anchor box, if the input is image feature\n            map, they are close to the origin of the coordinate system. \n            [xmax, ymax] is the right bottom coordinate of the anchor box.       \n        prior_box_var(List|Variable|None): prior_box_var supports three types \n            of input. One is variable with shape [M, 4] which holds M group and \n            data type is float32 or float64. The second is list consist of \n            4 elements shared by all boxes and data type is float32 or float64. \n            Other is None and not involved in calculation. \n        target_box(Variable): This input can be a 2-D LoDTensor with shape \n            [N, 4] when code_type is \'encode_center_size\'. This input also can \n            be a 3-D Tensor with shape [N, M, 4] when code_type is \n            \'decode_center_size\'. Each box is represented as \n            [xmin, ymin, xmax, ymax]. The data type is float32 or float64. \n            This tensor can contain LoD information to represent a batch of inputs. \n        code_type(str): The code type used with the target box. It can be\n            `encode_center_size` or `decode_center_size`. `encode_center_size` \n            by default.\n        box_normalized(bool): Whether treat the priorbox as a normalized box.\n            Set true by default.\n        name(str, optional): For detailed information, please refer \n            to :ref:`api_guide_Name`. Usually name is no need to set and \n            None by default. \n        axis(int): Which axis in PriorBox to broadcast for box decode, \n            for example, if axis is 0 and TargetBox has shape [N, M, 4] and \n            PriorBox has shape [M, 4], then PriorBox will broadcast to [N, M, 4]\n            for decoding. It is only valid when code type is \n            `decode_center_size`. Set 0 by default. \n\n    Returns:\n        Variable:\n\n        output_box(Variable): When code_type is \'encode_center_size\', the \n        output tensor of box_coder_op with shape [N, M, 4] representing the \n        result of N target boxes encoded with M Prior boxes and variances. \n        When code_type is \'decode_center_size\', N represents the batch size \n        and M represents the number of decoded boxes.\n\n    Examples:\n \n        .. code-block:: python\n \n            import paddle.fluid as fluid\n            # For encode\n            prior_box_encode = fluid.data(name=\'prior_box_encode\',\n                                  shape=[512, 4],\n                                  dtype=\'float32\')\n            target_box_encode = fluid.data(name=\'target_box_encode\',\n                                   shape=[81, 4],\n                                   dtype=\'float32\')\n            output_encode = fluid.layers.box_coder(prior_box=prior_box_encode,\n                                    prior_box_var=[0.1,0.1,0.2,0.2],\n                                    target_box=target_box_encode,\n                                    code_type="encode_center_size")\n            # For decode\n            prior_box_decode = fluid.data(name=\'prior_box_decode\',\n                                  shape=[512, 4],\n                                  dtype=\'float32\')\n            target_box_decode = fluid.data(name=\'target_box_decode\',\n                                   shape=[512, 81, 4],\n                                   dtype=\'float32\')\n            output_decode = fluid.layers.box_coder(prior_box=prior_box_decode,\n                                    prior_box_var=[0.1,0.1,0.2,0.2],\n                                    target_box=target_box_decode,\n                                    code_type="decode_center_size",\n                                    box_normalized=False,\n                                    axis=1)\n    '
    check_variable_and_dtype(prior_box, 'prior_box', ['float32', 'float64'], 'box_coder')
    check_variable_and_dtype(target_box, 'target_box', ['float32', 'float64'], 'box_coder')
    helper = LayerHelper('box_coder', **locals())
    output_box = helper.create_variable_for_type_inference(dtype=prior_box.dtype)
    inputs = {'PriorBox': prior_box, 'TargetBox': target_box}
    attrs = {'code_type': code_type, 'box_normalized': box_normalized, 'axis': axis}
    if isinstance(prior_box_var, Variable):
        inputs['PriorBoxVar'] = prior_box_var
    elif isinstance(prior_box_var, list):
        attrs['variance'] = prior_box_var
    else:
        raise TypeError('Input variance of box_coder must be Variable or lisz')
    helper.append_op(type='box_coder', inputs=inputs, attrs=attrs, outputs={'OutputBox': output_box})
    return output_box
:alias_main: paddle.nn.functional.box_coder
    :alias: paddle.nn.functional.box_coder,paddle.nn.functional.vision.box_coder
    :old_api: paddle.fluid.layers.box_coder

**Box Coder Layer**

Encode/Decode the target bounding box with the priorbox information.

The Encoding schema described below:

.. math::

    ox = (tx - px) / pw / pxv

    oy = (ty - py) / ph / pyv

    ow = \log(bs(tw / pw)) / pwv 

    oh = \log(bs(th / ph)) / phv 

The Decoding schema described below:

.. math::

    ox = (pw * pxv * tx * + px) - tw / 2

    oy = (ph * pyv * ty * + py) - th / 2

    ow = \exp(pwv * tw) * pw + tw / 2

    oh = \exp(phv * th) * ph + 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 priorbox's (anchor) center coordinates, width and height. `pxv`, 
`pyv`, `pwv`, `phv` denote the variance of the priorbox and `ox`, `oy`, 
`ow`, `oh` denote the encoded/decoded coordinates, width and height. 

During Box Decoding, two modes for broadcast are supported. Say target 
box has shape [N, M, 4], and the shape of prior box can be [N, 4] or 
[M, 4]. Then prior box will broadcast to target box along the 
assigned axis. 

Args:
    prior_box(Variable): Box list prior_box is a 2-D Tensor with shape 
        [M, 4] holds M boxes and data type is float32 or float64. 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(List|Variable|None): prior_box_var supports three types 
        of input. One is variable with shape [M, 4] which holds M group and 
        data type is float32 or float64. The second is list consist of 
        4 elements shared by all boxes and data type is float32 or float64. 
        Other is None and not involved in calculation. 
    target_box(Variable): This input can be a 2-D LoDTensor with shape 
        [N, 4] when code_type is 'encode_center_size'. This input also can 
        be a 3-D Tensor with shape [N, M, 4] when code_type is 
        'decode_center_size'. Each box is represented as 
        [xmin, ymin, xmax, ymax]. The data type is float32 or float64. 
        This tensor can contain LoD information to represent a batch of inputs. 
    code_type(str): The code type used with the target box. It can be
        `encode_center_size` or `decode_center_size`. `encode_center_size` 
        by default.
    box_normalized(bool): Whether treat the priorbox as a normalized box.
        Set true by default.
    name(str, optional): For detailed information, please refer 
        to :ref:`api_guide_Name`. Usually name is no need to set and 
        None by default. 
    axis(int): Which axis in PriorBox to broadcast for box decode, 
        for example, if axis is 0 and TargetBox has shape [N, M, 4] and 
        PriorBox has shape [M, 4], then PriorBox will broadcast to [N, M, 4]
        for decoding. It is only valid when code type is 
        `decode_center_size`. Set 0 by default. 

Returns:
    Variable:

    output_box(Variable): When code_type is 'encode_center_size', the 
    output tensor of box_coder_op with shape [N, M, 4] representing the 
    result of N target boxes encoded with M Prior boxes and variances. 
    When code_type is 'decode_center_size', N represents the batch size 
    and M represents the number of decoded boxes.

Examples:

    .. code-block:: python

        import paddle.fluid as fluid
        # For encode
        prior_box_encode = fluid.data(name='prior_box_encode',
                              shape=[512, 4],
                              dtype='float32')
        target_box_encode = fluid.data(name='target_box_encode',
                               shape=[81, 4],
                               dtype='float32')
        output_encode = fluid.layers.box_coder(prior_box=prior_box_encode,
                                prior_box_var=[0.1,0.1,0.2,0.2],
                                target_box=target_box_encode,
                                code_type="encode_center_size")
        # For decode
        prior_box_decode = fluid.data(name='prior_box_decode',
                              shape=[512, 4],
                              dtype='float32')
        target_box_decode = fluid.data(name='target_box_decode',
                               shape=[512, 81, 4],
                               dtype='float32')
        output_decode = fluid.layers.box_coder(prior_box=prior_box_decode,
                                prior_box_var=[0.1,0.1,0.2,0.2],
                                target_box=target_box_decode,
                                code_type="decode_center_size",
                                box_normalized=False,
                                axis=1)
@templatedoc()
def box_coder(prior_box, prior_box_var, target_box, code_type='encode_center_size', box_normalized=True, name=None, axis=0):
    '\n\t:alias_main: paddle.nn.functional.box_coder\n\t:alias: paddle.nn.functional.box_coder,paddle.nn.functional.vision.box_coder\n\t:old_api: paddle.fluid.layers.box_coder\n\n    **Box Coder Layer**\n\n    Encode/Decode the target bounding box with the priorbox information.\n    \n    The Encoding schema described below:\n\n    .. math::\n\n        ox = (tx - px) / pw / pxv\n\n        oy = (ty - py) / ph / pyv\n\n        ow = \\log(\x07bs(tw / pw)) / pwv \n\n        oh = \\log(\x07bs(th / ph)) / phv \n\n    The Decoding schema described below:\n    \n    .. math::\n  \n        ox = (pw * pxv * tx * + px) - tw / 2\n\n        oy = (ph * pyv * ty * + py) - th / 2\n\n        ow = \\exp(pwv * tw) * pw + tw / 2\n\n        oh = \\exp(phv * th) * ph + th / 2   \n\n    where `tx`, `ty`, `tw`, `th` denote the target box\'s center coordinates, \n    width and height respectively. Similarly, `px`, `py`, `pw`, `ph` denote \n    the priorbox\'s (anchor) center coordinates, width and height. `pxv`, \n    `pyv`, `pwv`, `phv` denote the variance of the priorbox and `ox`, `oy`, \n    `ow`, `oh` denote the encoded/decoded coordinates, width and height. \n\n    During Box Decoding, two modes for broadcast are supported. Say target \n    box has shape [N, M, 4], and the shape of prior box can be [N, 4] or \n    [M, 4]. Then prior box will broadcast to target box along the \n    assigned axis. \n\n    Args:\n        prior_box(Variable): Box list prior_box is a 2-D Tensor with shape \n            [M, 4] holds M boxes and data type is float32 or float64. Each box\n            is represented as [xmin, ymin, xmax, ymax], [xmin, ymin] is the \n            left top coordinate of the anchor box, if the input is image feature\n            map, they are close to the origin of the coordinate system. \n            [xmax, ymax] is the right bottom coordinate of the anchor box.       \n        prior_box_var(List|Variable|None): prior_box_var supports three types \n            of input. One is variable with shape [M, 4] which holds M group and \n            data type is float32 or float64. The second is list consist of \n            4 elements shared by all boxes and data type is float32 or float64. \n            Other is None and not involved in calculation. \n        target_box(Variable): This input can be a 2-D LoDTensor with shape \n            [N, 4] when code_type is \'encode_center_size\'. This input also can \n            be a 3-D Tensor with shape [N, M, 4] when code_type is \n            \'decode_center_size\'. Each box is represented as \n            [xmin, ymin, xmax, ymax]. The data type is float32 or float64. \n            This tensor can contain LoD information to represent a batch of inputs. \n        code_type(str): The code type used with the target box. It can be\n            `encode_center_size` or `decode_center_size`. `encode_center_size` \n            by default.\n        box_normalized(bool): Whether treat the priorbox as a normalized box.\n            Set true by default.\n        name(str, optional): For detailed information, please refer \n            to :ref:`api_guide_Name`. Usually name is no need to set and \n            None by default. \n        axis(int): Which axis in PriorBox to broadcast for box decode, \n            for example, if axis is 0 and TargetBox has shape [N, M, 4] and \n            PriorBox has shape [M, 4], then PriorBox will broadcast to [N, M, 4]\n            for decoding. It is only valid when code type is \n            `decode_center_size`. Set 0 by default. \n\n    Returns:\n        Variable:\n\n        output_box(Variable): When code_type is \'encode_center_size\', the \n        output tensor of box_coder_op with shape [N, M, 4] representing the \n        result of N target boxes encoded with M Prior boxes and variances. \n        When code_type is \'decode_center_size\', N represents the batch size \n        and M represents the number of decoded boxes.\n\n    Examples:\n \n        .. code-block:: python\n \n            import paddle.fluid as fluid\n            # For encode\n            prior_box_encode = fluid.data(name=\'prior_box_encode\',\n                                  shape=[512, 4],\n                                  dtype=\'float32\')\n            target_box_encode = fluid.data(name=\'target_box_encode\',\n                                   shape=[81, 4],\n                                   dtype=\'float32\')\n            output_encode = fluid.layers.box_coder(prior_box=prior_box_encode,\n                                    prior_box_var=[0.1,0.1,0.2,0.2],\n                                    target_box=target_box_encode,\n                                    code_type="encode_center_size")\n            # For decode\n            prior_box_decode = fluid.data(name=\'prior_box_decode\',\n                                  shape=[512, 4],\n                                  dtype=\'float32\')\n            target_box_decode = fluid.data(name=\'target_box_decode\',\n                                   shape=[512, 81, 4],\n                                   dtype=\'float32\')\n            output_decode = fluid.layers.box_coder(prior_box=prior_box_decode,\n                                    prior_box_var=[0.1,0.1,0.2,0.2],\n                                    target_box=target_box_decode,\n                                    code_type="decode_center_size",\n                                    box_normalized=False,\n                                    axis=1)\n    '
    check_variable_and_dtype(prior_box, 'prior_box', ['float32', 'float64'], 'box_coder')
    check_variable_and_dtype(target_box, 'target_box', ['float32', 'float64'], 'box_coder')
    helper = LayerHelper('box_coder', **locals())
    output_box = helper.create_variable_for_type_inference(dtype=prior_box.dtype)
    inputs = {'PriorBox': prior_box, 'TargetBox': target_box}
    attrs = {'code_type': code_type, 'box_normalized': box_normalized, 'axis': axis}
    if isinstance(prior_box_var, Variable):
        inputs['PriorBoxVar'] = prior_box_var
    elif isinstance(prior_box_var, list):
        attrs['variance'] = prior_box_var
    else:
        raise TypeError('Input variance of box_coder must be Variable or lisz')
    helper.append_op(type='box_coder', inputs=inputs, attrs=attrs, outputs={'OutputBox': output_box})
    return output_box