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.
- Python 3.8+
- PyTorch
- torchvision
- scikit-learn
- PIL
Install dependencies with:
pip install torch torchvision scikit-learn pillow
- Place your images in the
data/
directory or specify your own with--data_path
. - The dataset should be compatible with the
DeepfakeDataset
class (seedata/dataset.py
).
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.
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.)
- 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
andevaluate.py
.
- If you get argument errors, ensure you are using the latest
train.py
andevaluate.py
. - For CUDA errors, check your PyTorch and GPU drivers.
For questions, open an issue or contact the maintainer.