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)
New! Save questions or answers and organize your favorite content.
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.
tf. get_variable(<name>, <shape>, <initializer>) : Creates or returns a variable with a given name.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With