This package supports 1) Face extraction/alignment, 2) Training, 3) Inferring, 4) real-time webcam for Facial Emotion Recognition.
Install PyTorch.
Install OpenCV.
Install sklearn.
Install PIL, matplotlib, numpy, etc.
This package is checked in Conda + Python3.8 + Cuda 11.1 + PyTorch LTS (with CUDA 11.1)
1. Extract (crop) and align face from an image (MTCNN)
python extract_face.py
DIR_IN
: raw image path (before face extraction). The code expects one-level hierarchy under DIR_IN
(folders under DIR_IN
).
DIR_OUT
: face data path (after face extraction) with same one-level hierarchy.
NUM_IMAGES
: number of images to extract faces under each folder (DIR_IN
); 1) positive: from the first, 2) negative: from the last, 3) 0: all images
python train.py
Modify settings via argument parsing.
This code results in f'{args.identifier}_model_best.pth.tar'
python infer.py
Use f'{args.identifier}_model_best.pth.tar'
from python train.py
as --model.
The user has three options for --image
:
- If
--image
isNone
, the code test all images under--data
path and save the results under--results
- If
--image
isfault_finder
, the code makes csv file that includes how/what images were inferred incorrectly. - If
--image
is a specific path to an image, the code prints the probability and the class with the maximum probability on console.
python webcam.py
model(*.pth.tar
) must exist at --model
.
Use --gpu, --fps
for your convenience.
--resize-h
is 0 by default, which does not resize the input from the real-time webcam at all.