Skip to content

EmotionNet2 convolutional neural network for expression recognition

License

Notifications You must be signed in to change notification settings

TieSKey/EmotionNet2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EmotionNet2

Building on EmotionNet we improve generalization by improving the way we handle our input data.

What is EmotionNet?

EmotionNet is an application of Convolutional Neural Networks to emotion recognition in photographs of human faces. EmotionNet2 does face detection in addition to classification to assist in reducing variance due to backgroud noise. See the original EmotionNet. There is no web interface for this version as was present in the original version.

Support

You should please note that no support is guaranteed and only best effort is provided. I will gladly accept reasonable patches and would like to hear if documentation/instructions are unclear. By no means are the instructions 100% foolproof but I expect you to be able to have some understanding of Python, and Linux environments.

Instructions

  1. Install requirements, including requirements.txt. Use pip3 --requirement requirements.txt. Additionally, you need pytorch gpu.

Follow either Pretrained or Train Yourself streams after completing the requirements.

Pretrained

  1. Download the external checkpoint from my server and place in the root directory.
  2. Then, decompress using gzip, gunzip checkpoint.pth.tar.gz (removes .gz extension)
  3. Start python3 from the root directory with the PYTHONPATH=python as the python scripts are in the python directory.
  4. To try one image you can do the following:
import emotionnet
net = emotionnet.EmotionNet(layers=[3, 4, 23, 3])
net.load_checkpoint('checkpoint.pth.tar')
net.classify_one_image('filename of image.jpg')

To run this as a service you would want to keep the checkpoint loaded in memory as it takes some time to load.

Train Yourself

  1. In order to train you will need KDEF the scripts expect the file References.txt in the KDEF distribution to be in KDEF/References.txt from the root of the project.

  2. Once you have KDEF data you need to split the data up into training/validation/testing and extract the faces from the KDEF data.

  3. Run PYTHONPATH=python python3 python/extract_faces.py which extracts the faces into train/

  4. Run PYTHONPATH=python python3 python/split_dataset.py which splits into train/test/valid

  5. Finally run a trainer. This will take some time. It is recommended to make a file containing the below called train.sh and run this file. Set tname on the first line to whatever you like. The tname will be your checkpoint.pth.tar from the pretrained.

tname=model-01
PYTHONPATH=$PYTHONPATH python3 <<HEAD
import emotionnet
net = emotionnet.EmotionNet(layers=[3, 4, 23, 3])
net.train_model('train', 'valid', '$tname', epochs=200, csvout='${tname}-csv.csv')
net.load_checkpoint('best-${tname}.pth.tar')
net.valid_model('valid')
HEAD
  1. Now you've trained your model, follow the pretrained instructions from step 4. using your checkpoint file and not the checkpoint.pth.tar. Your best model will start with best-

About

EmotionNet2 convolutional neural network for expression recognition

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%