经过以下的代码测试,发现 tensorflow的工作流程是这样的
1.把list里的节点在图中圈红
2.找到所有下游节点形成的图sub
3.在一次性计算图sub
4.最后输出list里的节点的值
import tensorflow as tf
state = tf.Variable(0.0,dtype=tf.float32)
one = tf.constant(1.0,dtype=tf.float32)
new_val = tf.add(state, one)
update = tf.assign(state, new_val)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
u,s = sess.run([update,state])
print (s)
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
import tensorflow as tf
state = tf.Variable(0.0,dtype=tf.float32)
one = tf.constant(1.0,dtype=tf.float32)
new_val = tf.add(state, one)
update = tf.assign(state, new_val)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
u,s = sess.run([state,update])
print (s)
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
import tensorflow as tf
state = tf.Variable(0.0,dtype=tf.float32)
one = tf.constant(1.0,dtype=tf.float32)
new_val = tf.add(state, one)
update = tf.assign(state, new_val)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
s,u = sess.run([state,update])
print (s)
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
import tensorflow as tf
state = tf.Variable(0.0,dtype=tf.float32)
one = tf.constant(1.0,dtype=tf.float32)
new_val = tf.add(state, one)
update = tf.assign(state, new_val)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
s,u = sess.run([state,update])
print (u)
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
import tensorflow as tf
state = tf.Variable(0.0,dtype=tf.float32)
one = tf.constant(1.0,dtype=tf.float32)
new_val = tf.add(state, one)
update = tf.assign(state, new_val)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
s,u,u2= sess.run([state,update,update])
print (s,u,u2)
1.0 1.0 1.0
2.0 2.0 2.0
3.0 3.0 3.0
4.0 4.0 4.0
5.0 5.0 5.0
6.0 6.0 6.0
7.0 7.0 7.0
8.0 8.0 8.0
9.0 9.0 9.0
10.0 10.0 10.0
import tensorflow as tf
state = tf.Variable(0.0,dtype=tf.float32)
one = tf.constant(1.0,dtype=tf.float32)
new_val = tf.add(state, one)
update = tf.assign(state, new_val)
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for _ in range(10):
s,u,u2= sess.run([state,new_val,update])
print (s,u,u2)
1.0 1.0 1.0
2.0 2.0 2.0
3.0 3.0 3.0
4.0 4.0 4.0
5.0 5.0 5.0
6.0 6.0 6.0
7.0 7.0 7.0
8.0 8.0 8.0
9.0 9.0 9.0
10.0 10.0 10.0