在嵌套变量作用域中声明的变量的名称是什么?

3
考虑以下使用TensorFlow编写的Python 2代码段:
with tf.variable_scope('scope'):
    layer = slim.conv2d(input_tensor, 64, 7, 2, padding='SAME', scope='another_scope')

我正在创建一个conv2d层,该层在变量作用域内,但也将另一个变量作用域名称显式传递给conv2d层的构造函数。

我的问题如下:

  1. 变量layer的名称是什么,在哪个作用域中定义- scope还是another_scope
  2. 允许用户声明这样的变量有什么用途?
  3. 是否可以在TensorFlow中创建嵌套的变量作用域?如果是,请说明如何工作。
  4. 如果作用域another_scope尚未被创建,TensorFlow会自行创建吗?
1个回答

2

原来变量layer的完整范围是scope/another_scope。对我来说,他们提供了作用域参数,这样就可以简写为

with tf.variable_scope('scope'):
    with tf.variable_scope('another_scope'):
        layer = slim.conv2d(input_tensor, 64, 7, 2, padding='SAME')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接