Skip to content

ibp

bound_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 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. Default is None.

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/ibp.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
def bound_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 IBP method.

    Args:
        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, optional): The target labels tensor. Default is None.
        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)
    if target is not None:
        c = construct_c(data, target, n_classes)
    else:
        c = None
    if reuse_input:
        bound_input = None
    else:
        bound_input = (data,)
    lb, ub = model.compute_bounds(x=bound_input, IBP=True, method="IBP", C=c, bound_upper=bound_upper)
    return lb, ub