8

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)
Mohit Agarwal
  • 111
  • 1
  • 1
  • 5

2 Answers2

15

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.
mrry
  • 125,488
  • 26
  • 399
  • 400
5

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.

rocksyne
  • 1,264
  • 15
  • 17