Production-ready deepfake detection system using DenseNet121 (images) and GenConViT (videos).
Image → DenseNet121 (60%) ─┐
→ Noise Analysis (15%) ├→ Ensemble → REAL/FAKE
→ Compression (10%) ─┤
→ ELA Score (15%) ─┘
Video → Frame Extraction (20 frames)
→ Face Detection (OpenCV DNN / Haar)
→ ConvNeXt Features ─┐
→ Swin Transformer ├→ AE Error (45%) ─┐
→ Autoencoder ED │ VAE Score (35%) ├→ REAL/FAKE
→ VAE Pathway ─┘ Temporal (20%) ─┘
pip install -r requirements.txt
python app.py
# Open http://localhost:5000
# Analyze an image
python detect.py photo.jpg
# Analyze a video
python detect.py video.mp4
# Verify determinism (3 identical runs)
python detect.py photo.jpg --verify-determinism
# Get JSON output
python detect.py photo.jpg --json
# Batch analyze a folder
python detect.py --batch /media/folder/ --output results.json
# Upload file for analysis
curl -X POST http://localhost:5000/api/detect \
-F "[email protected]"
# Analyze from URL
curl -X POST http://localhost:5000/api/detect/url \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/photo.jpg"}'
# Health check
curl http://localhost:5000/health
# Model info
curl http://localhost:5000/api/models
deepfake-detector/
├── app.py # Flask web application
├── detect.py # CLI inference tool
├── train.py # Fine-tuning script
├── requirements.txt
├── config/
│ └── model_config.yaml # Model configuration
├── models/
│ ├── __init__.py
│ ├── image_detector.py # DenseNet121 ensemble
│ ├── video_detector.py # GenConViT pipeline
│ ├── model_manager.py # Singleton model loader
│ └── utils/
│ ├── deterministic.py # Seed management
│ ├── ela.py # Error Level Analysis
│ ├── noise_analysis.py # Noise & compression analysis
│ ├── face_detector.py # Face detection (OpenCV)
│ └── frame_extractor.py # Video frame extraction
├── weights/ # Model weights (place here)
│ ├── densenet_deepfake.pth # Fine-tuned image model
│ ├── convnext_base.pth # ConvNeXt weights
│ ├── swin_base.pth # Swin Transformer weights
│ ├── autoencoder_ed.pth # Autoencoder weights
│ └── vae_pathway.pth # VAE weights
├── templates/
│ └── index.html # Web UI
└── tests/
└── test_detector.py # Test suite
The system works out-of-the-box using ImageNet pretrained weights, but accuracy improves significantly with fine-tuning on deepfake datasets.
# Organize data:
# data/real/ ← real face images
# data/fake/ ← fake/generated images
python train.py \
--real-dir data/real \
--fake-dir data/fake \
--output weights/densenet_deepfake.pth \
--batch-size 16 \
--phase1-epochs 10 \
--phase2-epochs 20 \
--phase3-epochs 10
Training phases:
python tests/test_detector.py
Tests verify:
{
"prediction": "FAKE",
"confidence": 0.8234,
"fake_probability": 0.8234,
"analysis_time": 1.23,
"image_size": "1024x768",
"scores": {
"densenet121": 0.91,
"noise_analysis": 0.43,
"compression_artifacts": 0.67,
"ela_score": 0.55
},
"ensemble_weights": {"densenet": 0.60, "noise": 0.15, "compression": 0.10, "ela": 0.15},
"model": "DenseNet121 + Signal Analysis Ensemble",
"file_type": "image",
"error": null,
"success": true
}
{
"prediction": "REAL",
"confidence": 0.7812,
"fake_probability": 0.2188,
"analysis_time": 14.5,
"frames_analyzed": 20,
"video_metadata": {"total_frames": 600, "fps": 30.0, "width": 1920, "height": 1080},
"scores": {
"autoencoder_ed": 0.18,
"vae_pathway": 0.24,
"temporal_consistency": 0.22
},
"per_frame_scores": [0.21, 0.19, 0.23, ...],
"model": "GenConViT (ConvNeXt + Swin + AE + VAE)",
"file_type": "video",
"error": null,
"success": true
}
| Task | Expected Time | RAM |
|---|---|---|
| Image analysis | 0.5–2s | 300–600MB |
| Video analysis (20 frames) | 10–25s | 800MB–1.5GB |
| ELA + Noise | 0.1–0.2s | 50–100MB |
The system uses comprehensive seed management:
torch.manual_seed(42)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
numpy.random.seed(42)
random.seed(42)
All models run in eval() mode with torch.no_grad(). The VAE uses the mean (not sampled latent) during inference, ensuring 100% reproducible outputs.
densenet_deepfake.pth in the weights/ folder. The system automatically loads them on startup.{"prediction": "REAL", "confidence": 0.5} — conservative and never random.Production-ready deepfake detection system using DenseNet121 (images) and GenConViT (videos).
Image → DenseNet121 (60%) ─┐
→ Noise Analysis (15%) ├→ Ensemble → REAL/FAKE
→ Compression (10%) ─┤
→ ELA Score (15%) ─┘
Video → Frame Extraction (20 frames)
→ Face Detection (OpenCV DNN / Haar)
→ ConvNeXt Features ─┐
→ Swin Transformer ├→ AE Error (45%) ─┐
→ Autoencoder ED │ VAE Score (35%) ├→ REAL/FAKE
→ VAE Pathway ─┘ Temporal (20%) ─┘
pip install -r requirements.txt
python app.py
# Open http://localhost:5000
# Analyze an image
python detect.py photo.jpg
# Analyze a video
python detect.py video.mp4
# Verify determinism (3 identical runs)
python detect.py photo.jpg --verify-determinism
# Get JSON output
python detect.py photo.jpg --json
# Batch analyze a folder
python detect.py --batch /media/folder/ --output results.json
# Upload file for analysis
curl -X POST http://localhost:5000/api/detect \
-F "[email protected]"
# Analyze from URL
curl -X POST http://localhost:5000/api/detect/url \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/photo.jpg"}'
# Health check
curl http://localhost:5000/health
# Model info
curl http://localhost:5000/api/models
deepfake-detector/
├── app.py # Flask web application
├── detect.py # CLI inference tool
├── train.py # Fine-tuning script
├── requirements.txt
├── config/
│ └── model_config.yaml # Model configuration
├── models/
│ ├── __init__.py
│ ├── image_detector.py # DenseNet121 ensemble
│ ├── video_detector.py # GenConViT pipeline
│ ├── model_manager.py # Singleton model loader
│ └── utils/
│ ├── deterministic.py # Seed management
│ ├── ela.py # Error Level Analysis
│ ├── noise_analysis.py # Noise & compression analysis
│ ├── face_detector.py # Face detection (OpenCV)
│ └── frame_extractor.py # Video frame extraction
├── weights/ # Model weights (place here)
│ ├── densenet_deepfake.pth # Fine-tuned image model
│ ├── convnext_base.pth # ConvNeXt weights
│ ├── swin_base.pth # Swin Transformer weights
│ ├── autoencoder_ed.pth # Autoencoder weights
│ └── vae_pathway.pth # VAE weights
├── templates/
│ └── index.html # Web UI
└── tests/
└── test_detector.py # Test suite
The system works out-of-the-box using ImageNet pretrained weights, but accuracy improves significantly with fine-tuning on deepfake datasets.
# Organize data:
# data/real/ ← real face images
# data/fake/ ← fake/generated images
python train.py \
--real-dir data/real \
--fake-dir data/fake \
--output weights/densenet_deepfake.pth \
--batch-size 16 \
--phase1-epochs 10 \
--phase2-epochs 20 \
--phase3-epochs 10
Training phases:
python tests/test_detector.py
Tests verify:
{
"prediction": "FAKE",
"confidence": 0.8234,
"fake_probability": 0.8234,
"analysis_time": 1.23,
"image_size": "1024x768",
"scores": {
"densenet121": 0.91,
"noise_analysis": 0.43,
"compression_artifacts": 0.67,
"ela_score": 0.55
},
"ensemble_weights": {"densenet": 0.60, "noise": 0.15, "compression": 0.10, "ela": 0.15},
"model": "DenseNet121 + Signal Analysis Ensemble",
"file_type": "image",
"error": null,
"success": true
}
{
"prediction": "REAL",
"confidence": 0.7812,
"fake_probability": 0.2188,
"analysis_time": 14.5,
"frames_analyzed": 20,
"video_metadata": {"total_frames": 600, "fps": 30.0, "width": 1920, "height": 1080},
"scores": {
"autoencoder_ed": 0.18,
"vae_pathway": 0.24,
"temporal_consistency": 0.22
},
"per_frame_scores": [0.21, 0.19, 0.23, ...],
"model": "GenConViT (ConvNeXt + Swin + AE + VAE)",
"file_type": "video",
"error": null,
"success": true
}
| Task | Expected Time | RAM |
|---|---|---|
| Image analysis | 0.5–2s | 300–600MB |
| Video analysis (20 frames) | 10–25s | 800MB–1.5GB |
| ELA + Noise | 0.1–0.2s | 50–100MB |
The system uses comprehensive seed management:
torch.manual_seed(42)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
numpy.random.seed(42)
random.seed(42)
All models run in eval() mode with torch.no_grad(). The VAE uses the mean (not sampled latent) during inference, ensuring 100% reproducible outputs.
densenet_deepfake.pth in the weights/ folder. The system automatically loads them on startup.{"prediction": "REAL", "confidence": 0.5} — conservative and never random.