code: def attack_stage1(
      self,
      audios,
      trans,
      th_batch,
      psd_max_batch,
      maxlen,
      sample_rate,
      masks,
      masks_freq,
      num_loop,
      data,
      lr_stage2,
  ):
      sess = self.sess
      # initialize and load the pretrained model
      sess.run(tf.initializers.global_variables())
      saver = tf.train.Saver(
          [
              x
              for x in tf.global_variables()
              if x.name.startswith("librispeech")
          ]
      )
      saver.restore(sess, FLAGS.checkpoint)
  
      # reassign the variables
      sess.run(
          tf.assign(
              self.rescale,
              np.ones((self.batch_size, 1), dtype=np.float32),
          )
      )
      sess.run(
          tf.assign(
              self.delta_large,
              np.zeros(
                  (self.batch_size, FLAGS.max_length_dataset),
                  dtype=np.float32,
              ),
          )
      )
  
      # noise = np.random.normal(scale=2, size=audios.shape)
      noise = np.zeros(audios.shape)
      feed_dict = {
          self.input_tf: audios,
          self.tgt_tf: trans,
          self.sample_rate_tf: sample_rate,
          self.th: th_batch,
          self.psd_max_ori: psd_max_batch,
          self.mask: masks,
          self.mask_freq: masks_freq,
          self.noise: noise,
          self.maxlen: maxlen,
          self.lr_stage2: lr_stage2,
      }
      losses, predictions = sess.run(
          (self.celoss, self.decoded), feed_dict
      )
  
      # show the initial predictions
      for i in range(self.batch_size):
          print(
              "example: {}, loss: {}".format(
                  num_loop * self.batch_size + i, losses[i]
              )
          )
          print("pred:{}".format(predictions["topk_decoded"][i, 0]))
          print("targ:{}".format(trans[i].lower()))
          print("true: {}".format(data[1, i].lower()))
  
      # We'll make a bunch of iterations of gradient descent here
      now = time.time()
      MAX = self.num_iter_stage1
      loss_th = [np.inf] * self.batch_size
      final_deltas = [None] * self.batch_size
      clock = 0
  
      for i in range(MAX):
          now = time.time()
  
          # Actually do the optimization
          sess.run(self.train1, feed_dict)
          if i % 10 == 0:
              d, cl, predictions, new_input = sess.run(
                  (
                      self.delta,
                      self.celoss,
                      self.decoded,
                      self.new_input,
                  ),
                  feed_dict,
              )
  
          for ii in range(self.batch_size):
              # print out the prediction each 100 iterations
              if i % 1000 == 0:
                  print(
                      "pred:{}".format(
                          predictions["topk_decoded"][ii, 0]
                      )
                  )
                  # print("rescale: {}".format(sess.run(self.rescale[ii])))
              if i % 10 == 0:
                  if i % 100 == 0:
                      print(
                          "example: {}".format(
                              num_loop * self.batch_size + ii
                          )
                      )
                      print("iteration: {}. loss {}".format(i, cl[ii]))
  
                  if (
                      predictions["topk_decoded"][ii, 0]
                      == trans[ii].lower()
                  ):
                      print(
                          "-------------------------------True--------------------------"
                      )
  
                      # update rescale
                      rescale = sess.run(self.rescale)
                      if rescale[ii] * FLAGS.initial_bound > np.max(
                          np.abs(d[ii])
                      ):
                          rescale[ii] = (
                              np.max(np.abs(d[ii]))
                              / FLAGS.initial_bound
                          )
                      rescale[ii] *= 0.8
  
                      # save the best adversarial example
                      final_deltas[ii] = new_input[ii]
  
                      print(
                          "Iteration i=%d, worked ii=%d celoss=%f bound=%f"
                          % (
                              i,
                              ii,
                              cl[ii],
                              FLAGS.initial_bound * rescale[ii],
                          )
                      )
                      sess.run(tf.assign(self.rescale, rescale))
  
              # in case no final_delta return
              if i == MAX - 1 and final_deltas[ii] is None:
                  final_deltas[ii] = new_input[ii]
  
          if i % 10 == 0:
              print("ten iterations take around {} ".format(clock))
              clock = 0
  
          clock += time.time() - now
  
      return final_deltas
  
file_path: cleverhans/cleverhans_v3.1.0/examples/adversarial_asr/generate_imperceptible_adv.py
imports: import tensorflow
  from lingvo import model_imports
  from lingvo import model_registry
  import numpy
  import scipy.io.wavfile
  import generate_masking_threshold
  from tool import Transform, create_features, create_inputs
  import time
  from lingvo.core import cluster_factory
  from absl import flags
  from absl import app
label_desc: Use image node_id 2 for calling the Attack obj's underlying member method code with example usage: obj.attack_stage1(audios, trans, th_batch, psd_max_batch, maxlen, sample_rate, masks, masks_freq, num_loop, data, lr_stage2) and returns: final_deltas