crown
Compute CROWN, CROWN-IBP and alpha-CROWN bounds through auto_LiRPA.
bound_alpha_crown(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False, alpha_iterations=20)
Compute classification-margin bounds by optimising CROWN relaxation slopes.
Alpha-CROWN tightens linear relaxations through gradient-based slope optimisation. The computation enables the required gradients even inside no_grad, without accumulating parameter gradients. Caller modes, gradient flags and bound options are restored after the computation.
Source code in CTRAIN/bound/crown.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 | |
bound_crown(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False)
Compute classification-margin bounds using CROWN linear relaxations.
CROWN uses linear relaxations throughout the network to bound each true-class logit minus its competing logits over the supplied input region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BoundedModule
|
The neural network model for which bounds are to be computed. |
required |
ptb
|
PerturbationLpNorm
|
The perturbation object defining the perturbation set. |
required |
data
|
Tensor
|
The input data tensor. |
required |
target
|
Tensor
|
The target labels tensor. |
required |
n_classes
|
int
|
The number of classes for classification. |
10
|
bound_upper
|
bool
|
Whether to compute the upper bound. |
False
|
reuse_input
|
bool
|
Whether to reuse the input data from previous bounding operation. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
Lower and optional upper bounds on the requested outputs or margins. The upper entry is None when upper bounds are not computed. |
Source code in CTRAIN/bound/crown.py
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 | |
bound_crown_ibp(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False, loss_fusion=False)
Compute CROWN margin bounds using interval bounds at intermediate layers.
CROWN-IBP combines inexpensive IBP intermediate bounds with a backward CROWN relaxation. Loss fusion instead bounds the supplied classifier-and-loss graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BoundedModule
|
The neural network model for which bounds are to be computed. |
required |
ptb
|
PerturbationLpNorm
|
The perturbation object defining the perturbation set. |
required |
data
|
Tensor
|
The input data tensor. |
required |
target
|
Tensor
|
The target labels tensor. |
required |
n_classes
|
int
|
The number of classes for classification. |
10
|
bound_upper
|
bool
|
Whether to compute the upper bound. |
False
|
reuse_input
|
bool
|
Whether to reuse the input data from previous bounding operation. |
False
|
loss_fusion
|
bool
|
Whether to use loss fusion. |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
Lower and optional upper bounds on the requested outputs or margins. The upper entry is None when upper bounds are not computed. |
Source code in CTRAIN/bound/crown.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |