Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tf.trainable_variables() to show names of trainable variables

Tags:

tensorflow

I'm dealing with weights in a RNNCell.

I have the following code

var_names = []    
for var in tf.trainable_variables():    
    var_names.append(var.name)

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.

Do the weights of an RNNcell have names?

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)
like image 339
Jerry Nay Avatar asked Jan 31 '17 07:01

Jerry Nay


1 Answers

Try this:

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
like image 193
uniqueID Avatar answered Sep 28 '22 05:09

uniqueID