holocron.ops¶
holocron.ops implements operators that are specific for Computer Vision.
!!! note Those operators currently do not support TorchScript.
Boxes¶
box_giou
¶
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 \(\IoU\) is the Intersection over Union, \(A \cup B\) is the area of the boxes' union, and \(C\) is the area of the smallest enclosing box covering the two boxes.
| PARAMETER | DESCRIPTION |
|---|---|
boxes1
|
bounding boxes of shape [M, 4]
TYPE:
|
boxes2
|
bounding boxes of shape [N, 4]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Generalized-IoU of shape [M, N] |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
if the boxes are in incorrect coordinate format |
Source code in holocron/ops/boxes.py
diou_loss
¶
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 \(\IoU\) is the Intersection over Union, \(b\) and \(b^{GT}\) are the centers of the box and the ground truth box respectively, \(c\) c is the diagonal length of the smallest enclosing box covering the two boxes, and \(\rho(.)\) is the Euclidean distance.

| PARAMETER | DESCRIPTION |
|---|---|
boxes1
|
bounding boxes of shape [M, 4]
TYPE:
|
boxes2
|
bounding boxes of shape [N, 4]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Distance-IoU loss of shape [M, N] |
Source code in holocron/ops/boxes.py
ciou_loss
¶
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 \(\IoU\) is the Intersection over Union, \(b\) and \(b^{GT}\) are the centers of the box and the ground truth box respectively, \(c\) c is the diagonal length of the smallest enclosing box covering the two boxes, \(\rho(.)\) is the Euclidean distance, \(\alpha\) is a positive trade-off parameter, and \(v\) is the aspect ratio consistency.
More specifically:
and
| PARAMETER | DESCRIPTION |
|---|---|
boxes1
|
bounding boxes of shape [M, 4]
TYPE:
|
boxes2
|
bounding boxes of shape [N, 4]
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Complete IoU loss of shape [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)