如何在TensorFlow中打印输出Tensor的值?

时间:2018-06-11 17:42:32

标签: python tensorflow neural-network mnist

我正在尝试创建一个MNIST分类器,但我无法弄清楚如何实际打印输出。

我正在运行以下代码,但是收到错误:

#pick random number
num = np.random.randint(0, mnist.test.images.shape[0])
img = mnist.test.images[num]
img = np.array(img, dtype='float')
pixels = img.reshape((28, 28))
plt.imshow(pixels, cmap='gray')
plt.show()

#format the image
inp = np.asarray(img)
inp = np.transpose(inp)
image = np.expand_dims(inp, axis=0) # shape  : (1, 784)
image = np.float32(image)

out = predict(image, parameters)
print("Prediction forward propagation successful!")
print("Prediction: ")

with tf.Session() as sess:
    print(sess.run(out)) #This line is giving me an error.

我是TensorFlow的新手,所以非常感谢任何帮助!

0 个答案:

没有答案