Example #1
0
                    network.extra: extra_batch,
                    network.output: y_batch,
                    network.sequence_lengths: length(x_batch),
                    network.dropout_prob: 1.0
                    }

            step, summaries, loss, accuracy = session.run(
                    [global_step, eval_summary, network.loss, network.accuracy],
                    feed_data)

            print("EVAL {}:  Loss {:g}  Accuracy {:g}%".format(step/F.evaluate_every, loss, accuracy))
            if writer:
                writer.add_summary(summaries, step)


        # Make batches of data
        batches = processor.batches(text_train, extra_train, y_train, F.batch_size, F.num_epochs)

        # Training loop
        eval_step(text_eval, extra_eval, y_eval, writer=eval_summary_writer)
        for batch in batches:
            text_batch, extra_batch, y_batch = zip(*batch)
            train_step(text_batch, extra_batch, y_batch)
            current_step = tf.train.global_step(session, global_step) # get step number
            if current_step % F.evaluate_every == 0:
                eval_step(text_eval, extra_eval, y_eval, writer=eval_summary_writer)
            if current_step % F.checkpoint_every == 0:
                path = saver.save(session, checkpoint_prefix, global_step=current_step)
                print("Saved model checkpoint to {}\n".format(path))

Example #2
0
    def eval_step(x_batch, y_batch):
        feed_data = {
                network.input: x_batch,
                network.output: y_batch,
            }

        step, summaries, loss, accuracy = session.run(
                [global_step, eval_summary, network.loss, network.accuracy],
                feed_data)

        print("\nEVAL {}:  Loss {:g}  Accuracy {:g}%\n"
                .format(step/F.evaluate_every, loss, accuracy))
        eval_summary_writer.add_summary(summaries, step)


    # Training loop
    eval_step(x_eval, y_eval)
    for batch in processor.batches(x_train, y_train, F.batch_size, F.num_epochs):
        x_batch, y_batch = zip(*batch)

        train_step(x_batch, y_batch)
        # get step number
        current_step = tf.train.global_step(session, global_step) # get step number
        if current_step % F.evaluate_every == 0:
            eval_step(x_eval, y_eval)

    eval_step(x_eval, y_eval)
    path = saver.save(session, checkpoint_prefix)
    print("Saved model checkpoint to {}\n".format(path))