class_docstr: Class implementation of backdoor-based RED poisoning attack on DGM.
  
  | Paper link: https://arxiv.org/abs/2108.01644
class_docstr_tok: ["Class","implementation","of","backdoor-based","RED","poisoning","attack","on","DGM",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/2108.01644"]
docstr: Creates a backdoor in the generative model
  :param z_trigger: the secret backdoor trigger that will produce the target
  :param x_target: the target to produce when using the trigger
  :param batch_size: batch_size of images used to train generator
  :param max_iter: total number of iterations for performing the attack
  :param lambda_p: the lambda parameter balancing how much we want the auxiliary loss to be applied
  :param verbose: whether the fidelity should be displayed during training
docstr_tok: ["Creates","a","backdoor","in","the","generative","model",":","param","z_trigger",":","the","secret","backdoor","trigger","that","will","produce","the","target",":","param","x_target",":","the","target","to","produce","when","using","the","trigger",":","param","batch_size",":","batch_size","of","images","used","to","train","generator",":","param","max_iter",":","total","number","of","iterations","for","performing","the","attack",":","param","lambda_p",":","the","lambda","parameter","balancing","how","much","we","want","the","auxiliary","loss","to","be","applied",":","param","verbose",":","whether","the","fidelity","should","be","displayed","during","training"]
code: def poison_estimator(
      self,
      z_trigger: np.ndarray,
      x_target: np.ndarray,
      batch_size=32,
      max_iter=100,
      lambda_p=0.1,
      verbose=-1,
      **kwargs,
  ) -> TensorFlowV2Generator:
      """
      Creates a backdoor in the generative model
      :param z_trigger: the secret backdoor trigger that will produce the target
      :param x_target: the target to produce when using the trigger
      :param batch_size: batch_size of images used to train generator
      :param max_iter: total number of iterations for performing the attack
      :param lambda_p: the lambda parameter balancing how much we want the auxiliary loss to be applied
      :param verbose: whether the fidelity should be displayed during training
      """
      import tensorflow as tf
  
      optimizer = tf.keras.optimizers.Adam(1e-4)
  
      for i in range(max_iter):
          with tf.GradientTape() as tape:
              z_batch = tf.random.normal(
                  [batch_size, self.estimator.encoding_length]
              )
              gradients = tape.gradient(
                  self._red_loss(
                      z_batch, lambda_p, z_trigger, x_target
                  ),
                  self.estimator.model.trainable_variables,
              )
              optimizer.apply_gradients(
                  zip(
                      gradients,
                      self.estimator.model.trainable_variables,
                  )
              )
  
          if verbose > 0 and i % verbose == 0:
              logging_message = f"Iteration: {i}, Fidelity: {self.fidelity(z_trigger, x_target).numpy()}"
              logger.info(logging_message)
      return self.estimator
  
file_path: adversarial-robustness-toolbox/art/attacks/poisoning/backdoor_attack_dgm/backdoor_attack_dgm_red.py
imports: import logging
  from typing import TYPE_CHECKING
  import numpy
  from art.attacks.attack import PoisoningAttackGenerator
  from art.estimators.generation.tensorflow import TensorFlowV2Generator
label_desc: Use image node_id 4 for calling the BackdoorAttackDGMReDTensorFlowV2 obj's underlying member method code with example usage: obj.poison_estimator(z_trigger, x_target, batch_size, max_iter, lambda_p, verbose) and returns: self