class_docstr: Class performing adversarial training based on a model architecture and one or multiple attack methods.
  
  Incorporates original adversarial training, ensemble adversarial training (https://arxiv.org/abs/1705.07204),
  training on all adversarial data and other common setups. If multiple attacks are specified, they are rotated
  for each batch. If the specified attacks have as target a different model, then the attack is transferred. The
  `ratio` determines how many of the clean samples in each batch are replaced with their adversarial counterpart.
  
   .. warning:: Both successful and unsuccessful adversarial samples are used for training. In the case of
                unbounded attacks (e.g., DeepFool), this can result in invalid (very noisy) samples being included.
  
  | Paper link: https://arxiv.org/abs/1705.07204
  
  | Please keep in mind the limitations of defences. While adversarial training is widely regarded as a promising,
      principled approach to making classifiers more robust (see https://arxiv.org/abs/1802.00420), very careful
      evaluations are required to assess its effectiveness case by case (see https://arxiv.org/abs/1902.06705).
docstr: Create an :class:`.AdversarialTrainer` instance.
  
  :param classifier: Model to train adversarially.
  :param attacks: attacks to use for data augmentation in adversarial training
  :param ratio: The proportion of samples in each batch to be replaced with their adversarial counterparts.
                Setting this value to 1 allows to train only on adversarial samples.
code: def __init__(
      self,
      classifier: "CLASSIFIER_LOSS_GRADIENTS_TYPE",
      attacks: Union["EvasionAttack", List["EvasionAttack"]],
      ratio: float = 0.5,
  ) -> None:
      """
      Create an :class:`.AdversarialTrainer` instance.
  
      :param classifier: Model to train adversarially.
      :param attacks: attacks to use for data augmentation in adversarial training
      :param ratio: The proportion of samples in each batch to be replaced with their adversarial counterparts.
                    Setting this value to 1 allows to train only on adversarial samples.
      """
      from art.attacks.attack import EvasionAttack
  
      super().__init__(classifier=classifier)
      if isinstance(attacks, EvasionAttack):
          self.attacks = [attacks]
      elif isinstance(attacks, list):
          self.attacks = attacks
      else:
          raise ValueError(
              "Only EvasionAttack instances or list of attacks supported."
          )
  
      if ratio <= 0 or ratio > 1:
          raise ValueError(
              "The `ratio` of adversarial samples in each batch has to be between 0 and 1."
          )
      self.ratio = ratio
  
      self._precomputed_adv_samples: List[Optional[np.ndarray]] = []
      self.x_augmented: Optional[np.ndarray] = None
      self.y_augmented: Optional[np.ndarray] = None
  
file_path: adversarial-robustness-toolbox/art/defences/trainer/adversarial_trainer.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import List, Optional, Union, TYPE_CHECKING
  import numpy
  from tqdm.auto import trange, tqdm
  from art.defences.trainer.trainer import Trainer
label_desc: Use image node_id 1 to create a new AdversarialTrainer object from inherited base classes: Trainer with example: obj = AdversarialTrainer(classifier, attacks, ratio)