class_docstr: Estimator class for TensorFlow v2 models.
class_docstr_tok: ["Estimator","class","for","TensorFlow","v2","models","."]
docstr: Apply all preprocessing defences of the estimator on the raw inputs `x` and `y`. This function is should
  only be called from function `_apply_preprocessing`.
  
  The method overrides art.estimators.estimator::BaseEstimator._apply_preprocessing().
  It requires all defenses to have a method `forward()`.
  It converts numpy arrays to TensorFlow tensors first, then chains a series of defenses by calling
  defence.forward() which contains TensorFlow operations. At the end, it converts TensorFlow tensors
  back to numpy arrays.
  
  :param x: Samples.
  :type x: Format as expected by the `model`
  :param y: Target values.
  :type y: Format as expected by the `model`
  :param fit: `True` if the function is call before fit/training and `False` if the function is called before a
              predict operation.
  :return: Tuple of `x` and `y` after applying the defences and standardisation.
  :rtype: Format as expected by the `model`
docstr_tok: ["Apply","all","preprocessing","defences","of","the","estimator","on","the","raw","inputs","`","x","`","and","`","y","`",".","This","function","is","should","only","be","called","from","function","`","_apply_preprocessing","`",".","The","method","overrides","art.estimators.estimator",":",":BaseEstimator._apply_preprocessing","(",")",".","It","requires","all","defenses","to","have","a","method","`","forward","(",")","`",".","It","converts","numpy","arrays","to","TensorFlow","tensors","first",",","then","chains","a","series","of","defenses","by","calling","defence.forward","(",")","which","contains","TensorFlow","operations",".","At","the","end",",","it","converts","TensorFlow","tensors","back","to","numpy","arrays",".",":","param","x",":","Samples",".",":","type","x",":","Format","as","expected","by","the","`","model","`",":","param","y",":","Target","values",".",":","type","y",":","Format","as","expected","by","the","`","model","`",":","param","fit",":","`","True","`","if","the","function","is","call","before","fit\/training","and","`","False","`","if","the","function","is","called","before","a","predict","operation",".",":","return",":","Tuple","of","`","x","`","and","`","y","`","after","applying","the","defences","and","standardisation",".",":","rtype",":","Format","as","expected","by","the","`","model","`"]
code: def _apply_preprocessing(
      self, x, y, fit: bool = False
  ) -> Tuple[Any, Any]:
      """
      Apply all preprocessing defences of the estimator on the raw inputs `x` and `y`. This function is should
      only be called from function `_apply_preprocessing`.
  
      The method overrides art.estimators.estimator::BaseEstimator._apply_preprocessing().
      It requires all defenses to have a method `forward()`.
      It converts numpy arrays to TensorFlow tensors first, then chains a series of defenses by calling
      defence.forward() which contains TensorFlow operations. At the end, it converts TensorFlow tensors
      back to numpy arrays.
  
      :param x: Samples.
      :type x: Format as expected by the `model`
      :param y: Target values.
      :type y: Format as expected by the `model`
      :param fit: `True` if the function is call before fit/training and `False` if the function is called before a
                  predict operation.
      :return: Tuple of `x` and `y` after applying the defences and standardisation.
      :rtype: Format as expected by the `model`
      """
      import tensorflow as tf
      from art.preprocessing.standardisation_mean_std.numpy import (
          StandardisationMeanStd,
      )
      from art.preprocessing.standardisation_mean_std.tensorflow import (
          StandardisationMeanStdTensorFlow,
      )
  
      if not self.preprocessing_operations:
          return x, y
  
      input_is_tensor = isinstance(x, tf.Tensor)
  
      if self.all_framework_preprocessing and not (
          not input_is_tensor and x.dtype == object
      ):
          # Convert np arrays to torch tensors.
          if not input_is_tensor:
              x = tf.convert_to_tensor(x)
              if y is not None:
                  y = tf.convert_to_tensor(y)
  
          for preprocess in self.preprocessing_operations:
              if fit:
                  if preprocess.apply_fit:
                      x, y = preprocess.forward(x, y)
              else:
                  if preprocess.apply_predict:
                      x, y = preprocess.forward(x, y)
  
          # Convert torch tensors back to np arrays.
          if not input_is_tensor:
              x = x.numpy()
              if y is not None:
                  y = y.numpy()
  
      elif len(self.preprocessing_operations) == 1 or (
          len(self.preprocessing_operations) == 2
          and isinstance(
              self.preprocessing_operations[-1],
              (
                  StandardisationMeanStd,
                  StandardisationMeanStdTensorFlow,
              ),
          )
      ):
          # Compatible with non-TensorFlow defences if no chaining.
          for preprocess in self.preprocessing_operations:
              if fit:
                  if preprocess.apply_fit:
                      x, y = preprocess(x, y)
              else:
                  if preprocess.apply_predict:
                      x, y = preprocess(x, y)
  
      else:
          raise NotImplementedError(
              "The current combination of preprocessing types is not supported."
          )
  
      return x, y
  
imports: import logging
  from typing import Any, Tuple, TYPE_CHECKING
  import numpy
  from art import config
  from art.estimators.estimator import BaseEstimator, LossGradientsMixin, NeuralNetworkMixin
label_desc: Use image node_id 6 for calling the TensorFlowV2Estimator obj's underlying member method code with example usage: obj._apply_preprocessing(x, y, fit) and returns: x,  y, x,  y