deel.lip.losses
This module contains losses used in Wasserstein distance estimation. See this paper for more information.
CategoricalHinge ¶
CategoricalHinge(
min_margin,
reduction=Reduction.AUTO,
name="CategoricalHinge",
)
Bases: Loss
Similar to original categorical hinge, but with a settable margin parameter. This implementation is sligthly different from the Keras one.
y_true
and y_pred
must be of shape (batch_size, # classes).
Note that y_true
should be one-hot encoded or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
min_margin |
margin parameter.
TYPE:
|
reduction |
reduction of the loss, passed to original loss.
DEFAULT:
|
name |
name of the loss
TYPE:
|
Source code in deel/lip/losses.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
HKR ¶
HKR(
alpha,
min_margin=1.0,
multi_gpu=False,
reduction=Reduction.AUTO,
name="HKR",
)
Bases: Loss
Wasserstein loss with a regularization parameter based on the hinge margin loss.
Note that y_true
and y_pred
must be of rank 2: (batch_size, 1) or
(batch_size, C) for multilabel classification (with C categories).
y_true
accepts label values in (0, 1), (-1, 1), or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
Using a multi-GPU/TPU strategy requires to set multi_gpu
to True and to
pre-process the labels y_true
with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
alpha |
regularization factor
TYPE:
|
min_margin |
minimal margin ( see hinge_margin_loss ) Kantorovich-Rubinstein term of the loss. In order to be consistent between hinge and KR, the first label must yield the positive class while the second yields negative class.
TYPE:
|
multi_gpu |
set to True when running on multi-GPU/TPU
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
114 115 116 117 118 119 120 121 122 123 124 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 |
|
HingeMargin ¶
HingeMargin(
min_margin=1.0,
reduction=Reduction.AUTO,
name="HingeMargin",
)
Bases: Loss
Compute the hinge margin loss.
Note that y_true
and y_pred
must be of rank 2: (batch_size, 1) or
(batch_size, C) for multilabel classification (with C categories).
y_true
accepts label values in (0, 1), (-1, 1), or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
min_margin |
margin to enforce.
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
KR ¶
KR(multi_gpu=False, reduction=Reduction.AUTO, name='KR')
Bases: Loss
Loss to estimate Wasserstein-1 distance using Kantorovich-Rubinstein duality. The Kantorovich-Rubinstein duality is formulated as following:
Where mu and nu stands for the two distributions, the distribution where the label is 1 and the rest.
Note that y_true
and y_pred
must be of rank 2: (batch_size, 1) or
(batch_size, C) for multilabel classification (with C categories).
y_true
accepts label values in (0, 1), (-1, 1), or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
Using a multi-GPU/TPU strategy requires to set multi_gpu
to True and to
pre-process the labels y_true
with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
multi_gpu |
set to True when running on multi-GPU/TPU
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
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 |
|
MultiMargin ¶
MultiMargin(
min_margin=1.0,
reduction=Reduction.AUTO,
name="MultiMargin",
)
Bases: Loss
Compute the hinge margin loss for multiclass (equivalent to Pytorch multi_margin_loss)
Note that y_true
should be one-hot encoded or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
min_margin |
margin to enforce.
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
MulticlassHKR ¶
MulticlassHKR(
alpha=10.0,
min_margin=1.0,
multi_gpu=False,
reduction=Reduction.AUTO,
name="MulticlassHKR",
)
Bases: Loss
The multiclass version of HKR. This is done by computing the HKR term over each class and averaging the results.
Note that y_true
should be one-hot encoded or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
Using a multi-GPU/TPU strategy requires to set multi_gpu
to True and to
pre-process the labels y_true
with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
alpha |
regularization factor
TYPE:
|
min_margin |
margin to enforce.
TYPE:
|
multi_gpu |
set to True when running on multi-GPU/TPU
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|
MulticlassHinge ¶
MulticlassHinge(
min_margin=1.0,
reduction=Reduction.AUTO,
name="MulticlassHinge",
)
Bases: Loss
Loss to estimate the Hinge loss in a multiclass setup. It computes the element-wise Hinge term. Note that this formulation differs from the one commonly found in tensorflow/pytorch (which maximises the difference between the two largest logits). This formulation is consistent with the binary classification loss used in a multiclass fashion.
Note that y_true
should be one-hot encoded or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
min_margin |
margin to enforce.
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
MulticlassKR ¶
MulticlassKR(
multi_gpu=False,
reduction=Reduction.AUTO,
name="MulticlassKR",
)
Bases: Loss
Loss to estimate average of Wasserstein-1 distance using Kantorovich-Rubinstein duality over outputs. In this multiclass setup, the KR term is computed for each class and then averaged.
Note that y_true
should be one-hot encoded or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
Using a multi-GPU/TPU strategy requires to set multi_gpu
to True and to
pre-process the labels y_true
with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
multi_gpu |
set to True when running on multi-GPU/TPU
TYPE:
|
reduction |
passed to tf.keras.Loss constructor
DEFAULT:
|
name |
passed to tf.keras.Loss constructor
TYPE:
|
Source code in deel/lip/losses.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
TauBinaryCrossentropy ¶
TauBinaryCrossentropy(
tau,
reduction=Reduction.AUTO,
name="TauBinaryCrossentropy",
)
Bases: Loss
Similar to the original binary crossentropy, but with a settable temperature parameter. y_pred must be a logits tensor (before sigmoid) and not probabilities.
Note that y_true
and y_pred
must be of rank 2: (batch_size, 1). y_true
accepts label values in (0, 1) or (-1, 1).
PARAMETER | DESCRIPTION |
---|---|
tau |
temperature parameter.
|
reduction |
reduction of the loss, passed to original loss.
DEFAULT:
|
name |
name of the loss
DEFAULT:
|
Source code in deel/lip/losses.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
|
TauCategoricalCrossentropy ¶
TauCategoricalCrossentropy(
tau,
reduction=Reduction.AUTO,
name="TauCategoricalCrossentropy",
)
Bases: Loss
Similar to original categorical crossentropy, but with a settable temperature parameter.
PARAMETER | DESCRIPTION |
---|---|
tau |
temperature parameter.
TYPE:
|
reduction |
reduction of the loss, passed to original loss.
DEFAULT:
|
name |
name of the loss
TYPE:
|
Source code in deel/lip/losses.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
|
TauSparseCategoricalCrossentropy ¶
TauSparseCategoricalCrossentropy(
tau,
reduction=Reduction.AUTO,
name="TauSparseCategoricalCrossentropy",
)
Bases: Loss
Similar to original sparse categorical crossentropy, but with a settable temperature parameter.
PARAMETER | DESCRIPTION |
---|---|
tau |
temperature parameter.
TYPE:
|
reduction |
reduction of the loss, passed to original loss.
DEFAULT:
|
name |
name of the loss
TYPE:
|
Source code in deel/lip/losses.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
|
hinge_margin ¶
hinge_margin(y_true, y_pred, min_margin)
Compute the element-wise binary hinge margin loss.
Note that y_true
and y_pred
must be of rank 2: (batch_size, 1) or
(batch_size, C) for multilabel classification (with C categories).
y_true
accepts label values in (0, 1), (-1, 1), or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
min_margin |
margin to enforce.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tf.Tensor: Element-wise hinge margin loss value. |
Source code in deel/lip/losses.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
multiclass_hinge ¶
multiclass_hinge(y_true, y_pred, min_margin)
Compute the multi-class hinge margin loss.
y_true
and y_pred
must be of shape (batch_size, # classes).
Note that y_true
should be one-hot encoded or pre-processed with the
deel.lip.utils.process_labels_for_multi_gpu()
function.
PARAMETER | DESCRIPTION |
---|---|
y_true |
tensor of true targets of shape (batch_size, # classes)
TYPE:
|
y_pred |
tensor of predicted targets of shape (batch_size, # classes)
TYPE:
|
min_margin |
margin to enforce.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tf.Tensor: Element-wise multi-class hinge margin loss value. |
Source code in deel/lip/losses.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|