简单的代码:
import tensorflow as tf In [2]: matrix1=tf.constant([[3.,3.]]) In [3]: matrix2=tf.constant([[2.],[2.]]) with tf.Session() as sess: ...: writer = tf.summary.FileWriter('./graph', sess.graph) ...: result = sess.run(tf.matmul(matrix1, matrix2)) ...: writer.close()
ipython中使用!+命令可以直接运行terminal命令。
terminal输入: tensorboard --logdir graph/
跳出:Starting TensorBoard 54 at http://amax:6006
在浏览器输入地址加端口号并在graph中查看。
补充知识:tensorflow 利用保存的meta图文件生成log供tensorboard可视化 保存恢复模型
tensorboard可视化图:
import tensorflow as tf g = tf.Graph() with g.as_default() as g: tf.train.import_meta_graph('criteo_80.meta') with tf.Session(graph=g) as sess: file_writer = tf.summary.FileWriter(logdir='./', graph=g)
保存恢复模型:
# 建模型 saver = tf.train.Saver() with tf.Session() as sess: # 存模型,注意此处的model是文件名非路径 saver.save(sess, "/tmp/model") with tf.Session() as sess: # 恢复模型 saver.restore(sess, "/tmp/model")
# 先恢复图 saver = tf.train.import_meta_graph("/tmp/model.meta") with tf.Session() as sess: # 再恢复参数 saver.restore(sess, "/tmp/model")
以上这篇TensorFlow保存TensorBoard图像操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。