gpt4 book ai didi

python - 在打印变量类型时,如何在 Tensorflow 中获得 pretty-print 结果?

转载 作者:行者123 更新时间:2023-12-01 02:23:21 25 4
gpt4 key购买 nike

在ipython中我一直在尝试以下语句。

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

这意味着,我正在创建 2 个过滤器,每个尺寸为 3*3,具有 1 个 channel 。当打印这个 W1 时,我得到类似的东西

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

是否有可能获得显示整个矩阵的 pretty-print ?

最佳答案

这一行是tensorflow变量的定义,即计算图中的节点:

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

您已经提供了初始值,但在 session 启动并且初始化程序运行之前您无法访问它。以下是执行这一切的方法:

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

...输出如下:

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

关于python - 在打印变量类型时,如何在 Tensorflow 中获得 pretty-print 结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47710467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com