tensorflow学习之---tf.assign_add,tf.control_dependencies

x = tf.Variable(0.0)
#返回一个op,表示给变量x加1的操作
x_plus_1 = tf.assign_add(x, 1)
 
#control_dependencies的意义是,在执行with包含的内容(在这里就是 y = x)前
#先执行control_dependencies中的内容(在这里就是 x_plus_1)
with tf.control_dependencies([x_plus_1]):
    y = x
init = tf.initialize_all_variables()
 
with tf.Session() as session:
    init.run()
    for i in xrange(5):
        print(y.eval())

https://www.cnblogs.com/lovychen/p/8617524.html 

猜你喜欢

转载自blog.csdn.net/qq_32466233/article/details/82954094
今日推荐