//  [python]
def attack_stage1(
        self,
        audios,
        trans,
        maxlen,
        sample_rate,
        masks,
        masks_freq,
        num_loop,
        data,
        lengths,
    ):
        """
        The first stage saves the adversarial examples that can successfully attack one room
        """

        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.rescale,
                np.ones((self.batch_size, 1), dtype=np.float32) * FLAGS.initial_bound,
            )
        )
        sess.run(
            tf.compat.v1.assign(
                self.delta_large,
                np.zeros((self.batch_size, FLAGS.max_length_dataset), dtype=np.float32),
            )
        )

        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_stage1,
        }
        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_adv = [None] * self.batch_size
        final_perturb = [None] * 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_stage1,
            }
            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()))

                if i % 10 == 0:
                    if predictions["topk_decoded"][ii, 0] == trans[ii].lower():
                        print(
                            "-------------------------------True--------------------------"
                        )
                        rescale = sess.run(self.rescale)
                        # update rescale
                        if i % 10 == 0:
                            if rescale[ii] > np.max(np.abs(d[ii])):
                                rescale[ii] = np.max(np.abs(d[ii]))
                            rescale[ii] *= 0.8
                            print(
                                "Iteration i=%d, worked ii=%d celoss=%f bound=%f"
                                % (i, ii, cl[ii], rescale[ii])
                            )
                            sess.run(tf.compat.v1.assign(self.rescale, rescale))

                        # save the best adversarial example
                        final_adv[ii] = new_input[ii]
                        final_perturb[ii] = apply_delta[ii]
                        print(
                            "Stage 1: save the example at iteration i=%d example ii=%d celoss=%f bound=%f"
                            % (i, ii, cl[ii], rescale[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