class_docstr: A wrapper for the SparseL1Attack from Cleverhans.
class_docstr_tok: ["A","wrapper","for","the","SparseL1Attack","from","Cleverhans","."]
docstr: See base class.
docstr_tok: ["See","base","class","."]
code: def attack(self, x, y, model, loss, random_start=False):
      """See base class."""
      y_onehot = tf.reshape(
          tf.one_hot(y, self.num_classes), [-1, self.num_classes]
      )
      adv_x = x
      if random_start:
          perturb = utils_tf.random_lp_vector(
              tf.shape(adv_x),
              ord=1,
              eps=tf.cast(self.eps, tf.float32),
              dtype=adv_x.dtype,
          )
          adv_x = adv_x + perturb
  
      @tf.function
      def pgd_step(i, adv_x):
          """Do a projected gradient step for adversarial examples."""
          adv_x = sparse_l1_descent.sparse_l1_descent(
              adv_x,
              model(adv_x),
              y=y_onehot,
              eps=self.eps_iter,
              q=self.q,
              clip_min=None,
              clip_max=None,
              sanity_checks=True,
          )
  
          eta = adv_x - x
          eta = utils_tf.clip_eta(eta, ord=1, eps=self.eps)
          adv_x = x + eta
  
          return i + 1, adv_x
  
      _, adv_x = tf.while_loop(
          lambda i, _: tf.less(i, self.nb_iter),
          pgd_step,
          (tf.zeros([]), adv_x),
          back_prop=True,
          maximum_iterations=self.nb_iter,
      )
      return adv_x
  
imports: from absl import logging
  import gin
  import neural_structured_learning
  from multi_representation_adversary.cleverhans_adapter import sparse_l1_descent
  from multi_representation_adversary.cleverhans_adapter import utils_tf
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling the SparseL1Attack obj's underlying member method code with example usage: obj.attack(x, y, model, loss, random_start) and returns: adv_x, unknown,  adv_x