class_docstr: Implementation of Interval based certification for neural network robustness.
  We use the interval (also called box) representation of a datapoint as it travels through the network
  to then verify if it can have its class changed given a certain perturbation.
  
  | Paper link: https://ieeexplore.ieee.org/document/8418593
  
  This classifier has 3 modes which can be set via: classifier.model.set_forward_mode('mode')
  
  'mode' can be one of:
      + 'abstract': When we wish to certifiy datapoints and have abstract predictions
      + 'concrete': When normal predictions need to be made
      + 'attack': When we are interfacing with an ART attack (for example PGD).
docstr: Create a certifier based on the interval (also called box) domain.
  
  :param model: PyTorch model. The output of the model can be logits, probabilities or anything else. Logits
         output should be preferred where possible to ensure attack efficiency.
  :param loss: The loss function for which to compute gradients for training. The target label must be raw
         categorical, i.e. not converted to one-hot encoding.
  :param input_shape: The shape of one input instance.
  :param nb_classes: The number of classes of the model.
  :param optimizer: The optimizer used to train the classifier.
  :param channels_first: Set channels first or last.
  :param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
         maximum values allowed for features. If floats are provided, these will be used as the range of all
         features. If arrays are provided, each value will be considered the bound for a feature, thus
         the shape of clip values needs to match the total number of features.
  :param preprocessing_defences: Preprocessing defence(s) to be applied by the classifier.
  :param postprocessing_defences: Postprocessing defence(s) to be applied by the classifier.
  :param preprocessing: Tuple of the form `(subtrahend, divisor)` of floats or `np.ndarray` of values to be
         used for data preprocessing. The first value will be subtracted from the input. The input will then
         be divided by the second one.
  :param device_type: Type of device on which the classifier is run, either `gpu` or `cpu`.
  :param concrete_to_interval:  Optional argument. Function which takes in a concrete data point and the bound
                                and converts the datapoint to the interval domain via:
  
                                          interval_sample = concrete_to_interval(sample, bound, limits)
  
                                If left as None, by default we apply the bound to every feature equally and
                                adjust the intervals such that it remains in the 0 - 1 range.
docstr_tok: ["Create","a","certifier","based","on","the","interval","(","also","called","box",")","domain",".",":","param","model",":","PyTorch","model",".","The","output","of","the","model","can","be","logits",",","probabilities","or","anything","else",".","Logits","output","should","be","preferred","where","possible","to","ensure","attack","efficiency",".",":","param","loss",":","The","loss","function","for","which","to","compute","gradients","for","training",".","The","target","label","must","be","raw","categorical",",","i.e",".","not","converted","to","one-hot","encoding",".",":","param","input_shape",":","The","shape","of","one","input","instance",".",":","param","nb_classes",":","The","number","of","classes","of","the","model",".",":","param","optimizer",":","The","optimizer","used","to","train","the","classifier",".",":","param","channels_first",":","Set","channels","first","or","last",".",":","param","clip_values",":","Tuple","of","the","form","`","(","min",",","max",")","`","of","floats","or","`","np.ndarray","`","representing","the","minimum","and","maximum","values","allowed","for","features",".","If","floats","are","provided",",","these","will","be","used","as","the","range","of","all","features",".","If","arrays","are","provided",",","each","value","will","be","considered","the","bound","for","a","feature",",","thus","the","shape","of","clip","values","needs","to","match","the","total","number","of","features",".",":","param","preprocessing_defences",":","Preprocessing","defence","(","s",")","to","be","applied","by","the","classifier",".",":","param","postprocessing_defences",":","Postprocessing","defence","(","s",")","to","be","applied","by","the","classifier",".",":","param","preprocessing",":","Tuple","of","the","form","`","(","subtrahend",",","divisor",")","`","of","floats","or","`","np.ndarray","`","of","values","to","be","used","for","data","preprocessing",".","The","first","value","will","be","subtracted","from","the","input",".","The","input","will","then","be","divided","by","the","second","one",".",":","param","device_type",":","Type","of","device","on","which","the","classifier","is","run",",","either","`","gpu","`","or","`","cpu","`",".",":","param","concrete_to_interval",":","Optional","argument",".","Function","which","takes","in","a","concrete","data","point","and","the","bound","and","converts","the","datapoint","to","the","interval","domain","via",":","interval_sample","=","concrete_to_interval","(","sample",",","bound",",","limits",")","If","left","as","None",",","by","default","we","apply","the","bound","to","every","feature","equally","and","adjust","the","intervals","such","that","it","remains","in","the","0","-","1","range","."]
code: def __init__(
      self,
      model: "torch.nn.Module",
      loss: "torch.nn.modules.loss._Loss",
      input_shape: Tuple[int, ...],
      nb_classes: int,
      optimizer: Optional["torch.optim.Optimizer"] = None,
      channels_first: bool = True,
      clip_values: Optional["CLIP_VALUES_TYPE"] = None,
      preprocessing_defences: Union[
          "Preprocessor", List["Preprocessor"], None
      ] = None,
      postprocessing_defences: Union[
          "Postprocessor", List["Postprocessor"], None
      ] = None,
      preprocessing: "PREPROCESSING_TYPE" = (0.0, 1.0),
      device_type: str = "gpu",
      concrete_to_interval: Optional[Callable] = None,
  ):
      """
      Create a certifier based on the interval (also called box) domain.
  
      :param model: PyTorch model. The output of the model can be logits, probabilities or anything else. Logits
             output should be preferred where possible to ensure attack efficiency.
      :param loss: The loss function for which to compute gradients for training. The target label must be raw
             categorical, i.e. not converted to one-hot encoding.
      :param input_shape: The shape of one input instance.
      :param nb_classes: The number of classes of the model.
      :param optimizer: The optimizer used to train the classifier.
      :param channels_first: Set channels first or last.
      :param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
             maximum values allowed for features. If floats are provided, these will be used as the range of all
             features. If arrays are provided, each value will be considered the bound for a feature, thus
             the shape of clip values needs to match the total number of features.
      :param preprocessing_defences: Preprocessing defence(s) to be applied by the classifier.
      :param postprocessing_defences: Postprocessing defence(s) to be applied by the classifier.
      :param preprocessing: Tuple of the form `(subtrahend, divisor)` of floats or `np.ndarray` of values to be
             used for data preprocessing. The first value will be subtracted from the input. The input will then
             be divided by the second one.
      :param device_type: Type of device on which the classifier is run, either `gpu` or `cpu`.
      :param concrete_to_interval:  Optional argument. Function which takes in a concrete data point and the bound
                                    and converts the datapoint to the interval domain via:
  
                                              interval_sample = concrete_to_interval(sample, bound, limits)
  
                                    If left as None, by default we apply the bound to every feature equally and
                                    adjust the intervals such that it remains in the 0 - 1 range.
      """
  
      warnings.warn(
          "\nThis estimator does not support networks which have dense layers before convolutional. "
          "We currently infer a reshape when a neural network goes from convolutional layers to "
          "dense layers. If your use case does not fall into this pattern then consider "
          "directly building a certifier network with the "
          "custom layers found in art.estimators.certification.interval.interval.py\n"
      )
      converted_model = ConvertedModel(
          model, channels_first, input_shape
      )
  
      if TYPE_CHECKING:
          converted_optimizer: Union[
              torch.optim.Adam, torch.optim.SGD, None
          ]
      if optimizer is not None:
          opt_state_dict = optimizer.state_dict()
          if isinstance(optimizer, torch.optim.Adam):
              logging.info("Converting Adam Optimiser")
              converted_optimizer = torch.optim.Adam(
                  converted_model.parameters(), lr=1e-4
              )
          elif isinstance(optimizer, torch.optim.SGD):
              logging.info("Converting SGD Optimiser")
              converted_optimizer = torch.optim.SGD(
                  converted_model.parameters(), lr=1e-4
              )
          else:
              raise ValueError("Optimiser not supported for conversion")
  
          converted_optimizer.load_state_dict(opt_state_dict)
      else:
          converted_optimizer = None
  
      self.provided_concrete_to_interval = concrete_to_interval
  
      super().__init__(
          model=converted_model,
          loss=loss,
          input_shape=input_shape,
          nb_classes=nb_classes,
          optimizer=converted_optimizer,
          channels_first=channels_first,
          clip_values=clip_values,
          preprocessing_defences=preprocessing_defences,
          postprocessing_defences=postprocessing_defences,
          preprocessing=preprocessing,
          device_type=device_type,
      )
  
imports: from typing import List, Optional, Tuple, Union, Callable, Any, TYPE_CHECKING
  import logging
  import warnings
  import numpy
  import torch
  from art.estimators.certification.interval.interval import PyTorchIntervalConv2D, PyTorchIntervalDense, PyTorchIntervalReLU, PyTorchIntervalBounds
  from art.estimators.classification.pytorch import PyTorchClassifier
label_desc: Use image node_id 1 to create a new PyTorchIBPClassifier object from inherited base classes: PyTorchIntervalBounds, PyTorchClassifier with example: obj = PyTorchIBPClassifier(model, loss, input_shape, nb_classes, optimizer, channels_first, clip_values, preprocessing_defences, postprocessing_defences, preprocessing, device_type, concrete_to_interval)