1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| import tensorflow as tf INI = tf.constant_initializer(value=999)
with tf.variable_scope('variable_scope'): var1 = tf.get_variable(name='var1',shape=(),dtype=tf.float32,initializer=INI)
with tf.variable_scope('variable_scope',reuse=True): reuse_var1 = tf.get_variable(name='var1')
with tf.variable_scope('test1',reuse=tf.AUTO_REUSE): var2=tf.get_variable(name='var2',shape=(1,),dtype=tf.float32,initializer=INI) reuse_var2 = tf.get_variable(name='var2')
SESS=tf.Session(); SESS.run(tf.global_variables_initializer()) print(var1.eval(session=SESS),var1.name) print(reuse_var1.eval(session=SESS),reuse_var1.name) print(var2.eval(session=SESS),var2.name) print(reuse_var2.eval(session=SESS),reuse_var2.name)
|