A hybrid deep learning system to detect deepfakes in images and videos using EfficientNetB4 and CNN-GRU, combined with facial emotion analysis using DeepFace. Designed to be fast, scalable, and suitable for real-world deployment.
- β Detects deepfakes in both images and videos
- π Generates real-time metrics: Accuracy, Precision, Recall, F1, AUC
- π Performs emotion recognition on detected faces using DeepFace
- βοΈ Uses EfficientNetB4 for feature extraction
- π§ Includes CNN + GRU model for temporal video analysis
- π Live plots for deepfake probability and emotion timeline
- π» Lightweight, efficient & optimized for low-resource environments
| Area | Tools & Libraries |
|---|---|
| Deep Learning | TensorFlow, Keras, EfficientNetB4, GRU |
| Face Analysis | DeepFace (for emotion detection) |
| Image Processing | OpenCV, Haar Cascades |
| Data | NumPy, pandas, scikit-learn |
| Visualization | Matplotlib |
.
βββ models/
β βββ efficientnetB4_deepfake_final.keras
β βββ cnn_gru_model.h5
β
βββ real_and_fake_face/
β βββ real/
β βββ fake/
β
βββ real and fake video/
β βββ real/
β βββ fake/
β
βββ test real and fake video/
β βββ real/
β βββ fake/
β
βββ deepfake_train.py # Train EfficientNetB4 image model
βββ evaluate_image_model.py # Evaluate on static images
βββ analyze_single_image.py # Image deepfake + emotion detection
βββ analyze_video_with_emotion.py # Video deepfake + emotion + graph
βββ cnn_gru_train.py # Train CNN + GRU on video frames
βββ cnn_gru_evaluation.py # Evaluate videos & log predictionsEfficientNetB4 (frozen)
β GlobalAveragePooling2D
β Dropout + Dense
β Sigmoid output (real vs fake)
TimeDistributed(EfficientNetB4)
β GlobalAveragePooling2D (per frame)
β GRU layer
β Dropout + Dense
β Sigmoid output
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| EfficientNetB4 (Base) | 48.1% | 45.6% | 53.5% | 49.2% |
| Fine-tuned Model | 57.7% | 53.6% | 74.6% | 62.3% |
- Performed using DeepFace
- Extracted directly from video frames or static images
- Tracked over time in videos with frame-wise stats and plots
π Emotions supported: happy, sad, angry, surprise, neutral, etc.
-
Deepfake Probability Timeline across video frames
-
Emotion Timeline Plot to show mood shifts over time
-
Saved as:
deepfake_video_graph.pngemotion_over_time_graph.png
python deepfake_train.pypython evaluate_image_model.pypython analyze_single_image.pypython analyze_video_with_emotion.pypython cnn_gru_train.pypython cnn_gru_evaluation.pyreal_and_fake_face/β manually balanced dataset with real & fake face imagesreal and fake video/β training videos categorized as real/faketest real and fake video/β separate test set for generalization
Data preprocessing includes:
- Image validation and cleaning
- Frame extraction with resizing
- Haar cascade face detection
-
CNN-GRU video model improves temporal understanding vs. static image detection.
-
Emotion analysis adds context to deepfake results.
-
Decision logic includes:
- Average probability
- Max probability
- Smoothed curve thresholding
Frame 120 | Deepfake Probability: 0.8723 | Emotion: neutral
Frame 125 | Deepfake Probability: 0.9231 | Emotion: happy
Average Deepfake Probability: 0.89
Likely: π¨ Deepfake - Add race, age, and gender analysis using DeepFace
- Deploy model using Streamlit or Flask Web App
- Use Hugging Face Hub for model sharing
- Add real-time webcam streaming analysis
Harshit Bansal π« [email protected] π GitHub | LinkedIn
This project is licensed under the MIT License.
Feel free to use, adapt, and cite the work with attribution.