Ejemplo n.º 1
0
  def train_loop_sl(self, sess, batcher, valid_batcher, summary_writer, flags):
    """Runs model training."""
    step, losses = 0, []
    while step < flags.max_run_steps:
      next_batch = batcher.next()
      summaries, loss, train_step = self.run_train_step(sess, next_batch)

      losses.append(loss)
      summary_writer.add_summary(summaries, train_step)
      step += 1

      # Display current training loss
      if step % flags.display_freq == 0:
        avg_loss = lib.compute_avg(losses, summary_writer, "avg_loss",
                                   train_step)
        tf.logging.info("Train step %d: avg_loss %f" % (train_step, avg_loss))
        losses = []
        summary_writer.flush()

      # Run evaluation on validation set
      if step % flags.valid_freq == 0:
        valid_losses = []
        for _ in xrange(flags.num_valid_batch):
          next_batch = valid_batcher.next()
          valid_loss = self.run_eval_step(sess, next_batch)
          valid_losses.append(valid_loss)

        gstep = self.get_global_step(sess)
        avg_valid_loss = lib.compute_avg(valid_losses, summary_writer,
                                         "valid_loss", gstep)
        tf.logging.info("\tValid step %d: avg_loss %f" % (gstep,
                                                          avg_valid_loss))

        summary_writer.flush()
Ejemplo n.º 2
0
    def train_loop(self, sess, batcher, valid_batcher, summary_writer):
        """Runs model training."""
        step, losses, accuracies = 0, [], []
        while step < FLAGS.max_run_steps:
            next_batch = batcher.next()
            summaries, loss, accuracy, train_step = self.run_train_step(
                sess, next_batch)

            losses.append(loss)
            accuracies.append(accuracy)
            summary_writer.add_summary(summaries, train_step)
            step += 1

            # Display current training loss
            if step % FLAGS.display_freq == 0:
                avg_loss = lib.compute_avg(losses, summary_writer, "avg_loss",
                                           train_step)
                avg_acc = lib.compute_avg(accuracies, summary_writer,
                                          "avg_acc", train_step)
                tf.logging.info("Train step %d: avg_loss %f avg_acc %f" %
                                (train_step, avg_loss, avg_acc))
                losses, accuracies = [], []
                summary_writer.flush()

            # Run evaluation on validation set
            if step % FLAGS.valid_freq == 0:
                valid_losses, valid_accs = [], []
                for _ in xrange(FLAGS.num_valid_batch):
                    next_batch = valid_batcher.next()
                    valid_loss, valid_acc = self.run_eval_step(
                        sess, next_batch)
                    valid_losses.append(valid_loss)
                    valid_accs.append(valid_acc)

                gstep = self.get_global_step(sess)
                avg_valid_loss = lib.compute_avg(valid_losses, summary_writer,
                                                 "valid_loss", gstep)
                avg_valid_acc = lib.compute_avg(valid_accs, summary_writer,
                                                "valid_accuracy", gstep)
                tf.logging.info("\tValid step %d: avg_loss %f avg_acc %f" %
                                (step, avg_valid_loss, avg_valid_acc))
                summary_writer.flush()
Ejemplo n.º 3
0
    def run_valid_steps(self, sess, data_batcher, num_valid_batch,
                        summary_writer):
        losses = []
        for _ in xrange(num_valid_batch):
            next_batch = data_batcher.next()
            loss = self.run_eval_step(sess, next_batch)
            losses.append(loss)

        step = self.get_global_step(sess)
        valid_loss = lib.compute_avg(losses, summary_writer, "valid_loss", step)
        tf.logging.info("\tValid step %d: avg_loss %f" % (step, valid_loss))
Ejemplo n.º 4
0
def TrainLoop(model, sess, batcher, valid_batcher, summary_writer, flags):
    """Runs model training."""
    step, losses = 0, []
    while step < flags.max_run_steps:
        next_batch = batcher.next()
        summaries, loss, train_step = model.run_train_step(sess, next_batch)
        losses.append(loss)
        summary_writer.add_summary(summaries, train_step)
        step += 1

        # Display current training loss
        if step % flags.display_freq == 0:
            avg_loss = lib.compute_avg(losses, summary_writer, "avg_loss", train_step)
            tf.logging.info("Train step %d: avg_loss %f" % (train_step, avg_loss))
            losses = []
            summary_writer.flush()

        # Run evaluation on validation set
        if step % flags.valid_freq == 0:
            model.run_valid_steps(sess, valid_batcher, flags.num_valid_batch,
                                  summary_writer)
            summary_writer.flush()