0

I am trying to have a look at the MNIST data set for machine learning. In Tensorflow the MNIST data set can be imported with

mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
full_data_x = mnist.train.images

However when I try to visualize an 80x80 array of the data using

test_x, test_y = mnist.test.images, mnist.test.labels
plt.gray()
plt.imshow(1-test_x[80:160,80:160])

it looks really strange like this:

Image of the dataset array

How can I extract an image of the actual hand-written digits, like they are shown in the internet:

Internet image of the MNIST dataset

I saw the similar questions like this. However I would especially be interested where in the training data array the images are actually hidden. I know that tensor flow module provides a function to display the images.

Axel
  • 1,415
  • 1
  • 16
  • 40
  • 1
    Possible duplicate of [TensorFlow - Show image from MNIST DataSet](https://stackoverflow.com/questions/38308378/tensorflow-show-image-from-mnist-dataset) – LeKhan9 Oct 23 '18 at 19:50
  • I saw the other question. However there it is not discussed *where* the images are in the test data array. This is what I would like to know. – Axel Oct 23 '18 at 20:09

1 Answers1

2

I think I understand your question now, and it is a bit different than the one I thought was duplicate.

The images are not necessarily hidden. Each index of that list is an image in itself:

num_test_images, num_train_images = len(mnist.test.images), len(mnist.train.images)

size_of_first_test_image, size_of_first_train_image =  len(mnist.test.images[0]), len(mnist.train.images[0])

print num_test_images, num_train_images
print size_of_first_test_image, size_of_first_train_image

output:

10000 55000
784 784

You can see that the number of training and testing images is the length of each mnist list. Each image is a flat array of size 784. You will have to reshape it yourself to display it using numpy or something of the sort.

Try this:

first_test_image = np.array(mnist.test.images[0], dtype='float')
reshaped_image = first_image.reshape((28, 28))
LeKhan9
  • 1,300
  • 1
  • 5
  • 15
  • Ah I see! That was exactly the missing information for me to understand the data set. Thanks for your help! – Axel Oct 23 '18 at 20:38