tensorflow / 2.9.1 / compat / v1 / get_variable_scope.html /

tf.compat.v1.get_variable_scope

Returns the current variable scope.

Migrate to TF2

Although it is a legacy compat.v1 api, tf.compat.v1.get_variable is compatible with eager execution and tf.function

However, to maintain variable-scope based variable reuse you will need to combine it with tf.compat.v1.keras.utils.track_tf1_style_variables. (Though it will behave as if reuse is always set to tf.compat.v1.AUTO_REUSE.)

See the migration guide for more info.

The TF2 equivalent, if you are just trying to track variable name prefixes and not control get_variable-based variable reuse, would be to use tf.name_scope and capture the output of opening the scope (which represents the current name prefix).

For example:

x = tf.name_scope('foo') as current_scope:
  ...

Description

© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/compat/v1/get_variable_scope