#!/usr/bin/python3.5import tensorflow as tf
a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
# Define some operations
add = tf.add(a, b)
mul = tf.multiply(a, b)
with tf.Session() as sess:
print(sess.run(add, feed_dict={a: 2, b: 3})) # ==> 5
print(sess.run(mul, feed_dict={a: 2, b: 3})) # ==> 6
运行结果
5
6
Graph
代码
#!/usr/bin/python3.5import tensorflow as tf
a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_b")
c = tf.multiply(a, b, name="mul_c")
d = tf.add(a, b, name="add_d")
e = tf.add(c, d, name="add_e")
with tf.Session() as sess:
print(sess.run(e)) # output => 23
writer = tf.summary.FileWriter("./hello_graph", sess.graph)