Loss Function
bi_tempered_logistic_loss(activations, labels, t1, t2, label_smooth=0.0, num_iters=5, reduction='mean')
Bi-Tempered Logistic Loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activations |
Tensor
|
torch.Tensor. A multidimensional tensor with last dimension |
required |
labels |
Tensor
|
torch.Tensor. A tensor with shape and dtype as activations (onehot), or a long tensor of one dimension less than activations (pytorch standard) |
required |
t1 |
float
|
float. Temperature 1 (< 1.0 for boundedness). |
required |
t2 |
float
|
float. Temperature 2 (> 1.0 for tail heaviness, < 1.0 for finite support). |
required |
label_smooth |
float
|
float. Label smoothing parameter between [0, 1). |
0.0
|
num_iters |
int
|
int. Number of iterations to run the method. |
5
|
reduction |
str
|
str. type of reduction. |
'mean'
|
Source code in pytorch_optimizer/loss/bi_tempered.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
BiTemperedLogisticLoss
Bases: Module
Bi-Tempered Log Loss.
Reference : https://github.com/BloodAxe/pytorch-toolbelt/blob/develop/pytorch_toolbelt/losses/bitempered_loss.py
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t1 |
float
|
float. Temperature 1 (< 1.0 for boundedness). |
required |
t2 |
float
|
float. Temperature 2 (> 1.0 for tail heaviness, < 1.0 for finite support). |
required |
label_smooth |
float
|
float. Label smoothing parameter between [0, 1). |
0.0
|
ignore_index |
Optional[int]
|
Optional[int]. Index to ignore. |
None
|
reduction |
str
|
str. type of reduction. |
'mean'
|
Source code in pytorch_optimizer/loss/bi_tempered.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
BinaryBiTemperedLogisticLoss
Bases: Module
Modification of BiTemperedLogisticLoss for binary classification case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t1 |
float
|
float. Temperature 1 (< 1.0 for boundedness). |
required |
t2 |
float
|
float. Temperature 2 (> 1.0 for tail heaviness, < 1.0 for finite support). |
required |
label_smooth |
float
|
float. Label smoothing parameter between [0, 1). |
0.0
|
ignore_index |
Optional[int]
|
Optional[int]. Index to ignore. |
None
|
reduction |
str
|
str. type of reduction. |
'mean'
|
Source code in pytorch_optimizer/loss/bi_tempered.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
BCELoss
Bases: Module
binary cross entropy with label smoothing + probability input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_smooth |
float
|
float. Smoothness constant for dice coefficient (a). |
0.0
|
eps |
float
|
float. epsilon. |
1e-06
|
reduction |
str
|
str. type of reduction. |
'mean'
|
Source code in pytorch_optimizer/loss/cross_entropy.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
SoftF1Loss
Bases: Module
Soft-F1 loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
beta |
float
|
float. f-beta. |
1.0
|
eps |
float
|
float. epsilon. |
1e-06
|
Source code in pytorch_optimizer/loss/f1.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
FocalLoss
Bases: Module
Focal loss function w/ logit input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
float
|
float. alpha. |
1.0
|
gamma |
float
|
float. gamma. |
2.0
|
Source code in pytorch_optimizer/loss/focal.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
FocalCosineLoss
Bases: Module
Focal Cosine loss function w/ logit input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
float
|
float. alpha. |
1.0
|
gamma |
float
|
float. gamma. |
2.0
|
focal_weight |
float
|
float. weight of focal loss. |
0.1
|
reduction |
str
|
str. type of reduction. |
'mean'
|
Source code in pytorch_optimizer/loss/focal.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
BCEFocalLoss
Bases: Module
BCEFocal loss function w/ probability input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
float
|
float. alpha. |
0.25
|
gamma |
float
|
float. gamma. |
2.0
|
label_smooth |
float
|
float. Smoothness constant for dice coefficient (a). |
0.0
|
eps |
float
|
float. epsilon. |
1e-06
|
reduction |
str
|
str. type of reduction. |
'mean'
|
Source code in pytorch_optimizer/loss/focal.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
FocalTverskyLoss
Bases: Module
Focal Tversky Loss w/ logits input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
float
|
float. alpha. |
0.5
|
beta |
float
|
float. beta. |
0.5
|
gamma |
float
|
float. gamma. |
1.0
|
smooth |
float
|
float. smooth factor. |
1e-06
|
Source code in pytorch_optimizer/loss/focal.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
soft_jaccard_score(output, target, label_smooth=0.0, eps=1e-06, dims=None)
Get soft jaccard score.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output |
Tensor
|
torch.Tensor. predicted segments. |
required |
target |
Tensor
|
torch.Tensor. ground truth segments. |
required |
label_smooth |
float
|
float. label smoothing factor. |
0.0
|
eps |
float
|
float. epsilon. |
1e-06
|
dims |
Optional[Tuple[int, ...]]
|
Optional[Tuple[int, ...]]. target dimensions to reduce. |
None
|
Source code in pytorch_optimizer/loss/jaccard.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
JaccardLoss
Bases: _Loss
Jaccard loss for image segmentation task. It supports binary, multiclass and multilabel cases.
Reference : https://github.com/BloodAxe/pytorch-toolbelt
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
CLASS_MODE
|
CLASS_MODE. loss mode 'binary', 'multiclass', or 'multilabel. |
required |
classes |
List[int]
|
Optional[List[int]]. List of classes that contribute in loss computation. By default, all channels are included. |
None
|
log_loss |
bool
|
If True, loss computed as |
False
|
from_logits |
bool
|
bool. If True, assumes input is raw logits. |
True
|
label_smooth |
float
|
float. Smoothness constant for dice coefficient (a). |
0.0
|
eps |
float
|
float. epsilon. |
1e-06
|
Source code in pytorch_optimizer/loss/jaccard.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
LDAMLoss
Bases: Module
LDAM Loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_class_list |
List[int]
|
List[int]. list of number of class. |
required |
max_m |
float
|
float. max margin ( |
0.5
|
weight |
Optional[Tensor]
|
Optional[torch.Tensor]. class weight. |
None
|
s |
float
|
float. scaler. |
30.0
|
Source code in pytorch_optimizer/loss/ldam.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
LovaszHingeLoss
Bases: Module
Binary Lovasz hinge loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
per_image |
bool
|
bool. compute the loss per image instead of per batch. |
True
|
Source code in pytorch_optimizer/loss/lovasz.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
TverskyLoss
Bases: Module
Tversky Loss w/ logits input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
float
|
float. alpha. |
0.5
|
beta |
float
|
float. beta. |
0.5
|
smooth |
float
|
float. smooth factor. |
1e-06
|
Source code in pytorch_optimizer/loss/tversky.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|