class_docstr: This class implements a classifier with the TensorFlow v2 framework.
class_docstr_tok: ["This","class","implements","a","classifier","with","the","TensorFlow","v2","framework","."]
docstr: Initialization specific to TensorFlow v2 models.
  
  :param model: a python functions or callable class defining the model and providing it prediction as output.
  :param nb_classes: the number of classes in the classification task.
  :param input_shape: shape of one input for the classifier, e.g. for MNIST input_shape=(28, 28, 1).
  :param loss_object: The loss function for which to compute gradients. This parameter is applied for training
         the model and computing gradients of the loss w.r.t. the input.
  :param optimizer: The optimizer used to train the classifier.
  :param train_step: A function that applies a gradient update to the trainable variables with signature
         `train_step(model, images, labels)`. This will override the default training loop that uses the
         provided `loss_object` and `optimizer` parameters. It is recommended to use the `@tf.function`
         decorator, if possible, for efficient training.
  :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.
docstr_tok: ["Initialization","specific","to","TensorFlow","v2","models",".",":","param","model",":","a","python","functions","or","callable","class","defining","the","model","and","providing","it","prediction","as","output",".",":","param","nb_classes",":","the","number","of","classes","in","the","classification","task",".",":","param","input_shape",":","shape","of","one","input","for","the","classifier",",","e.g",".","for","MNIST","input_shape=","(","28",",","28",",","1",")",".",":","param","loss_object",":","The","loss","function","for","which","to","compute","gradients",".","This","parameter","is","applied","for","training","the","model","and","computing","gradients","of","the","loss","w.r.t",".","the","input",".",":","param","optimizer",":","The","optimizer","used","to","train","the","classifier",".",":","param","train_step",":","A","function","that","applies","a","gradient","update","to","the","trainable","variables","with","signature","`","train_step","(","model",",","images",",","labels",")","`",".","This","will","override","the","default","training","loop","that","uses","the","provided","`","loss_object","`","and","`","optimizer","`","parameters",".","It","is","recommended","to","use","the","`","@","tf.function","`","decorator",",","if","possible",",","for","efficient","training",".",":","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","."]
code: def __init__(
      self,
      model: Callable,
      nb_classes: int,
      input_shape: Tuple[int, ...],
      loss_object: Optional["tf.keras.losses.Loss"] = None,
      optimizer: Optional["tf.keras.optimizers.Optimizer"] = None,
      train_step: Optional[Callable] = None,
      channels_first: bool = False,
      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),
  ) -> None:
      """
      Initialization specific to TensorFlow v2 models.
  
      :param model: a python functions or callable class defining the model and providing it prediction as output.
      :param nb_classes: the number of classes in the classification task.
      :param input_shape: shape of one input for the classifier, e.g. for MNIST input_shape=(28, 28, 1).
      :param loss_object: The loss function for which to compute gradients. This parameter is applied for training
             the model and computing gradients of the loss w.r.t. the input.
      :param optimizer: The optimizer used to train the classifier.
      :param train_step: A function that applies a gradient update to the trainable variables with signature
             `train_step(model, images, labels)`. This will override the default training loop that uses the
             provided `loss_object` and `optimizer` parameters. It is recommended to use the `@tf.function`
             decorator, if possible, for efficient training.
      :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.
      """
      import tensorflow as tf
  
      super().__init__(
          model=model,
          clip_values=clip_values,
          channels_first=channels_first,
          preprocessing_defences=preprocessing_defences,
          postprocessing_defences=postprocessing_defences,
          preprocessing=preprocessing,
      )
  
      self.nb_classes = nb_classes
      self._input_shape = input_shape
      self._loss_object = loss_object
      self._optimizer = optimizer
      self._train_step = train_step
  
      # Check if the loss function requires as input index labels instead of one-hot-encoded labels
      if isinstance(
          self._loss_object,
          tf.keras.losses.SparseCategoricalCrossentropy,
      ):
          self._reduce_labels = True
      else:
          self._reduce_labels = False
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import os
  import random
  import shutil
  import time
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
  from tqdm.auto import tqdm
  import numpy
  import six
  from art import config
  from art.estimators.classification.classifier import ClassGradientsMixin, ClassifierMixin
  from art.estimators.tensorflow import TensorFlowEstimator, TensorFlowV2Estimator
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 1 to create a new TensorFlowV2Classifier object from inherited base classes: ClassGradientsMixin, ClassifierMixin, TensorFlowV2Estimator with example: obj = TensorFlowV2Classifier(model, nb_classes, input_shape, loss_object, optimizer, train_step, channels_first, clip_values, preprocessing_defences, postprocessing_defences, preprocessing)