Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While debugging, how to print all variables (which is in list format) who are trainable in Tensorflow?

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)
like image 773
Mohit Agarwal Avatar asked Jul 21 '16 17:07

Mohit Agarwal


People also ask

Is tf variable trainable?

New! Save questions or answers and organize your favorite content.

How do you find the value of TensorFlow variable?

To get the current value of a variable x in TensorFlow 2, you can simply print it with print(x) . This prints a representation of the tf. Variable object that also shows you its current value.

What does tf Get_variable do?

tf. get_variable(<name>, <shape>, <initializer>) : Creates or returns a variable with a given name.

What are variables and placeholders in TensorFlow?

A placeholder is simply a variable that we will assign data to at a later date. It allows us to create our operations and build our computation graph, without needing the data. In TensorFlow terminology, we then feed data into the graph through these placeholders.


2 Answers

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.
like image 107
mrry Avatar answered Oct 06 '22 14:10

mrry


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.

like image 29
rocksyne Avatar answered Oct 06 '22 12:10

rocksyne