This repository contains a deep learning-based system for detecting deepfake content in both standalone images and video files. It leverages transfer learning with state-of-the-art Convolutional Neural Networks (CNNs) and automated face extraction to classify media as either "Real" or "Fake".
- Image Deepfake Detection: Utilizes a fine-tuned
Xceptionmodel with custom dense layers to classify static images. - Video Deepfake Detection: Features an automated pipeline that extracts faces from video frames using
MTCNNand classifies them using anEfficientNetV2B0architecture. - Mixed Precision & Multi-GPU Training: The video model utilizes
mixed_float16andMirroredStrategyfor optimized, distributed training. - Interactive Inference: Includes a ready-to-use Python script (
test.py) for quick manual testing of images against the trained model.
model.ipynb: Jupyter Notebook for training the image-based deepfake detector. It includes data loading, augmentation (rotation, shifting, flips), Xception model compilation, training, and evaluation.model.ipynb: Jupyter Notebook for training the video-based deepfake detector. It handles face extraction from video datasets (FaceForensics++ and Celeb-DF v2), sets up an EfficientNetV2B0 model, and performs a two-phase training process (frozen base followed by fine-tuning).test.py: A command-line inference script. It takes an image path as input, pre-processes it, and outputs the model's prediction along with a confidence score and a matplotlib visualization.dataset/(Not included): Expected directory for training, validation, and test data.
The video pipeline is built to process standard deepfake datasets:
- Celeb-DF v2 (Real and Synthesis sets)
- FaceForensics++ C23 (Original, Deepfakes, Face2Face, FaceSwap, FaceShifter, NeuralTextures)
Ensure you have Python 3.x installed. Install the required dependencies using pip:
pip install numpy opencv-python tensorflow matplotlib seaborn scikit-learn mtcnn tqdm-
1. Training the Image Model Open and run
model.ipynb. Ensure your dataset is organized intotrain,Sample_fake_images(validation), andtestdirectories inside a./datasetfolder. The notebook will output a trained model namedimage.keras. -
2. Training the Video Model Open and run
model.ipynb. Update theREAL_SOURCESandFAKE_SOURCESpaths to point to your local FaceForensics++ and Celeb-DF v2 datasets. The script will automatically extract faces using MTCNN, save them, and train theEfficientNetV2B0model, eventually outputtingvideo_model.keras. -
3. Testing an Image (Inference) Once image.keras is generated, you can test individual images using
test.py.
python test.pyWhen prompted, enter the path to the image you want to test. The script will output the Raw Model Score, the final classification (Real/Fake), and display the analyzed image with the confidence percentage.
Image Classification (model.ipynb)
-
Base Model: Pre-trained Xception (ImageNet weights).
-
Custom Head: Global Average Pooling -> Batch Normalization -> Dropout (0.5) -> Dense (512, ReLU) -> Batch Normalization -> Dropout (0.5) -> Dense (1, Sigmoid).
-
Loss Function: Binary Crossentropy.
Video Classification (model.ipynb)
-
Face Extraction: MTCNN (Multi-task Cascaded Convolutional Networks).
-
Base Model: Pre-trained EfficientNetV2B0.
-
Custom Head: Batch Normalization -> Dropout (0.5) -> Dense (128, ReLU) -> Dropout (0.3) -> Dense (2, Softmax).
-
Loss Function: Sparse Categorical Crossentropy.