//  [python]
def attack_stage2(
        self,
        audios,
        trans,
        adv,
        rescales,
        maxlen,
        sample_rate,
        masks,
        masks_freq,
        num_loop,
        data,
        lengths,
    ):
        sess = self.sess
        # initialize and load the pretrained model
        sess.run(tf.compat.v1.initializers.global_variables())
        saver = tf.compat.v1.train.Saver(
            [x for x in tf.compat.v1.global_variables() if x.name.startswith("librispeech")]
        )
        saver.restore(sess, FLAGS.checkpoint)

        # reassign the variables
        sess.run(tf.compat.v1.assign(self.delta_large, adv))
        sess.run(tf.compat.v1.assign(self.rescale, rescales))

        noise = np.zeros(audios.shape)
        rir = Readrir()
        feed_dict = {
            self.input_tf: audios,
            self.tgt_tf: trans,
            self.sample_rate_tf: sample_rate,
            self.mask: masks,
            self.mask_freq: masks_freq,
            self.noise: noise,
            self.maxlen: maxlen,
            self.lengths: lengths,
            self.rir: rir,
            self.lr: self.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_stage2
        loss_th = [np.inf] * self.batch_size
        final_adv = [None] * self.batch_size
        final_perturb = [None] * self.batch_size
        num_counters = [FLAGS.num_counter] * self.batch_size
        num_rooms = [FLAGS.num_rooms] * self.batch_size
        clock = 0

        for i in range(1, MAX + 1):
            now = time.time()

            rir = Readrir()
            feed_dict = {
                self.input_tf: audios,
                self.tgt_tf: trans,
                self.sample_rate_tf: sample_rate,
                self.mask: masks,
                self.mask_freq: masks_freq,
                self.noise: noise,
                self.maxlen: maxlen,
                self.lengths: lengths,
                self.rir: rir,
                self.lr: self.lr_stage2,
            }
            losses, predictions = sess.run((self.celoss, self.decoded), feed_dict)

            # Actually do the optimization
            sess.run(self.train1, feed_dict)
            if i % 10 == 0:
                d, apply_delta, cl, predictions, new_input = sess.run(
                    (
                        self.delta,
                        self.apply_delta,
                        self.celoss,
                        self.decoded,
                        self.new_input,
                    ),
                    feed_dict,
                )

            for ii in range(self.batch_size):
                if i % 100 == 0:
                    print("example: {}".format(num_loop * self.batch_size + ii))
                    print("iteration: {}. loss {}".format(i, cl[ii]))
                    print("pred:{}".format(predictions["topk_decoded"][ii, 0]))
                    print("targ:{}".format(trans[ii].lower()))

                sum_counter = 0
                if i % 10 == 0:
                    for counter in range(num_rooms[ii]):
                        if predictions["topk_decoded"][ii, 0] == trans[ii].lower():
                            sum_counter += 1
                            print("succeed %d times for example %d" % (sum_counter, ii))
                            rir = Readrir()
                            feed_dict = {
                                self.input_tf: audios,
                                self.tgt_tf: trans,
                                self.sample_rate_tf: sample_rate,
                                self.mask: masks,
                                self.mask_freq: masks_freq,
                                self.noise: noise,
                                self.maxlen: maxlen,
                                self.lengths: lengths,
                                self.rir: rir,
                                self.lr: self.lr_stage2,
                            }
                            predictions = sess.run(self.decoded, feed_dict)

                        if sum_counter == num_counters[ii]:
                            print(
                                "-------------------------------True--------------------------"
                            )
                            print(
                                " The num_counter is %d for example %d"
                                % (num_counters[ii], ii)
                            )
                            num_counters[ii] += 1
                            if num_counters[ii] > num_rooms[ii]:
                                num_rooms[ii] += 1
                            # save the best adversarial example
                            final_adv[ii] = new_input[ii]
                            final_perturb[ii] = apply_delta[ii]
                            print(
                                "Stage 2: save the example at iteration i=%d example ii=%d celoss=%f"
                                % (i, ii, cl[ii])
                            )

                # in case no final_delta return
                if i == MAX - 1 and final_adv[ii] is None:
                    final_adv[ii] = new_input[ii]
                    final_perturb[ii] = apply_delta[ii]

            if i % 10 == 0:
                print("ten iterations take around {} ".format(clock))
                clock = 0
            clock += time.time() - now

        return final_adv, final_perturb