Feeding image into tensorflow

395 views Asked by At

I am new to using TensorFlow. So I wastrying the MNIST tutorials in ML for beginners. The code runs just fine. But what if I want to input an image of my own, which has say a handwritten number on it, and se if it predicts what number it might be? How do I feed my own image into the TensorFlow program?

1

There are 1 answers

0
chris On

Assuming you're using this file.

If you look at x, the shape is [None, 784]. To feed your own image in, you'll have to store the image as a variable (loading it using PIL or OpenCV or something), flatten it, wrap it in a list, and pass it to the graph in the feed_dict, looking something like this:

sess.run(y_, feed_dict={x: [np.flatten(image_you_loaded_in)]})

It will need to be a 28x28 image in order for this code to work without modification.