(threshold, truths, priors, variances, labels, landms, loc_t, conf_t, landm_t, idx)
Match each prior box with the ground truth box of the highest jaccard
    overlap, encode the bounding boxes, then return the matched indices
    corresponding to both confidence and location preds.
    Args:
        threshold: (float) The overlap threshold used when mathing boxes.
        truths: (tensor) Ground truth boxes, Shape: [num_obj, 4].
        priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4].
        variances: (tensor) Variances corresponding to each prior coord,
            Shape: [num_priors, 4].
        labels: (tensor) All the class labels for the image, Shape: [num_obj].
        landms: (tensor) Ground truth landms, Shape [num_obj, 10].
        loc_t: (tensor) Tensor to be filled w/ endcoded location targets.
        conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds.
        landm_t: (tensor) Tensor to be filled w/ endcoded landm targets.
        idx: (int) current batch index
    Return:
        The matched indices corresponding to 1)location 2)confidence 3)landm preds.
Match each prior box with the ground truth box of the highest jaccard
    overlap, encode the bounding boxes, then return the matched indices
    corresponding to both confidence and location preds.
    Args:
        threshold: (float) The overlap threshold used when mathing boxes.
        truths: (tensor) Ground truth boxes, Shape: [num_obj, 4].
        priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4].
        variances: (tensor) Variances corresponding to each prior coord,
            Shape: [num_priors, 4].
        labels: (tensor) All the class labels for the image, Shape: [num_obj].
        landms: (tensor) Ground truth landms, Shape [num_obj, 10].
        loc_t: (tensor) Tensor to be filled w/ endcoded location targets.
        conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds.
        landm_t: (tensor) Tensor to be filled w/ endcoded landm targets.
        idx: (int) current batch index
    Return:
        The matched indices corresponding to 1)location 2)confidence 3)landm preds.
Match each prior box with the ground truth box of the highest jaccard overlap encode the bounding boxes then return the matched indices corresponding to both confidence and location preds . Args : threshold : ( float ) The overlap threshold used when mathing boxes . truths : ( tensor ) Ground truth boxes Shape : [ num_obj 4 ] . priors : ( tensor ) Prior boxes from priorbox layers Shape : [ n_priors 4 ] . variances : ( tensor ) Variances corresponding to each prior coord Shape : [ num_priors 4 ] . labels : ( tensor ) All the class labels for the image Shape : [ num_obj ] . landms : ( tensor ) Ground truth landms Shape [ num_obj 10 ] . loc_t : ( tensor ) Tensor to be filled w / endcoded location targets . conf_t : ( tensor ) Tensor to be filled w / matched indices for conf preds . landm_t : ( tensor ) Tensor to be filled w / endcoded landm targets . idx : ( int ) current batch index Return : The matched indices corresponding to 1 ) location 2 ) confidence 3 ) landm preds .
def match(threshold, truths, priors, variances, labels, landms, loc_t, conf_t, landm_t, idx):
    """Match each prior box with the ground truth box of the highest jaccard
    overlap, encode the bounding boxes, then return the matched indices
    corresponding to both confidence and location preds.
    Args:
        threshold: (float) The overlap threshold used when mathing boxes.
        truths: (tensor) Ground truth boxes, Shape: [num_obj, 4].
        priors: (tensor) Prior boxes from priorbox layers, Shape: [n_priors,4].
        variances: (tensor) Variances corresponding to each prior coord,
            Shape: [num_priors, 4].
        labels: (tensor) All the class labels for the image, Shape: [num_obj].
        landms: (tensor) Ground truth landms, Shape [num_obj, 10].
        loc_t: (tensor) Tensor to be filled w/ endcoded location targets.
        conf_t: (tensor) Tensor to be filled w/ matched indices for conf preds.
        landm_t: (tensor) Tensor to be filled w/ endcoded landm targets.
        idx: (int) current batch index
    Return:
        The matched indices corresponding to 1)location 2)confidence 3)landm preds.
    """
    # jaccard index
    overlaps = jaccard(
        truths,
        point_form(priors)
    )
    # (Bipartite Matching)
    # [1,num_objects] best prior for each ground truth
    best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True)

    # ignore hard gt
    valid_gt_idx = best_prior_overlap[:, 0] >= 0.2
    best_prior_idx_filter = best_prior_idx[valid_gt_idx, :]
    if best_prior_idx_filter.shape[0] <= 0:
        loc_t[idx] = 0
        conf_t[idx] = 0
        return

    # [1,num_priors] best ground truth for each prior
    best_truth_overlap, best_truth_idx = overlaps.max(0, keepdim=True)
    best_truth_idx.squeeze_(0)
    best_truth_overlap.squeeze_(0)
    best_prior_idx.squeeze_(1)
    best_prior_idx_filter.squeeze_(1)
    best_prior_overlap.squeeze_(1)
    best_truth_overlap.index_fill_(0, best_prior_idx_filter, 2)  # ensure best prior
    # TODO refactor: index  best_prior_idx with long tensor
    # ensure every gt matches with its prior of max overlap
    for j in range(best_prior_idx.size(0)):     # 判别此anchor是预测哪一个boxes
        best_truth_idx[best_prior_idx[j]] = j
    matches = truths[best_truth_idx]            # Shape: [num_priors,4] 此处为每一个anchor对应的bbox取出来
    conf = labels[best_truth_idx]               # Shape: [num_priors]      此处为每一个anchor对应的label取出来
    conf[best_truth_overlap < threshold] = 0    # label as background   overlap<0.35的全部作为负样本
    loc = encode(matches, priors, variances)

    matches_landm = landms[best_truth_idx]
    landm = encode_landm(matches_landm, priors, variances)
    loc_t[idx] = loc    # [num_priors,4] encoded offsets to learn
    conf_t[idx] = conf  # [num_priors] top class label for each prior
    landm_t[idx] = landm
def match ( threshold , truths , priors , variances , labels , landms , loc_t , conf_t , landm_t , idx ) : # jaccard index overlaps = jaccard ( truths , point_form ( priors ) ) # (Bipartite Matching) # [1,num_objects] best prior for each ground truth best_prior_overlap , best_prior_idx = overlaps . max ( 1 , keepdim = True ) # ignore hard gt valid_gt_idx = best_prior_overlap [ : , 0 ] >= 0.2 best_prior_idx_filter = best_prior_idx [ valid_gt_idx , : ] if best_prior_idx_filter . shape [ 0 ] <= 0 : loc_t [ idx ] = 0 conf_t [ idx ] = 0 return # [1,num_priors] best ground truth for each prior best_truth_overlap , best_truth_idx = overlaps . max ( 0 , keepdim = True ) best_truth_idx . squeeze_ ( 0 ) best_truth_overlap . squeeze_ ( 0 ) best_prior_idx . squeeze_ ( 1 ) best_prior_idx_filter . squeeze_ ( 1 ) best_prior_overlap . squeeze_ ( 1 ) best_truth_overlap . index_fill_ ( 0 , best_prior_idx_filter , 2 ) # ensure best prior # TODO refactor: index  best_prior_idx with long tensor # ensure every gt matches with its prior of max overlap for j in range ( best_prior_idx . size ( 0 ) ) : # 判别此anchor是预测哪一个boxes best_truth_idx [ best_prior_idx [ j ] ] = j matches = truths [ best_truth_idx ] # Shape: [num_priors,4] 此处为每一个anchor对应的bbox取出来 conf = labels [ best_truth_idx ] # Shape: [num_priors]      此处为每一个anchor对应的label取出来 conf [ best_truth_overlap < threshold ] = 0 # label as background   overlap<0.35的全部作为负样本 loc = encode ( matches , priors , variances ) matches_landm = landms [ best_truth_idx ] landm = encode_landm ( matches_landm , priors , variances ) loc_t [ idx ] = loc # [num_priors,4] encoded offsets to learn conf_t [ idx ] = conf # [num_priors] top class label for each prior landm_t [ idx ] = landm