本文介绍了TensorFlow - 显示来自 MNIST 数据集的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 TensorFlow,我从以下链接实现了 MNIST 示例:http://openmachin.es/blog/tensorflow-mnist我希望能够实际查看训练/测试图像.所以我正在尝试添加将显示第一批火车的第一张图片的代码:

I'm trying to learn TensorFlow and I implemented the MNIST example from the the following link: http://openmachin.es/blog/tensorflow-mnistI want to be able to actually view the training/test images.So I'm trying to add code that will show the first train picture of the first batch:

x_i = batch_xs[0]
image = tf.reshape(x_i,[28,28])

现在,因为数据是 float32 类型(值在 [0,1] 范围内),我尝试将其转换为 uint16,然后将其编码为 png 以显示图像.我尝试使用 tf.image.convert_image_dtype 和 tf.image.encode_png,但没有成功.你们能帮我理解如何将原始数据转换为图像并显示图像吗?

Now, because the Data is in float32 type (with values in [0,1] range), I tried to convert it to uint16 and then to encode it to png in order to show the image.I tried using tf.image.convert_image_dtype and tf.image.encode_png, but with no success.Can you guys please help me understand how can I convert the raw Data to an image and show the image?

推荐答案

阅读教程后,您可以在 numpy 中完成所有工作,无需 TF:

After reading the tutorial you can do it all in numpy no need for TF:

import matplotlib.pyplot as plt
first_array=batch_xs[0]
#Not sure you even have to do that if you just want to visualize it
#first_array=255*first_array
#first_array=first_array.astype("uint8")
plt.imshow(first_array)
#Actually displaying the plot if you are not in interactive mode
plt.show()
#Saving plot
plt.savefig("fig.png")

您还可以使用 PIL 或任何您喜欢的可视化工具.

You can also use PIL or whatever visualization tool you are into.

这篇关于TensorFlow - 显示来自 MNIST 数据集的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 02:55