gradio/examples/Emotional Detector (ImageUpload).ipynb
2019-03-06 22:09:49 -08:00

4.7 KiB

In [1]:
import numpy as np
import sklearn
import gradio
from keras.models import load_model

%load_ext autoreload
%autoreload 2
Using TensorFlow backend.

Load an Facial Emotion Detector Model

In [2]:
model = load_model('../.models/emotion.h5')
In [3]:
def post_p(prediction): 
    emotional_dict = {0: "Angry", 1: "Disgusted", 2: "Fearful", 3: "Happy", 4: "Neutral", 5: "Sad", 6: "Surprised"}
    return emotional_dict[prediction.squeeze().argmax()]
In [4]:
iface = gradio.Interface(inputs='imageupload', outputs='label', model=model, model_type='keras')
iface.launch(share=False)
NOTE: Gradio is in beta stage, please report all bugs to: a12d@stanford.edu
Model is running locally at: http://localhost:7860/interface.html
To create a public link, set `share=True` in the argument to `launch()`
Out[4]:
('http://localhost:7860/interface.html', None)
127.0.0.1 - - [06/Mar/2019 12:13:52] "GET /interface.html HTTP/1.1" 200 -
127.0.0.1 - - [06/Mar/2019 12:13:52] "GET /static/css/gradio.css HTTP/1.1" 200 -
127.0.0.1 - - [06/Mar/2019 12:13:52] "GET /static/js/all-io.js HTTP/1.1" 200 -
127.0.0.1 - - [06/Mar/2019 12:13:52] "GET /static/js/image-upload-input.js HTTP/1.1" 200 -
127.0.0.1 - - [06/Mar/2019 12:13:52] "GET /static/js/class-output.js HTTP/1.1" 200 -
Error in connection handler
Traceback (most recent call last):
  File "C:\Users\islam\Anaconda3\envs\tensorflow\lib\site-packages\websockets\server.py", line 169, in handler
    yield from self.ws_handler(self, path)
  File "C:\Users\islam\Anaconda3\envs\tensorflow\lib\site-packages\gradio\interface.py", line 106, in communicate
    prediction = self.predict(processed_input)
  File "C:\Users\islam\Anaconda3\envs\tensorflow\lib\site-packages\gradio\interface.py", line 122, in predict
    return self.model_obj.predict(preprocessed_input)
  File "C:\Users\islam\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\training.py", line 1149, in predict
    x, _, _ = self._standardize_user_data(x)
  File "C:\Users\islam\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\training.py", line 751, in _standardize_user_data
    exception_prefix='input')
  File "C:\Users\islam\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\training_utils.py", line 138, in standardize_input_data
    str(data_shape))
ValueError: Error when checking input: expected conv2d_1_input to have shape (48, 48, 1) but got array with shape (224, 224, 3)