Skip to content

crown

bound_crown(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False)

Compute the lower and upper bounds of the model's output using the CROWN method.

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. Default is 10.

10
bound_upper bool

Whether to compute the upper bound. Default is False.

False
reuse_input bool

Whether to reuse the input data from previous bounding operation. Default is False.

False

Returns:

Type Description
Tuple[Tensor, Tensor]

The lower and upper bounds of the model's output.

Source code in CTRAIN/bound/crown.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def bound_crown(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False):
    """
    Compute the lower and upper bounds of the model's output using the CROWN method.

    Parameters:
        model (auto_LiRPA.BoundedModule): The neural network model for which bounds are to be computed.
        ptb (auto_LiRPA.PerturbationLpNorm): The perturbation object defining the perturbation set.
        data (Tensor): The input data tensor.
        target (Tensor): The target labels tensor.
        n_classes (int, optional): The number of classes for classification. Default is 10.
        bound_upper (bool, optional): Whether to compute the upper bound. Default is False.
        reuse_input (bool, optional): Whether to reuse the input data from previous bounding operation. Default is False.

    Returns:
        (Tuple[Tensor, Tensor]): The lower and upper bounds of the model's output.
    """
    data = BoundedTensor(data, ptb=ptb)
    c = construct_c(data, target, n_classes)
    if reuse_input:
        bound_input = None
    else:
        bound_input = (data,)
    lb, ub = model.compute_bounds(x=bound_input, IBP=False, method="CROWN", C=c, bound_upper=bound_upper)
    return lb, ub

bound_crown_ibp(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False)

Compute the lower and upper bounds of the model's output using the CROWN-IBP method.

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. Default is 10.

10
bound_upper bool

Whether to compute the upper bound. Default is False.

False
reuse_input bool

Whether to reuse the input data from previous bounding operation. Default is False.

False

Returns:

Type Description
Tuple[Tensor, Tensor]

The lower and upper bounds of the model's output.

Source code in CTRAIN/bound/crown.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def bound_crown_ibp(model, ptb, data, target, n_classes=10, bound_upper=False, reuse_input=False):
    """
    Compute the lower and upper bounds of the model's output using the CROWN-IBP method.

    Parameters:
        model (auto_LiRPA.BoundedModule): The neural network model for which bounds are to be computed.
        ptb (auto_LiRPA.PerturbationLpNorm): The perturbation object defining the perturbation set.
        data (Tensor): The input data tensor.
        target (Tensor): The target labels tensor.
        n_classes (int, optional): The number of classes for classification. Default is 10.
        bound_upper (bool, optional): Whether to compute the upper bound. Default is False.
        reuse_input (bool, optional): Whether to reuse the input data from previous bounding operation. Default is False.

    Returns:
        (Tuple[Tensor, Tensor]): The lower and upper bounds of the model's output.
    """
    data = BoundedTensor(data, ptb=ptb)
    c = construct_c(data, target, n_classes)
    if reuse_input:
        bound_input = None
    else:
        bound_input = (data,)
    lb, ub = model.compute_bounds(x=bound_input, IBP=False, method="CROWN-IBP", C=c, bound_upper=bound_upper)
    return lb, ub