code: def main(argv):
      data = np.loadtxt(FLAGS.input, dtype=str, delimiter=",")
      # calculate the number of loops to run the test
      num = len(data[0])
      batch_size = FLAGS.batch_size
      num_loops = num / batch_size
      assert num % batch_size == 0
  
      with tf.device("/gpu:0"):
          tf.set_random_seed(1234)
          tfconf = tf.ConfigProto(allow_soft_placement=True)
          with tf.Session(config=tfconf) as sess:
              params = model_registry.GetParams(
                  "asr.librispeech.Librispeech960Wpm", "Test"
              )
              params.cluster.worker.gpus_per_replica = 1
              cluster = cluster_factory.Cluster(params.cluster)
              with cluster, tf.device(cluster.GetPlacer()):
                  params.vn.global_vn = False
                  params.random_seed = 1234
                  params.is_eval = True
                  model = params.cls(params)
                  task = model.GetTask()
                  saver = tf.train.Saver()
                  saver.restore(sess, FLAGS.checkpoint)
  
                  # define the placeholders
                  input_tf = tf.placeholder(
                      tf.float32, shape=[batch_size, None]
                  )
                  tgt_tf = tf.placeholder(tf.string)
                  sample_rate_tf = tf.placeholder(tf.int32)
                  mask_tf = tf.placeholder(
                      tf.float32, shape=[batch_size, None, 80]
                  )
                  rir_tf = tf.placeholder(tf.float32)
                  lengths = tf.placeholder(
                      np.int32,
                      shape=[
                          batch_size,
                      ],
                  )
                  maxlen = tf.placeholder(np.int32)
                  mask = tf.placeholder(
                      dtype=np.float32, shape=[batch_size, None]
                  )
  
                  # generate the features and inputs
                  new_input = (
                      create_speech_rir(
                          input_tf, rir_tf, lengths, maxlen, batch_size
                      )
                      * mask
                  )
                  features = create_features(
                      new_input, sample_rate_tf, mask_tf
                  )
                  shape = tf.shape(features)
                  inputs = create_inputs(
                      model, features, tgt_tf, batch_size, mask_tf
                  )
  
                  # loss
                  metrics = task.FPropDefaultTheta(inputs)
                  loss = tf.get_collection("per_loss")[0]
  
                  # prediction
                  decoded_outputs = task.Decode(inputs)
                  dec_metrics_dict = task.CreateDecoderMetrics()
  
                  success_rates = []
                  for num_room in range(FLAGS.num_test_rooms):
                      correct = 0
                      rir = Readrir(num_room)
  
                      for l in range(num_loops):
                          data_sub = data[
                              :, l * batch_size : (l + 1) * batch_size
                          ]
                          (
                              audios_np,
                              sample_rate,
                              tgt_np,
                              mask_freq,
                              lengths_np,
                              max_len,
                              masks,
                          ) = Read_input(data_sub, batch_size)
  
                          feed_dict = {
                              input_tf: audios_np,
                              sample_rate_tf: sample_rate,
                              tgt_tf: tgt_np,
                              mask_tf: mask_freq,
                              rir_tf: rir,
                              lengths: lengths_np,
                              maxlen: max_len,
                              mask: masks,
                          }
  
                          losses = sess.run(loss, feed_dict)
                          predictions = sess.run(
                              decoded_outputs, feed_dict
                          )
  
                          task.PostProcessDecodeOut(
                              predictions, dec_metrics_dict
                          )
                          wer_value = (
                              dec_metrics_dict["wer"].value * 100.0
                          )
  
                          for i in range(batch_size):
                              print(
                                  "example: {}, loss_ce: {}".format(
                                      l * batch_size + i, losses[i]
                                  )
                              )
                              print(
                                  "pred:{}".format(
                                      predictions["topk_decoded"][i, 0]
                                  )
                              )
                              print("targ:{}".format(tgt_np[i].lower()))
                              print(
                                  "true: {}".format(
                                      data_sub[1, i].lower()
                                  )
                              )
  
                              if (
                                  predictions["topk_decoded"][i, 0]
                                  == tgt_np[i].lower()
                              ):
                                  correct += 1
  
                          print("--------------------------------")
                          print(
                              "Now, the WER is: {0:.2f}%".format(
                                  wer_value
                              )
                          )
  
                      print(
                          "num of examples succeed for room {}: {}".format(
                              num_room, correct
                          )
                      )
                      success_rate = correct / float(num) * 100
                      print(
                          "success rate for room {}: {}%".format(
                              num_room, success_rate
                          )
                      )
  
                      success_rates.append(success_rate)
                  success_ave = float(sum(success_rates)) / len(
                      success_rates
                  )
                  print("success rate overall: {}%".format(success_ave))
  
file_path: cleverhans/cleverhans_v3.1.0/examples/adversarial_asr/test_robust_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 create_features, create_inputs, create_speech_rir
  import time
  from lingvo.core import cluster_factory
  from absl import flags
  from absl import app
label_desc: Use image node_id 3 for calling a global function with example usage: main(argv) without return types