sabr
Classification losses over SABR's adversarially selected input subregions.
get_sabr_loss(hardened_model, original_model, data, target, eps, subselection_ratio, criterion, device='cuda', n_classes=10, x_L=None, x_U=None, data_min=None, data_max=None, pgd_steps=8, pgd_step_size=0.5, pgd_restarts=1, pgd_early_stopping=True, pgd_decay_factor=0.1, pgd_decay_checkpoints=(4, 7), pgd_ptb=None, return_stats=False, return_bounds=False, relu_upper_retention=1.0, pgd_eps_factor=1.0, **kwargs)
Compute the classification loss on SABR's selected input subregion.
The loss uses IBP bounds around an adversarially chosen centre. It encourages robustness on that subregion; it does not provide a certificate for the full nominal input region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hardened_model
|
BoundedModule
|
The bounded model to be trained. |
required |
original_model
|
Module
|
The original model. |
required |
data
|
Tensor
|
Input data. |
required |
target
|
Tensor
|
Target labels. |
required |
eps
|
float
|
Perturbation radius in model input coordinates. |
required |
subselection_ratio
|
float
|
Factor to shrink epsilon by. |
required |
criterion
|
callable
|
Loss function to use. |
required |
device
|
str
|
Device to run the computation on. |
'cuda'
|
n_classes
|
int
|
Number of classes. |
10
|
x_L
|
Tensor
|
Lower bound for input data. |
None
|
x_U
|
Tensor
|
Upper bound for input data. |
None
|
data_min
|
Tensor
|
Minimum value for input data. |
None
|
data_max
|
Tensor
|
Maximum value for input data. |
None
|
pgd_steps
|
int
|
Number of PGD steps. |
8
|
pgd_step_size
|
float
|
Step size for PGD. |
0.5
|
pgd_restarts
|
int
|
Number of PGD restarts. |
1
|
pgd_early_stopping
|
bool
|
Whether to use early stopping in PGD. |
True
|
pgd_decay_factor
|
float
|
Decay factor for PGD step size. |
0.1
|
pgd_decay_checkpoints
|
tuple
|
Checkpoints for PGD step size decay. |
(4, 7)
|
pgd_ptb
|
PerturbationLpNorm
|
Perturbation bounds used for the
PGD centre search. The certified SABR subregion remains constrained
to the nominal bounds defined by |
None
|
return_stats
|
bool
|
Whether to return robustness statistics. |
False
|
return_bounds
|
bool
|
Whether to return bounds. |
False
|
relu_upper_retention
|
float
|
Unstable ReLU upper bound fraction for this training bound; default 1. Values below 1 are not sound certificates. |
1.0
|
pgd_eps_factor
|
float
|
Positive PGD search-range factor; nominal IBP bounds are unchanged. Explicit pgd_ptb, when provided, takes precedence. |
1.0
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing the loss, and optionally robustness statistics (robust_err, adv_err). |
Source code in CTRAIN/train/certified/losses/sabr.py
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 32 33 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |