(flat_approxs,
                           inside_flags,
                           flat_squares,
                           gt_bboxes,
                           gt_bboxes_ignore,
                           img_meta,
                           approxs_per_octave,
                           cfg,
                           sampling=True,
                           unmap_outputs=True)
return (bbox_anchors, bbox_gts, bbox_weights, pos_inds, neg_inds)
Compute guided anchoring targets.

    This function returns sampled anchors and gt bboxes directly
    rather than calculates regression targets.

    Args:
        flat_approxs (Tensor): flat approxs of a single image,
            shape (n, 4)
        inside_flags (Tensor): inside flags of a single image,
            shape (n, ).
        flat_squares (Tensor): flat squares of a single image,
            shape (approxs_per_octave * n, 4)
        gt_bboxes (Tensor): Ground truth bboxes of a single image.
        img_meta (dict): Meta info of a single image.
        approxs_per_octave (int): number of approxs per octave
        cfg (dict): RPN train configs.
        sampling (bool): sampling or not.
        unmap_outputs (bool): unmap outputs or not.

    Returns:
        tuple
Compute guided anchoring targets.
Compute guided anchoring targets .
def ga_shape_target_single(flat_approxs,
                           inside_flags,
                           flat_squares,
                           gt_bboxes,
                           gt_bboxes_ignore,
                           img_meta,
                           approxs_per_octave,
                           cfg,
                           sampling=True,
                           unmap_outputs=True):
    """Compute guided anchoring targets.

    This function returns sampled anchors and gt bboxes directly
    rather than calculates regression targets.

    Args:
        flat_approxs (Tensor): flat approxs of a single image,
            shape (n, 4)
        inside_flags (Tensor): inside flags of a single image,
            shape (n, ).
        flat_squares (Tensor): flat squares of a single image,
            shape (approxs_per_octave * n, 4)
        gt_bboxes (Tensor): Ground truth bboxes of a single image.
        img_meta (dict): Meta info of a single image.
        approxs_per_octave (int): number of approxs per octave
        cfg (dict): RPN train configs.
        sampling (bool): sampling or not.
        unmap_outputs (bool): unmap outputs or not.

    Returns:
        tuple
    """
    if not inside_flags.any():
        return (None, ) * 6
    # assign gt and sample anchors
    expand_inside_flags = inside_flags[:, None].expand(
        -1, approxs_per_octave).reshape(-1)
    approxs = flat_approxs[expand_inside_flags, :]
    squares = flat_squares[inside_flags, :]

    bbox_assigner = build_assigner(cfg.ga_assigner)
    assign_result = bbox_assigner.assign(approxs, squares, approxs_per_octave,
                                         gt_bboxes, gt_bboxes_ignore)
    if sampling:
        bbox_sampler = build_sampler(cfg.ga_sampler)
    else:
        bbox_sampler = PseudoSampler()
    sampling_result = bbox_sampler.sample(assign_result, squares, gt_bboxes)

    bbox_anchors = torch.zeros_like(squares)
    bbox_gts = torch.zeros_like(squares)
    bbox_weights = torch.zeros_like(squares)

    pos_inds = sampling_result.pos_inds
    neg_inds = sampling_result.neg_inds
    if len(pos_inds) > 0:
        bbox_anchors[pos_inds, :] = sampling_result.pos_bboxes
        bbox_gts[pos_inds, :] = sampling_result.pos_gt_bboxes
        bbox_weights[pos_inds, :] = 1.0

    # map up to original set of anchors
    if unmap_outputs:
        num_total_anchors = flat_squares.size(0)
        bbox_anchors = unmap(bbox_anchors, num_total_anchors, inside_flags)
        bbox_gts = unmap(bbox_gts, num_total_anchors, inside_flags)
        bbox_weights = unmap(bbox_weights, num_total_anchors, inside_flags)

    return (bbox_anchors, bbox_gts, bbox_weights, pos_inds, neg_inds)
def ga_shape_target_single ( flat_approxs , inside_flags , flat_squares , gt_bboxes , gt_bboxes_ignore , img_meta , approxs_per_octave , cfg , sampling = True , unmap_outputs = True ) : if not inside_flags . any ( ) : return ( None , ) * 6 # assign gt and sample anchors expand_inside_flags = inside_flags [ : , None ] . expand ( - 1 , approxs_per_octave ) . reshape ( - 1 ) approxs = flat_approxs [ expand_inside_flags , : ] squares = flat_squares [ inside_flags , : ] bbox_assigner = build_assigner ( cfg . ga_assigner ) assign_result = bbox_assigner . assign ( approxs , squares , approxs_per_octave , gt_bboxes , gt_bboxes_ignore ) if sampling : bbox_sampler = build_sampler ( cfg . ga_sampler ) else : bbox_sampler = PseudoSampler ( ) sampling_result = bbox_sampler . sample ( assign_result , squares , gt_bboxes ) bbox_anchors = torch . zeros_like ( squares ) bbox_gts = torch . zeros_like ( squares ) bbox_weights = torch . zeros_like ( squares ) pos_inds = sampling_result . pos_inds neg_inds = sampling_result . neg_inds if len ( pos_inds ) > 0 : bbox_anchors [ pos_inds , : ] = sampling_result . pos_bboxes bbox_gts [ pos_inds , : ] = sampling_result . pos_gt_bboxes bbox_weights [ pos_inds , : ] = 1.0 # map up to original set of anchors if unmap_outputs : num_total_anchors = flat_squares . size ( 0 ) bbox_anchors = unmap ( bbox_anchors , num_total_anchors , inside_flags ) bbox_gts = unmap ( bbox_gts , num_total_anchors , inside_flags ) bbox_weights = unmap ( bbox_weights , num_total_anchors , inside_flags ) return ( bbox_anchors , bbox_gts , bbox_weights , pos_inds , neg_inds )