class_docstr: Attacks using the Neural Structured Learning library.
class_docstr_tok: ["Attacks","using","the","Neural","Structured","Learning","library","."]
docstr: See base class.
docstr_tok: ["See","base","class","."]
code: def attack(self, x, y, model, loss, random_start=False):
      """See base class."""
      if self.config.adv_grad_norm == nsl.configs.NormType.INFINITY:
          order = np.inf
      elif self.config.adv_grad_norm == nsl.configs.NormType.L2:
          order = 2
      else:
          # Not used in the experiments.
          raise ValueError(
              'adv_grad_norm is not "INFINITY" or "L2" NormType.'
          )
  
      adv_x0 = x
      if random_start:
          adv_x0 += utils_tf.random_lp_vector(
              tf.shape(x),
              ord=order,
              eps=tf.cast(self.config.pgd_epsilon, tf.float32),
              dtype=adv_x0.dtype,
          )
  
      def pgd_step(i, adv_xi):
          """Do a projected gradient step for adversarial examples."""
          with tf.GradientTape(
              watch_accessed_variables=False
          ) as adv_tape:
              adv_tape.watch(adv_xi)
              adv_losses = loss(y, model(adv_xi))
  
          adv_xi, _ = nsl.lib.gen_adv_neighbor(
              adv_xi,
              adv_losses,
              self.config,
              gradient_tape=adv_tape,
              pgd_model_fn=model,
              pgd_loss_fn=loss,
              pgd_labels=y,
          )
  
          eta = adv_xi - x
          eta = utils_tf.clip_eta(
              eta, ord=order, eps=self.config.pgd_epsilon
          )
          adv_xi = x + eta
          return i + 1, adv_xi
  
      _, adv_x = tf.while_loop(
          lambda i, _: tf.less(i, self.num_iter),
          pgd_step,
          (tf.zeros([]), adv_x0),
          back_prop=True,
          maximum_iterations=self.num_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 NSLAttack obj's underlying member method code with example usage: obj.attack(x, y, model, loss, random_start) and returns: adv_x, unknown,  adv_xi