chuangchuangtan / LGrad

Code for the paper: Learning on Gradients: Generalized Artifacts Representation for GAN-Generated Images Detection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Learning on Gradients: Generalized Artifacts Representation for GAN-Generated Images Detection


Beijing Jiaotong University, YanShan University

overall pipeline

Reference github repository for the paper Learning on Gradients: Generalized Artifacts Representation for GAN-Generated Images Detection. Tan CC et al., proceedings of the IEEE/CVF CVPR 2023 . If you use our code, please cite our paper:

@inproceedings{tan2023learning,
  title={Learning on Gradients: Generalized Artifacts Representation for GAN-Generated Images Detection},
  author={Tan, Chuangchuang and Zhao, Yao and Wei, Shikui and Gu, Guanghua and Wei, Yunchao},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={12105--12114},
  year={2023}
}

Update

  • 2023.08.17 The Gradient data is released. Baidu drive
  • 2023.08.17 The Pytorch version of img2grad is released.

Environment setup

Img2grad environment: We suggest transforming the image into a gradient using the tensorflow environment in docker image nvcr.io/nvidia/tensorflow:21.02-tf1-py3 from nvidia.

Classification environment: We recommend installing the required packages by running the command:

pip install -r requirements.txt

Getting the data

Download dataset from CNNDetection.

Transform Image to Gradients

  1. Download pretrained model of stylegan, and put this <project dir>/img2grad/stylegan/networks/. Or run using
mkdir -p ./img2gad/stylegan/networks
wget https://lid-1302259812.cos.ap-nanjing.myqcloud.com/tmp/karras2019stylegan-bedrooms-256x256.pkl -O ./img2gad/stylegan/networks/karras2019stylegan-bedrooms-256x256.pkl
  1. Run using
sh ./transform_img2grad.sh {GPU-ID} {Data-Root-Dir} {Grad-Save-Dir}

Training the model

sh ./train-detector.sh {GPU-ID} {Grad-Save-Dir}

Testing the detector

Download all pretrained weight files fromhttps://drive.google.com/drive/folders/17-MAyCpMqyn4b_DFP2LekrmIgRovwoix?usp=share_link.

cd CNNDetection
CUDA_VISIBLE_DEVICES=0 python eval_test8gan.py --model_path {Model-Path}  --dataroot {Grad-Test-Path} --batch_size {BS}

Acknowledgments

This repository borrows partially from the CNNDetection, stylegan, and genforce.

About

Code for the paper: Learning on Gradients: Generalized Artifacts Representation for GAN-Generated Images Detection


Languages

Language:Python 99.0%Language:Shell 1.0%