116、TensorFlow变量的版本

import tensorflow as tf
v = tf.get_variable("v", shape=(), initializer=tf.zeros_initializer())
assignment = v.assign_add(1)
# Because variables are mutable 
# it's sometimes useful to know what version of  a variable's value is being used
# at any point in time.
# To force a re-read of the value of a variable after something has happened
# you can use tf.Variable.read_value.

with tf.control_dependencies([assignment]):
    w = v.read_value()  # w is guaranteed to reflect v's value after the assign_add operation
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    print(sess.run(w))

下面是上面输出的结果

2018-02-17 10:57:11.629704: I C:	f_jenkinsworkspace
el-winMwindowsPY35	ensorflowcoreplatformcpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
1.0
原文地址:https://www.cnblogs.com/weizhen/p/8451476.html