Skip to content

chenchen-usyd/DP-GAN-DPAC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DP-GAN-DPAC

This is the official code base for our CVPR2023 paper: Private Image Generation with Dual-Purpose Auxiliary Classifier.

Contact: Chen Chen (cche0711@uni.sydney.edu.au)

Dependencies

The environment can be prepared with the following commands:

conda create --name virtualenv python=3.7
conda activate virtualenv
conda install pytorch==1.11.0 torchvision==0.12.0 -c pytorch
conda install tensorflow==1.14.0
pip install "pillow<7"
pip install -r requirements.txt

Dataset

  • MNIST and FashionMNIST datasets can be automatically downloaded during pre-training and training.
  • For CelebA, please refer to their official websites for downloading, and put the files into the data/celeba/ directory.

Training

Step 1. To warm-start the discriminators:

MNIST

cd source
sh pretrain_mnist.sh

Fashion MNIST

cd source
sh pretrain_fashionmnist.sh

CelebA

cd source
sh pretrain_celeba_gender.sh
  • The pre-training can be done in parallel by adjusting the 'meta_start', 'dis_per_job', and 'njobs' arguments and run the script multiple times in parallel.

Step 2. To train the differentially private generator:

MNIST

cd source
python main.py -data 'mnist' -name 'ResNet_default' -ldir '../results/mnist/pretrain/ResNet_default' -ndis 1000 -sstep 1000 -iter 20000 -wd .8 -wc1 .2 -C1in 6000 -C1_fake_iters 10 -C1_real_iters 10 -ngpus 2 

Fashion MNIST

cd source
python main.py -data 'fashionmnist' -name 'ResNet_default' -ldir '../results/fashionmnist/pretrain/ResNet_default' -ndis 1000 -sstep 1000 -iter 20000 -wd .8 -wc1 .2 -C1in 6000 -C1_fake_iters 10 -C1_real_iters 10 -ngpus 2 

CelebA

cd source
python main_celeba_gender.py -data 'celeba_gender' -name 'ResNet_default' -ldir '../results/celeba_gender/pretrain/ResNet_default' -ndis 2543 -bs 32 -sstep 1000 -iter 20000 -wd .8 -wc1 .2 -C1in 1000 -C1_fake_iters 10 -C1_real_iters 10 -noise 0.61135 -diters 10 -ngpus 5
  • Please refer to source/config.py (or execute python main.py -h) for the complete list of arguments.
  • Please allocate appropriate number of GPUs by adjusting the '-ngpus' argument according to your GPU memory. Our implementations use 2 cards of RTX 3090 with 24GB memory for MNIST and Fashion MNIST, and 5 cards for CelebA.

Evaluation

Privacy

  • To compute the privacy cost:

MNIST and Fashion MNIST

cd evaluation
python privacy_analysis.py -name 'ResNet_default' -bs 32 -ndis 1000 -noise 1.07 -iters 20000

CelebA

cd evaluation
python privacy_analysis.py -name 'ResNet_default' -bs 32 -ndis 2543 -noise 0.61135 -iters 20000

Standard Utility - gen2real with MLP classifiers

MNIST

cd evaluation
python eval_mlp.py --gen_data './../results/mnist/main/ResNet_default/gen_data.npz' -data 'mnist'

Fashion MNIST

cd evaluation
python eval_mlp.py --gen_data './../results/fashionmnist/main/ResNet_default/gen_data.npz' -data 'fashionmnist'

CelebA

cd evaluation
python eval_celeba.py --gen_data './../results/celeba_gender/main/ResNet_default/gen_data.npz' -arch 'mlp'

Standard Utility - gen2real with CNN classifiers

MNIST

cd evaluation
python eval_cnn.py --gen_data './../results/mnist/main/ResNet_default/gen_data.npz' -data 'mnist' -lr 0.05

Fashion MNIST

cd evaluation
python eval_cnn.py --gen_data './../results/fashionmnist/main/ResNet_default/gen_data.npz' -data 'fashionmnist' -lr 0.05

CelebA

cd evaluation
python eval_celeba.py --gen_data './../results/celeba_gender/main/ResNet_default/gen_data.npz' -lr 0.05

Reversed Utility - real2gen with MLP classifiers

MNIST

cd evaluation
python eval_mlp.py --gen_data './../results/mnist/main/ResNet_default/gen_data.npz' -data 'mnist'

Fashion MNIST

cd evaluation
python eval_mlp.py --gen_data './../results/fashionmnist/main/ResNet_default/gen_data.npz' -data 'fashionmnist'

CelebA

cd evaluation
python eval_celeba_real2gen.py --gen_data './../results/celeba_gender/main/ResNet_default/gen_data.npz' -arch 'mlp'

Reversed Utility - real2gen with CNN classifiers

MNIST

cd evaluation
python eval_cnn_real2gen.py --gen_data './../results/mnist/main/ResNet_default/gen_data.npz' -data 'mnist' -ep 100 -lr 0.01

Fashion MNIST

cd evaluation
python eval_cnn_real2gen.py --gen_data './../results/fashionmnist/main/ResNet_default/gen_data.npz' -data 'fashionmnist' -ep 100 -lr 0.01

CelebA

cd evaluation
python eval_celeba_real2gen.py --gen_data './../results/celeba_gender/main/ResNet_default/gen_data.npz'

Inception Score

MNIST

cd evaluation
python train_mnist_inception_score.py -data 'mnist'
python eval_mnist_inception_score.py -data 'mnist' --gen_data './../results/mnist/main/ResNet_default/gen_data.npz'

Fashion MNIST

cd evaluation
python train_mnist_inception_score.py -data 'fashionmnist'
python eval_mnist_inception_score.py -data 'fashionmnist' --gen_data './../results/fashionmnist/main/ResNet_default/gen_data.npz'

CelebA

cd evaluation
python eval_celeba_inception_score.py --gen_data './../results/celeba_gender/main/ResNet_default/gen_data.npz'

Frechet Inception Distance (FID)

MNIST

cd evaluation
python eval_fid.py -data 'mnist' --gen_data './../results/mnist/main/ResNet_default/gen_data.npz' 

Fashion MNIST

cd evaluation
python eval_fid.py -data 'fashionmnist' --gen_data './../results/fashionmnist/main/ResNet_default/gen_data.npz' 

CelebA

cd evaluation
python eval_celeba_fid.py -data 'celeba' --gen_data './../results/celeba_gender/main/ResNet_default/gen_data.npz' 

Acknowledgements

Our implementation uses the source code from the following repositories:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published