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?
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.
X = X.reshape([28, 28]);
plt.gray()
plt.imshow(X)
this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With