This repository contains the implementation of a deepfake detection model that can work with multiple datasets.
- Install Rye if you haven't already:
curl -sSf https://rye-up.com/get | bash
- Initialize the project and install dependencies:
rye sync
- Activate the virtual environment:
.venv/bin/activate
All datasets should follow this structure:
dataset_root/
train/
real/
image1.jpg
image2.jpg
...
fake/
image1.jpg
image2.jpg
...
val/
real/
...
fake/
...
test/
real/
...
fake/
...
For each dataset, you need to modify the root values in config/dataset/
to your actual dataset path. Here's an example for Celeb-DF:
# config/dataset/celeb_df.yml
train_cfg:
root: "../../final_dataset/01_celebdf_unaltered" # Path to dataset root
test_cfg:
root: "../../final_dataset/01_celebdf_unaltered"
Modify the following in config/Recce.yml
for the model settings:
# config/model/recce.yml
name: CelebDF
file: "./config/dataset/celeb_df.yml" # Path to dataset config
python train.py --config config/train/recce.yml
-
Make sure you have a trained model checkpoint (
.pth
file) -
Run the test script:
python test.py --config config/train/recce.yml --ckpt path/to/your/checkpoint.pth
- For inference on custom images:
python inference.py --bin path/to/model.bin --image_folder path/to/image_folder --device cuda:0 --image_size 256
--config
: Path to the config file--ckpt
: Path to the model checkpoint--device
: Device to run on (cuda:0, cpu)--image_size
: Input image size (default: 256)
The test script will output metrics like accuracy, AUC, and AP scores. For inference, you'll see:
path: path/to/image1.jpg | fake probability: 0.1296 | prediction: real
path: path/to/image2.jpg | fake probability: 0.9146 | prediction: fake
-
If you get CUDA errors:
- Make sure you have the correct CUDA version installed
- Check if your GPU is available:
nvidia-smi
- Try using CPU by setting
--device cpu
-
If you get memory errors:
- Reduce the batch size in your config file
- Use a smaller image size
- Try using CPU if GPU memory is insufficient
-
If you get import errors:
- Make sure you're in the virtual environment:
.venv/bin/activate
- Try reinstalling dependencies:
rye sync
- Make sure you're in the virtual environment: