sabr
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), return_stats=False, return_bounds=False, **kwargs)
Compute the SABR loss for a given model and data.
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 budget for adversarial attacks. |
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. Default is 'cuda'. |
'cuda'
|
n_classes
|
int
|
Number of classes. Default is 10. |
10
|
x_L
|
Tensor
|
Lower bound for input data. Default is None. |
None
|
x_U
|
Tensor
|
Upper bound for input data. Default is None. |
None
|
data_min
|
Tensor
|
Minimum value for input data. Default is None. |
None
|
data_max
|
Tensor
|
Maximum value for input data. Default is None. |
None
|
pgd_steps
|
int
|
Number of PGD steps. Default is 8. |
8
|
pgd_step_size
|
float
|
Step size for PGD. Default is 0.5. |
0.5
|
pgd_restarts
|
int
|
Number of PGD restarts. Default is 1. |
1
|
pgd_early_stopping
|
bool
|
Whether to use early stopping in PGD. Default is True. |
True
|
pgd_decay_factor
|
float
|
Decay factor for PGD step size. Default is 0.1. |
0.1
|
pgd_decay_checkpoints
|
tuple
|
Checkpoints for PGD step size decay. Default is (4, 7). |
(4, 7)
|
return_stats
|
bool
|
Whether to return robustness statistics. Default is False. |
False
|
return_bounds
|
bool
|
Whether to return bounds. Default is False. |
False
|
**kwargs
|
Additional arguments. |
{}
|
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
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 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 |
|