This project focuses on detecting deepfake images using deep learning. The model is trained using ResNet18 with transfer learning to classify images as either Real or Fake.
The goal of this project is to demonstrate an end-to-end machine learning pipeline, starting from dataset preprocessing and model training to deployment through a Flask API and a simple web interface where users can upload an image and get predictions.
The system performs the following tasks:
- Preprocess image datasets
- Train a deep learning model using PyTorch
- Evaluate model performance
- Deploy the trained model using Flask
- Provide a simple frontend interface for testing predictions
- Python
- PyTorch
- Torchvision
- Flask
- HTML + TailwindCSS
- NumPy
- Pillow
Clone the repository
git clone https://github.com/anujpratap12/Detecting-Deepfake
Navigate to the project folder
cd Detecting-Deepfake
Install dependencies
The model uses ResNet18 pretrained on ImageNet. Transfer learning allows the network to reuse powerful visual feature representations learned from large datasets.
- Input image is resized to 224 × 224
- Image is converted into a tensor
- ResNet18 extracts image features
- The final fully connected layer is modified for binary classification
- The model predicts whether the image is Real or Fake
Loss Function
CrossEntropyLoss
Optimizer
Adam Optimizer
Learning Rate
0.0001
Number of Epochs
10
The dataset is organized into training and validation folders.
dataset/
│
├── train/
│ ├── fake/
│ └── real/
│
└── valid/
├── fake/
└── real/
Each folder contains images belonging to the respective class.
To train the model run:
python train_model.py
Example training output:
Epoch 1/10 | Train Acc: 76.2% | Val Acc: 72.4%
Epoch 5/10 | Train Acc: 88.3% | Val Acc: 84.7%
Epoch 10/10 | Train Acc: 92.5% | Val Acc: 90.1%
After training, the model weights are saved as:
deepfake_detector.pth
The model performance was evaluated using the validation dataset.
Evaluation metrics used:
- Accuracy
- Precision
- Recall
- F1-Score
Example results:
- Accuracy: 90.1%
- Precision: 89.4%
- Recall: 88.7%
- F1 Score: 89.0%
Start the Flask server:
python app.py
Once the server is running, open the frontend page and upload an image. The model will process the image and return whether it is Real or Fake.
POST /predict
Input Image file
Example Response
{
"prediction": "fake"
}
Detecting-Deepfake
│
├── train_model.py # model training script
├── app.py # Flask API server
├── index.html # frontend interface
├── deepfake_detector.pth # trained model weights
├── requirements.txt # project dependencies
└── README.md
Some possible improvements for this project:
- Train using larger deepfake datasets
- Improve accuracy using more advanced architectures like EfficientNet
- Extend the system to detect video deepfakes
- Deploy the model using Docker or cloud services
- Build a real-time detection system
Anuj Pratap Singh Final Year B.Tech Student Interested in Artificial Intelligence and Machine Learning

