Giter VIP home page Giter VIP logo

stig's Introduction

STIG: Spectrum Translation for refinement of Image Generation

STIG is for boosting the quality of image generation by reducing spectral discrepancies of current generative models including GANs and Diffusion Models. The algorithm is elaborated in our paper "Spectrum Translation for Refinement of Image Generation (STIG) Based on Contrastive Learning and Spectral Filter Profile" that has been published in AAAI 2024.

Quick Overview

STIG Framework

STIG mitigates spectral discrepancies of the generated images based on GAN-based image-to-image translation architecture and patch-wise contrastive learning. It manipulates the frequency components to address the spectral discrepancy components effectively in the frequency domain. Auxiliary regularizations prevent the potential corruption of the image during spectral translation.

figure_3_camera_ready_version

Effectiveness of STIG

STIG can reduce the spectral disparity of various generative models including GANs and diffusion models. It erased the disparity pattern (checkerboard artifacts) on the spectrum of GAN models and enriched high-frequency details for images from diffusion models.

effectiveness_figure

Installing dependency

conda create -n stig python=3.9.2
conda activate stig
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install -r requirements.txt

Especially, our version of pytorch is as follows.

pytorch==1.8.0
torchvision==0.9.0
cudatoolkit==1.11.1

Preparing datasets

Put real and fake datasets in the folder datasets/.

The real images should be located in datasets/{dataset_name}/real/ and generated images should be in datasets/{dataset_name}/fake/. We suppose the type of image file is .png, so you should consider it.

Training STIG

Enter the command below. You can change the GPU device by modifying the option --device.

The sampled results are visualized in the results/{experiment_name}/sample/ during the training. After training, the results image and magnitude spectrum will be saved at each folder in results/{experiment_name}/eval/.

python train.py --size {size} --data {dataset_name} --epoch 10 --batch_size 1 --lr 0.00008 --device {gpu_ids} --dst {experiment_name}

We also provide a training log using the tensorboard library. If you want to use it, you can access the training log using the code below.

tensorboard --logdir='./results/{experiment_name}/tensorboard'

Evaluation STIG

We provide three evaluation metric, FID and log frequency distance. To evaluate your experiment result, enter the command below. You can choose the evaluation metric in [image_fid / magnitude_fid / lfd]. The default option is set to magnitude_fid.

python eval.py --eval_root {experiment_name} --eval_mode {metric} --device {gpu_ids}

Deepfake detection

We provide sample codes to train and evaluate the detectors in the paper. To train the detector, choose the classifier from [cnn / vit] and enter the command below.

python detect.py --is_train True --classifier {classifier} --lr 0.0002 --size {size} --device {gpu_ids} --class_epoch 20 --class_batch_size 32 --dst {experiment_name}

The training results of the detector are saved in the folder results/{experiment_name}/{classifier}_classifier/.

For evaluation a classifier using generated images, enter the command below.

python detect.py --is_train True --classifier {classifier} --lr 0.0002 --size {size} --device {gpu_ids} --class_batch_size 32 --dst {experiment_name} --eval_root {folder_of_generated_images}

Non-deterministic behavior of the upsampling layer

We use the bi-linear upsampling layer (nn.Upsample) in the STIG.

It is well known that nn.Upsample behaves non-deterministically because the internal layer F.interpolate of the PyTorch implementation.

stig's People

Contributors

ykykyk112 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.