Reputation: 111
While debugging, how to print all variables (which is in list format) who are trainable in Tensorflow?
For instance,
tvars = tf.trainable_variables()
I want to check all the variables in tvars (which is list type).
I've already tried the below code which returns error,
myvars = session.run([tvars])
print(myvars)
Upvotes: 8
Views: 11446
Reputation: 1372
To print the complete list of all all variables or nodes of a tensor-flow graph, you may try this:
[n.name for n in tf.get_default_graph().as_graph_def().node]
I copied this from here.
Upvotes: 5
Reputation: 126154
Since tf.trainable_variables()
returns a list of tf.Variable
objects, you should be able to pass its result straight to Session.run()
:
tvars = tf.trainable_variables()
tvars_vals = sess.run(tvars)
for var, val in zip(tvars, tvars_vals):
print(var.name, val) # Prints the name of the variable alongside its value.
Upvotes: 15