#初始化cup的分配
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
"""
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
"""
import tensorflow as tf
state = tf.Variable(0, name='counter')
#print(state.name)
one = tf.constant(1)
new_value = tf.add(state, one) #将两个变量相加
update = tf.compat.v1.assign(state, new_value) #用后面的new_value更新前面的变量state
init = tf.compat.v1.global_variables_initializer() # must have if define variable
with tf.compat.v1.Session() as sess:
sess.run(init)
for _ in range(3):
sess.run(update)
print(sess.run(state))
tensorflow更新变量
最新推荐文章于 2023-04-21 08:34:56 发布