holocron.ops¶
holocron.ops
implements operators that are specific for Computer Vision.
Note
Those operators currently do not support TorchScript.
Boxes¶
- holocron.ops.box_giou(boxes1: Tensor, boxes2: Tensor) Tensor [source]¶
Computes the Generalized-IoU as described in “Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression”. This implementation was adapted from https://github.com/facebookresearch/detr/blob/master/util/box_ops.py
The generalized IoU is defined as follows:
where
is the Intersection over Union, is the area of the boxes’ union, and is the area of the smallest enclosing box covering the two boxes.- Parameters:
boxes1 (torch.Tensor[M, 4]) – bounding boxes
boxes2 (torch.Tensor[N, 4]) – bounding boxes
- Returns:
Generalized-IoU
- Return type:
torch.Tensor[M, N]
- holocron.ops.diou_loss(boxes1: Tensor, boxes2: Tensor) Tensor [source]¶
Computes the Distance-IoU loss as described in “Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression”.
The loss is defined as follows:
where
is the Intersection over Union, and are the centers of the box and the ground truth box respectively, c is the diagonal length of the smallest enclosing box covering the two boxes, and is the Euclidean distance.- Parameters:
boxes1 (torch.Tensor[M, 4]) – bounding boxes
boxes2 (torch.Tensor[N, 4]) – bounding boxes
- Returns:
Distance-IoU loss
- Return type:
torch.Tensor[M, N]
- holocron.ops.ciou_loss(boxes1: Tensor, boxes2: Tensor) Tensor [source]¶
Computes the Complete IoU loss as described in “Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression”.
The loss is defined as follows:
where
is the Intersection over Union, and are the centers of the box and the ground truth box respectively, c is the diagonal length of the smallest enclosing box covering the two boxes, is the Euclidean distance, is a positive trade-off parameter, and is the aspect ratio consistency.More specifically:
and
- Parameters:
boxes1 (torch.Tensor[M, 4]) – bounding boxes
boxes2 (torch.Tensor[N, 4]) – bounding boxes
- Returns:
Complete IoU loss
- Return type:
torch.Tensor[M, N]
Example
>>> import torch >>> from holocron.ops.boxes import box_ciou >>> boxes1 = torch.tensor([[0, 0, 100, 100], [100, 100, 200, 200]], dtype=torch.float32) >>> boxes2 = torch.tensor([[50, 50, 150, 150]], dtype=torch.float32) >>> box_ciou(boxes1, boxes2)