1. 首先看看比较简单的 tf.name_scope(‘scope_name’).
tf.name_scope 主要结合 tf.Variable() 来使用,方便参数命名管理。
'''
Signature: tf.name_scope(*args, **kwds)
Docstring:
Returns a context manager for use when defining a Python op.
'''
# 也就是说,它的主要目的是为了更加方便地管理参数命名。
# 与 tf.Variable() 结合使用。简化了命名
with tf.name_scope('conv1') as scope:
weights1 = tf.Variable([1.0, 2.0], name='weights')
bias1 = tf.Variable([0.3], name='bias')
# 下面是在另外一个命名空间来定义变量的
with tf.name_scope('conv2') as scope:
weights2 = tf.Variable([4.0, 2.0], name='weights')
bias2 = tf.Variable([0.33], name='bias')
# 所以,实际上weights1 和 weights2 这两个引用名指向了不同的空间,不会冲突
print weights1.name
print weights2.name