otx.algo.segmentation.losses#
Custom Losses for OTX segmentation model.
Classes
|
CrossEntropyLossWithIgnore with Ignore Mode Support for Class Incremental Learning. |
- class otx.algo.segmentation.losses.CrossEntropyLossWithIgnore(weight: Tensor | None = None, size_average: str | None = None, ignore_index: int = -100, reduce: bool | None = None, reduction: str = 'mean', label_smoothing: float = 0.0)[source]#
Bases:
CrossEntropyLoss
CrossEntropyLossWithIgnore with Ignore Mode Support for Class Incremental Learning.
When new classes are added through continual training cycles, images from previous cycles may become partially annotated if they are not revisited. To prevent the model from predicting these new classes for such images, CrossEntropyLossWithIgnore can be used to ignore the unseen classes.
Initialize the CrossEntropyLossWithIgnore.
- Parameters:
weight (Tensor, optional) – Sample-wise loss weight. Defaults to None.
size_average (Optional[str], optional) – Deprecated (see reduction). Defaults to None.
ignore_index (int, optional) – Specifies a target value that is ignored and does not contribute to the input gradients. Defaults to -100.
reduce (Optional[bool], optional) – Deprecated (see reduction). Defaults to None.
reduction (str, optional) – Specifies the reduction to apply to the output. Defaults to ‘mean’.
label_smoothing (float, optional) – The amount of label smoothing to apply. Defaults to 0.0.
- forward(cls_score: Tensor, label: Tensor, img_metas: dict | None = None, weight: Tensor | None = None, avg_factor: int | None = None, reduction_override: str = 'mean', valid_label_mask: Tensor | None = None, **kwargs) Tensor [source]#
Forward.
- Parameters:
cls_score (torch.Tensor, optional) – The prediction with shape (N, 1).
label (torch.Tensor, optional) – The learning label of the prediction.
weight (torch.Tensor, optional) – Sample-wise loss weight. Default: None.
class_weight (list[float], optional) – The weight for each class. Default: None.
avg_factor (int, optional) – Average factor that is used to average the loss. Default: None.
reduction_override (str, optional) – The method used to reduce the loss. Options are ‘none’, ‘mean’ and ‘sum’. Default: ‘mean’.
valid_label_mask (torch.Tensor, optional) – The valid labels with shape (N, num_classes). If the value in the valid_label_mask is 0, mask label of the the mask label of the class corresponding to its index will be ignored like ignore_index.
**kwargs (Any) – Additional keyword arguments.
- property loss_name: str#
Loss Name.
This function must be implemented and will return the name of this loss function. This name will be used to combine different loss items by simple sum operation. In addition, if you want this loss item to be included into the backward graph, loss_ must be the prefix of the name.
- Returns:
The name of this loss item.
- Return type: