[英]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.