使用 tf.trainable_variables() 显示可训练变量的名称 [英] Using tf.trainable_variables() to show names of trainable variables
本文介绍了使用 tf.trainable_variables() 显示可训练变量的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理 RNNCell
中的 权重.
I'm dealing with weights in a RNNCell
.
我有以下代码
var_names = []
for var in tf.trainable_variables():
var_names.append(var.name)
在另一个名为 model.py
的文件中,我正在打印刚刚附加到 var_names
的可训练变量的名称.但是,我发现可训练变量的名称"属性没有用,因为描述性不强.
In another file called model.py
, I am printing the names of the trainable variables just appended to var_names
. However, I find that the "name" attribute of the trainable variables is not useful because not very descriptive.
RNNcell
的权重有名字吗?
如果有用,这里还有一段可能相关的代码:
If that's useful, here's another possibly relevant piece of code:
cell_fn = tf.nn.rnn_cell.GRUCell
rnn_fw_1 = cell_fn(num_hidden_1, **additional_cell_args)
rnn_fw_1 = tf.nn.rnn_cell.DropoutWrapper(rnn_fw_1, input_keep_prob=keep_prob_1)
推荐答案
试试这个:
variables_names = [v.name for v in tf.trainable_variables()]
values = sess.run(variables_names)
for k, v in zip(variables_names, values):
print "Variable: ", k
print "Shape: ", v.shape
print v
这篇关于使用 tf.trainable_variables() 显示可训练变量的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文