Adds AUTO_REUSE as a reuse mode to variable scopes. This mode modifies the...
Adds AUTO_REUSE as a reuse mode to variable scopes. This mode modifies the behavior of get_variable() to create requested variables if they do not exist or return them if they do exist. It is now possible to write the following code:
def foo():
with tf.variable_scope("foo", reuse=tf.AUTO_REUSE):
v = tf.get_variable("v", [1])
return v
v1 = foo() # Creates v.
v2 = foo() # Gets the same, existing v.
assert v1 == v2
PiperOrigin-RevId: 165642400
Loading
Please sign in to comment