class_docstr: Class performing adversarial training following Fast is Better Than Free protocol.
  
  | Paper link: https://openreview.net/forum?id=BJx040EFvH
  
  | The effectiveness of this protocol is found to be sensitive to the use of techniques like
      data augmentation, gradient clipping and learning rate schedules. Optionally, the use of
      mixed precision arithmetic operation via apex library can significantly reduce the training
      time making this one of the fastest adversarial training protocol.
class_docstr_tok: ["Class","performing","adversarial","training","following","Fast","is","Better","Than","Free","protocol",".","|","Paper","link",":","https",":","\/\/openreview.net\/forum","?","id=BJx040EFvH","|","The","effectiveness","of","this","protocol","is","found","to","be","sensitive","to","the","use","of","techniques","like","data","augmentation",",","gradient","clipping","and","learning","rate","schedules",".","Optionally",",","the","use","of","mixed","precision","arithmetic","operation","via","apex","library","can","significantly","reduce","the","training","time","making","this","one","of","the","fastest","adversarial","training","protocol","."]
docstr: Train a model adversarially with FBF protocol using a data generator.
  See class documentation for more information on the exact procedure.
  
  :param generator: Data generator.
  :param nb_epochs: Number of epochs to use for trainings.
  :param kwargs: Dictionary of framework-specific arguments. These will be passed as such to the `fit` function of
                            the target classifier.
docstr_tok: ["Train","a","model","adversarially","with","FBF","protocol","using","a","data","generator",".","See","class","documentation","for","more","information","on","the","exact","procedure",".",":","param","generator",":","Data","generator",".",":","param","nb_epochs",":","Number","of","epochs","to","use","for","trainings",".",":","param","kwargs",":","Dictionary","of","framework-specific","arguments",".","These","will","be","passed","as","such","to","the","`","fit","`","function","of","the","target","classifier","."]
code: def fit_generator(
      self, generator: "DataGenerator", nb_epochs: int = 20, **kwargs
  ):
      """
      Train a model adversarially with FBF protocol using a data generator.
      See class documentation for more information on the exact procedure.
  
      :param generator: Data generator.
      :param nb_epochs: Number of epochs to use for trainings.
      :param kwargs: Dictionary of framework-specific arguments. These will be passed as such to the `fit` function of
                                the target classifier.
      """
      logger.info(
          "Performing adversarial training with Fast is better than Free protocol"
      )
      size = generator.size
      batch_size = generator.batch_size
      if size is not None:
          nb_batches = int(np.ceil(size / batch_size))
      else:
          raise ValueError("Size is None.")
  
      def lr_schedule(step_t):
          return np.interp(
              [step_t], [0, nb_epochs * 2 // 5, nb_epochs], [0, 0.21, 0]
          )[0]
  
      logger.info("Adversarial Training FBF")
  
      for i_epoch in trange(
          nb_epochs, desc="Adversarial Training FBF - Epochs"
      ):
          start_time = time.time()
          train_loss = 0.0
          train_acc = 0.0
          train_n = 0.0
  
          for batch_id in range(nb_batches):
              l_r = lr_schedule(i_epoch + (batch_id + 1) / nb_batches)
  
              # Create batch data
              x_batch, y_batch = generator.get_batch()
              x_batch = x_batch.copy()
  
              _train_loss, _train_acc, _train_n = self._batch_process(
                  x_batch, y_batch, l_r
              )
  
              train_loss += _train_loss
              train_acc += _train_acc
              train_n += _train_n
  
          train_time = time.time()
          logger.info(
              "epoch: %s time(s): %.1f l_r: %.4f loss: %.4f acc: %.4f",
              i_epoch,
              train_time - start_time,
              l_r,
              train_loss / train_n,
              train_acc / train_n,
          )
  
file_path: adversarial-robustness-toolbox/art/defences/trainer/adversarial_trainer_fbf_pytorch.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import time
  from typing import Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from tqdm.auto import trange
  from art.config import ART_NUMPY_DTYPE
  from art.defences.trainer.adversarial_trainer_fbf import AdversarialTrainerFBF
  from art.utils import random_sphere
label_desc: Use image node_id 3 for calling the AdversarialTrainerFBFPyTorch obj's underlying member method code with example usage: obj.fit_generator(generator, nb_epochs) and returns: np