TensorFlow - 显示来自MNIST DataSet的图像 [英] TensorFlow - Show image from MNIST DataSet

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

问题描述

我正在尝试学习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-mnist I 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 DataSet的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆