2

In TensorFlow 2, eager execution is the default execution. There is no need for annoying sessions or placeholders.

There are so many questions related to name_scope, variable_scope, etc., on Stack Overflow, for example, 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? and Why do we use tf.name_scope(), because people understandably do not get the idea behind these functions and their purpose. Essentially, these functions are used to name the variables in the underlying computational graph.

Do variable_scope, name_scope, etc., have any purpose or usage in TensorFlow 2 with eager execution? If so, can you please provide an example?

nbro
  • 15,395
  • 32
  • 113
  • 196

1 Answers1

0

In TensorFlow 2 with Eager execution, you can still use tf.name_scope which was moved to TF2.

Below is an example.

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" 

But since Variable is in Tensorflow 2 has many changes and improvements by addressing drawbacks like variables reusing, reliance on global scopes.
It is not really necessary to use variable_scope with these changes to the Variables.

But if you still need to use variable_scope you can use it in the following way.

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

You can follow community RFC Variables in TensorFlow 2.0 for detailed information on all the major changes on Variables from Tensorflow 1 to Tensorflow 2