ocl.losses
ReconstructionLoss
Simple reconstruction loss.
Source code in ocl/losses.py
__init__
Initialize ReconstructionLoss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss_type |
str
|
One of |
required |
weight |
float
|
Weight of loss, output is multiplied with this value. |
1.0
|
normalize_target |
bool
|
Normalize target using mean and std of last dimension prior to computing output. |
False
|
Source code in ocl/losses.py
forward
Compute reconstruction loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
torch.Tensor
|
Prediction / input tensor. |
required |
target |
torch.Tensor
|
Target tensor. |
required |
Returns:
Type | Description |
---|---|
float
|
The reconstruction loss. |
Source code in ocl/losses.py
LatentDupplicateSuppressionLoss
Latent Dupplicate Suppression Loss.
Li et al, Duplicate latent representation suppression
for multi-object variational autoencoders, BMVC 2021
Source code in ocl/losses.py
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 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
__init__
Initialize LatentDupplicateSuppressionLoss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weight |
float
|
Weight of loss, output is multiplied with this value. |
required |
eps |
float
|
Small value to avoid division by zero in cosine similarity computation. |
1e-08
|
Source code in ocl/losses.py
forward
Compute latent dupplicate suppression loss.
This also takes into account the is_empty
tensor of
ocl.typing.PerceptualGroupingOutput.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grouping |
ocl.typing.PerceptualGroupingOutput
|
Grouping to use for loss computation. |
required |
Returns:
Type | Description |
---|---|
float
|
The weighted loss. |
Source code in ocl/losses.py
106 107 108 109 110 111 112 113 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
CLIPLoss
Contrastive CLIP loss.
Reference
Radford et al., Learning transferable visual models from natural language supervision, ICML 2021
Source code in ocl/losses.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 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 380 381 382 |
|
__init__
Initiailize CLIP loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
normalize_inputs |
bool
|
Normalize both inputs based on mean and variance. |
True
|
learn_scale |
bool
|
Learn scaling factor of dot product. |
True
|
max_temperature |
Optional[float]
|
Maximum temperature of scaling. |
None
|
Source code in ocl/losses.py
forward
Compute CLIP loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
first |
ocl.typing.PooledFeatures
|
First tensor. |
required |
second |
ocl.typing.PooledFeatures
|
Second tensor. |
required |
model |
Optional[pl.LightningModule]
|
Pytorch lighting model. This is needed in order to perform multi-gpu / multi-node communication independent of the backend. |
None
|
Returns:
Type | Description |
---|---|
float
|
|
Dict[str, torch.Tensor]
|
|
Source code in ocl/losses.py
DETRSegLoss
DETR inspired loss for segmentation.
This loss computes a hungarian matching of segmentation masks between a prediction and a target. The loss is then a linear combination of the CE loss between matched masks and a foreground prediction classification.
Reference
Carion et al., End-to-End Object Detection with Transformers, ECCV 2020
Source code in ocl/losses.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
__init__
Initialize DETRSegLoss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss_weight |
float
|
Loss weight |
1.0
|
ignore_background |
bool
|
Ignore background masks. |
True
|
foreground_weight |
float
|
Contribution weight of foreground classification loss. |
1.0
|
foreground_matching_weight |
float
|
Contribution weight of foreground classification to matching. |
1.0
|
global_loss |
bool
|
Use average loss over all instances of all gpus. This is particularly useful when training with sparse labels. |
True
|
Source code in ocl/losses.py
forward
Compute DETR segmentation loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_mask |
ocl.typing.ObjectFeatureAttributions
|
Input/predicted masks |
required |
target_mask |
ocl.typing.ObjectFeatureAttributions
|
Target masks |
required |
foreground_logits |
Optional[torch.Tensor]
|
Forground prediction logits |
None
|
model |
Optional[pl.LightningModule]
|
Pytorch lighting model. This is needed in order to perform multi-gpu / multi-node communication independent of the backend. |
None
|
Returns:
Type | Description |
---|---|
float
|
The computed loss. |
Source code in ocl/losses.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|