DeepFocus is an end-to-end deepfake detection platform that combines a 4-model CNN ensemble, BiLSTM temporal analysis, frequency-domain forensics, and a meta-learner fusion layer to classify images and videos as real or AI-generated. It ships with a clinical-grade Next.js forensic dashboard and a FastAPI backend for real-time analysis.
Built as a Major Project for academic research in AI-powered media forensics.
- Architecture Overview
- Key Features
- Tech Stack
- Project Structure
- Installation
- Usage
- Detection Pipeline
- Models
- Frontend Dashboard
- API Endpoints
- Screenshots
- Acknowledgements
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js Frontend Dashboard β
β Upload β Analyze β Forensic Report + PDF Export β
ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β REST API
ββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (main.py) β
β /analyze/image /analyze/video β
ββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββ
β β
ββββββββΌβββββββββββββββ βββββββββββββΌβββββββββββββββββ
β IMAGE PIPELINE β β VIDEO PIPELINE β
β deepfake_detection β β hybrid_vid_improved.py β
β .py β β β
β β β ββββββββββββββββββββββ β
β βββββββββββββββββ β β β Temporal Analyzer β β
β β 4-CNN Ensembleβ β β β (Blink, Flow, β β
β β EfficientNet β β β β Landmark Jitter) β β
β β Xception β β β ββββββββββββββββββββββ β
β β ViT-Small β β β ββββββββββββββββββββββ β
β β ConvNeXt β β β β BiLSTM Temporal β β
β βββββββββ¬ββββββββ β β β (Optical Flow RNN) β β
β β β β ββββββββββββββββββββββ β
β βββββββββΌββββββββ β β ββββββββββββββββββββββ β
β β Watermark β β β β Quality Forensics β β
β β Detection β β β β (DCT, Color, Edge) β β
β β (DCT + SVM) β β β ββββββββββββββββββββββ β
β βββββββββ¬ββββββββ β β ββββββββββββββββββββββ β
β β β β β 4-CNN Ensemble β β
β βββββββββΌββββββββ β β β (per-keyframe) β β
β β Meta-Learner β β β ββββββββββ¬ββββββββββββ β
β β (Stacking β β β β β
β β Ensemble) β β β ββββββββββΌββββββββββββ β
β βββββββββββββββββ β β β Meta-Learner β β
β β β β (LogReg Fusion) β β
βββββββββββββββββββββββ β ββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββ
| Feature | Description |
|---|---|
| 4-Model CNN Ensemble | EfficientNet-B3, Xception, ViT-Small, ConvNeXt-Small β each fine-tuned on deepfake datasets |
| BiLSTM Temporal Branch | Optical-flow-based Bidirectional LSTM that detects unnatural motion in videos |
| Temporal Consistency Analyzer | Blink detection, optical flow analysis, and facial landmark stability tracking |
| Quality Forensics | Sharpness mismatch, frequency analysis, edge anomaly, compression artifact, DCT anomaly, and color inconsistency detection |
| Watermark / Frequency Detection | DCT mid-frequency feature extraction + SVM classifier for AI watermark artifacts |
| Meta-Learner Fusion | Stacking ensemble (Logistic Regression / XGBoost) that fuses all signals into a final prediction |
| GradCAM Visualization | Spatial attention heatmaps showing which image regions triggered the detection |
| Forensic Dashboard | Premium Next.js UI with radar plots, bar charts, signal breakdowns, and PDF report export |
| Analysis History | LocalStorage-backed forensic log with export to JSON |
| Single-Pass Frame Extraction | Optimized video decoding β reads the video exactly once for both CNN and BiLSTM branches |
| Technology | Purpose |
|---|---|
| Python 3.10+ | Core language |
| PyTorch 2.x | Deep learning framework |
| timm | Pre-trained model zoo (EfficientNet, Xception, ViT, ConvNeXt) |
| FastAPI | REST API server |
| OpenCV | Video processing, optical flow, face detection (Haar Cascade) |
| facenet-pytorch | MTCNN face detection |
| pytorch-grad-cam | GradCAM visualization |
| scikit-learn | Meta-learner training and inference |
| XGBoost | Ensemble boosting for meta-learner |
| joblib | Model serialization |
| Matplotlib | Radar plots and bar chart generation |
| Technology | Purpose |
|---|---|
| Next.js 16 | React framework |
| TypeScript | Type safety |
| Tailwind CSS 4 | Styling |
| Framer Motion | Animations and transitions |
| Lucide React | Icon library |
| jsPDF + modern-screenshot | PDF report export |
deepfocus/
βββ backend/
β βββ main.py # FastAPI server β /analyze/image & /analyze/video
β βββ static/ # Generated visualizations (GradCAM, radar, bar charts)
β βββ uploads/ # Temporary uploaded files
β
βββ frontend/
β βββ src/app/page.tsx # Main forensic dashboard (single-page app)
β βββ src/lib/api.ts # API client for backend communication
β βββ package.json # Node.js dependencies
β βββ ... # Next.js config files
β
βββ final/ # Pre-trained model weights (not tracked in Git)
β βββ convnext_finetuned_v5.pth
β βββ efficientnet_b3_finetuned_v5.pth
β βββ xception_finetuned_v5.pth
β βββ vit_finetuned_v5.pth
β βββ meta_learner_fusion.pkl
β βββ new_watermark_classifier.pkl
β βββ new_feature_scaler.pkl
β βββ ...
β
βββ deepfake_detection.py # Image analysis pipeline (4-CNN + Watermark + Meta-Learner)
βββ hybrid_vid_improved.py # Video analysis pipeline (CNN + BiLSTM + Temporal + Quality)
βββ temporal_analysis.py # Temporal consistency analyzer (Blink, Flow, Landmark)
βββ quality_forensic.py # Quality forensics (Sharpness, Frequency, DCT, Color)
βββ dct_features.py # DCT mid-frequency feature extraction
βββ visualizer_utils.py # GradCAM, radar plot, and bar chart generation
βββ video_meta_learner_v2.pkl # Video meta-learner model
βββ run_all.ps1 # PowerShell script to launch both servers
βββ requirements.txt # Python dependencies
βββ .gitignore
- Python 3.10+ with
pip - Node.js 18+ with
npm - CUDA-capable GPU (recommended, falls back to CPU)
git clone https://github.com/<your-username>/deepfocus.git cd deepfocus
# Create and activate virtual environment python -m venv venv # Windows .\venv\Scripts\activate # Linux/macOS source venv/bin/activate # Install dependencies pip install -r requirements.txt
cd frontend npm install cd ..
β οΈ Model weights are not included in this repository (.pth,.pkl,.ptfiles are gitignored due to their large size).
Place the following pre-trained weights in the final/ directory:
| File | Size | Description |
|---|---|---|
convnext_finetuned_v5.pth |
~198 MB | ConvNeXt-Small fine-tuned weights |
efficientnet_b3_finetuned_v5.pth |
~43 MB | EfficientNet-B3 fine-tuned weights |
xception_finetuned_v5.pth |
~84 MB | Xception fine-tuned weights |
vit_finetuned_v5.pth |
~87 MB | ViT-Small fine-tuned weights |
meta_learner_fusion.pkl |
~1 KB | Stacking meta-learner (image pipeline) |
new_watermark_classifier.pkl |
~155 MB | Watermark SVM classifier |
new_feature_scaler.pkl |
~492 KB | Feature scaler for watermark pipeline |
Also place video_meta_learner_v2.pkl in the project root for video analysis.
.\run_all.ps1
This starts both the backend API and frontend dashboard in separate terminal windows.
Terminal 1 β Backend:
# From project root, with venv activated
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000Terminal 2 β Frontend:
cd frontend
npm run dev- Frontend Dashboard: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs (Swagger): http://localhost:8000/docs
Input Image
β
ββββΊ 4Γ CNN Inference (EfficientNet-B3, Xception, ViT-Small, ConvNeXt)
β ββββΊ Per-model fake probability
β
ββββΊ Watermark Detection
β ββββΊ DCT mid-frequency feature extraction (8Γ8 blocks)
β ββββΊ Global frequency statistics (energy, variance, flatness, entropy)
β ββββΊ SVM classification β watermark probability
β
ββββΊ Meta-Learner Fusion (Stacking Ensemble)
ββββΊ Input: [eff_b3_prob, xception_prob, vit_prob, convnext_prob, watermark_prob]
ββββΊ Output: Final fake probability + label
Input Video
β
ββββΊ Single-Pass Frame Extraction (optimized decode β reads video once)
β ββββΊ CNN keyframe candidates (evenly sampled)
β ββββΊ BiLSTM temporal clip frames
β
ββββΊ Temporal Consistency Analyzer
β ββββΊ Blink detection (eye brightness changes)
β ββββΊ Optical flow analysis (Farneback dense flow)
β ββββΊ Facial landmark stability (normalized eye jitter)
β
ββββΊ BiLSTM Temporal Branch
β ββββΊ Optical flow feature extraction (12-dim per frame pair)
β ββββΊ Multi-clip inference (3 clips Γ 48 frames)
β ββββΊ Attention-weighted BiLSTM β temporal fake score
β
ββββΊ Smart Keyframe Selection (MTCNN face detection + quality ranking)
β ββββΊ 4Γ CNN Ensemble on top-N face crops
β
ββββΊ Quality Forensics Analyzer
β ββββΊ Sharpness mismatch (face vs. body Laplacian variance)
β ββββΊ Frequency mismatch (FFT high-frequency energy)
β ββββΊ Edge anomaly (Canny edge density at face boundary)
β ββββΊ Compression mismatch (JPEG blocking artifacts)
β ββββΊ DCT anomaly (mid-frequency coefficient patterns)
β ββββΊ Color inconsistency (LAB color space face/boundary comparison)
β
ββββΊ Meta-Learner Fusion (Logistic Regression)
ββββΊ Input: [eff_b3, xception, vit, convnext, quality, flow, blink, landmark]
ββββΊ Output: Final fake probability + label
| Model | Input Size | Architecture Strength |
|---|---|---|
| EfficientNet-B3 | 300Γ300 | Compression artifact detection, mobile-scale forensics |
| Xception | 299Γ299 | Depthwise separable convolutions for phase inconsistencies |
| ViT-Small | 224Γ224 | Global self-attention for long-range pixel dependencies |
| ConvNeXt-Small | 224Γ224 | Modern ConvNet for texture and geometric anomalies |
- Architecture: 2-layer Bidirectional LSTM with attention mechanism
- Input: 12-dimensional optical flow features per frame pair
- Sequence Length: 48 frames per clip, 3 clips per video
- Features: Flow magnitude, direction, boundary scores, spatial entropy, quadrant correlation
- Image pipeline: Stacking ensemble (trained on CNN + watermark outputs)
- Video pipeline: Logistic Regression meta-learner (trained on CNN + temporal + quality outputs)
The forensic dashboard provides:
- Drag-and-drop upload for images and videos
- Real-time analysis with animated progress tracking
- Verdict display β large, clear Real/Fake classification with confidence score
- Meta-Learner Inputs panel β per-model signal bars with weights and status
- Visual Diagnostics β GradCAM heatmap, radar plot, and ensemble bar chart
- CNN Ensemble Deep-Dive β cross-architectural agreement analysis
- BiLSTM Motion Forensics (video only) β temporal inconsistency breakdown
- Biological Sync (video only) β blink rate and landmark jitter analysis
- Forensic Artifacts β DCT anomaly, sharpness mismatch, color inconsistency details
- PDF Export β full forensic report download
- Analysis History β LocalStorage log with JSON export
Analyze a single image for deepfake indicators.
Request: multipart/form-data with file field (image)
Response:
{
"label": "Fake",
"confidence": 0.9523,
"final_score": 0.9523,
"gradcam_url": "/static/grad_cams/gradcam_Fake_0.9523_a1b2c3d4.jpg",
"radar_url": "/static/radar_plots/radar_fake_0.9523_e5f6g7h8.png",
"barchart_url": "/static/bar_charts/barchart_fake_0.9523_i9j0k1l2.png",
"forensic_report": { ... },
"ensemble_fake_probability": 0.8912,
"watermark_probability": 0.7634,
"decision_source": "meta_learner_stacking",
"models": { ... }
}Analyze a video for deepfake indicators using the full hybrid pipeline.
Request: multipart/form-data with file field (video)
Response:
{
"label": "Fake",
"confidence": 0.8765,
"final_score": 0.8765,
"gradcam_url": "/static/grad_cams/...",
"radar_url": "/static/radar_plots/...",
"barchart_url": "/static/bar_charts/...",
"forensic_report": {
"ai_consensus": { ... },
"motion_integrity": { ... },
"forensic_artifacts": { ... },
"biological_signals": { ... },
"metadata": { ... },
"interpretation": { ... }
}
}Screenshots of the dashboard can be added here after deployment.
- timm β PyTorch Image Models
- facenet-pytorch β MTCNN face detection
- pytorch-grad-cam β GradCAM visualization
- FastAPI β Modern Python web framework
- Next.js β React framework for the frontend dashboard
This project is developed for academic purposes. See LICENSE for details.
Built with π¬ by the DeepFocus Team