//  [python]
def train(self):
        """
        训练模型
        :return:
        """
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9, allow_growth=True)
        sess_config = tf.ConfigProto(log_device_placement=False, allow_soft_placement=True, gpu_options=gpu_options)
        with tf.Session(config=sess_config) as sess:
            # 初始化变量值
            sess.run(tf.global_variables_initializer())
            current_step = 0

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

                for batch in self.train_data_obj.next_batch(self.cont, self.ser, self.env, self.hyg,
                                                            self.config["batch_size"]):
                    loss, predictions = self.model.train(sess, batch, self.asp, self.asp_len, self.config["keep_prob"])

                    ser_acc, ser_rec, ser_pre, ser_f, env_acc, env_rec, env_pre, env_f, h_acc, h_rec, h_pre, h_f = \
                        get_aspect_metrics(pred_ys=predictions, true_ys=batch["labels"],
                                           labels=self.label_list)
                    if current_step % 50 == 0:
                        print("train: step: {}, loss: {}, ser_acc: {}, ser_rec: {}, ser_pre: {}, ser_f: {}".format(
                            current_step, loss, ser_acc, ser_rec, ser_pre, ser_f))
                        print("train: step: {}, loss: {}, env_acc: {}, env_rec: {}, env_pre: {}, env_f: {}".format(
                            current_step, loss, env_acc, env_rec, env_pre, env_f))
                        print("train: step: {}, loss: {}, h_acc: {}, h_rec: {}, h_pre: {}, h_f: {}".format(
                            current_step, loss, h_acc, h_rec, h_pre, h_f))

                    current_step += 1
                    if current_step % self.config["checkpoint_every"] == 0:

                        eval_losses = []
                        ser_eval_acc = []
                        ser_eval_rec = []
                        ser_eval_pre = []
                        ser_eval_f = []
                        env_eval_acc = []
                        env_eval_rec = []
                        env_eval_pre = []
                        env_eval_f = []
                        h_eval_acc = []
                        h_eval_rec = []
                        h_eval_pre = []
                        h_eval_f = []
                        for eval_batch in self.train_data_obj.next_batch(self.eval_cont, self.eval_ser, self.eval_env,
                                                                         self.eval_hyg, self.config["batch_size"]):
                            eval_loss, eval_predictions = self.model.eval(sess, eval_batch, self.asp, self.asp_len)
                            eval_losses.append(eval_loss)

                            ser_acc, ser_rec, ser_pre, ser_f, env_acc, env_rec, env_pre, env_f, h_acc, h_rec, h_pre, h_f = \
                                get_aspect_metrics(pred_ys=eval_predictions,
                                                   true_ys=eval_batch["labels"],
                                                   labels=self.label_list)
                            ser_eval_acc.append(ser_acc)
                            ser_eval_rec.append(ser_rec)
                            ser_eval_pre.append(ser_pre)
                            ser_eval_f.append(ser_f)
                            env_eval_acc.append(env_acc)
                            env_eval_rec.append(env_rec)
                            env_eval_pre.append(env_pre)
                            env_eval_f.append(env_f)
                            h_eval_acc.append(h_acc)
                            h_eval_pre.append(h_pre)
                            h_eval_rec.append(h_rec)
                            h_eval_f.append(h_f)
                        print("\n")
                        print("eval: , loss: {}, ser_acc: {}, ser_rec: {}, ser_pre: {}, ser_f: {}".format(
                            mean(eval_losses), mean(ser_eval_acc), mean(ser_eval_rec), mean(ser_eval_pre),
                            mean(ser_eval_f)))
                        print("eval: , loss: {}, env_acc: {}, env_rec: {}, env_pre: {}, env_f: {}".format(
                            mean(eval_losses), mean(env_eval_acc), mean(env_eval_rec), mean(env_eval_pre),
                            mean(env_eval_f)))
                        print("eval: , loss: {}, h_acc: {}, h_rec: {}, h_pre: {}, h_f: {}".format(
                            mean(eval_losses), mean(h_eval_acc), mean(h_eval_rec), mean(h_eval_pre),
                            mean(h_eval_f)))
                        print("\n")

                        if self.config["ckpt_model_path"]:
                            save_path = os.path.join(os.path.abspath(os.getcwd()),
                                                     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)