Coder Social home page Coder Social logo

facial-expression-recognition's Introduction

Facial-Expression-Recognition

CNN on imbalanced FER Dataset using Keras on top of Tensorflow.

NOTE: No transfer learning (or any pre-trained weights such as those trained on imagenet) was used (although that would have improved the results), because that would defeat the purpose of training a CNN from scratch for an imbalanced dataset.

Contents

Installation

pip install -r requirements.txt

Why this project?

This project was mainly built to learn how to work with imbalanced datasets with Deep Learning. Provided how prone neural networks are to over-fitting, I decided to use this dataset with Convolutional Neural Networks, to try to build a model that would not suffer from over-fitting.

How to use?

Use pre-trained model

  • To use the pre-trained model, download the model from the GitHub releases page, link here.
  • Move the downloaded .h5 file inside the 'model' directory.
  • Run detect_expression.py file.

Train from scratch

Get data

  • Make a directory named 'data', and inside that, two directories named 'train' and 'test'.
  • Inside each of those two directories, make a directory for each image class, and move the images in it accordingly.

Train a model

  • Run train.py to train a model for the FER dataset.
  • Once the model is finished training, it is automatically saved, and results are plotted and saved under the 'models' directory.

Detect Expressions

  • Have the model that you want to use, named 'model.h5', under the 'model' directory.
  • Run detect_expression.py to run the trained model, and detect expressions using the webcam.
    • You might have to change the video capture number if you have multiple webcams, and want to change cameras.
  • A pre-trained haarcascade classifier first detects a face, and a boundary box is drawn. The detected face is then cropped from the webcam input stream, preprocessed, and fed into the model.
  • Press q to stop the running model and quit the script.

Dataset

The Facial Expression Recognition (FER) dataset is an image classification task, wherein there are grayscale images of size (48, 48), and are to be classified into 7 different classes. It is also worthy to mention that the dataset is very much imbalanced, with the number of samples for each class ranging from 111 to 1774.

Model

A convolutional neural network is used to train on this dataset, and since the dataset is imbalanced, class weights are calculated and passed, during the training phase. Also, AUC metric is tracked, along with accuracy and loss.

The default model architecture is defined in model_configs.py file. Dropout is used for regularization, along with Batch Normalization for faster convergence.

The Keras Image DataGenerator, defined under generators.py file is used for image augmentation during training phase, to prevent over-fitting and combat the imbalanceness in the dataset.

Training results

Accuracy Loss AUC

Confusion Matrix

Confusion Matrix

Classification Report

Classification Report

Model Architecture

modelPlot

facial-expression-recognition's People

Contributors

gautam-j avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.