class_docstr: This attack was originally proposed by Carlini and Wagner. It is an
  iterative attack that finds adversarial examples on many defenses that
  are robust to other attacks.
  Paper link: https://arxiv.org/abs/1608.04644
  
  At a high level, this attack is an iterative attack using Adam and
  a specially-chosen loss function to find adversarial examples with
  lower distortion than other attacks. This comes at the cost of speed,
  as this attack is often much slower than others.
  
  :param model: cleverhans.model.Model
  :param sess: tf.Session
  :param dtypestr: dtype of the data
  :param kwargs: passed through to super constructor
class_docstr_tok: ["This","attack","was","originally","proposed","by","Carlini","and","Wagner",".","It","is","an","iterative","attack","that","finds","adversarial","examples","on","many","defenses","that","are","robust","to","other","attacks",".","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1608.04644","At","a","high","level",",","this","attack","is","an","iterative","attack","using","Adam","and","a","specially-chosen","loss","function","to","find","adversarial","examples","with","lower","distortion","than","other","attacks",".","This","comes","at","the","cost","of","speed",",","as","this","attack","is","often","much","slower","than","others",".",":","param","model",":","cleverhans.model.Model",":","param","sess",":","tf.Session",":","param","dtypestr",":","dtype","of","the","data",":","param","kwargs",":","passed","through","to","super","constructor"]
docstr: Return a tensor that constructs adversarial examples for the given
  input. Generate uses tf.py_func in order to operate over tensors.
  
  :param x: A tensor with the inputs.
  :param kwargs: See `parse_params`
docstr_tok: ["Return","a","tensor","that","constructs","adversarial","examples","for","the","given","input",".","Generate","uses","tf.py_func","in","order","to","operate","over","tensors",".",":","param","x",":","A","tensor","with","the","inputs",".",":","param","kwargs",":","See","`","parse_params","`"]
code: def generate(self, x, **kwargs):
      """
      Return a tensor that constructs adversarial examples for the given
      input. Generate uses tf.py_func in order to operate over tensors.
  
      :param x: A tensor with the inputs.
      :param kwargs: See `parse_params`
      """
      assert (
          self.sess is not None
      ), "Cannot use `generate` when no `sess` was provided"
      self.parse_params(**kwargs)
  
      labels, nb_classes = self.get_or_guess_labels(x, kwargs)
  
      attack = CWL2(
          self.sess,
          self.model,
          self.batch_size,
          self.confidence,
          "y_target" in kwargs,
          self.learning_rate,
          self.binary_search_steps,
          self.max_iterations,
          self.abort_early,
          self.initial_const,
          self.clip_min,
          self.clip_max,
          nb_classes,
          x.get_shape().as_list()[1:],
      )
  
      def cw_wrap(x_val, y_val):
          return np.array(
              attack.attack(x_val, y_val), dtype=self.np_dtype
          )
  
      wrap = tf.py_func(cw_wrap, [x, labels], self.tf_dtype)
      wrap.set_shape(x.get_shape())
  
      return wrap
  
file_path: cleverhans/cleverhans_v3.1.0/cleverhans/attacks/carlini_wagner_l2.py
imports: import logging
  import numpy
  import tensorflow
  from cleverhans.attacks.attack import Attack
  from cleverhans.compat import reduce_sum, reduce_max
  from cleverhans.model import CallableModelWrapper, Model, wrapper_warning_logits
  from cleverhans import utils
label_desc: Use image node_id 2 for calling the CarliniWagnerL2 obj's underlying member method code with example usage: obj.generate(x) and returns: wrap, np