Skip to content

Deepfake Detection using Meta-Learning is a few-shot learning pipeline for detecting deepfakes with a ResNet18-based encoder and SVM classifier, utilizing episodic (meta-)training for improved generalization, and designed for easy use and customization.

Notifications You must be signed in to change notification settings

jnvw/deepFake_using_meta-learning

Repository files navigation

Deepfake Detection using Meta-Learning

This repository provides a few-shot learning pipeline for deepfake detection using meta-learning (episodic training). It uses a ResNet18-based encoder and an SVM classifier. The code is designed to be easy to use for new users.

1. Requirements

  • Python 3.8+
  • PyTorch
  • torchvision
  • scikit-learn
  • PIL

Install dependencies with:

pip install torch torchvision scikit-learn pillow

2. Dataset Preparation

  • Place your images in the data/ directory or specify your own with --data_path.
  • The dataset should be compatible with the DeepfakeDataset class (see data/dataset.py).

3. Training the Encoder (Meta-Learning)

Run the following command to start meta-training:

python train.py --episodes 2000 --data_path data --model_save_dir models --n_way 2 --k_shot 5 --k_query 5
  • --episodes: Number of meta-training episodes (increase for better results)
  • --data_path: Path to your dataset
  • --model_save_dir: Where to save encoder checkpoints
  • --n_way: Number of classes per episode (e.g., 2 for real/fake)
  • --k_shot: Number of support samples per class
  • --k_query: Number of query samples per class

Checkpoints will be saved in the models/ directory every 50 episodes.

4. Evaluating the Encoder

After training, evaluate the encoder using your evaluation script. Example:

python evaluate.py --encoder_checkpoint models/encoder_ep2000.pth --data_path data --n_way 2 --k_shot 5 --k_query 5

(Adjust arguments as needed.)

5. Tips

  • For best results, use a balanced dataset (equal real/fake samples).
  • You can change episode configuration (n_way, k_shot, k_query) to match your use case.
  • For help, check the comments in train.py and evaluate.py.

6. Troubleshooting

  • If you get argument errors, ensure you are using the latest train.py and evaluate.py.
  • For CUDA errors, check your PyTorch and GPU drivers.

7. Contact

For questions, open an issue or contact the maintainer.

About

Deepfake Detection using Meta-Learning is a few-shot learning pipeline for detecting deepfakes with a ResNet18-based encoder and SVM classifier, utilizing episodic (meta-)training for improved generalization, and designed for easy use and customization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published