While debugging, how to print all variables (which is in list format) who are trainable in Tensorflow?
在调试时,如何打印Tensorflow中可训练的所有变量(列表格式)?
For instance,
例如,
tvars = tf.trainable_variables()
I want to check all the variables in tvars (which is list type).
我想检查tvars中的所有变量(列表类型)。
I've already tried the below code which returns error,
我已经尝试过以下代码返回错误,
myvars = session.run([tvars])
print(myvars)
2 个解决方案
#1
10
Since tf.trainable_variables()
returns a list of tf.Variable
objects, you should be able to pass its result straight to Session.run()
:
由于tf.trainable_variables()返回tf.Variable对象的列表,因此您应该能够将其结果直接传递给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.
#2
3
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.
我从这里复制了这个。
#1
10
Since tf.trainable_variables()
returns a list of tf.Variable
objects, you should be able to pass its result straight to Session.run()
:
由于tf.trainable_variables()返回tf.Variable对象的列表,因此您应该能够将其结果直接传递给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.
#2
3
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.
我从这里复制了这个。