How to reuse variables in TensorFlow? I want to reusetf.contrib.layers.linear
with tf.variable_scope("root") as varscope:
inputs_1 = tf.constant(0.5, shape=[2, 3, 4])
inputs_2 = tf.constant(0.5, shape=[2, 3, 4])
outputs_1 = tf.contrib.layers.linear(inputs_1, 5)
varscope.reuse_variables()
outputs_2 = tf.contrib.layers.linear(inputs_2, 5)
But this gives me the following result:
ValueError Traceback (most recent call last)
<ipython-input-51-a40b9ec68e25> in <module>()
5 outputs_1 = tf.contrib.layers.linear(inputs_1, 5)
6 varscope.reuse_variables()
...
ValueError: Variable root/fully_connected_1/weights does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?
source
share