Skip to content

Instantly share code, notes, and snippets.

@athena15
Created December 12, 2018 22:45
Show Gist options
  • Save athena15/b0ef8a46b38d92b0d1ad59a3dce18440 to your computer and use it in GitHub Desktop.
Save athena15/b0ef8a46b38d92b0d1ad59a3dce18440 to your computer and use it in GitHub Desktop.
from keras import load_model
model = load_model(path) # open saved model/weights from .h5 file
def predict_image(image):
image = np.array(image, dtype='float32')
image /= 255
pred_array = model.predict(image)
# model.predict() returns an array of probabilities -
# np.argmax grabs the index of the highest probability.
result = gesture_names[np.argmax(pred_array)]
# A bit of magic here - the score is a float, but I wanted to
# display just 2 digits beyond the decimal point.
score = float("%0.2f" % (max(pred_array[0]) * 100))
print(f'Result: {result}, Score: {score}')
return result, score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment