【问题标题】:Do variable_scope and name_scope have any purpose in TensorFlow 2 with eager execution?variable_scope 和 name_scope 在 TensorFlow 2 中具有急切执行的目的吗?
【发布时间】:2020-02-28 02:02:37
【问题描述】:

在 TensorFlow 2 中,Eager Execution 是默认执行。不需要烦人的会话或占位符。

在 Stack Overflow 上有很多与name_scopevariable_scope 等相关的问题,例如What is the difference between variable_scope and name_scope?What's the difference of name scope and a variable scope in tensorflow?What are the practical differences between the variable_scope and name_scope?Why do we use tf.name_scope(),因为人们可以理解地不明白这些功能及其目的背后的想法。本质上,这些函数用于命名底层计算图中的变量。

variable_scopename_scope 等在 TensorFlow 2 中具有急切执行的目的或用途吗?如果有,能否举个例子?

【问题讨论】:

    标签: tensorflow tensorflow2.0 eager-execution


    【解决方案1】:

    在带有 Eager 执行的 TensorFlow 2 中,您仍然可以使用已移至 TF2 的 tf.name_scope

    下面是一个例子。

    with tf.name_scope("foo"):
        with tf.name_scope("bar"):
            v = tf.Variable([0], dtype=tf.float32, name="v")
            assert v.name == "foo/bar/v:0" 
    

    但由于变量在 Tensorflow 2 中,通过解决 variables reusingreliance on global scopes 等缺点,有许多变化和改进。
    对于变量的这些更改,实际上没有必要使用variable_scope

    但是如果你仍然需要使用 variable_scope 你可以通过以下方式使用它。

    to control variable naming users can use tf.name_scope + tf.Variable

    您可以关注社区 RFC Variables in TensorFlow 2.0,了解有关从 Tensorflow 1 到 Tensorflow 2 的变量的所有主要变化的详细信息

    【讨论】:

      猜你喜欢
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 1970-01-01
      • 2020-03-14
      相关资源
      最近更新 更多