Giter VIP home page Giter VIP logo

defend_mi's Introduction

Bilateral Dependency Optimization: Defending Against Model-inversion Attacks

Paper Github License

Hi, this is the code for our KDD 2022 paper: Bilateral Dependency Optimization: Defending Against Model-inversion Attacks. BiDO_vs_MID Overview of MID framework vs. bilateral dependency optimization (BiDO) framework. BiDO forces DNNs to learn robust latent representations by minimizing $๐‘‘(๐‘‹,๐‘_j)$ to limit redundant information propagated from the inputs to the latent representations while maximizing $๐‘‘(๐‘_j,๐‘Œ)$ to keep the latent representations informative enough of the label.

Requiements

This code has been tested on Ubuntu 16.04/18.04, with Python 3.7, Pytorch 1.7 and CUDA 10.2/11.0

Getting started

Download relevant datasets: CelebA, MNIST.

  • CelebA
  • MNIST
    python prepare_data.py
    

The directory of datasets is organized as follows:

./attack_dataset
โ”œโ”€โ”€ MNIST 
โ”‚   โ”œโ”€โ”€ *.txt 
โ”‚   โ””โ”€โ”€ Img
โ”‚       โ””โ”€โ”€ *.png
โ””โ”€โ”€ CelebA                            
    โ”œโ”€โ”€ *.txt 
    โ””โ”€โ”€ Img
        โ””โ”€โ”€ *.png

Privacy enhancement with BiDO

You can also skip to the next section for defending against MI attacks with well-trained defense models.

  • For GMI and KED-MI
    # dataset:celeba, mnist, cifar; 
    # measure:COCO, HSIC; 
    # balancing hyper-parameters: tune them in train_HSIC.py
    python train_HSIC.py --measure=HSIC --dataset=celeba
    
    For KED-MI, if you trained a defense model yourself, you have to train an attack model (generative model) specific to this defense model.
    # put your hyper-parameters in k+1_gan_HSIC.py first
    python k+1_gan_HSIC --dataset=celeba --defense=HSIC
    
  • For VMI
    Please refer to this section (Defending against MI attacks - VMI - train with BiDO).

Defending against MI attacks

Here, we only provide the weights file of the well-trained defense models that achieve the best trade-off between model robustness and utility, which are highlighted in the experimental results.

  • GMI

    • Weights file (defense model / eval model / GAN) :

    • Launch attack

      # balancing hyper-parameters: (0.05, 0.5)
      python attack.py --dataset=celeba --defense=HSIC
      
    • Calculate FID

      # sample real images from training set
      cd attack_res/celeba/pytorch-fid && python private_domain.py 
      # calculate FID between fake and real images
      python fid_score.py ../celeba/trainset/ ../celeba/HSIC/all/
      
  • KED-MI

    • Weights file (defense model / eval model / GAN) :
    • Launch attack
      # balancing hyper-parameters: (0.05, 0.5)
      python recovery.py --dataset=celeba --defense=HSIC
      # balancing hyper-parameters: (1, 50)
      python recovery.py --dataset=mnist --defense=COCO
      
    • Calculate FID
      # celeba
      cd attack_res/celeba/pytorch-fid && python private_domain.py 
      python fid_score.py ../celeba/trainset/ ../celeba/HSIC/all/ --dataset=celeba
      # mnist
      cd attack_res/mnist/pytorch-fid && python private_domain.py 
      python fid_score.py ../mnist/trainset/ ../mnist/COCO/all/ --dataset=mnist
      
  • VMI
    To run this code, you need ~38G of memory for data loading. The attacking of 20 identities takes ~20 hours on a TiTAN-V GPU (12G).

    • Data (CelebA)
      # create a link to CelebA
      cd VMI/data && ln -s ../../attack_data/CelebA/Img img_align_celeba
      python celeba.py
      
    • Weights file (defense model / eval model / GAN) :
      • Place defense model in VMI/clf_results/celeba/hsic_0.1&2/
      • Place ir_se50.pth in VMI/3rd_party/InsightFace_Pytorch/work_space/save/; Place evaluation classifer in VMI/pretrained/eval_clf/celeba/
      • Place StyleGAN in VMI/pretrained/stylegan/neurips2021-celeba-stylegan/
    • Launch attack
      # balancing hyper-parameters: (0.1, 2)
      cd VMI
      # x.sh  (1st) path/to/attack_results (2nd) config_file  (3rd) batch_size
      ./run_scripts/neurips2021-celeba-stylegan-flow.sh  'hsic_0.1&2'  'hsic_0.1&2.yml' 32
      
    • Train with BiDO
      python classify_mnist.py --epochs=100 --dataset=celeba --output_dir=./clf_results/celeba/hsic_0.1&2 --model=ResNetClsH --measure=hsic --a1=0.1 --a2=2
      

References

If you find this code helpful in your research, please consider citing

@inproceedings{peng2022BiDO,
title={Bilateral Dependency Optimization: Defending Against Model-inversion Attacks},
author={Peng, Xiong and Liu, Feng and Zhang, Jingfeng and Lan, Long and Ye, Junjie and Liu, Tongliang and Han, Bo},
booktitle={KDD},
year={2022}
}

Implementation Credits

Some of our implementations rely on other repos. We want to thank the authors (MID, GMI, KED-MI, VMI) for making their code publicly available.๐Ÿ˜„

defend_mi's People

Contributors

alanpeng0897 avatar zcysky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

defend_mi's Issues

BiDO (lambda_x=0 and lambda_y=0) and No. Def models

Hi,

Thank you for sharing amazing work.

I am currently working on your code and curious about the difference between models training with BiDO (lambda_x=0 and lambda_y=0) and No. Def model.

Based on my understanding, it should be similar? In your code, I noticed that the difference comes from hyper-parameters (learning rate, learning rate scheduler, etc)?

Thank you very much.

Missing config.json

Hey,

thank you for providing code for your defense. I am currently trying to evaluate the models with VMI. However, the code seems currently missing the args.json file loaded here:

with open(os.path.join(os.path.split(cls_path)[0], 'args.json'), 'r') as f:
.

Without the config, the code seems not to work properly. Could you please provide the missing config file?

Best,
Lukas

reg and vib

Can you explain what the reg and vib in the defends parameter means, thank you!
image

No Defend Code

Can you provide no defense and MID model training code also to compare?
Thank you.

mnist result

I could not get the adorable DMI attack accuracy and recovery performance on MNIST. I used the same running setting to train the targetor model and launch the DMI attack. could you tell me some possible points causing the bad performance?

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.