Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

python - TensorFlow - Show image from MNIST DataSet

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])

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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")

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...