将summary protocol buffer写入event file。FileWriter类提供了一种机制,用于在给定目录中创建事件文件,并向其中添加摘要和事件。该类异步更新文件内容。这允许训练程序调用方法直接从训练循环中将数据添加到文件中,而不会减慢训练的速度。
Methods
__init__
__init__(
logdir,
graph=None,
max_queue=10,
flush_secs=120,
graph_def=None,
filename_suffix=None
)
创建一个FileWriter和一个event file。在构建过程中,摘要编写器在logdir中创建一个新的事件文件。此事件文件将包含调用以下函数之一时构造的事件协议缓冲区:add_summary()、add_session_log()、add_event()或add_graph()。如果您将图传递给构造函数,它将被添加到事件文件中。(这相当于稍后调用add_graph())。TensorBoard将从文件中选择图形并以图形方式显示,这样您就可以交互式地查看您构建的图形。你通常会从你启动它的会话中传递图:
...create a graph...
# Launch the graph in a session.
sess = tf.Session()
# Create a summary writer, add the 'graph' to the event file.
writer = tf.summary.FileWriter(<some-directory>, sess.graph)
构造函数的其他参数控制对事件文件的异步写入:
- flush_secs:以秒为单位将添加的摘要和事件刷新到磁盘的频率。
- max_queue:在“添加”调用块之前,等待写入磁盘的汇总或事件的最大数量。
参数:
- logdir: 一个字符串。将写入事件文件的目录。
- graph: 图形对象,如ses .graph。
- max_queue: 整数。等待事件和摘要的队列大小。
- flush_secs: 数量,将挂起的事件和摘要刷新到磁盘的频率(以秒为单位)。
- graph_def: DEPRECATED:使用graph参数。
- filename_suffix: 一个字符串。每个事件文件的名称都带有后缀。
异常:
RuntimeError
: If called with eager execution enabled.
@compatibility(eager) FileWriter与eager执行不兼容。要在热切执行下编写TensorBoard摘要,请使用tf.contrib。总结。@end_compatbility
__enter__
__enter__()
使用with语句。
__exit__
__exit__(
unused_type,
unused_value,
unused_traceback
)
使用with语句。
add_event
add_event(event)
将事件添加到事件文件中。
参数:
- event:事件协议缓冲区。
add_graph
add_graph(
graph,
global_step=None,
graph_def=None
)
将图添加到事件文件中。协议缓冲区描述的图形将由TensorBoard显示。大多数用户在构造函数中传递一个图。
参数:
- graph: 图形对象,如ses .graph。
- global_step: 号码。可选的全局步骤计数器,以记录与图形。
- graph_def: deprecated。而是使用graph参数。
异常:
ValueError
: If both graph and graph_def are passed to the method.
add_meta_graph
add_meta_graph(
meta_graph_def,
global_step=None
)
将MetaGraphDef添加到事件文件中。MetaGraphDef允许通过saver.import_meta_graph()运行给定的图。
参数:
- meta_graph_def: MetaGraphDef对象,通常由saver.export_meta_graph()返回。
- global_step: Number,可选的全局步骤计数器,以记录与图。
异常:
TypeError
: If bothmeta_graph_def
is not an instance ofMetaGraphDef
.
add_run_metadata
add_run_metadata(
run_metadata,
tag,
global_step=None
)
为单个session.run()调用添加元数据信息。
参数:
- run_metadata: 一个RunMetadata原buf对象。
- tag: 此元数据的标记名称。
- global_step: Number,可选的全局步骤计数器,以记录与StepStats。
异常:
ValueError
: If the provided tag was already used for this type of event.
add_session_log
add_session_log(
session_log,
global_step=None
)
向事件文件添加一个SessionLog协议缓冲区。此方法将提供的会话包装在事件协议缓冲区中,并将其添加到事件文件中。
参数:
- summary: 摘要协议缓冲区,可选地序列化为字符串。
- global_step: Number,可选的全局步骤值,以记录摘要。
close
close()
将事件文件刷新到磁盘并关闭该文件。当你不再需要摘要编写器时调用此方法。
flush
flush()
将事件文件刷新到磁盘。调用此方法以确保所有挂起事件都已写入磁盘。
get_logdir
get_logdir()
返回将写入事件文件的目录。
reopen
reopen()
EventFileWriter重开。可以在close()之后调用,以便在同一目录中添加更多事件。事件将进入一个新的事件文件。如果EventFileWriter未关闭,则不执行任何操作。
原链接: https://tensorflow.google.cn/versions/r1.8/api_docs/python/tf/summary/FileWriter?hl=en