import tensorflow as tf
with tf.name_scope('123'):
with tf.name_scope('456'):
with tf.variable_scope('789'):
a = tf.Variable(1, name='a')
print(a.name)
b = tf.get_variable('b',1)
print(b.name)
with tf.variable_scope('789'):
e = tf.get_variable('e',1)
print(e.name)
with tf.name_scope('123'):
with tf.name_scope(None):
c = tf.Variable(1, name='c')
print(c.name)
输出结果:
123/456/789/a:0
789/b:0
789/e:0
c:0