Basic math operation
from __future__ import print_function
import tensorflow as tf
import os
# Defining some constant values
a = tf.constant(5.0, name="a")
b = tf.constant(10.0, name="b")
# Some basic operations
x = tf.add(a, b, name="add")
y = tf.div(a, b, name="divide")
name = "some_name"
的定义是为了之后可以在tensorBoard
中更好的进行可视化
运行
# Run the session
with tf.Session() as sess:
writer = tf.summary.FileWriter(os.path.expanduser(FLAGS.log_dir), sess.graph)
print("output: ", sess.run([a,b,x,y]))
# Closing the writer.
writer.close()
sess.close()
Tensorflow中的所有运行都需要先声明,然后在运行才能得到结果
Result
尝试了一下,运行这段代码一直跑不出来他的结果