Created
December 12, 2018 22:45
-
-
Save athena15/b0ef8a46b38d92b0d1ad59a3dce18440 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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