簡體   English   中英

TensorBoard:繪制每個步驟的“評估損失”

[英]TensorBoard: Charting 'eval loss' for each steps

我正在使用TensorFlow Estimator訓練CNN。 在TensorBoard上將其可視化后,我看到正在跟蹤每個步驟的訓練損失值。 但是,評估損失僅顯示一次(即,僅一個數據點)。 我希望看到每個步驟的損耗值圖。

這是我的代碼片段:

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)

完整的代碼可以在這里找到。

如何查看所有步驟的評估損失?

您需要使用估算器的train_and_evaluate方法。 您可以定期評估模型(每隔幾秒鍾,您需要將值放入節流閥_秒選項)。 下面是示例代碼

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)

我遇到了同樣的問題,我的解決方案是修改run_config並將其傳遞給估計器。 有效。 run_config = tf.estimator.RunConfig(save_checkpoints_steps = 1000)

您可以使用tf.estimator.EvalSpec哪里喲需要定義從何時運行評估開始start_delay_secs :和最低延遲throttle_secs

僅當新的檢查點可用時才進行評估。 因此,您需要使用config = tf.estimator.RunConfig(save_checkpoints_steps = 100))定期創建檢查點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM