Face & Landmark Detection
- RetinaFace (CVPR 2020)
Face Recognition
- AdaFace (CVPR 2022)
Facial Expression Recognition
- DAN (ArXiv 2021)
Facial Attribute Classification
Check the models' comparison and download their pretrained weights from below.
- Face & Landmark Detection
- Face Recognition
- Facial Expression Recognition
- Facial Attribute Classification
- torch >= 1.11.0
- torchvision >= 0.12.0
Other requirements can be installed with:
$ pip install -r requirements.txt
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 \
Need to download the pretrained weights for Face Detection and Face Recognition models from Benchmarks & Pretrained Models section.
$ 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 |
---|---|---|
# similarity scores
tensor([[1.0000, 0.0028, 0.0021],
[0.0028, 1.0000, 0.6075],
[0.0021, 0.6075, 1.0000]])
- 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)
# 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
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 \
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 \