.
├── prepare\_cifar\_binary.py # Converts CIFAR-10 to binary real/fake dataset
├── multi\_model\_inference.py # Training, evaluation, and inference pipeline
├── cifar\_binary/ # Generated dataset directory (created automatically)
├── enhanced\_deepfake\_ensemble.pth # Saved ensemble model (after training)
├── evaluation\_results/ # Metrics, plots, and reports
└── sample\_image.jpg # Optional test image for demo inference
- 🔄 Ensemble of models: EfficientNet, ResNet, Vision Transformer
- 🧠 Face extraction option: Built-in OpenCV face detection support
- ⚖️ Handles class imbalance: Weighted sampling during training
- 📊 Detailed evaluation: AUC, ROC, Precision-Recall, Confusion Matrix
- 🧪 Single image inference: Predicts with ensemble and confidence score
- 🗂️ Synthetic dataset preparation: From CIFAR-10 (real/fake classes)
pip install torch torchvision timm transformers scikit-learn matplotlib seaborn tqdm opencv-python- Download CIFAR-10 Python version.
- Update the
cifar_dirvariable inprepare_cifar_binary.pywith the path to your dataset. - Run:
python prepare_cifar_binary.pyThis creates the dataset in the following structure:
cifar_binary/
├── train/
│ ├── real/
│ └── fake/
├── val/
├── test/
- Real (Label 0): cat, deer, dog, horse
- Fake (Label 1): airplane, automobile, ship, truck
python multi_model_inference.pyThis will:
- Train EfficientNet, ResNet, and ViT models
- Save best weights per model (e.g.,
best_resnet50.pth) - Save the final ensemble as
enhanced_deepfake_ensemble.pth - Generate evaluation plots and metrics in
evaluation_results/
Place a file named sample_image.jpg in the project root and re-run the script:
python multi_model_inference.pyYou will see per-model and ensemble predictions with confidence scores.
evaluation_results/evaluation_report.json: Accuracy, AUC, classification reportevaluation_results/evaluation_plots.png: Confusion matrix, ROC, PR curves
- Face extraction is optional and handled via OpenCV's Haar cascade.
- Early stopping and learning rate scheduling are included.
- The ensemble uses a weighted average strategy by default.
For educational and research purposes only.