简体   繁体   English

在打印变量类型时,如何在Tensorflow中获得漂亮的打印效果?

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

In the ipython I have been trying the following statement. 在ipython中,我一直在尝试以下语句。

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. 这意味着,我要创建2个具有1个通道的每个大小为3 * 3的滤镜。 When this W1 is printed, I am getting something like 当打印此W1时,我得到类似

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? 是否有可能获得可以显示整个矩阵的漂亮打印效果?

This line is a definition of the tensorflow variable, ie a node in computational graph: 该行是tensorflow变量的定义,即计算图中的一个节点:

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]]]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM