(anchor_list,
                  valid_flag_list,
                  gt_bboxes_list,
                  img_metas,
                  target_means,
                  target_stds,
                  cfg,
                  gt_bboxes_ignore_list=None,
                  gt_labels_list=None,
                  label_channels=1,
                  sampling=True,
                  unmap_outputs=True)
return (labels_list, label_weights_list, bbox_targets_list,
            bbox_weights_list, num_total_pos, num_total_neg)
Compute regression and classification targets for anchors.

    Args:
        anchor_list (list[list]): Multi level anchors of each image.
        valid_flag_list (list[list]): Multi level valid flags of each image.
        gt_bboxes_list (list[Tensor]): Ground truth bboxes of each image.
        img_metas (list[dict]): Meta info of each image.
        target_means (Iterable): Mean value of regression targets.
        target_stds (Iterable): Std value of regression targets.
        cfg (dict): RPN train configs.

    Returns:
        tuple
Compute regression and classification targets for anchors.
Compute regression and classification targets for anchors .
def anchor_target(anchor_list,
                  valid_flag_list,
                  gt_bboxes_list,
                  img_metas,
                  target_means,
                  target_stds,
                  cfg,
                  gt_bboxes_ignore_list=None,
                  gt_labels_list=None,
                  label_channels=1,
                  sampling=True,
                  unmap_outputs=True):
    """Compute regression and classification targets for anchors.

    Args:
        anchor_list (list[list]): Multi level anchors of each image.
        valid_flag_list (list[list]): Multi level valid flags of each image.
        gt_bboxes_list (list[Tensor]): Ground truth bboxes of each image.
        img_metas (list[dict]): Meta info of each image.
        target_means (Iterable): Mean value of regression targets.
        target_stds (Iterable): Std value of regression targets.
        cfg (dict): RPN train configs.

    Returns:
        tuple
    """
    num_imgs = len(img_metas)
    assert len(anchor_list) == len(valid_flag_list) == num_imgs

    # anchor number of multi levels
    num_level_anchors = [anchors.size(0) for anchors in anchor_list[0]]
    # concat all level anchors and flags to a single tensor
    for i in range(num_imgs):
        assert len(anchor_list[i]) == len(valid_flag_list[i])
        anchor_list[i] = torch.cat(anchor_list[i])
        valid_flag_list[i] = torch.cat(valid_flag_list[i])

    # compute targets for each image
    if gt_bboxes_ignore_list is None:
        gt_bboxes_ignore_list = [None for _ in range(num_imgs)]
    if gt_labels_list is None:
        gt_labels_list = [None for _ in range(num_imgs)]
    (all_labels, all_label_weights, all_bbox_targets, all_bbox_weights,
     pos_inds_list, neg_inds_list) = multi_apply(
         anchor_target_single,
         anchor_list,
         valid_flag_list,
         gt_bboxes_list,
         gt_bboxes_ignore_list,
         gt_labels_list,
         img_metas,
         target_means=target_means,
         target_stds=target_stds,
         cfg=cfg,
         label_channels=label_channels,
         sampling=sampling,
         unmap_outputs=unmap_outputs)
    # no valid anchors
    if any([labels is None for labels in all_labels]):
        return None
    # sampled anchors of all images
    num_total_pos = sum([max(inds.numel(), 1) for inds in pos_inds_list])
    num_total_neg = sum([max(inds.numel(), 1) for inds in neg_inds_list])
    # split targets to a list w.r.t. multiple levels
    labels_list = images_to_levels(all_labels, num_level_anchors)
    label_weights_list = images_to_levels(all_label_weights, num_level_anchors)
    bbox_targets_list = images_to_levels(all_bbox_targets, num_level_anchors)
    bbox_weights_list = images_to_levels(all_bbox_weights, num_level_anchors)
    return (labels_list, label_weights_list, bbox_targets_list,
            bbox_weights_list, num_total_pos, num_total_neg)
def anchor_target ( anchor_list , valid_flag_list , gt_bboxes_list , img_metas , target_means , target_stds , cfg , gt_bboxes_ignore_list = None , gt_labels_list = None , label_channels = 1 , sampling = True , unmap_outputs = True ) : num_imgs = len ( img_metas ) assert len ( anchor_list ) == len ( valid_flag_list ) == num_imgs # anchor number of multi levels num_level_anchors = [ anchors . size ( 0 ) for anchors in anchor_list [ 0 ] ] # concat all level anchors and flags to a single tensor for i in range ( num_imgs ) : assert len ( anchor_list [ i ] ) == len ( valid_flag_list [ i ] ) anchor_list [ i ] = torch . cat ( anchor_list [ i ] ) valid_flag_list [ i ] = torch . cat ( valid_flag_list [ i ] ) # compute targets for each image if gt_bboxes_ignore_list is None : gt_bboxes_ignore_list = [ None for _ in range ( num_imgs ) ] if gt_labels_list is None : gt_labels_list = [ None for _ in range ( num_imgs ) ] ( all_labels , all_label_weights , all_bbox_targets , all_bbox_weights , pos_inds_list , neg_inds_list ) = multi_apply ( anchor_target_single , anchor_list , valid_flag_list , gt_bboxes_list , gt_bboxes_ignore_list , gt_labels_list , img_metas , target_means = target_means , target_stds = target_stds , cfg = cfg , label_channels = label_channels , sampling = sampling , unmap_outputs = unmap_outputs ) # no valid anchors if any ( [ labels is None for labels in all_labels ] ) : return None # sampled anchors of all images num_total_pos = sum ( [ max ( inds . numel ( ) , 1 ) for inds in pos_inds_list ] ) num_total_neg = sum ( [ max ( inds . numel ( ) , 1 ) for inds in neg_inds_list ] ) # split targets to a list w.r.t. multiple levels labels_list = images_to_levels ( all_labels , num_level_anchors ) label_weights_list = images_to_levels ( all_label_weights , num_level_anchors ) bbox_targets_list = images_to_levels ( all_bbox_targets , num_level_anchors ) bbox_weights_list = images_to_levels ( all_bbox_weights , num_level_anchors ) return ( labels_list , label_weights_list , bbox_targets_list , bbox_weights_list , num_total_pos , num_total_neg )