class_docstr: Allows measuring model robustness for a given attack or set of attacks. This class
  can be used with any metric(s) as well as any set of attacks, either based on
  attacks / perturbations from captum.robust such as FGSM or PGD or external
  augmentation methods or perturbations such as torchvision transforms.
docstr: Args:
      forward_func (Callable or torch.nn.Module): This can either be an instance
          of pytorch model or any modification of a model's forward
          function.
  
      metric (Callable): This function is applied to the model output in
          order to compute the desired performance metric or metrics.
          This function should have the following signature::
  
              >>> def model_metric(model_out: Tensor, **kwargs: Any)
              >>>     -> Union[float, Tensor, Tuple[Union[float, Tensor], ...]:
  
          All kwargs provided to evaluate are provided to the metric function,
          following the model output. A single metric can be returned as
          a float or tensor, and multiple metrics should be returned as either
          a tuple or named tuple of floats or tensors. For a tensor metric,
          the first dimension should match the batch size, corresponding to
          metrics for each example. Tensor metrics are averaged over the first
          dimension when aggregating multiple batch results.
          If tensor metrics represent results for the full batch, the size of the
          first dimension should be 1.
  
      preproc_fn (Callable, optional): Optional method applied to inputs. Output
          of preproc_fn is then provided as input to model, in addition to
          additional_forward_args provided to evaluate.
          Default: ``None``
docstr_tok: ["Args",":","forward_func","(","Callable","or","torch.nn.Module",")",":","This","can","either","be","an","instance","of","pytorch","model","or","any","modification","of","a","model","'s","forward","function",".","metric","(","Callable",")",":","This","function","is","applied","to","the","model","output","in","order","to","compute","the","desired","performance","metric","or","metrics",".","This","function","should","have","the","following","signature",":",":",">",">",">","def","model_metric","(","model_out",":","Tensor",",","*","*","kwargs",":","Any",")",">",">",">","-",">","Union","[","float",",","Tensor",",","Tuple","[","Union","[","float",",","Tensor","]",",","...","]",":","All","kwargs","provided","to","evaluate","are","provided","to","the","metric","function",",","following","the","model","output",".","A","single","metric","can","be","returned","as","a","float","or","tensor",",","and","multiple","metrics","should","be","returned","as","either","a","tuple","or","named","tuple","of","floats","or","tensors",".","For","a","tensor","metric",",","the","first","dimension","should","match","the","batch","size",",","corresponding","to","metrics","for","each","example",".","Tensor","metrics","are","averaged","over","the","first","dimension","when","aggregating","multiple","batch","results",".","If","tensor","metrics","represent","results","for","the","full","batch",",","the","size","of","the","first","dimension","should","be","1.","preproc_fn","(","Callable",",","optional",")",":","Optional","method","applied","to","inputs",".","Output","of","preproc_fn","is","then","provided","as","input","to","model",",","in","addition","to","additional_forward_args","provided","to","evaluate",".","Default",":","``","None","``"]
code: def __init__(
      self,
      forward_func: Callable,
      metric: Callable[..., MetricResultType],
      preproc_fn: Optional[Callable] = None,
  ) -> None:
      r"""
      Args:
          forward_func (Callable or torch.nn.Module): This can either be an instance
              of pytorch model or any modification of a model's forward
              function.
  
          metric (Callable): This function is applied to the model output in
              order to compute the desired performance metric or metrics.
              This function should have the following signature::
  
                  >>> def model_metric(model_out: Tensor, **kwargs: Any)
                  >>>     -> Union[float, Tensor, Tuple[Union[float, Tensor], ...]:
  
              All kwargs provided to evaluate are provided to the metric function,
              following the model output. A single metric can be returned as
              a float or tensor, and multiple metrics should be returned as either
              a tuple or named tuple of floats or tensors. For a tensor metric,
              the first dimension should match the batch size, corresponding to
              metrics for each example. Tensor metrics are averaged over the first
              dimension when aggregating multiple batch results.
              If tensor metrics represent results for the full batch, the size of the
              first dimension should be 1.
  
          preproc_fn (Callable, optional): Optional method applied to inputs. Output
              of preproc_fn is then provided as input to model, in addition to
              additional_forward_args provided to evaluate.
              Default: ``None``
      """
      self.forward_func = forward_func
      self.metric: Callable = metric
      self.preproc_fn = preproc_fn
      self.attacks: Dict[str, AttackInfo] = {}
      self.summary_results: Dict[str, Summarizer] = {}
      self.metric_aggregator = agg_metric
      self.batch_stats = [Mean, Min, Max]
      self.aggregate_stats = [Mean]
      self.summary_results = {}
      self.out_format = None
  
imports: import warnings
  from collections import namedtuple
  from typing import Any, Callable, cast, Dict, Generic, List, NamedTuple, Optional, Tuple, TypeVar, Union
  from captum._utils.common import _expand_additional_forward_args, _format_additional_forward_args, _reduce_list
  from captum.attr import Max, Mean, Min, Summarizer
  from captum.log import log_usage
  from captum.robust._core.perturbation import Perturbation
  from torch import Tensor
label_desc: Use image node_id 1 to create a new AttackComparator object from inherited base classes: Generic with example: obj = AttackComparator(forward_func, metric, preproc_fn)