[英]Continue training of a custom tf.Estimator with AdamOptimizer
[英]Tensorflow: Is there a way to store the training loss in tf.Estimator
我正在使用 tensorflow estimator 對象來訓練來自官方 tensorflow 層文檔 ( https://www.tensorflow.org/tutorials/layers ) 的模型。 我可以看到在訓練期間在控制台上顯示了訓練損失。 有沒有辦法存儲這些訓練損失值?
謝謝!
顯示是通過logging.info
完成的。 tf.estimator
為訓練損失創建一個LoggingTensorHook
來執行此操作,請參見此處。
我想您可以將日志輸出重新路由到某個文件,但這仍然不會為您提供原始值。
我能想到的兩種方法:
LoggingTensorHook
,您只需要將數字寫入文件而不是打印它們。tf.estimator
還會在 Tensorboard 中為訓練損失創建匯總數據; 您可以在 Tensorboard 中打開“標量”選項卡,您應該在其中看到損失曲線。 勾選左上角的“顯示數據下載鏈接”。 這將為您提供以 CSV 或 JSON 格式下載每個圖形數據的選項。 默認情況下,日志和摘要掛鈎都設置為每 100 步記錄一次值。 因此,圖表應具有您在控制台中看到的相同信息。 如果你不熟悉 Tensorboard,Tensorflow 網站上也有教程; 基本用法應該很簡單!通過 estimator.train() 訓練您的估算器后,您可以在 model_dir 中使用 TensorBoard 事件文件
model = tf.estimator.Estimator(..., model_dir= 'tmp')
# model data will be save in tmp directory after training
事件文件名為 events.out.tfevents.15121254....,該文件保存了訓練過程的日志(eval 文件夾中還有一個保存評估日志的事件文件)。 您可以通過以下方式獲得訓練損失:
for e in tf.train.summary_iterator(path_to_events_file):
for v in e.summary.value:
if v.tag == 'loss':
print(v.simple_value)
此外,您可以通過在 model_fn 中添加 tf.summary 來保存訓練期間的其他值:
tf.summary.scalar('accuracy', accuracy)
參考: https : //www.tensorflow.org/api_docs/python/tf/train/summary_iterator
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.