2

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

Stack Overflow 上有很多与 , 等相关的问题name_scopevariable_scope比如variable_scope 和 name_scope 有什么区别?, tensorflow中名称范围和变量范围有什么区别?, variable_scope 和 name_scope 的实际区别是什么?以及为什么我们使用 tf.name_scope(),因为人们不明白这些函数背后的想法及其目的是可以理解的。本质上,这些函数用于命名底层计算图中的变量。

variable_scope,name_scope等在 TensorFlow 2 中是否有任何目的或用途以及急切执行?如果是这样,你能举个例子吗?

4

1 回答 1

0

在具有 Eager 执行的 TensorFlow 2 中,您仍然可以使用tf.name_scope移至 TF2 的版本。

下面是一个例子。

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 reusing诸如reliance on global scopes. 对变量的这些更改
实际上没有必要使用。variable_scope

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

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

您可以关注TensorFlow 2.0 中的社区 RFC 变量,以获取有关从 Tensorflow 1 到 Tensorflow 2 的所有主要变量更改的详细信息

于 2020-06-04T07:58:11.990 回答