Skip to content

Instantly share code, notes, and snippets.

@quangnhat185
Created May 17, 2020 21:43
Show Gist options
  • Save quangnhat185/5be028129effd02954f54de99c637eed to your computer and use it in GitHub Desktop.
Save quangnhat185/5be028129effd02954f54de99c637eed to your computer and use it in GitHub Desktop.
# pre-processing input images and pedict with model
def predict_from_model(image,model,labels):
image = cv2.resize(image,(80,80))
image = np.stack((image,)*3, axis=-1)
prediction = labels.inverse_transform([np.argmax(model.predict(image[np.newaxis,:]))])
return prediction
fig = plt.figure(figsize=(15,3))
cols = len(crop_characters)
grid = gridspec.GridSpec(ncols=cols,nrows=1,figure=fig)
final_string = ''
for i,character in enumerate(crop_characters):
fig.add_subplot(grid[i])
title = np.array2string(predict_from_model(character,model,labels))
plt.title('{}'.format(title.strip("'[]"),fontsize=20))
final_string+=title.strip("'[]")
plt.axis(False)
plt.imshow(character,cmap='gray')
print("Achieved result: ", final_string)
#plt.savefig('final_result.png', dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment