gasparian/quick-draw_classifier_lite

How to run/predict the model ?

shubhank008 opened this issue · 0 comments

Tried to use your train.py's code to make a prediction on a .jpg/.png saved image of Apple (from quick draw data set, directly saved the image).
However, the prediction came off quite wrong and can't seem to get top 3 prediction thing.

from quickdraw import QuickDrawData
from keras.models import load_model
import numpy as np
import cv2
from keras import metrics
import ast
import h5py
from PIL import Image

model = load_model('model.hdf5')
model.summary()

qd = QuickDrawData(recognized=True)
apple = qd.get_drawing("apple")
apple.image.save("./apple.jpg")

image = cv2.imread("./apple.jpg")
img_size = (64,64)
normed = True
trsh = 100
img = image
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img = cv2.bitwise_not(img)
img = cv2.resize(img, img_size, Image.LANCZOS)
img = cv2.threshold(img, trsh, 255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
img = img.astype('float32') / 255.
img = img[:,:,np.newaxis]

preds = model.predict(img)
for pred in preds:
  pred_class = list(pred).index(max(pred))
  print("Class: {}".format(pred_class))
  print("Probab: {}".format(max(pred)))