Giter Site home page Giter Site logo

juliafc / invgan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yogeshbalaji/invgan

0.0 1.0 0.0 397 KB

Official codebase of our paper "Invert and Defend: Model-based Approximate Inversion of Generative Adversarial Network For Secure Inference"

License: Apache License 2.0

Python 99.99% Shell 0.01%

invgan's Introduction

Invert and Defend: Model-based Approximate Inversion of Generative Adversarial Network For Secure Inference

Installation

  1. Install pyenv from https://github.com/pyenv/pyenv#installation
  2. Create a directory for InvGAN:
mkdir <path-to-invgan>
cd <path-to-invgan>
  1. git clone [email protected]:yogeshbalaji/InvGAN.git invgan
  2. cd invgan Now you should be in the project root directory.
  3. Run the setup script ./setup.sh
  4. Download datasets:
python download_dataset.py mnist
python download_dataset.py f-mnist
python download_dataset.py cifar-10

Download the pre-trained gans and classifiers from the following links into the root directory:

Classifiers: https://drive.google.com/file/d/1wws8pvE2slWXGIcQt5QYlH4N78yNZ8lw/view?usp=sharing

MNIST: https://drive.google.com/file/d/1L_U8A_aKvmuLNo9hdz4IgEK7UQ8d5t10/view?usp=sharing

FMNIST: https://drive.google.com/file/d/1NkktHH7VDMk8A2pMz2XSDQwf2dFX59o0/view?usp=sharing

CIFAR10: https://drive.google.com/file/d/1NkktHH7VDMk8A2pMz2XSDQwf2dFX59o0/view?usp=sharing

Put the *.tar.gz files in the root directory and run:

tar -xzvf classifiers.tar.gz
tar -xzvf mnist.tar.gz
tar -xzvf fmnist.tar.gz
tar -xzvf cifar10.tar.gz

These should create an output/ and classifiers/model directories.

Experiments

Prepare the cache

python train.py --cfg experiments/cfgs/gans_inv_notrain/mnist.yml --save_ds
python train.py --cfg experiments/cfgs/gans_inv_notrain/fmnist.yml --save_ds
python train.py --cfg experiments/cfgs/gans_inv_notrain/cifar_resnet.yml --save_ds

These scripts will normalize the datasets and save them in pickle files.

White-box experiments (Table 2)

To reproduce the results of Table 2 run:

InvGAN

python whitebox.py --cfg experiments/cfgs/gans_inv_notrain/{mnist,fmnist,cifar_resnet}.yml \ 
       --results_dir whitebox \
       --attack_type {fgsm,cw,bpda,bpda-l2} \
       --model A \
       --load_classifier \
       --defense_type defense_gan \
       --rec_iters 1000 \
       --debug

The defense_type is intentionally defense_gan, the config file instructs the code to use InvGAN. This will be fixed for the camera ready version.

DefenseGAN

python whitebox.py --cfg experiments/cfgs/gans/{mnist,fmnist,cifar10_hinge_resnet}.yml \ 
       --results_dir whitebox \
       --attack_type {fgsm,cw,bpda,bpda-l2} \
       --model A \
       --load_classifier \
       --defense_type defense_gan \
       --debug

Detection experiments (Table 3)

InvGAN

After running the whitebox experiments, the ROC results can be produced:

python plots/plot_ROC.py \
       --pkl_file_adv results/gans_inv_notrain/{mnist,fmnist,cifar_resnet}/whitebox/0_model=A_orig_Iter=1000_RR=1_LR=0.0100_defense_ganattack={fgsm,cw,bpda,bpda-l2}_roc.pkl \
       --pkl_file_clean results/gans_inv_notrain/{mnist,fmnist,cifar_resnet,celeba_resnet}/whitebox/0_model=A_orig_Iter=1000_RR=1_LR=0.0100_defense_ganattack={fgsm,cw,bpda,bpda-l2}_roc_clean.pkl

DefenseGAN

python plots/plot_ROC.py \
--pkl_file_adv results/gans/{mnist,fmnist,cifar10_hinge_resnet}/whitebox/0_model=A_orig_Iter=200_RR=10_LR=10.0000_defense_ganattack={fgsm,cw,bpda,bpda-l2}_roc.pkl \
--pkl_file_clean results/gans/{mnist,fmnist,cifar10_hinge_resnet}/whitebox/0_model=A_orig_Iter=200_RR=10_LR=10.0000_defense_ganattack={fgsm,cw,bpda,bpda-l2}_roc_clean.pkl

Train the Inverter

To train the inverter and the pre-trained models instead of the provided pre-trained models:

python train.py --cfg experiments/cfgs/gans_inv_notrain/{mnist,fmnist,cifar_resnet}.yml \
    --is_train

The code for attacks are in whitebox.py and blackbox.py.

The code for the inverter is in model/gan_v2.py.

invgan's People

Contributors

hugemicrobe avatar po0ya avatar

Watchers

James Cloos 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.