Real-time Facial Expression Emoji Masking with Convolutional Neutral Networks and Homography.

Authors: Qinchen Wang, Sixuan Wu, Tingfeng Xia

| Report | arXiv(2012.13447) | Code | Demo |


You will need to install dlib, imutils, and cv2 via:

pip install dlib imutils opencv-python
# notice that you will need cmake if it is not yet installed on your machine, 
# you can do so on mac
brew install cmake
# or check for linux

See for how to install torch and torchvision locally.

Local Quick Start

The app folder contains a standalone app that allows you test our pipeline with input from your own webcam! You can do so by

# clone this repo via git
cd Emoji-Expression-Mask.PyTorch/app/
# a window should pop up and you will see your beautiful face and the masked result. 

Note: Once you start the app, if you don’t see the window poping up, that’s because we failed to detect your face, please adjust tha angle and make sure your face is complete in the camera. During the execution of the app, if you see that the video is stuck, that’s also mostly likely because we didn’t detect your face.

Pretrained Models

Our implementation uses VGG BA SMALL network, whose model weights are already included in the standalone app. Here are all our trained models, in case you wish to experiment.

# Xception pretrained weights
# VGG 11 pretrained weights
# VGG 13 pretrained weights
# VGG 16 pretrained weights
# VGG 19 pretrained weights
# VGG BA SMALL pretrained weights (the one that we are using in our report)
# see the report for a detailed discussion
# Squeeze net pretrained weights

Training Your Own Model

Apart from our default VGG BA SMALL network implementation, we have also prepared trained models, in PyTorch, for VGG11, 13, 16, 19, Xception, and Shuffle Net. To load these models see the Model Preparation Section above. Alternatively, you can train your own weights for the expression categorization. We used FER2013 as our training data, and you can download it here: (please put them in the data folder once downloaded)

The data.h5 file provided is a preprocessed version of the FER2013 dataset, which you can use the torch dataloader load directly. You can also customize your preprocessing by editing and then running the file and using the fer2013.csv file. A data.h5 file should be generated in the data/ folder. It contains your freshly processed dataset.

Check train_and_test.ipynb for how to train the model once you have the dataset ready.

Other Experiments

See the report for a comprehensive discussion of our experiments with VGG BA SMALL network. Below are some other experiments that we conducted.

ShuffleNet experiments

The main file that trains and validates the model is called shuffle_net.ipynb. This file loads data from folders, and the version pushed to the branch experiments with the CK+ dataset. If you want to run the file with FER2013, please follow the guide in the section FER2013 dataset preparation on where the dataset is stored as image folders.

SqueezeNet experiments

All experiments related to SqueezeNet are stored in the master branch. The main file that trains and validates the model is called csc420 squeezenet.ipynb. If you would like to play with the model that achieved 97% accuracy on both the training and validation set for the CK+ dataset:

The model training, evaluation and saving are implemented in a file called train_and_test.ipynb. After training, the model is stored in a folder called FER2013_{model name} with filename validation_model.t7. Our pretrained VGG_BA_SMALL model is stored in Google drive via the link:

Test model with your own input

The file named load_and_test_qinchen.ipynb currently loads images from the folder ./qinchen and makes preditions usinig a pretrained network. You can replace the images in the folder ./qinchen and run this file to see the model prediction on your own face expressions. Note, this is only the second module in our pipeline, so in order to get a satisfactory performance you will have to crop out the face yourself.