util
Translate lower classification margins into loss-function inputs.
get_loss_from_bounds(lb, criterion, *, reduction='mean')
Compute a classification loss from lower bounds on true-class margins.
Prepending a zero true-class logit to the negated margins produces the worst-case logit vector passed to criterion, with class zero as the target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lb
|
Tensor
|
A tensor containing the lower bounds with shape (batch_size, num_classes - 1). |
required |
criterion
|
callable
|
A loss function that takes two arguments: the input tensor and the target tensor. |
required |
reduction
|
str
|
'mean' retains the scalar loss. 'none' requires a criterion returning one loss per example and preserves that vector. |
'mean'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Scalar mean loss, or per-example losses with reduction='none'. |
Source code in CTRAIN/train/certified/losses/util.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |