Fer2013
Facial Emotion Recognition on FER2013 Dataset Using a Convolutional Neural Network
Install / Use
/learn @gitshanks/Fer2013README
FER2013
Kaggle Challenge - https://www.kaggle.com/c/challenges-in-representation-learning-facial-expression-recognition-challenge/data
Facial Emotion Recognition on FER2013 Dataset Using a Convolutional Neural Network.
80-10-10 ratio for training-validation-test sets.
Winner - 71.161% accuracy
This Model - 66.369% accuracy

Getting Started
These instructions will get this model up and running. Follow them to make use of the fertestcusstom.py file to recognize facial emotions using custom images. This model can also be used as facial emotion recognition part of projects with broader applications
Prerequisites
Install these prerequisites before proceeding-
pip3 install tensorflow
pip3 install keras
pip3 install numpy
pip3 install sklearn
pip3 install pandas
pip3 install opencv-python
Method 1 : Using the built model
If you don't want to train the classifier from scratch, you can make the use of fertestcustom.py directly as the the repository already has fer.json (trained model) and fer.h5 (parameters) which can be used to predict emotion on any test image present in the folder. You can modify fertestcustom.py according to your requirements and use it to predict fatial emotion in any use case.
Method 2 : Build from scratch
Clone this repository using-
git clone https://github.com/gitshanks/fer2013.git
Download and extract the dataset from Kaggle link above.
Run the preprocessing.py file, which would generate fadataX.npy and flabels.npy files for you.
Run the fertrain.py file, this would take sometime depending on your processor and gpu. Took around 1 hour for with an Intel Core i7-7700K 4.20GHz processor and an Nvidia GeForce GTX 1060 6GB gpu, with tensorflow running on gpu support. This would create modXtest.npy, modytest,npy, fer.json and fer.h5 file for you.
Running the tests (Optional)
You can test the accuracy of trained classifier using modXtest.npy and modytest.npy by running fertest.py file. This would give youy the accuracy in % of the recently trained classifier.
Getting the Confusion Matrix (Optional)
You can get the confusion matrix for this model by running confmatrix.py file. This would evaluate the most confused expressions and generate a confusionmatrix.png file for your trained model, which would look something like this.

Model Summary
The layers in the Convolution Neural Network used in implementing this classifier can be summarized as follows. You can git a similar summary by decommenting the model.summar() function before executing fertrain.py file.

Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
