我对TensorFlow 1.x非常熟悉,并且正在考虑为即将进行的项目切换到TensorFlow 2。我在理解如何使用自定义训练循环,急切执行将标量写入TensorBoard日志时遇到一些麻烦。
在tf1中,您将创建一些摘要操作(每个要存储的操作一个操作),然后将其合并为一个操作,在会话中运行合并的操作,然后使用FileWriter对象将其写入文件。假设sess是我们tf.Session(),下面是一个如何工作的示例:
# While defining our computation graph, define summary ops:
# ... some ops ...
tf.summary.scalar('scalar_1', scalar_1)
# ... some more ops ...
tf.summary.scalar('scalar_2', scalar_2)
# ... etc.
# Merge all these summaries into a single op:
merged = tf.summary.merge_all()
# Define a FileWriter (i.e. an object that writes summaries to files):
writer = tf.summary.FileWriter(log_dir, sess.graph)
# Inside the training loop run the op and write the …Run Code Online (Sandbox Code Playgroud)