How snarayan43/mls_final_project2025 works
1. Repository purpose
- This is an end-to-end deepfake detection experiment, not a general application.
- The architecture is split into two major phases: offline video preprocessing and online model training/evaluation.
2. External data boundary
- The source data comes from FaceForensics++ (C23), specifically original vs Face2Face.
- Raw inputs are video files; the project does not train directly from videos during the main experiment.
3. Preprocessing subsystem: preprocess.py
- This is the data-engine layer.
- It uses OpenCV face detection with haarcascade_frontalface_default.xml to locate facial regions.
- For each video, it samples 32 frames and extracts three region views in one pass:
- Full face
- Eyes
- Mouth
- Frames are resized to 224x224 and written out as NumPy .npy arrays for fast later loading.
4. Preprocessed data boundary
- Preprocessing creates three separate datasets on disk:
- Processed_Data_Full_HighRes
- Processed_Data_Eyes_HighRes
- Processed_Data_Mouth_HighRes
- This cleanly separates expensive video decoding/face cropping from model training.
5. Training data ingestion
- run.py loads the preprocessed .npy files through a custom VideoDataGenerator.
- The generator is the interface between stored frame tensors and the TensorFlow training loop.
- This means training consumes frame sequences, not raw images or videos.
6. Model subsystem: models.py
- Both experiment variants share the same temporal feature extractor:
- TimeDistributed EfficientNetB1 as the per-frame CNN backbone
- Bidirectional LSTM to model temporal dynamics across the 32-frame sequence
- The key architectural difference is only in the final temporal aggregation layer.
7. Two model heads
- Control model: uses GlobalAveragePooling1D to average temporal features across frames.
- Attention model: uses a learned temporal soft-attention mechanism (Dense → Softmax → Multiply) to weight important frames more heavily.
- This is the main experimental comparison in the repo.
8. Experiment orchestration: run.py
- run.py is the top-level orchestrator for training.
- It selects the region to train on (full, eyes, or mouth) and the model type.
- It also handles GPU memory safety, training setup, and early stopping.
9. Evaluation path
- After training, the pipeline produces a confusion matrix for final evaluation.
- The architecture therefore includes a standard supervised classification loop: load preprocessed sequences → train model → evaluate predictions against labels.
10. Utility/support files
- inspect_img.py is a helper for visually checking preprocessed outputs.
- post_cropping_images/ appears to be auxiliary experiment/output storage rather than part of the core training path.
- requirements.txt defines the Python runtime dependencies, with the main stack centered on Python 3.10, TensorFlow/Keras, OpenCV, and NumPy.
11. Overall system diagram perspective
- The cleanest architecture view is:
- Raw videos + face cascade → offline preprocessing → region-specific .npy datasets → generator-based training → shared CNN+BiLSTM model → control vs attention head → classification metrics
- The main architectural boundary is between data preparation and model experimentation.
Main entry points: preprocess.py Preprocess · models.py BiLSTM · post_cropping_images Full Dataset · run.py Run
Components 17
External Data
Raw FaceForensics++ video inputs and face detector asset boundary.
- FaceForensics++ · Source video data for original vs Face2Face C23 experiments.
- Face Cascade · OpenCV Haar cascade used to locate faces during preprocessing.
haarcascade_frontalface_default.xml
Preprocessing
Offline video decoding, face localization, region cropping, and .npy export.
- Preprocess · Samples frames, crops regions, resizes to 224x224, and writes .npy arrays.
preprocess.py - Full Face · Full-face frame sequence extracted during preprocessing.
- Eyes · Eye-region frame sequence extracted during preprocessing.
- Mouth · Mouth-region frame sequence extracted during preprocessing.
Stored Datasets
Region-specific preprocessed sequence datasets used for training.
- Full Dataset · Processed_Data_Full_HighRes sequence store.
post_cropping_images - Eyes Dataset · Processed_Data_Eyes_HighRes sequence store.
post_cropping_images - Mouth Dataset · Processed_Data_Mouth_HighRes sequence store.
post_cropping_images
Training
Generator-based TensorFlow training orchestration and runtime safeguards.
- Run · Selects region and model variant, configures GPU safety, and launches training.
run.py - VideoDataGenerator · Loads preprocessed frame sequences into the TensorFlow training loop.
Modeling
Shared temporal backbone plus alternative aggregation heads.
- EfficientNetB1 · TimeDistributed per-frame CNN backbone.
models.py - BiLSTM · Models temporal dynamics across the 32-frame sequence.
models.py - Average Head · GlobalAveragePooling1D temporal aggregation for the control model.
models.py - Attention Head · Dense→Softmax→Multiply temporal weighting for the attention model.
models.py
Evaluation
Final classification assessment and confusion-matrix reporting.
- Confusion Matrix · Final prediction-vs-label evaluation artifact.
Support
Auxiliary inspection and experiment-output files.
- Inspect Img · Helper for visually validating preprocessed outputs.
inspect_img.py
Connections 20
- FaceForensics++ → Preprocess: video input · Raw videos are decoded and sampled offline.
- Face Cascade → Preprocess: face detect · Haar cascade provides face localization for cropping.
- Preprocess → Full Face: extract · Produces full-face frame sequences.
- Preprocess → Eyes: extract · Produces eye-region frame sequences.
- Preprocess → Mouth: extract · Produces mouth-region frame sequences.
- Full Face → Full Dataset: write .npy · Stores processed full-face sequences.
- Eyes → Eyes Dataset: write .npy · Stores processed eye-region sequences.
- Mouth → Mouth Dataset: write .npy · Stores processed mouth-region sequences.
- Full Dataset → VideoDataGenerator: load · Training can consume the full-face dataset.
- Eyes Dataset → VideoDataGenerator: load · Training can consume the eye-region dataset.
- Mouth Dataset → VideoDataGenerator: load · Training can consume the mouth-region dataset.
- Run → VideoDataGenerator: orchestrate · Run.py configures data loading and experiment setup.
- VideoDataGenerator → EfficientNetB1: frame tensors · Sequence batches enter the TimeDistributed CNN backbone.
- EfficientNetB1 → BiLSTM: features · Per-frame embeddings are passed to temporal modeling.
- BiLSTM → Average Head: control path · Baseline model aggregates temporal features with averaging.
- BiLSTM → Attention Head: attention path · Attention model reweights temporal features before classification.
- Average Head → Confusion Matrix: predict · Control model predictions are evaluated.
- Attention Head → Confusion Matrix: predict · Attention model predictions are evaluated.
- Inspect Img → Full Dataset: check output · Visual inspection supports preprocessing validation.
- Run → Confusion Matrix: report · Training run produces the final confusion matrix.