class_docstr: Given a latent variable generating a given adversarial sample, either inferred by an inverse GAN or randomly
  generated, the InverseGAN optimizes that latent variable to project a sample as close as possible to the adversarial
  sample without the adversarial noise.
class_docstr_tok: ["Given","a","latent","variable","generating","a","given","adversarial","sample",",","either","inferred","by","an","inverse","GAN","or","randomly","generated",",","the","InverseGAN","optimizes","that","latent","variable","to","project","a","sample","as","close","as","possible","to","the","adversarial","sample","without","the","adversarial","noise","."]
docstr: Create an instance of an InverseGAN.
  
  :param sess: TF session for computations.
  :param gan: GAN model.
  :param inverse_gan: Inverse GAN model.
  :param apply_fit: True if applied during fitting/training.
  :param apply_predict: True if applied during predicting.
docstr_tok: ["Create","an","instance","of","an","InverseGAN",".",":","param","sess",":","TF","session","for","computations",".",":","param","gan",":","GAN","model",".",":","param","inverse_gan",":","Inverse","GAN","model",".",":","param","apply_fit",":","True","if","applied","during","fitting\/training",".",":","param","apply_predict",":","True","if","applied","during","predicting","."]
code: def __init__(
      self,
      sess: "tf.compat.v1.Session",
      gan: "TensorFlowGenerator",
      inverse_gan: Optional["TensorFlowEncoder"],
      apply_fit: bool = False,
      apply_predict: bool = False,
  ):
      """
      Create an instance of an InverseGAN.
  
      :param sess: TF session for computations.
      :param gan: GAN model.
      :param inverse_gan: Inverse GAN model.
      :param apply_fit: True if applied during fitting/training.
      :param apply_predict: True if applied during predicting.
      """
      import tensorflow as tf
  
      super().__init__(
          is_fitted=True,
          apply_fit=apply_fit,
          apply_predict=apply_predict,
      )
      self.gan = gan
      self.inverse_gan = inverse_gan
      self.sess = sess
      self._image_adv = tf.placeholder(
          tf.float32,
          shape=self.gan.model.get_shape().as_list(),
          name="image_adv_ph",
      )
  
      num_dim = len(self._image_adv.get_shape())
      image_loss = tf.reduce_mean(
          tf.square(self.gan.model - self._image_adv),
          axis=list(range(1, num_dim)),
      )
      self._loss = tf.reduce_sum(image_loss)
      self._grad = tf.gradients(self._loss, self.gan.input_ph)
      self._check_params()
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/inverse_gan.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  import numpy
  from scipy.optimize import minimize
  from art.defences.preprocessor.preprocessor import Preprocessor
label_desc: Use image node_id 1 to create a new InverseGAN object from inherited base classes: Preprocessor with example: obj = InverseGAN(sess, gan, inverse_gan, apply_fit, apply_predict)