ZhendongWang6 / DIRE

[ICCV 2023] Official implementation of the paper: "DIRE for Diffusion-Generated Image Detection"
306 stars 24 forks source link
diffusion-model fake-image-detection image-forensics

DIRE for Diffusion-Generated Image Detection (ICCV 2023)

Zhendong Wang, Jianmin Bao, Wengang Zhou, Weilun Wang, Hezhen Hu, Hong Chen, Houqiang Li

[paper] [[DiffusionForensics dataset](BaiduDrive (password: dire)] [[pre-trained model](BaiduDrive (password: dire)]

News

DIRE pipeline

Requirements

conda create -n dire python=3.9
conda activate dire
pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 -f https://download.pytorch.org/whl/torch_stable.html
pip install -r requirements.txt

DiffusionForensics Dataset

The DiffusionForensics dataset can be downloaded from [BaiduDrive (password: dire)] or [RecDrive (password: dire)]. The dataset is organized as follows:

images/recons/dire
└── train/val/test
    ├── lsun_bedroom
    │   ├── real
    │   │   └──img1.png...
    │   ├── adm
    │   │   └──img1.png...
    │   ├── ...
    ├── imagenet
    │   ├── real
    │   │   └──img1.png...
    │   ├── adm
    │   │   └──img1.png...
    │   ├── ...
    └── celebahq
        ├── real
        │   └──img1.png...
        ├── adm
        │   └──img1.png...
        ├── ...

Training

Before training, you should link the training real and DIRE images to the data/train folder. For example, you can link the DIRE images of real LSUN-Bedroom to data/train/lsun_adm/0_real and link the DIRE images of ADM-LSUN-Bedroom to data/train/lsun_adm/1_fake. And do the same for validation set and testing set, just modify data/train to data/val and data/test. Then, you can train the DIRE model by running the following command:

sh train.sh

Evaluation

We provide the pre-trained DIRE model in [BaiduDrive (password: dire)] and [RecDrive (password: dire)]. You can evaluate the DIRE model by running the following command:

sh test.sh

Inference

We also provide a inference demo demo.py. You can run the following command to inference a single image or a folder of images:

python demo.py -f [image_path/image_dir] -m [model_path]

Acknowledgments

Our code is developed based on guided-diffusion and CNNDetection. Thanks for their sharing codes and models.

Citation

If you find this work useful for your research, please cite our paper:

@article{wang2023dire,
  title={DIRE for Diffusion-Generated Image Detection},
  author={Wang, Zhendong and Bao, Jianmin and Zhou, Wengang and Wang, Weilun and Hu, Hezhen and Chen, Hong and Li, Houqiang},
  journal={arXiv preprint arXiv:2303.09295},
  year={2023}
}