Reputation: 515
I am trying to manipulate the weights of a multilayered LSTM RNN by first extracting the trainable variables in a session, like so:
variables_names =[v.name for v in tf.trainable_variables()]
values = session.run(variables_names)
Now the variable values
is a list of all weights and biases in my tensorflow graph. After some arithmetic operations to the weights and biases, I would like to upload them back into the graph to continue training the RNN. Does anyone know how to do this? I thought if I use the numpy list values
as a source for re-initializing the graph it would work but I have been unsuccessful. I've tried the following methods till now:
init = tf.constant(values)
tf.get_variables(variables_names, initializer = init).run()
and
init = tf.constant(values)
session.run(tf.variables_initializer(values))
In both these cases the code finishes executing abruptly by printing values I want to initialize back into the graph.
Upvotes: 0
Views: 153
Reputation: 216
Variables have a .load() method. You can pass your updated values back to the graph this way.
Upvotes: 1