Modules
- class uotod.loss.SigmoidFocalLoss(reduction: str = 'mean', alpha: float = -1.0, gamma: float = 2.0)
Creates a criterion that computes the Sigmoid Focal Loss.
\[loss(x, y) = \sum_{i=1}^{N_c} \left( y_i \alpha (1 - p_i)^{\gamma} (-log(p_i)) + (1 - y_i) (1 - \alpha) p_i^{\gamma} (-log(1 - p_i)) \right)\]where \(p_i = \sigma(x_i)\) is the probability of class i, \(y \in \{0,1\}^{N_c}\) is the target label in one-hot encoding, \(N_c\) is the number of classes, \(\gamma\) is the focusing parameter and \(\alpha\) is the weighting factor.
It was introduced in the paper Focal Loss for Dense Object Detection.
- Parameters:
reduction (str, optional) – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’.
alpha (float, optional) – Weighting factor alpha (default: -1.)
gamma (float, optional) – Focusing parameter gamma (default: 2.)
- forward(input, targets)
- Parameters:
input (Tensor (float)) – Predictions (num_pred, num_classes)
targets (Tensor (float)) – Targets in one-hot encoding (num_pred, num_classes)
- Returns:
loss
- Return type:
Tensor (float)
- reduction: str
- class uotod.loss.SigmoidFocalCost(reduction: str = 'mean', alpha: float = -1.0, gamma: float = 2.0)
Creates a criterion that computes the Sigmoid Focal Cost.
It is a variant of the Sigmoid Focal Loss, where both a negative and a positive cost term are used. Unlike the original focal loss, the loss is computed only for the target class.
\[cost(x, y) = \alpha (1 - p_y)^{\gamma} (-log(p_y)) - (1 - \alpha) p_y^{\gamma} (-log(1 - p_y))\]where \(p_y = \sigma(x_y)\) is the probability of the target class y, \(\gamma\) is the focusing parameter, and \(\alpha\) is the weighting factor.
It was introduced in the paper [ZSL+21].
- Parameters:
reduction (str, optional) – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’.
alpha (float, optional) – Weighting factor alpha (default: -1.)
gamma (float, optional) – Focusing parameter gamma (default: 2.)
- forward(input, targets)
- Parameters:
input (Tensor (float)) – Predictions (num_pred, num_classes)
targets (Tensor (int) or Tensor (float)) – Targets labels (num_pred,) or one-hot encoding (num_pred, num_classes)
- Returns:
loss
- Return type:
Tensor (float)
- reduction: str
- class uotod.loss.NegativeProbLoss(reduction: str = 'mean')
Creates a criterion that computes the negative probability of the target class.
\[\text{loss}(x, y) = -softmax(x)[y]\]- Parameters:
reduction (str, optional) – reduction method
- forward(input: Tensor, target: Tensor) Tensor
- Parameters:
input (Tensor (float)) – Predicted scores (num_pred, num_classes)
target (Tensor (long)) – Ground-truth label (num_pred, )
- Returns:
loss
- Return type:
Tensor (float)
- reduction: str
- class uotod.loss.IoULoss(reduction: str = 'mean')
Creates a criterion that measures the IoU loss between each predicted box and target box.
\[\text{loss} = 1 - \text{IoU}\]- Parameters:
reduction (str, optional) – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’.
- forward(input: Tensor, target: Tensor) Tensor
- Parameters:
input (Tensor (float)) – predicted boxes (num_pred, 4)
target (Tensor (float)) – ground truth boxes (num_pred, 4)
- Returns:
loss
- Return type:
Tensor (float)
- reduction: str
- class uotod.loss.GIoULoss(reduction: str = 'mean')
Creates a criterion that measures the generalized IoU loss between each predicted box and target box.
\[\text{loss} = 1 - \text{GIoU}\]- Parameters:
reduction (str, optional) – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’.
- forward(input: Tensor, target: Tensor) Tensor
- Parameters:
input (Tensor (float)) – predicted boxes (num_pred, 4)
target (Tensor (float)) – ground truth boxes (num_pred, 4)
- Returns:
loss
- Return type:
Tensor (float)
- reduction: str