Tensorflow打印tensor值的方法

Tensorflow由于经过了封装,所以它的值在控制台上是打印不出来的,只能打印出维度,例如这样:

import tensorflow as tf
A = tf.constant(666)
print(A)

输出结果:

<tf.Tensor ‘Const:0’ shhape=() dtype=int32>

这是因为tensorflow的基本执行原理是数据流,以上语句只是占用了一个节点,并没有做实际的赋值操作。而有时候需要查看tensor里边的内容来调试程序,解决方案就是建立一个session,并调用Session里的eval()方法:

import tensorflow as tf
A = tf.constant(666)
sess = tf.Session()
A.eval(session = sess)
发布了63 篇原创文章 · 获赞 189 · 访问量 27万+

猜你喜欢

转载自blog.csdn.net/u013044310/article/details/88363769