import numpy as np
from keras.preprocessing import image
# Loading images
img_path = '2.png'
# Loading grayscale image for MNIST
img = image.load_img(img_path, target_size=(28, 28), grayscale=True)
# Loading color image for CIFAR-10
# img = image.load_img(img_path, target_size=(32, 32))
# Converting images to numpy
x = image.img_to_array(img)
# Inverting and normalizing image
x = 255 - x
x /= 255
x = np.expand_dims(x, axis=0)
# For Dense network
x = x.reshape(1,784)
# Create a model
prediction = model.predict(x)
print(np.argmax(prediction))