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

2024-06-11 09:22:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试生成一个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的新手,所以非常感谢您的帮助!在


Tags: testimageimgnppltrandomoutnum