3

I am new to Deep Learning and am using Keras to learn it. I followed instructions at this link to build a handwritten digit recognition classifier using MNIST dataset. It worked fine in terms of seeing comparable evaluation results. I used tensorflow as the backend of Keras.

Now I want to read an image file with a handwritten digit and predict its digit using the same model. I think the image needs to be transformed to be in 28x28 dimension with 255 depth first? I am not sure whether my understanding is correct to begin with. If so, how can I do this transformation in Python? If my understanding is incorrect, what kind of transformation is required?

Thank you in advance!

Marcin Możejko
  • 39,542
  • 10
  • 109
  • 120
kee
  • 10,969
  • 24
  • 107
  • 168

1 Answers1

1

To my knowledge, you will need to turn this into a 28x28 grayscale image in order to work with this in Python. That's the same shape and scheme as the images that were used to train MNIST, and the tensors are all expecting 784 (28 * 28)-sized items, each with a value between 0-255 in their tensors as input.

To resize an image you could use PIL or Pillow. See this SO post or this page in the Pillow docs (linked to by Wtower in the previously mentioned post, copied here for ease of accesson resizing and keeping aspect ratio, if that's what you want to do.

HTH!

Cheers,

-Maashu

Maashu
  • 305
  • 2
  • 10
  • Thank you @Masshu! That answers the scaling part perfectly! For grayscaling, I found a very useful doc (which actually handles resizing at the same time): https://www.reddit.com/r/learnpython/comments/4uzuym/convert_image_to_grayscale_with_pillow/ (not so sure how to link this to text in comment) – kee Aug 07 '17 at 20:13