cvnets.misc.third_party package
Submodules
cvnets.misc.third_party.ssd_utils module
- cvnets.misc.third_party.ssd_utils.assign_priors(gt_boxes: Tensor, gt_labels: Tensor, corner_form_priors: Tensor, iou_threshold: float, background_id: int | None = 0, *args, **kwargs) Tuple[Tensor, Tensor] [source]
Assign ground truth boxes and targets to priors (or anchors)
- Parameters:
gt_boxes (Tensor) – Ground-truth boxes tensor of shape (num_targets, 4)
gt_labels (Tensor) – Ground-truth labels of shape (num_targets)
corner_form_priors (Tensor) – Priors in corner form and has shape (num_priors, 4)
iou_threshold (float) – Overlap between priors and gt_boxes.
background_id (int) – Background class index. Default: 0
- Returns:
Boxes mapped to priors and has shape (num_priors, 4) labels (Tensor): Labels for mapped boxes and has shape (num_priors)
- Return type:
boxes (Tensor)
- cvnets.misc.third_party.ssd_utils.box_iou(boxes0: Tensor, boxes1: Tensor, eps: float | None = 1e-05, *args, **kwargs) Tensor [source]
Computes intersection-over-union between two boxes :param boxes0: Boxes 0 of shape (N, 4) :type boxes0: Tensor :param boxes1: Boxes 1 of shape (N or 1, 4) :type boxes1: Tensor :param eps: A small value is added to denominator for numerical stability :type eps: Optional[float]
- Returns:
IoU values between boxes0 and boxes1 and has shape (N)
- Return type:
iou (Tensor)
- cvnets.misc.third_party.ssd_utils.hard_negative_mining(loss: Tensor, labels: Tensor, neg_pos_ratio: int, *args, **kwargs) Tensor [source]
This function is used to suppress the presence of a large number of negative predictions. For any example/image, it keeps all the positive predictions and cut the number of negative predictions to make sure the ratio between the negative examples and positive examples is no more than the given ratio for an image. :param loss: the loss for each example and has shape (N, num_priors). :type loss: Tensor :param labels: the labels and has shape (N, num_priors). :type labels: Tensor :param neg_pos_ratio: the ratio between the negative examples and positive examples. Usually, it is set as 3. :type neg_pos_ratio: int