A liveness detector capable of spotting fake faces and performing anti-face spoofing in face recognition systems.
- dataset
- fake_images
- real_images
- face_detector
- deploy.prototxt
- res10_300x300_ssd_iter_140000.caffemodel
- videos
- fake_generated_videos
- real_generated_videos
- generate_frames.py
- le.pickle
- liveness.model
- livenessnet.py
- test.py
- trainmodel.py
There are three main directories in the project:
- dataset: This directory consists of two classes of images: Fake images captured from a camera aimed at the screen while playing a video of some face. Real images captured from a selfie video with the phone.
- face_detector: Consists of our pretrained Caffe face detector to locate face ROIs.
- videos: The videos are collected from people where they first capture themselves on their phones and then that video is captured on a laptop gain to generate fake frames
- Collect videos from friends of themselves of around 10-15 seconds.These are the "real" videos.
- Create "fake" videos by capturing the real videos on your laptop by playing them on your phone.
- Manually arrange them into subdirectories of real and fake in the videos folder.
- Run the generate_frames.py script in the terminal/cmd to generate image frames of the videos, whilst manually arranging the generated images into subdirectories in the dataset directories.
To run:
i. for real videospython generate_frames.py --input videos/real1.mp4 --output dataset/real --detector face_detector --skip 1
To run:
ii. for fake videospython generate_frames.py --input videos/fake1.mp4 --output dataset/fake --detector face_detector --skip 4
Here skip is used to skip N frames between detections because adjacent frames will be similar.
- Run the trainmodel.py script by typing in the terminal/cmd:
python trainmodel.py --dataset dataset --model liveness.model --le le.pickle
- After training the model, run the test.py script by typing in the terminal/cmd:
python test.py --model liveness.model --le le.pickle --detector face_detector
To make sure you do not get an imbalanced dataset, set the skip rate accordingly while running the generate_frames.py script.
- Can be implemented in Face Recognition systems in companies and can be used for face unlocking in phones.
- The current liveness detection can be combined with eye blink detection(using facial landmark detector and setting an eye blink threshold) which will be feasible to filter out most of the remaining cases.