Whoami
Whoami

Reputation: 14408

How exactly do I get the pretty print in Tensorflow while printing variable type?

In the ipython I have been trying the following statement.

W1 = tf.Variable(tf.random_normal([3, 3, 1, 2], stddev=0.01))

This Means, I m creating 2 filters of each size 3*3 with 1 channel. When this W1 is printed, I am getting something like

print W1
<tf.Variable 'Variable_4:0' shape=(3, 3, 1, 2) dtype=float32_ref>

Is there any possibility of getting sort of pretty print that displays entire matrix?

Upvotes: 1

Views: 580

Answers (1)

Maxim
Maxim

Reputation: 53758

This line is a definition of the tensorflow variable, i.e. a node in computational graph:

W1 = tf.Variable(tf.random_normal([3, 3, 1, 2], stddev=0.01))

You have provided the initial value, but you can't access it until the session is started and the initializer is run. Here's how you do all this:

with tf.Session() as sess:
    sess.run(W1.initializer)
    print(W1.eval())  # another way: sess.run(W1)

... which outputs something like:

[[[[-0.00224525  0.00417244]]
  [[ 0.00627046 -0.01300699]]
  [[ 0.01755865 -0.01225026]]]
 [[[-0.01875982  0.00103016]]
  [[-0.01131416 -0.00079146]]
  [[-0.00957317  0.00036654]]]
 [[[ 0.00464012  0.0016774 ]]
  [[-0.00546181 -0.00818472]]
  [[ 0.01199017  0.00849589]]]]

Upvotes: 2

Related Questions