tensorflow的可视化是通过summary和tensorboard完成的。以tensorflow运作方式入门为例,可视化主要通过以下步骤完成:
(1)将所有的即时数据整合在一个op中:
# Build the summary operation based on the TF collection of Summaries.
summary_op = tf.summary.merge_all()
(2)创建Session会话,并初始化Variables变量:
# Create a session for running Ops on the Graph.
sess = tf.Session()
# Run the Op to initialize the variables.
init = tf.initialize_all_variables()
sess.run(init)
(3)创建tf.Summary.FileWriter对象,用于写入包含了图表本身和即时数据具体值的事件文件:
# Instantiate a SummaryWriter to output summaries and the Graph.
summary_writer = tf.summary.FileWriter(FLAGS.train_dir,
graph_def=sess.graph_def)
(4)运行summary_op,得到即时数据,然后通过add_summary()向FileWriter对象的缓存中存入事件数据
summary_str = sess.run(summary_op, feed_dict=feed_dict)
summary_writer.add_summary(summary_str, step)
事件文件写入完毕后,就可以打开一个TensorBoard查看即时数据的情况。