使用TensorFlow的基本步骤一般为:定义计算图,执行计算图,查看计算图
import tensorflow as tf
#定义计算图
g = tf.Graph()
with g.as_default():
hello = tf.constant('hello',name = 'hello')
world = tf.constant('world',name = 'world')
helloworld = tf.string_join([hello,world],name = 'join',separator=' ')
#执行计算图
with tf.Session(graph = g) as sess:
print(sess.run(fetches = helloworld,feed_dict={}))
#查看计算图
with tf.summary.FileWriter('F:\lys\my_graph') as writer:
writer.add_graph(g)
#1,在命令行中切换到 F:\lys\my_graph
#2,运行 tensorboard --logdir=my_graph
#3, 打开浏览器输入地址
或者
writer = tf.summary.FileWriter('F:\lys\my_graph', tf.get_default_graph())
writer.close()