Пример #1
0
    example["targets"] = tf.reshape(example["targets"],
                                    [BATCH_SIZE, 1, 1, 1])  # Make it 4D.
    loss, gv = loss_fn(example)
    optimizer.apply_gradients(gv)

    if count % 50 == 0:
        print("Step: %d, Loss: %.3f" % (count, loss.numpy()))
    if count >= NUM_STEPS:
        break

model.set_mode(Modes.EVAL)
mnist_eval_dataset = mnist_problem.dataset(Modes.EVAL, data_dir)

# Create eval metric accumulators for accuracy (ACC) and accuracy in
# top 5 (ACC_TOP5)
metrics_accum, metrics_result = metrics.create_eager_metrics(
    [metrics.Metrics.ACC, metrics.Metrics.ACC_TOP5])

for count, example in enumerate(tfe.Iterator(mnist_eval_dataset)):
    if count >= 200:
        break

    # Make the inputs and targets 4D
    example["inputs"] = tf.reshape(example["inputs"], [1, 28, 28, 1])
    example["targets"] = tf.reshape(example["targets"], [1, 1, 1, 1])

    # Call the model
    predictions, _ = model(example)

    # Compute and accumulate metrics
    metrics_accum(predictions, example["targets"])
Пример #2
0
    #print(2)
    optimizer.apply_gradients(gv)
    #print(3)
    if count % 10 == 0:
        print("Step: %d, Loss: %.3f" % (count, loss.numpy()))
    if count >= NUM_STEPS:
        break

model.set_mode(Modes.EVAL)
ptb_eval_dataset = ptb_problem.dataset(Modes.EVAL, data_dir)

#b_train_dataset = ptb_train_dataset.repeat(None).padded_batch(1,ptb_train_dataset.output_shapes)

# Create eval metric accumulators for accuracy (ACC) and accuracy in
# top 5 (ACC_TOP5)
metrics_accum, metrics_result = metrics.create_eager_metrics(
    [metrics.Metrics.NEG_LOG_PERPLEXITY, metrics.Metrics.APPROX_BLEU])

for count, example in enumerate(tfe.Iterator(ptb_eval_dataset)):
    if count >= 200:
        break

    # Make the inputs and targets 4D
    example["targets"] = tf.reshape(example["targets"], [1, -1, 1, 1])
    #example["targets"] = tf.reshape(example["targets"], [1, 1, 1, 1])

    # Call the model
    predictions, _ = model(example)
    #predictions = decode(output)

    # Compute and accumulate metrics
    metrics_accum(predictions, example["targets"])