Created
January 4, 2019 09:12
-
-
Save jonathanoheix/5acf50dc36cbd0a560040d2fff5dbe86 to your computer and use it in GitHub Desktop.
This file contains 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.models import model_from_json | |
import numpy as np | |
class FacialExpressionModel(object): | |
EMOTIONS_LIST = ["Angry", "Disgust", | |
"Fear", "Happy", | |
"Neutral", "Sad", | |
"Surprise"] | |
def __init__(self, model_json_file, model_weights_file): | |
# load model from JSON file | |
with open(model_json_file, "r") as json_file: | |
loaded_model_json = json_file.read() | |
self.loaded_model = model_from_json(loaded_model_json) | |
# load weights into the new model | |
self.loaded_model.load_weights(model_weights_file) | |
self.loaded_model._make_predict_function() | |
def predict_emotion(self, img): | |
self.preds = self.loaded_model.predict(img) | |
return FacialExpressionModel.EMOTIONS_LIST[np.argmax(self.preds)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment