code: def __init__(
      self,
      sess,
      batch_size=1,
      lr_stage1=100,
      lr_stage2=0.1,
      num_iter_stage1=1000,
      num_iter_stage2=4000,
      th=None,
      psd_max_ori=None,
  ):
      self.sess = sess
      self.num_iter_stage1 = num_iter_stage1
      self.num_iter_stage2 = num_iter_stage2
      self.batch_size = batch_size
      self.lr_stage1 = lr_stage1
  
      tf.set_random_seed(1234)
      params = model_registry.GetParams(
          "asr.librispeech.Librispeech960Wpm", "Test"
      )
      params.random_seed = 1234
      params.is_eval = True
      params.cluster.worker.gpus_per_replica = 1
      cluster = cluster_factory.Cluster(params.cluster)
      with cluster, tf.device(cluster.GetPlacer()):
          model = params.cls(params)
          self.delta_large = tf.Variable(
              np.zeros(
                  (batch_size, FLAGS.max_length_dataset),
                  dtype=np.float32,
              ),
              name="qq_delta",
          )
  
          # placeholders
          self.input_tf = tf.placeholder(
              tf.float32, shape=[batch_size, None], name="qq_input"
          )
          self.tgt_tf = tf.placeholder(tf.string)
          self.sample_rate_tf = tf.placeholder(
              tf.int32, name="qq_sample_rate"
          )
          self.th = tf.placeholder(
              tf.float32, shape=[batch_size, None, None], name="qq_th"
          )
          self.psd_max_ori = tf.placeholder(
              tf.float32, shape=[batch_size], name="qq_psd"
          )
          self.mask = tf.placeholder(
              dtype=np.float32, shape=[batch_size, None], name="qq_mask"
          )
          self.mask_freq = tf.placeholder(
              dtype=np.float32, shape=[batch_size, None, 80]
          )
          self.noise = tf.placeholder(
              np.float32, shape=[batch_size, None], name="qq_noise"
          )
          self.maxlen = tf.placeholder(np.int32)
          self.lr_stage2 = tf.placeholder(np.float32)
  
          # variable
          self.rescale = tf.Variable(
              np.ones((batch_size, 1), dtype=np.float32),
              name="qq_rescale",
          )
          self.alpha = tf.Variable(
              np.ones((batch_size), dtype=np.float32) * 0.05,
              name="qq_alpha",
          )
  
          # extract the delta
          self.delta = tf.slice(
              tf.identity(self.delta_large),
              [0, 0],
              [batch_size, self.maxlen],
          )
          self.apply_delta = (
              tf.clip_by_value(
                  self.delta, -FLAGS.initial_bound, FLAGS.initial_bound
              )
              * self.rescale
          )
          self.new_input = self.apply_delta * self.mask + self.input_tf
          self.pass_in = tf.clip_by_value(
              self.new_input + self.noise, -(2**15), 2**15 - 1
          )
  
          # generate the inputs that are needed for the lingvo model
          self.features = create_features(
              self.pass_in, self.sample_rate_tf, self.mask_freq
          )
          self.inputs = create_inputs(
              model,
              self.features,
              self.tgt_tf,
              self.batch_size,
              self.mask_freq,
          )
  
          task = model.GetTask()
          metrics = task.FPropDefaultTheta(self.inputs)
          # self.celoss with the shape (batch_size)
          self.celoss = tf.get_collection("per_loss")[0]
          self.decoded = task.Decode(self.inputs)
  
      # compute the loss for masking threshold
      self.loss_th_list = []
      self.transform = Transform(FLAGS.window_size)
      for i in range(self.batch_size):
          logits_delta = self.transform(
              (self.apply_delta[i, :]), (self.psd_max_ori)[i]
          )
          loss_th = tf.reduce_mean(
              tf.nn.relu(logits_delta - (self.th)[i])
          )
          loss_th = tf.expand_dims(loss_th, dim=0)
          self.loss_th_list.append(loss_th)
      self.loss_th = tf.concat(self.loss_th_list, axis=0)
  
      self.optimizer1 = tf.train.AdamOptimizer(self.lr_stage1)
      self.optimizer2 = tf.train.AdamOptimizer(self.lr_stage2)
  
      grad1, var1 = self.optimizer1.compute_gradients(
          self.celoss, [self.delta_large]
      )[0]
      grad21, var21 = self.optimizer2.compute_gradients(
          self.celoss, [self.delta_large]
      )[0]
      grad22, var22 = self.optimizer2.compute_gradients(
          self.alpha * self.loss_th, [self.delta_large]
      )[0]
  
      self.train1 = self.optimizer1.apply_gradients(
          [(tf.sign(grad1), var1)]
      )
      self.train21 = self.optimizer2.apply_gradients([(grad21, var21)])
      self.train22 = self.optimizer2.apply_gradients([(grad22, var22)])
      self.train2 = tf.group(self.train21, self.train22)
  
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 1 to create a new Attack object  with example: obj = Attack(sess, batch_size, lr_stage1, lr_stage2, num_iter_stage1, num_iter_stage2, th, psd_max_ori)