Detect AI-generated or manipulated images and videos instantly using a custom-trained Convolutional Neural Network.
# 1. Install dependencies
pip install -r requirements.txt
# 2. Run the app (model is already included)
python inference.py
# 3. Open browser
# http://127.0.0.1:5000No training required — the pre-trained model (deepfake_detector_model.keras) is bundled.
Upload any image or video and the model tells you in seconds whether it is REAL or FAKE (AI-generated / deepfake), along with a confidence score. For images, a Grad-CAM heatmap is overlaid to highlight which regions influenced the prediction.
User uploads image/video
↓
Flask receives file → saves to /uploads
↓
Image: resized to 128×128 RGB → CNN inference → Grad-CAM overlay
Video: up to 16 frames sampled → per-frame CNN inference → mean score
↓
Sigmoid output: ≥ 0.5 → FAKE | < 0.5 → REAL
↓
Result + confidence % returned to UI
↓
Uploaded file deleted
| Property | Value |
|---|---|
| Architecture | EfficientNetB0 (ImageNet pretrained, fine-tuned) |
| Input size | 224 × 224 × 3 (RGB) |
| Training | 2-phase: frozen backbone → fine-tune top 30 layers |
| Output | Sigmoid (0 = Real, 1 = Fake) |
| Loss | Binary Crossentropy + label smoothing 0.1 |
| Optimizer | Adam (Phase 1: 1e-3, Phase 2: 1e-5) |
| Expected Accuracy | ~95%+ |
| Training data | ~140,000 images (70k Fake + 70k Real) |
| Framework | TensorFlow 2.x / Keras |
| Inference | Test-Time Augmentation (4-variant averaging) |
- Backend: Python, Flask
- ML: TensorFlow 2.x, Keras, OpenCV (Grad-CAM)
- Frontend: Vanilla HTML/CSS/JS (no framework, fully self-contained)
TruthLens/
├── inference.py # Flask web app + inference logic (entry point)
├── train.py # Training pipeline (model already trained)
├── deepfake_detector_model.keras # Pre-trained model weights
├── requirements.txt # Python dependencies
├── templates/
│ └── index.html # Frontend UI
├── static/
│ └── k.ico # Favicon
├── samples/ # Demo test images
├── uploads/ # Temp folder (auto-cleaned after each request)
└── data/ # Dataset directory (gitignored)
└── Dataset/
├── Train/
├── Test/
└── Validation/
| Type | Extensions |
|---|---|
| Images | PNG, JPG, JPEG |
| Videos | MP4, MOV, AVI, MKV, WEBM |
# Place the dataset at data/Dataset/ with Train/, Test/, Validation/ subdirs
python train.pyThis saves deepfake_detector_model.keras to the project root.
- Dataset: Trung-Nghia Le (Kaggle: deepfake-and-real-images)
- Model & App: TruthLens team