Making predictions
First, let's prepare data to make predictions about the images:
array = np.mat(data.pixels[1]).reshape(48, 48) image = scipy.misc.toimage(array, cmin=0.0) display(image) print(emotion_labels[data.emotion[1]]) <Image>
Let us input an angry emotion image:
input_img = np.array(array).reshape(1,48,48,1)
Okay, we have an angry face. Now let's make prediction and check if the network can recognize it correctly:
prediction = model.predict(input_img) print(prediction) [[ 0.05708674 0.35863262 0.03299783 0.17862292 0.00069717 0.37196276]] emotion_labels[prediction.argmax()] 'Neutral'
Note those array of 6 float numbers. These are probabilities of belonging to each class. In other words, the model predicts, that this face can be of an angry person only with the probability of 5%. The full table would look like this:
Angry | Fear | Happy | Sad | Surprise | Neutral |
0.05708674 | 0.35863262 | 0.03299783 | 0.17862292 | 0.00069717 | 0.37196276 |
for i in xrange(1, 100): array = np.mat(data.pixels...