vision/utils/box_utils.py
def assign_priors(gt_boxes, gt_labels, corner_form_priors,
                  iou_threshold):
    """Assign ground truth boxes and targets to priors.

    Args:
        gt_boxes (num_targets, 4): ground truth boxes.
        gt_labels (num_targets): labels of targets.
        priors (num_priors, 4): corner form priors
    Returns:
        boxes (num_priors, 4): real values for priors.
        labels (num_priros): labels for priors.
    """
    # size: num_priors x num_targets

    if gt_boxes.shape[0] == 0:
        boxes = torch.zeros_like(corner_form_priors)
        labels = torch.zeros( corner_form_priors.shape[0], dtype=gt_labels.dtype )
        return boxes, labels

    ious = iou_of(gt_boxes.unsqueeze(0), corner_form_priors.unsqueeze(1))
    # size: num_priors
    best_target_per_prior, best_target_per_prior_index = ious.max(1)
    # size: num_targets
    best_prior_per_target, best_prior_per_target_index = ious.max(0)

    for target_index, prior_index in enumerate(best_prior_per_target_index):
        best_target_per_prior_index[prior_index] = target_index
    # 2.0 is used to make sure every target has a prior assigned
    best_target_per_prior.index_fill_(0, best_prior_per_target_index, 2)
    # size: num_priors
    labels = gt_labels[best_target_per_prior_index]
    labels[best_target_per_prior < iou_threshold] = 0  # the backgournd id
    boxes = gt_boxes[best_target_per_prior_index]
    return boxes, labels
Assign ground truth boxes and targets to priors.

    Args:
        gt_boxes (num_targets, 4): ground truth boxes.
        gt_labels (num_targets): labels of targets.
        priors (num_priors, 4): corner form priors
    Returns:
        boxes (num_priors, 4): real values for priors.
        labels (num_priros): labels for priors.
    
Assign ground truth boxes and targets to priors.
Assign ground truth boxes and targets to priors .
def assign_priors(gt_boxes, gt_labels, corner_form_priors,
                  iou_threshold):
    if gt_boxes.shape[0] == 0:
        boxes = torch.zeros_like(corner_form_priors)
        labels = torch.zeros( corner_form_priors.shape[0], dtype=gt_labels.dtype )
        return boxes, labels
    ious = iou_of(gt_boxes.unsqueeze(0), corner_form_priors.unsqueeze(1))
    best_target_per_prior, best_target_per_prior_index = ious.max(1)
    best_prior_per_target, best_prior_per_target_index = ious.max(0)
    for target_index, prior_index in enumerate(best_prior_per_target_index):
        best_target_per_prior_index[prior_index] = target_index
    best_target_per_prior.index_fill_(0, best_prior_per_target_index, 2)
    labels = gt_labels[best_target_per_prior_index]
    labels[best_target_per_prior < iou_threshold] = 0  
    boxes = gt_boxes[best_target_per_prior_index]
    return boxes, labels
def assign_priors ( gt_boxes , gt_labels , corner_form_priors , iou_threshold ) : if gt_boxes . shape [ 0 ] == 0 : boxes = torch . zeros_like ( corner_form_priors ) labels = torch . zeros ( corner_form_priors . shape [ 0 ] , dtype = gt_labels . dtype ) return boxes , labels ious = iou_of ( gt_boxes . unsqueeze ( 0 ) , corner_form_priors . unsqueeze ( 1 ) ) best_target_per_prior , best_target_per_prior_index = ious . max ( 1 ) best_prior_per_target , best_prior_per_target_index = ious . max ( 0 ) for target_index , prior_index in enumerate ( best_prior_per_target_index ) : best_target_per_prior_index [ prior_index ] = target_index best_target_per_prior . index_fill_ ( 0 , best_prior_per_target_index , 2 ) labels = gt_labels [ best_target_per_prior_index ] labels [ best_target_per_prior < iou_threshold ] = 0 boxes = gt_boxes [ best_target_per_prior_index ] return boxes , labels
Assign ground truth boxes and targets to priors.
Assign ground truth boxes and targets to priors .
"""Assign ground truth boxes and targets to priors.

    Args:
        gt_boxes (num_targets, 4): ground truth boxes.
        gt_labels (num_targets): labels of targets.
        priors (num_priors, 4): corner form priors
    Returns:
        boxes (num_priors, 4): real values for priors.
        labels (num_priros): labels for priors.
    """ # size: num_priors x num_targets # size: num_priors # size: num_targets # 2.0 is used to make sure every target has a prior assigned # size: num_priors # the backgournd id
boxes (num_priors, 4): real values for priors.
labels (num_priros): labels for priors.
boxes ( num_priors 4 ) : real values for priors . labels ( num_priros ) : labels for priors .
gt_boxes
ground truth boxes.
ground truth boxes .
gt_labels
labels of targets.
labels of targets .
corner_form_priors
iou_threshold
priors
corner form priors
corner form priors