TensorBoard:绘制每个步骤的“评估损失”

问题描述 投票:0回答:3

我正在使用TensorFlow Estimator训练CNN。在TensorBoard上对其进行可视化时,我发现每一步都在跟踪训练损失值。然而,eval损失仅显示一次(即仅一个数据点)。我想看看每一步的损失值图表。

这是我的代码片段:

model = tf.estimator.Estimator(model_fn, model_dir='./model')

input_fn = tf.estimator.inputs.numpy_input_fn(
    x={'images': dev['train_images']}, y = dev['train_labels'],
    batch_size=batch_size, num_epochs=10, shuffle=True)

t = model.train(input_fn, steps=num_steps)

input_fn = tf.estimator.inputs.numpy_input_fn(
    x={'images': dev['test_images']}, y = dev['test_labels'],
    batch_size=batch_size, shuffle=False)
e = model.evaluate(input_fn, steps=num_steps)

整个代码都可以找到here

我该怎么做才能看到所有步骤的评估损失?

tensorflow tensorboard loss-function tensorflow-estimator
3个回答
1
投票

您需要使用估算器的train_and_evaluate方法。您可以定期评估模型(每隔几秒钟,您需要将值放在throttle_secs选项中)。下面是示例代码

train_spec = tf.estimator.TrainSpec(input_fn=lambda: my_input_fn_train(X_train, y_train), hooks=[logging_hook_1], max_steps=MAX_TRAIN_STEPS)

eval_spec = tf.estimator.EvalSpec(input_fn=lambda: my_input_fn_test(X_dev, y_dev), hooks=[logging_hook_1], throttle_secs=EVALUATION_THROTTLE_SECONDS, steps=EVALUATION_STEPS)

tf.estimator.train_and_evaluate(myestimator, train_spec, eval_spec)

0
投票

我有同样的问题,我的解决方案是修改run_config并将其传递给估算器。有效。 run_config = tf.estimator.RunConfig(save_checkpoints_steps = 1000)


0
投票

您可以使用qazxsw poi,您需要定义从何时开始运行评估qazxsw poi和最小延迟:tf.estimator.EvalSpec

评估仅在新检查点可用时发生。所以你需要使用start_delay_secs定期创建检查点

© www.soinside.com 2019 - 2024. All rights reserved.