Skip to content

sithu31296/EasyFace

Repository files navigation

EasyFace: Easy Face Analysis Tool with SOTA Models

Table of Contents

Supported Models

Face & Landmark Detection

Face Recognition

Facial Expression Recognition

  • DAN (ArXiv 2021)

Facial Attribute Classification

Benchmarks & Pretrained Models

Check the models' comparison and download their pretrained weights from below.

Requirements

  • torch >= 1.11.0
  • torchvision >= 0.12.0

Other requirements can be installed with:

$ pip install -r requirements.txt

Usage

Face & Landmark Detection

Need to download the pretrained weights for Face Detection Model from here.

Run the following command to detect face and show bounding box and landmarks:

$ python detect_align.py \
    --source IMAGE_OR_FOLDER \
    --model RetinaFace \
    --checkpoint DET_MODEL_WEIGHTS_PATH \

det_result

Face Recognition

Need to download the pretrained weights for Face Detection and Face Recognition models from Benchmarks & Pretrained Models section.

Find Similarities of Given Images

$ python find_similarity.py \
    --source assets/test_faces \
    --model AdaFace \
    --checkpoint FR_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH

Notes: The size of the testing images can be different.

img1 img2 img3
nc rdj1 rdj
# similarity scores
tensor([[1.0000, 0.0028, 0.0021],
        [0.0028, 1.0000, 0.6075],
        [0.0021, 0.6075, 1.0000]])

Register New Faces

  • Create a folder containing the face images.
  • One image per person.
  • Rename the filename of the image to a person's name.
  • Restrictions:
    • All images should be in the same size.
    • Only one face must exist in the image.
  • Run the following to save all face embeddings into a pickle file:
$ python register.py \
    --source assets/test_faces \
    --output assets/faces.pkl \
    --model AdaFace \
    --checkpoint FR_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH

Sample testing structure:

|__ data
    |__ test_faces
        |__ rdj.jpg
        |__ nc.jpg
        |__ ...
    |__ faces.pkl (output)

Recognize with a Webcam or an Image or a Video

# with an image or a video
$ python recognize.py \
    --source IMAGE_OR_VIDEO \
    --face_data assets/faces.pkl \
    --model AdaFace \
    --checkpoint FR_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH \
    --recog_threshold RECOGNITION_THRESHOLD

# with a webcam
$ python recognize.py \
    --source webcam \
    --face_data assets/faces.pkl \
    --model AdaFace \
    --checkpoint FR_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH \
    --recog_threshold RECOGNITION_THRESHOLD

recog_result

Facial Expression Recognition

Need to download the pretrained weights for Facial Expression Recognition Model from here.

Run the following:

# with an image or a video
$ python recognize_emotion.py \
    --source IMAGE_OR_VIDEO \
    --dataset AffectNet8 \
    --model DAN \
    --checkpoint FER_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH \

# with a webcam
$ python recognize_emotion.py \
    --source webcam \
    --dataset AffectNet8 \
    --model DAN \
    --checkpoint FER_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH \

fer_result

Facial Attribute Classification

Need to download the pretrained weights for Facial Attribute Classification Model from here.

Run the following:

# with an image or a video
$ python recognize_att.py \
    --source IMAGE_OR_VIDEO \
    --model FairFace \
    --checkpoint FAC_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH \

# with a webcam
$ python recognize_att.py \
    --source webcam \
    --model FairFace \
    --checkpoint FAC_MODEL_WEIGHTS_PATH \
    --det_model RetinaFace \
    --det_checkpoint DET_MODEL_WEIGHTS_PATH \

att_result

References

About

Easy-to-use Face Analysis Tool

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages