How Instrumental Finance complements the Composable ecosystem

As Instrumental Finance works towards creating new cross-layer yield generation opportunities, it aligns itself with Composable Finance, the face of DeFi’s future. Composable is growing in its…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Facial Expressions Recognition using Keras

Testing the model with a live webcam using OpenCV

The objective of the project:- The aim of this project is to identify people’s emotions based on their live video by building and training a system that automatically monitors people's emotions and expressions with more than 24000 facial images, with their associated facial expression labels. The chosen labels were angry, happy, neutral, sad, and surprise.

Flow diagram of deep learning

Part 1: Importing the libraries and loading the dataset

Part 2: Data augmentation to increase the amount of data artificially by generating new data points from existing data.

Part 3: We will create a sequential deep learning model based on Convolutional Neural Network and Residual Blocks to predict the facial expression.

Part 4: Optimising the training using ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, and compiling the model.

Part 5: Test the model using OpenCV

Data Augmentation of training datasets

Both these operations are performed on both the training and validation datasets.

Architecture
Convolution Block
1st convolution block

Among 4 deep neural networks, one of the neural networks is shown above. It includes conv2D block, activation layer, batch normalization, and max-pooling.

Now we want the weighted sum of the input to be transformed into an output from the nodes in a layer of the network, thus we use the ‘elu’ activation function, ELU is very similar to RELU except for negative inputs. They are both in identity function form for non-negative inputs. On the other hand, ELU becomes smooth slowly until its output is equal to −α whereas RELU sharply smoothes.

ELU (Exponential Linear Units)

Batch normalization is a layer that allows every layer of the network to do learning more independently. It is used to normalize the output of the previous layers and often we add it after the activation layer for better results.

Maximum pooling is done which calculates the maximum, or largest, value in each patch of each feature map. The results are downsampled or pooled feature maps that highlight the most present/important feature in the patch.

Now a dropout layer with 20% is added to prevent neural networks from Overfitting. Dropout is a technique where randomly selected neurons are ignored during training.

After 4 layers flatten and dense layers are added together with ‘elu’ activation, batch normalization, and dropout layer where:

After this 3 dense layers are added to a fully connected layer and the SOFTMAX activation function which is normally applied to the very last in the neural network. Softmax is useful because it converts the output of the last layer in the neural network into a probability distribution. It is generally used as the activation function for multi-class classification problems where class membership is required on more than two class labels here also we need 5 class labels.

Optimizing the training model

ModelCheckpoint callback -

EarlyStopping callback-

ReduceLROnPlateau callback-

Compiling the model

COMPILING THE MODEL- It includes loss function as ‘categorical crossentropy’, optimizer as ADAM, and accuracy metrics.

model.fit()

Lastly, we fit our training model. Hyperparameters used are self-explanatory.

Importing libraries and loading model

Part 5.1: Importing the libraries- Keras, OpenCV as cv2, numpy.

Part 5.2: Introducing the Cascade classifier- Which is an Object Detection Algorithm used to identify faces in an image or a real-time video. The algorithm uses edge or line detection features. Loading the model saved in the.h5 file and defining the class labels as ‘Angry’, ‘Happy’, ‘Sad’, ‘Neutral’, ‘Surprise’.

Part 5.3: Testing using the inbuilt webcam- VideoCapture(0) turns on the laptop’s inbuilt camera.

Capturing video from a live webcam

(other explanation of the above code is commented in the snippet itself)

Part 5.4: Results

Surprise
Angry
Sad

Here we come to the end of the project.

Happy reading :)

Add a comment

Related posts:

Writers Are The Stork Who Delivers The Message

Waking up to comments from fellow writers are always welcome, and they remind me why I write each day. Most of the time, the comments would come from stories I wrote from the heart, of personal…

AWS EKS

Hey lets get it right, k8s is the default container orchestration system these days. One of the earlier challenges with the k8s was it was hard to spin a k8s cluster. There are tools like kops which…

Enabling SQLite FTS in Room 2.1

I was so very fortunate to be able to attend the Android Dev Summit in Mountain View this week, where one announcement in particular caught my attention: the 2.1 release of the Room library supports…