Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing RNN weights- Tensorflow

I am using tf.python.ops.rnn_cell.GRUCell

output, state = tf.nn.dynamic_rnn(
        GRUCell(HID_DIM),
        sequence,
        dtype=tf.float32,
        sequence_length=length(sequence)
)

How do I get the weights of this GRUCell. I need to see them for debugging.

like image 226
Raghuram Vadapalli Avatar asked Mar 26 '17 14:03

Raghuram Vadapalli


People also ask

Are weights shared in RNN?

Recurrent networks also share parameters across each layer of the network. In feedforward networks, there are different weights across each node. Whereas RNN shares the same weights within each layer of the network and during gradient descent, the weights and basis are adjusted individually to reduce the loss.

Can RNN be trained with GPU?

The parallel processing capabilities of GPUs can accelerate both the training and inference processes of RNNs.

Is RNN strictly more powerful than CNN?

CNN is considered to be more powerful than RNN. RNN includes less feature compatibility when compared to CNN. This network takes fixed size inputs and generates fixed size outputs. RNN can handle arbitrary input/output lengths.


1 Answers

The values of all the variables in the current session can be printed using:

with tf.Session() as sess:
    variables_names =[v.name for v in tf.trainable_variables()]
    values = sess.run(variables_names)
    for k,v in zip(variables_names, values):
        print(k, v)
like image 154
Filipe Avatar answered Oct 20 '22 08:10

Filipe