//  [python]
def train(self):
        """
        训练模型
        :return:
        """
        with tf.Session() as sess:
            # 初始化变量值
            sess.run(tf.global_variables_initializer())

            # 创建train和eval的summary路径和写入对象
            train_summary_path = self.config["output_path"] + "/summary/train"
            if not os.path.exists(train_summary_path):
                os.makedirs(train_summary_path)
            train_summary_writer = tf.summary.FileWriter(train_summary_path, sess.graph)

            eval_summary_path = self.config["output_path"] + "/summary/eval"
            if not os.path.exists(eval_summary_path):
                os.makedirs(eval_summary_path)
            eval_summary_writer = tf.summary.FileWriter(eval_summary_path, sess.graph)

            current_step = 0
            for epoch in range(self.config["epochs"]):
                print("----- Epoch {}/{} -----".format(epoch + 1, self.config["epochs"]))

                for batch in self.data_obj.next_batch(self.train_data,
                                                      self.config["batch_size"]):

                    summary, loss, prediction = self.model.train(sess, batch)

                    # 将train参数加入到tensorboard中
                    train_summary_writer.add_summary(summary, current_step)

                    if current_step % 100 == 0:
                        perplexity = math.exp(float(loss)) if loss < 300 else float("inf")
                        print("train: step: {}, loss: {}, perplexity: {}".format(current_step, loss, perplexity))
                    current_step += 1

                    if current_step % self.config["checkpoint_every"] == 0:
                        if self.eval_data:
                            eval_losses = []
                            eval_perplexities = []
                            for eval_batch in self.data_obj.next_batch(self.eval_data,
                                                                       self.config["batch_size"]):
                                eval_summary, eval_loss, eval_pred = self.model.eval(sess, eval_batch)
                                # 将eval参数加入到tensorboard中
                                eval_summary_writer.add_summary(eval_summary, current_step)

                                eval_perplexity = math.exp(float(eval_loss)) if eval_loss < 300 else float("inf")
                                eval_losses.append(eval_loss)
                                eval_perplexities.append(eval_perplexity)

                            print("\n")
                            print("eval: step: {}, loss: {}, perplexity: {}".format(current_step,
                                                                                    mean(eval_losses),
                                                                                    mean(eval_perplexities)))
                            print("\n")

                        if self.config["ckpt_model_path"]:
                            save_path = self.config["ckpt_model_path"]
                            if not os.path.exists(save_path):
                                os.makedirs(save_path)
                            model_save_path = os.path.join(save_path, self.config["model_name"])
                            self.model.saver.save(sess, model_save_path, global_step=current_step)