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:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
1.0

 

posted @ 2018-02-17 10:58  香港胖仔  阅读(156)  评论(0编辑  收藏  举报