Computer Vision
tensoris.backend.losses.cv ¶
Computer Vision Loss Functions.
Classes¶
DiceLoss ¶
Bases: Module
Dice Loss for semantic image segmentation tasks.
Formula
where \(p_i\) is the predicted probability and \(y_i\) is the ground-truth mask label.
References
Milletari, F., Navab, N., & Ahmadi, S. A. (2016). V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation. Fourth International Conference on 3D Vision (3DV 2016), pp. 565-571. DOI: https://doi.org/10.1109/3DV.2016.79 | arXiv: https://arxiv.org/abs/1606.04797
Source code in src/tensoris/backend/losses/cv.py
Methods:¶
__init__ ¶
Initialize Dice Loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smooth
|
float
|
Smoothing epsilon factor to prevent division by zero. |
1.0
|
forward ¶
Compute Dice Loss score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Predicted logits tensor of shape (N, C, H, W) or (N, H, W). |
required |
targets
|
Tensor
|
Ground truth target binary mask tensor of matching shape. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scalar Dice loss value (1.0 - Dice coefficient). |
Source code in src/tensoris/backend/losses/cv.py
FocalLoss ¶
Bases: Module
Focal Loss for addressing class imbalance in computer vision tasks.
Formula
where \(p_t\) is the model's estimated probability for the ground-truth class, \(\alpha_t\) is the class balancing factor, and \(\gamma\) is the focusing factor.
References
Lin, T. Y., Goyal, P., Girshick, R., He, K., & Dollár, P. (2017). Focal Loss for Dense Object Detection. Proceedings of the IEEE International Conference on Computer Vision (ICCV 2017), pp. 2980-2988. DOI: https://doi.org/10.1109/ICCV.2017.324 | arXiv: https://arxiv.org/abs/1708.02002
Source code in src/tensoris/backend/losses/cv.py
Methods:¶
__init__ ¶
Initialize Focal Loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Weighting factor for class balancing. |
0.25
|
gamma
|
float
|
Focusing parameter for modulating easy example down-weighting. |
2.0
|
reduction
|
str
|
Reduction mode ('mean', 'sum', or 'none'). |
'mean'
|
Source code in src/tensoris/backend/losses/cv.py
forward ¶
Compute Focal Loss over logits and targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Predicted class logits tensor of shape (N, C) or (N, C, H, W). |
required |
targets
|
Tensor
|
Ground truth class index tensor of shape (N) or (N, H, W). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Computed Focal loss tensor. |