4. Test our model

4.1 Import files

In google colab we can download files through the following commands:

In [0]:
# !wget - utility for non-interactive download of files from the Web
temp = !wget "https://i.imgur.com/QpRi94e.jpg"
temp = !wget "https://i.imgur.com/gHiDhQX.jpg"
temp = !wget "https://i.imgur.com/8ENsVRq.jpg"
temp = !wget "https://i.imgur.com/wRIin6s.jpg"
temp = !wget "https://i.imgur.com/rADfXRd.jpg"
temp = !wget "https://i.imgur.com/QgL9Uy8.jpg"
temp = !wget "https://i.imgur.com/jtF0AEr.jpg"
temp = !wget "https://i.imgur.com/RDPUU7m.jpg?1"
temp = !wget "https://i.imgur.com/0KJJTi5.jpg"
temp = !wget "https://i.imgur.com/EZDYuqg.jpg"

4.2 Reshape pictures

Test out model on imported images:

In order to transfer the image to the grayscale, we will do the following:

In [0]:
import cv2
numbers = ['QpRi94e.jpg','gHiDhQX.jpg','8ENsVRq.jpg','wRIin6s.jpg','rADfXRd.jpg',\
           'QgL9Uy8.jpg','jtF0AEr.jpg','RDPUU7m.jpg?1','0KJJTi5.jpg','EZDYuqg.jpg']
for i in range(10):
    # this will work in google colab, in jupyter the path will be different
    file  = '/content/'+numbers[i]
    image = cv2.imread(file)
    image  = cv2.resize(image,(img_rows, img_cols))
    grayImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    image_n = cv2.bitwise_not(grayImage)
    image_n = image_n[:,:].reshape(1,28,28,1)
    image_n = image_n.astype('float32')
    image_n /= 255.
    predict = model.predict_classes(image_n)
    plt.subplot(2,5,i+1)
    plt.imshow(image_n.reshape(28,28))
    plt.text(0, 7, predict[0])
    plt.grid('off')
    plt.axis('off')