victorchika/igp-group-15-anti-spoofing-app
Face Liveness Detection Project
This project follows the pipeline:
- video input
- extract 10 frames per video
- detect and crop faces automatically
- keep frames grouped per video
- train a CNN + LSTM model
- classify as real or fake
Folder structure
liveness_detection_project/
├── data/
│ ├── raw_videos/
│ │ ├── Real/ ← real face videos
│ │ │ └── Selfies/ ← images only, skipped automatically
│ │ ├── 3D_paper_mask_/ ← fake
│ │ ├── Cutout_attacks/ ← fake
│ │ ├── Latex_mask/ ← fake
│ │ ├── Printouts/ ← fake
│ │ │ ├── WITH CUTOUT/
│ │ │ └── WITHOUT CUTOUT/
│ │ ├── Replay_display_attacks/ ← fake
│ │ ├── Silicone_mask/ ← fake
│ │ ├── Textile 3D Face Mask Attack Sample/ ← fake
│ │ └── Wrapped_3D_paper_mask/ ← fake
│ ├── extracted_frames/
│ └── face_sequences/
├── models/
├── src/
├── requirements.txt
└── README.mdHow folders are classified
The script extract_frames.py uses an explicit mapping to assign each folder to real or fake. If you add a new attack folder to raw_videos/, you must also add it to the FOLDER_LABELS dictionary at the top of src/extract_frames.py, otherwise it will be skipped with a warning.
The Real/Selfies/ subfolder contains .jpg images, not videos. It is skipped automatically.
Before you start
Make sure Python is installed on your laptop.
Step-by-step setup on Windows PowerShell
1. Open PowerShell in this project folder
Use cd to move into the folder that contains this project.
2. Create a virtual environment
python -m venv venv3. Activate it
.\venv312\Scripts\ActivateIf activation is blocked, run this once in PowerShell:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassThen activate again.
4. Install dependencies
pip install -r requirements.txtRun the project step by step
Step 1. Extract exactly 10 frames from each video
python src\extract_frames.pyOutput goes to:
data/extracted_frames/
├── real/
└── fake/At the end it prints a summary like:
Done. Real: 95 | Fake: 112 | Skipped: 3Step 2. Detect and crop faces using OpenCV
python src\crop_faces_opencv.pyOutput goes to:
data/face_sequences/
├── real/
└── fake/Important:
- only video folders with at least 7 usable face crops are kept
- folders with fewer valid faces are skipped automatically
- each kept folder is padded or trimmed to exactly 10 frames
Step 3. Check a few output folders manually
Open a few folders in:
data/face_sequences/real/
data/face_sequences/fake/Check that:
- the face is visible
- the crop is not broken
- each kept folder has exactly 10 images
- each folder still represents one single video
Step 4. Train the model
python src\train.pyBest model is saved to:
models/best_model.pthSplit indices are also saved to:
models/split_indices.jsonStep 5. Evaluate the model
python src\evaluate.pyThis prints:
- classification report
- confusion matrix
- APCER
- BPCER
- ACER
Step 6. Webcam demo
python src\webcam_demo.pyStep 7. Launch Streamlit
streamlit run app.pyPress q to quit.
One-command run
If your dataset is already in place and dependencies are installed, you can run:
python run_pipeline.pyThat will run:
- frame extraction
- face cropping
- training
- evaluation
To redo frame extraction and face cropping
If you want to clear the processed data and start fresh:
Remove-Item -Recurse -Force "data\extracted_frames\*"
Remove-Item -Recurse -Force "data\face_sequences\*"Then rerun Steps 1 and 2.
Common issues
python not found
Try:
py --versionIf py works, use py instead of python.
ModuleNotFoundError
Make sure the virtual environment is activated and dependencies were installed.
A folder is being skipped with a WARNING
If you see WARNING: Unknown folder '...' — not in FOLDER_LABELS, open src/extract_frames.py and add the folder name and its label to the FOLDER_LABELS dictionary at the top of the file.
Not enough valid face folders
That usually means face detection failed on many extracted frames. Check your raw videos and cropped outputs.
Training starts but does not save a model
Make sure models/ exists. This starter project already includes that folder.
evaluate.py raises FileNotFoundError for split_indices.json
You must run train.py before evaluate.py. Training saves the split indices that evaluation depends on.
Recommended workflow
- Create and activate
venv - Install requirements
- Confirm your dataset folders are inside
data/raw_videos/as shown in the folder structure above - Run
python src\extract_frames.py - Run
python src\crop_faces_opencv.py - Inspect the output folders manually
- Run
python src\train.py - Run
python src\evaluate.py - Try webcam demo only after the model is saved
AFTER DOWNLOADING THE ZIP
1. Activate it
.\venv312\Scripts\ActivateIf activation is blocked, run this once in PowerShell/terminal:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassThen activate again.
2. Run webcam_demo.py
python src\webcam_demo.py 