def generate_proposal_labels(rpn_rois, gt_classes, is_crowd, gt_boxes, im_info, batch_size_per_im=256, fg_fraction=0.25, fg_thresh=0.25, bg_thresh_hi=0.5, bg_thresh_lo=0.0, bbox_reg_weights=[0.1, 0.1, 0.2, 0.2], class_nums=None, use_random=True, is_cls_agnostic=False, is_cascade_rcnn=False):
    "\n\t:alias_main: paddle.nn.functional.generate_proposal_labels\n\t:alias: paddle.nn.functional.generate_proposal_labels,paddle.nn.functional.vision.generate_proposal_labels\n\t:old_api: paddle.fluid.layers.generate_proposal_labels\n\n    **Generate Proposal Labels of Faster-RCNN**\n\n    This operator can be, for given the GenerateProposalOp output bounding boxes and groundtruth,\n    to sample foreground boxes and background boxes, and compute loss target.\n\n    RpnRois is the output boxes of RPN and was processed by generate_proposal_op, these boxes\n    were combined with groundtruth boxes and sampled according to batch_size_per_im and fg_fraction,\n    If an instance with a groundtruth overlap greater than fg_thresh, then it was considered as a foreground sample.\n    If an instance with a groundtruth overlap greater than bg_thresh_lo and lower than bg_thresh_hi,\n    then it was considered as a background sample.\n    After all foreground and background boxes are chosen (so called Rois),\n    then we apply random sampling to make sure\n    the number of foreground boxes is no more than batch_size_per_im * fg_fraction.\n\n    For each box in Rois, we assign the classification (class label) and regression targets (box label) to it.\n    Finally BboxInsideWeights and BboxOutsideWeights are used to specify whether it would contribute to training loss.\n\n    Args:\n        rpn_rois(Variable): A 2-D LoDTensor with shape [N, 4]. N is the number of the GenerateProposalOp's output, each element is a bounding box with [xmin, ymin, xmax, ymax] format. The data type can be float32 or float64.\n        gt_classes(Variable): A 2-D LoDTensor with shape [M, 1]. M is the number of groundtruth, each element is a class label of groundtruth. The data type must be int32.\n        is_crowd(Variable): A 2-D LoDTensor with shape [M, 1]. M is the number of groundtruth, each element is a flag indicates whether a groundtruth is crowd. The data type must be int32.\n        gt_boxes(Variable): A 2-D LoDTensor with shape [M, 4]. M is the number of groundtruth, each element is a bounding box with [xmin, ymin, xmax, ymax] format.\n        im_info(Variable): A 2-D LoDTensor with shape [B, 3]. B is the number of input images, each element consists of im_height, im_width, im_scale.\n\n        batch_size_per_im(int): Batch size of rois per images. The data type must be int32.\n        fg_fraction(float): Foreground fraction in total batch_size_per_im. The data type must be float32.\n        fg_thresh(float): Overlap threshold which is used to chose foreground sample. The data type must be float32.\n        bg_thresh_hi(float): Overlap threshold upper bound which is used to chose background sample. The data type must be float32.\n        bg_thresh_lo(float): Overlap threshold lower bound which is used to chose background sample. The data type must be float32.\n        bbox_reg_weights(list|tuple): Box regression weights. The data type must be float32.\n        class_nums(int): Class number. The data type must be int32.\n        use_random(bool): Use random sampling to choose foreground and background boxes.\n        is_cls_agnostic(bool): bbox regression use class agnostic simply which only represent fg and bg boxes.\n        is_cascade_rcnn(bool): it will filter some bbox crossing the image's boundary when setting True.\n\n    Returns:\n        tuple:\n        A tuple with format``(rois, labels_int32, bbox_targets, bbox_inside_weights, bbox_outside_weights)``.\n\n        - **rois**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4]``. The data type is the same as ``rpn_rois``.\n        - **labels_int32**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 1]``. The data type must be int32.\n        - **bbox_targets**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The regression targets of all RoIs. The data type is the same as ``rpn_rois``.\n        - **bbox_inside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of foreground boxes' regression loss. The data type is the same as ``rpn_rois``.\n        - **bbox_outside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of regression loss. The data type is the same as ``rpn_rois``.\n\n\n    Examples:\n        .. code-block:: python\n\n            import paddle.fluid as fluid\n            rpn_rois = fluid.data(name='rpn_rois', shape=[None, 4], dtype='float32')\n            gt_classes = fluid.data(name='gt_classes', shape=[None, 1], dtype='float32')\n            is_crowd = fluid.data(name='is_crowd', shape=[None, 1], dtype='float32')\n            gt_boxes = fluid.data(name='gt_boxes', shape=[None, 4], dtype='float32')\n            im_info = fluid.data(name='im_info', shape=[None, 3], dtype='float32')\n            rois, labels, bbox, inside_weights, outside_weights = fluid.layers.generate_proposal_labels(\n                           rpn_rois, gt_classes, is_crowd, gt_boxes, im_info,\n                           class_nums=10)\n\n    "
    helper = LayerHelper('generate_proposal_labels', **locals())
    check_variable_and_dtype(rpn_rois, 'rpn_rois', ['float32', 'float64'], 'generate_proposal_labels')
    check_variable_and_dtype(gt_classes, 'gt_classes', ['int32'], 'generate_proposal_labels')
    check_variable_and_dtype(is_crowd, 'is_crowd', ['int32'], 'generate_proposal_labels')
    rois = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    labels_int32 = helper.create_variable_for_type_inference(dtype=gt_classes.dtype)
    bbox_targets = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    bbox_inside_weights = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    bbox_outside_weights = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    helper.append_op(type='generate_proposal_labels', inputs={'RpnRois': rpn_rois, 'GtClasses': gt_classes, 'IsCrowd': is_crowd, 'GtBoxes': gt_boxes, 'ImInfo': im_info}, outputs={'Rois': rois, 'LabelsInt32': labels_int32, 'BboxTargets': bbox_targets, 'BboxInsideWeights': bbox_inside_weights, 'BboxOutsideWeights': bbox_outside_weights}, attrs={'batch_size_per_im': batch_size_per_im, 'fg_fraction': fg_fraction, 'fg_thresh': fg_thresh, 'bg_thresh_hi': bg_thresh_hi, 'bg_thresh_lo': bg_thresh_lo, 'bbox_reg_weights': bbox_reg_weights, 'class_nums': class_nums, 'use_random': use_random, 'is_cls_agnostic': is_cls_agnostic, 'is_cascade_rcnn': is_cascade_rcnn})
    rois.stop_gradient = True
    labels_int32.stop_gradient = True
    bbox_targets.stop_gradient = True
    bbox_inside_weights.stop_gradient = True
    bbox_outside_weights.stop_gradient = True
    return (rois, labels_int32, bbox_targets, bbox_inside_weights, bbox_outside_weights)
:alias_main: paddle.nn.functional.generate_proposal_labels
    :alias: paddle.nn.functional.generate_proposal_labels,paddle.nn.functional.vision.generate_proposal_labels
    :old_api: paddle.fluid.layers.generate_proposal_labels

**Generate Proposal Labels of Faster-RCNN**

This operator can be, for given the GenerateProposalOp output bounding boxes and groundtruth,
to sample foreground boxes and background boxes, and compute loss target.

RpnRois is the output boxes of RPN and was processed by generate_proposal_op, these boxes
were combined with groundtruth boxes and sampled according to batch_size_per_im and fg_fraction,
If an instance with a groundtruth overlap greater than fg_thresh, then it was considered as a foreground sample.
If an instance with a groundtruth overlap greater than bg_thresh_lo and lower than bg_thresh_hi,
then it was considered as a background sample.
After all foreground and background boxes are chosen (so called Rois),
then we apply random sampling to make sure
the number of foreground boxes is no more than batch_size_per_im * fg_fraction.

For each box in Rois, we assign the classification (class label) and regression targets (box label) to it.
Finally BboxInsideWeights and BboxOutsideWeights are used to specify whether it would contribute to training loss.

Args:
    rpn_rois(Variable): A 2-D LoDTensor with shape [N, 4]. N is the number of the GenerateProposalOp's output, each element is a bounding box with [xmin, ymin, xmax, ymax] format. The data type can be float32 or float64.
    gt_classes(Variable): A 2-D LoDTensor with shape [M, 1]. M is the number of groundtruth, each element is a class label of groundtruth. The data type must be int32.
    is_crowd(Variable): A 2-D LoDTensor with shape [M, 1]. M is the number of groundtruth, each element is a flag indicates whether a groundtruth is crowd. The data type must be int32.
    gt_boxes(Variable): A 2-D LoDTensor with shape [M, 4]. M is the number of groundtruth, each element is a bounding box with [xmin, ymin, xmax, ymax] format.
    im_info(Variable): A 2-D LoDTensor with shape [B, 3]. B is the number of input images, each element consists of im_height, im_width, im_scale.

    batch_size_per_im(int): Batch size of rois per images. The data type must be int32.
    fg_fraction(float): Foreground fraction in total batch_size_per_im. The data type must be float32.
    fg_thresh(float): Overlap threshold which is used to chose foreground sample. The data type must be float32.
    bg_thresh_hi(float): Overlap threshold upper bound which is used to chose background sample. The data type must be float32.
    bg_thresh_lo(float): Overlap threshold lower bound which is used to chose background sample. The data type must be float32.
    bbox_reg_weights(list|tuple): Box regression weights. The data type must be float32.
    class_nums(int): Class number. The data type must be int32.
    use_random(bool): Use random sampling to choose foreground and background boxes.
    is_cls_agnostic(bool): bbox regression use class agnostic simply which only represent fg and bg boxes.
    is_cascade_rcnn(bool): it will filter some bbox crossing the image's boundary when setting True.

Returns:
    tuple:
    A tuple with format``(rois, labels_int32, bbox_targets, bbox_inside_weights, bbox_outside_weights)``.

    - **rois**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4]``. The data type is the same as ``rpn_rois``.
    - **labels_int32**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 1]``. The data type must be int32.
    - **bbox_targets**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The regression targets of all RoIs. The data type is the same as ``rpn_rois``.
    - **bbox_inside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of foreground boxes' regression loss. The data type is the same as ``rpn_rois``.
    - **bbox_outside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of regression loss. The data type is the same as ``rpn_rois``.


Examples:
    .. code-block:: python

        import paddle.fluid as fluid
        rpn_rois = fluid.data(name='rpn_rois', shape=[None, 4], dtype='float32')
        gt_classes = fluid.data(name='gt_classes', shape=[None, 1], dtype='float32')
        is_crowd = fluid.data(name='is_crowd', shape=[None, 1], dtype='float32')
        gt_boxes = fluid.data(name='gt_boxes', shape=[None, 4], dtype='float32')
        im_info = fluid.data(name='im_info', shape=[None, 3], dtype='float32')
        rois, labels, bbox, inside_weights, outside_weights = fluid.layers.generate_proposal_labels(
                       rpn_rois, gt_classes, is_crowd, gt_boxes, im_info,
                       class_nums=10)
def generate_proposal_labels(rpn_rois, gt_classes, is_crowd, gt_boxes, im_info, batch_size_per_im=256, fg_fraction=0.25, fg_thresh=0.25, bg_thresh_hi=0.5, bg_thresh_lo=0.0, bbox_reg_weights=[0.1, 0.1, 0.2, 0.2], class_nums=None, use_random=True, is_cls_agnostic=False, is_cascade_rcnn=False):
    "\n\t:alias_main: paddle.nn.functional.generate_proposal_labels\n\t:alias: paddle.nn.functional.generate_proposal_labels,paddle.nn.functional.vision.generate_proposal_labels\n\t:old_api: paddle.fluid.layers.generate_proposal_labels\n\n    **Generate Proposal Labels of Faster-RCNN**\n\n    This operator can be, for given the GenerateProposalOp output bounding boxes and groundtruth,\n    to sample foreground boxes and background boxes, and compute loss target.\n\n    RpnRois is the output boxes of RPN and was processed by generate_proposal_op, these boxes\n    were combined with groundtruth boxes and sampled according to batch_size_per_im and fg_fraction,\n    If an instance with a groundtruth overlap greater than fg_thresh, then it was considered as a foreground sample.\n    If an instance with a groundtruth overlap greater than bg_thresh_lo and lower than bg_thresh_hi,\n    then it was considered as a background sample.\n    After all foreground and background boxes are chosen (so called Rois),\n    then we apply random sampling to make sure\n    the number of foreground boxes is no more than batch_size_per_im * fg_fraction.\n\n    For each box in Rois, we assign the classification (class label) and regression targets (box label) to it.\n    Finally BboxInsideWeights and BboxOutsideWeights are used to specify whether it would contribute to training loss.\n\n    Args:\n        rpn_rois(Variable): A 2-D LoDTensor with shape [N, 4]. N is the number of the GenerateProposalOp's output, each element is a bounding box with [xmin, ymin, xmax, ymax] format. The data type can be float32 or float64.\n        gt_classes(Variable): A 2-D LoDTensor with shape [M, 1]. M is the number of groundtruth, each element is a class label of groundtruth. The data type must be int32.\n        is_crowd(Variable): A 2-D LoDTensor with shape [M, 1]. M is the number of groundtruth, each element is a flag indicates whether a groundtruth is crowd. The data type must be int32.\n        gt_boxes(Variable): A 2-D LoDTensor with shape [M, 4]. M is the number of groundtruth, each element is a bounding box with [xmin, ymin, xmax, ymax] format.\n        im_info(Variable): A 2-D LoDTensor with shape [B, 3]. B is the number of input images, each element consists of im_height, im_width, im_scale.\n\n        batch_size_per_im(int): Batch size of rois per images. The data type must be int32.\n        fg_fraction(float): Foreground fraction in total batch_size_per_im. The data type must be float32.\n        fg_thresh(float): Overlap threshold which is used to chose foreground sample. The data type must be float32.\n        bg_thresh_hi(float): Overlap threshold upper bound which is used to chose background sample. The data type must be float32.\n        bg_thresh_lo(float): Overlap threshold lower bound which is used to chose background sample. The data type must be float32.\n        bbox_reg_weights(list|tuple): Box regression weights. The data type must be float32.\n        class_nums(int): Class number. The data type must be int32.\n        use_random(bool): Use random sampling to choose foreground and background boxes.\n        is_cls_agnostic(bool): bbox regression use class agnostic simply which only represent fg and bg boxes.\n        is_cascade_rcnn(bool): it will filter some bbox crossing the image's boundary when setting True.\n\n    Returns:\n        tuple:\n        A tuple with format``(rois, labels_int32, bbox_targets, bbox_inside_weights, bbox_outside_weights)``.\n\n        - **rois**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4]``. The data type is the same as ``rpn_rois``.\n        - **labels_int32**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 1]``. The data type must be int32.\n        - **bbox_targets**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The regression targets of all RoIs. The data type is the same as ``rpn_rois``.\n        - **bbox_inside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of foreground boxes' regression loss. The data type is the same as ``rpn_rois``.\n        - **bbox_outside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of regression loss. The data type is the same as ``rpn_rois``.\n\n\n    Examples:\n        .. code-block:: python\n\n            import paddle.fluid as fluid\n            rpn_rois = fluid.data(name='rpn_rois', shape=[None, 4], dtype='float32')\n            gt_classes = fluid.data(name='gt_classes', shape=[None, 1], dtype='float32')\n            is_crowd = fluid.data(name='is_crowd', shape=[None, 1], dtype='float32')\n            gt_boxes = fluid.data(name='gt_boxes', shape=[None, 4], dtype='float32')\n            im_info = fluid.data(name='im_info', shape=[None, 3], dtype='float32')\n            rois, labels, bbox, inside_weights, outside_weights = fluid.layers.generate_proposal_labels(\n                           rpn_rois, gt_classes, is_crowd, gt_boxes, im_info,\n                           class_nums=10)\n\n    "
    helper = LayerHelper('generate_proposal_labels', **locals())
    check_variable_and_dtype(rpn_rois, 'rpn_rois', ['float32', 'float64'], 'generate_proposal_labels')
    check_variable_and_dtype(gt_classes, 'gt_classes', ['int32'], 'generate_proposal_labels')
    check_variable_and_dtype(is_crowd, 'is_crowd', ['int32'], 'generate_proposal_labels')
    rois = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    labels_int32 = helper.create_variable_for_type_inference(dtype=gt_classes.dtype)
    bbox_targets = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    bbox_inside_weights = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    bbox_outside_weights = helper.create_variable_for_type_inference(dtype=rpn_rois.dtype)
    helper.append_op(type='generate_proposal_labels', inputs={'RpnRois': rpn_rois, 'GtClasses': gt_classes, 'IsCrowd': is_crowd, 'GtBoxes': gt_boxes, 'ImInfo': im_info}, outputs={'Rois': rois, 'LabelsInt32': labels_int32, 'BboxTargets': bbox_targets, 'BboxInsideWeights': bbox_inside_weights, 'BboxOutsideWeights': bbox_outside_weights}, attrs={'batch_size_per_im': batch_size_per_im, 'fg_fraction': fg_fraction, 'fg_thresh': fg_thresh, 'bg_thresh_hi': bg_thresh_hi, 'bg_thresh_lo': bg_thresh_lo, 'bbox_reg_weights': bbox_reg_weights, 'class_nums': class_nums, 'use_random': use_random, 'is_cls_agnostic': is_cls_agnostic, 'is_cascade_rcnn': is_cascade_rcnn})
    rois.stop_gradient = True
    labels_int32.stop_gradient = True
    bbox_targets.stop_gradient = True
    bbox_inside_weights.stop_gradient = True
    bbox_outside_weights.stop_gradient = True
    return (rois, labels_int32, bbox_targets, bbox_inside_weights, bbox_outside_weights)