TensorFlow使用新变量
import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import numpy as np
state = tf.Variable(0,name='counter')
# print(state.name)
one = tf.constant(1)
new_val = tf.add(state,one)
update = tf.assign(state,new_val)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for _ in range(3):
sess.run(update)
print(sess.run(state))