/LFM

The offical code of LFM (BMVC2025)

Primary LanguagePythonApache License 2.0Apache-2.0

LFM (BMVC 2025)

License Python 3.10 Pytorch

Official PyTorch implementation of LFM (BMVC 2025). This repository contains training and evaluation code for our paper "A Novel Local Focusing Mechanism for Deepfake Detection Generalization" accepted at BMVC 2025.

📦 Installation

Prerequisites

  • NVIDIA GPU + CUDA cuDNN
  • Python 3.10
  • PyTorch 2.6+

Setup Environment

# Clone repository
git clone https://github.com/lmlpy/LFM.git
cd LFM

# Create and activate conda environment
conda create -n LFM python=3.10.16
conda activate LFM

# Install dependencies
pip install -r requirements.txt

Data preparation

Getting the data

paper Url
Train set CNNDetection CVPR2020 Baidudrive
Val set CNNDetection CVPR2020 Baidudrive
Table1 Test CNNDetection CVPR2020 Baidudrive
Table2 Test FreqNet AAAI2024 googledrive
Table3 Test DIRE ICCV2023 googledrive
Table4 Test UniversalFakeDetect CVPR2023 googledrive
Table5 Test NPR CVPR2024 googledrive

Data structure

Click to expand the folder tree structure.
datasets
|-- ForenSynths_train_val
|   |-- train
|   |   |-- car
|   |   |-- cat
|   |   |-- chair
|   |   `-- horse
|   `-- val
|   |   |-- car
|   |   |-- cat
|   |   |-- chair
|   |   `-- horse
|   |-- test
|       |-- biggan
|       |-- cyclegan
|       |-- deepfake
|       |-- gaugan
|       |-- progan
|       |-- stargan
|       |-- stylegan
|       `-- stylegan2
`-- Generalization_Test
    |-- ForenSynths_test       # Table1
    |   |-- biggan
    |   |-- cyclegan
    |   |-- deepfake
    |   |-- gaugan
    |   |-- progan
    |   |-- stargan
    |   |-- stylegan
    |   `-- stylegan2
    |-- GANGen-Detection     # Table2
    |   |-- AttGAN
    |   |-- BEGAN
    |   |-- CramerGAN
    |   |-- InfoMaxGAN
    |   |-- MMDGAN
    |   |-- RelGAN
    |   |-- S3GAN
    |   |-- SNGAN
    |   `-- STGAN
    |-- DiffusionForensics  # Table3
    |   |-- adm
    |   |-- ddpm
    |   |-- iddpm
    |   |-- ldm
    |   |-- pndm
    |   |-- sdv1_new
    |   |-- sdv2
    |   `-- vqdiffusion
    `-- UniversalFakeDetect # Table4
    |   |-- dalle
    |   |-- glide_100_10
    |   |-- glide_100_27
    |   |-- glide_50_27
    |   |-- guided          # Also known as ADM.
    |   |-- ldm_100
    |   |-- ldm_200
    |   `-- ldm_200_cfg
    |-- Diffusion1kStep     # Table5
        |-- DALLE
        |-- ddpm
        |-- guided-diffusion    # Also known as ADM.
        |-- improved-diffusion  # Also known as IDDPM.
        `-- midjourney

Training

python train.py --name lfm --dataroot ./datasets/ForenSynths_train_val --classes car,cat,chair,horse \
       --batch_size 32 --delr_freq 10 --lr 0.0001 --niter 50

Testing

python test.py --model_path ./weights/bs_model.pth --batch_size 32

📌 LFM Visualization

visualization of LFM

Acknowledgments

This repository borrows partially from the NPR.

📜 Citation

If you find this repository useful for your research, please consider citing:

@misc{li2025novellocalfocusingmechanism,
      title={A Novel Local Focusing Mechanism for Deepfake Detection Generalization}, 
      author={Mingliang Li and Lin Yuanbo Wu and Changhong Liu and Hanxi Li},
      year={2025},
      eprint={2508.17029},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2508.17029}, 
}