Giter Club home page Giter Club logo

real-time-facial-expression-recognition-with-deeplearning's Introduction

Real-Time-Facial-Expression-Recognition-with-DeepLearning

A real-time facial expression recognition system through webcam streaming and CNN.

Abstract

This project aims to recognize facial expression with CNN implemented by Keras. I also implement a real-time module which can real-time capture user's face through webcam steaming called by opencv. OpenCV cropped the face it detects from the original frames and resize the cropped images to 48x48 grayscale image, then take them as inputs of deep leanring model. Moreover, this project also provides a function to combine users' spoken content and facial expression detected by our system to generate corresponding sentences with appropriate emoticons.

Dataset

fer2013 is the dataset I chose, which is anounced in Kaggle competition in 2013.

Environment

I provide my work environment for references.

Hadware

CPU : i5-6500
GPU : nvidia GTX 960 2G
RAM : 8G

Software

OS : Ubuntu 16.04
Keras 1.2.0
scikit-learn 0.18.1
opencv 3.1.0

Installation

I strongly recommend you to use Anaconda, which is a package manager and provides python virtual environment.
After you install Anaconda, you can create a virtual environment with python 3.4.

conda create -n env-name python=3.4

you can also check if your env. has been created by,

conda info --envs

You should activate your virtual environment in different way corresponding to your operating system. For example, In Ubuntu, you can activate your virtual environment by,

source activate env-name

And,

source deactivate 

to exit the virtual environment.

The following instructions will lead you to install dependencies, and I suggest you to fllow the order.

Install scikit-learn

conda install scikit-learn

Install OpenCV

Note that the version Anaconda provided may not be the latest one.

conda install opencv

If you fail to install opencv due to python version conflicts, try this command instead,

conda install -c menpo opencv3=3.1.0

the version 3.1.0 can be replaced with the lateset one, but in this project, I use opencv 3.1.0.

Install Keras

Keras is a high-level wrapper of Theano and Tensorflow, it provides friendly APIs to manipulate several kinds of deep learning models.

pip install --upgrade keras

Install pandas and h5py

pandas can help you to preprocess data if you want train your own deep learning model.

conda install pandas

h5py is used to save weights of pre-trained models.

conda install h5py

Configuration

Before executing this project, you should make Keras use Theano backend by modifying configuration file in

~/.keras/keras.json

If it doesn't exist, you can create a new one, and then change the content to

if you use kears 1 :

{
    "image_dim_ordering": "th",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "theano"
}

if you use kears 2 :

{
    "image_data_format": "th",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "theano"
}

Usage

Simple facial expression detection

After installing dependencies, you can move to webcam directory and simply type this command,

python webcam_detection.py

and the system will start detecting user's emotions and print results to the console.

Affecting computing system

If you want to combine facail expression detection and speech recognition to generate a completed sentence with appropriate emoticons, you should install an additional dependency.

pip install SpeechRecognition

After installing the above library, you can type this to lauch the detector.

python gen_sentence_with_emoticons.py

Launch the system and input "y" to start the detection, then you can speek something with facial expression to try to acquire a sentence with emoticons.

Contact

Please give me a star if you like my project.

real-time-facial-expression-recognition-with-deeplearning's People

Contributors

a514514772 avatar yaya0805 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

real-time-facial-expression-recognition-with-deeplearning's Issues

oserror

why am i getting this error please help
"OSError: Unable to open file (unable to open file: name = 'my_model_weights_83.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)"

I am getting the following error

I followed the steps as mentioned in the readme file but I am getting the following error please help.

Traceback (most recent call last):
File "webcam_detection.py", line 5, in
import cv2
ModuleNotFoundError: No module named 'cv2'

detection not very precise (mostly sad)

I'm using tensorflow backend and I've converted your weights via the folowing code:

import sys, os
sys.path.append("../")
from keras import backend as K
from keras.utils.conv_utils import convert_kernel
import tensorflow as tf
ops = []
import model.myVGG as vgg

model = vgg.VGG_16('my_model_weights_83.h5')
model.load_weights('my_model_weights_83.h5')
for layer in model.layers:
   if layer.__class__.__name__ in ['Convolution1D', 'Convolution2D', 'Convolution3D', 'AtrousConvolution2D']:
      original_w = K.get_value(layer.W)
      converted_w = convert_kernel(original_w)
      ops.append(tf.assign(layer.W, converted_w).op)
K.get_session().run(ops)
model.save_weights('my_model_weights_83_tf.h5')

It runs and it shows me the predictions, but they're mostly wrong (always sad, angry and very rarely happy, etc.).

then i downloaded fer2013 and ran fer20134atagen.py and model_training.py with tensorflow backend and the results improved somewhat.

Anything hints on how to improve training and the predictions?
Or Is there maybe a better better trained_model to download?

Webcam Error

I run both script webcam start but not showing anything please reply me

Dataset access - Help

Hello,

I'm testing your code.
But I stopped initially in obtaining the
fer2013 dataset

I already signed up for kagler but I did not find this dataset.

Do you have a link that helps me find it?

blank webcam preview window

Everything looks perfect but preview window is blank. But video is captured and result is displayed on terminal.

preview window constantly buffers and becomes "non-responding"

Help in Retraining Model

i used your code, and its works really awesome. but i am facing just one issue. your trained model contains mostly asain faces. and their expressions are not exactly like indian faces. I wish to retrain the model. can i just do it by replacing the images in the folder, or is there any other way to train it? help will be really appreciated!

image

WebCam error

i got a preview screen with a grey view and doesn't show anything esle

It hangs at

For me, it hangs at - "D:\AI\Real-Time-Facial-Expression-Recognition-with-DeepLearning-master\model\myVGG.py: 33: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(128, (3, 3), activation="relu")
model.add(Convolution2D(128, 3, 3, activation='relu'))
Traceback (most recent call last):

I am using windows. Anaconda with spyder.

When it hanged, i stopped debugging. then the follwoing appeared at console.

File "C:\Users\Ishwar\Anaconda3-new\envs\tf-py35-udemy-env\lib\site-packages\theano\tensor\elemwise.py", line 790, in perform
variables = ufunc(*ufunc_args, **ufunc_kwargs)

File "C:\Users\Ishwar\Anaconda3-new\envs\tf-py35-udemy-env\lib\site-packages\theano\scalar\basic.py", line 4023, in impl
output_storage = [[None] for i in xrange(self.nout)]

SystemError: <class 'range'> returned a result with an error set
Apply node that caused the error: Elemwise{Composite{(i0 + (i1 * i2))}}[(0, 2)](TensorConstant{(1, 1) of ..0.03263956}, TensorConstant{(1, 1) of 0.06527912}, mrg_uniform{TensorType(float32, matrix),inplace}.1)
Toposort index: 1
Inputs types: [TensorType(float32, (True, True)), TensorType(float32, (True, True)), TensorType(float32, matrix)]
Inputs shapes: [(1, 1), (1, 1), (4608, 1024)]
Inputs strides: [(4, 4), (4, 4), (4096, 4)]
Inputs values: [array([[-0.03263956]], dtype=float32), array([[0.06527912]], dtype=float32), 'not shown']
Outputs clients: [['output']]

HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'.
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

In summary, it did not work for me (yet!). Please suggest if there are ways to sort this this out.

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.