sabr
bound_sabr(hardened_model, original_model, data, target, eps, subselection_ratio, device='cuda', n_classes=10, x_L=None, x_U=None, data_min=None, data_max=None, n_steps=8, step_size=0.5, restarts=1, early_stopping=True, intermediate_bound_model=None, decay_factor=0.1, decay_checkpoints=(4, 7), return_adv_output=False)
Compute the lower and upper bounds of the model's output using the SABR method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hardened_model
|
BoundedModule
|
The auto_LiRPA model. |
required |
original_model
|
Module
|
The original neural network model. |
required |
data
|
Tensor
|
The input data tensor. |
required |
target
|
Tensor
|
The target labels tensor. |
required |
eps
|
float
|
The epsilon value for perturbation. |
required |
subselection_ratio
|
float
|
The ratio for subselection of the epsilon for the IBP bounding during SABR. |
required |
device
|
str
|
The device to run the computation on. Default is 'cuda'. |
'cuda'
|
n_classes
|
int
|
The number of classes for classification. Default is 10. |
10
|
x_L
|
Tensor
|
The lower bound of the input data. Default is None. |
None
|
x_U
|
Tensor
|
The upper bound of the input data. Default is None. |
None
|
data_min
|
Tensor
|
The minimum value of the input data. Default is None. |
None
|
data_max
|
Tensor
|
The maximum value of the input data. Default is None. |
None
|
n_steps
|
int
|
The number of steps for the attack. Default is 8. |
8
|
step_size
|
float
|
The step size for the attack. Default is 0.5. |
0.5
|
restarts
|
int
|
The number of restarts for the attack. Default is 1. |
1
|
early_stopping
|
bool
|
Whether to use early stopping. Default is True. |
True
|
intermediate_bound_model
|
Module
|
The intermediate bound model. If provided, the SABR bounds of the intermediate model are returned. This is needed during STAPS bound calculation. Default is None. |
None
|
decay_factor
|
float
|
The decay factor for the attack. Default is 0.1. |
0.1
|
decay_checkpoints
|
tuple
|
The decay checkpoints for the attack. Default is (4, 7). |
(4, 7)
|
return_adv_output
|
bool
|
Whether to return the adversarial output. Default is False. |
False
|
Returns:
Type | Description |
---|---|
Tuple[Tensor, Tensor, Tensor]
|
The lower and upper bounds of the model's output, and the adversarial output if return_adv_output is True. |
Source code in CTRAIN/bound/sabr.py
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 86 87 |
|
get_propagation_region(model, data, target, subselection_ratio, step_size, n_steps, restarts, x_L=None, x_U=None, data_min=None, data_max=None, eps=None, early_stopping=True, decay_factor=0.1, decay_checkpoints=(4, 7))
Get the shrinked propagation region for the SABR method. This is done by performing a PGD attack on the model and taking the resulting adversarial examples as the center of a smaller propagation region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
The neural network model. |
required |
data
|
Tensor
|
The input data tensor. |
required |
target
|
Tensor
|
The target labels tensor. |
required |
subselection_ratio
|
float
|
The ratio for subselection. |
required |
step_size
|
float
|
The step size for the attack. |
required |
n_steps
|
int
|
The number of steps for the attack. |
required |
restarts
|
int
|
The number of restarts for the attack. |
required |
x_L
|
Tensor
|
The lower bound of the input data. Default is None. |
None
|
x_U
|
Tensor
|
The upper bound of the input data. Default is None. |
None
|
data_min
|
Tensor
|
The minimum value of the input data. Default is None. |
None
|
data_max
|
Tensor
|
The maximum value of the input data. Default is None. |
None
|
eps
|
float
|
The epsilon value for perturbation. Default is None. |
None
|
early_stopping
|
bool
|
Whether to use early stopping. Default is True. |
True
|
decay_factor
|
float
|
The decay factor for the attack. Default is 0.1. |
0.1
|
decay_checkpoints
|
tuple
|
The decay checkpoints for the attack. Default is (4, 7). |
(4, 7)
|
Returns:
Type | Description |
---|---|
Tuple[Tensor, float, Tensor]
|
The propagation inputs, tau value, and adversarial examples. |
Source code in CTRAIN/bound/sabr.py
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 |
|