Code Monkey home page Code Monkey logo

patchsmoothing's Introduction

(De)Randomized Smoothing for Certifiable Defense against Patch Attacks

Code for the paper (De)Randomized Smoothing for Certifiable Defense against Patch Attacks by Alexander Levine and Soheil Feizi.

Files are provided for training and evaluation of classifiers robust to patch attacks on MNIST, CIFAR-10, and ImageNet datasets.

For MNIST and CIFAR-10, both the "block" and "band" methods are supported. On MNIST, there is also a supported "row" method.

For MNIST and CIFAR-10, there are additional certification options, using just the "top one" classification or (in the case of band smoothing) using randomized (as opposed to derandomized) smoothing. Additionally, multi-block and multi-band smoothing is supported for MNIST.

ImageNet code expects the ILSVRC2012 training and validation sets to be in the directories 'imagenet-train/train' and 'imagenet-val/val', respectively. This can be changed using the '--trainpath' and '--valpath' options.

Explanation of files: (substitute 'mnist' for 'cifar' or 'imagenet' appropriately; similarly substitute 'block' for 'band')

- train_mnist_band.py # Will train the base classifier, and save the model to the 'checkpoints' directory

- certify_mnist_band.py # Will load a model from 'checkpoints', and calculate and print clean and certified accuracies. The '--test' option will use the test set, rather than the validation set.

Example Usage:

python3 train_mnist_band.py --band_size 4 --lr 0.01 --end_epoch 199
python3 train_mnist_band.py --band_size 4 --lr 0.001 --end_epoch 399 --resume mnist_one_band_lr_0.01_regularization_0.0005_band_4_epoch_199.pth
python3 certify_mnist_band.py --band_size 4 --size_to_certify 5 --checkpoint mnist_one_band_lr_0.001_regularization_0.0005_band_4_epoch_399_resume_mnist_one_band_lr_0.01_regularization_0.0005_band_4_epoch_199.pth.pth
python3 certify_mnist_band.py --band_size 4 --size_to_certify 5 --test --checkpoint mnist_one_band_lr_0.001_regularization_0.0005_band_4_epoch_399_resume_mnist_one_band_lr_0.01_regularization_0.0005_band_4_epoch_199.pth.pth

There is also code to attack column-smoothed CIFAR-10 models:

attack_cifar_band.py  -- Patch attack on smoothed classifier
attack_cifar_band_linf.py  -- L-infinity attack on smoothed classifier
attack_cifar_baseline.py  -- Patch attack on baseline classifier
attack_cifar_band_linf.py  -- L-infinity attack on baseline classifier

Attributions:

patchsmoothing's People

Contributors

alevine0 avatar

Stargazers

 avatar Mihail Stoian avatar  avatar wcsa23187 avatar Jeff Carpenter avatar  avatar  avatar  avatar jiaxin Hu avatar chenyiming avatar Chenhui Zhang avatar  avatar TzuRen avatar Yanghao ZHANG avatar Xiangyu Qi avatar Kai Xiao avatar

Watchers

 avatar paper2code - bot avatar

patchsmoothing's Issues

Checkpoint accuracy?

Why is the accuracy of the checkpoint provided so low(cifar=69.05%,imagenet=26.82%)? Do I need to retrain?

Gradient problem for attack.

Dear author,

First of all, thanks for your great work!

There are something confusing for me about how the patch attack is implemented.

To my understanding, because you use the "double channel" encoding trick in the paper https://arxiv.org/pdf/1911.09272.pdf (Architectural and training considerations part), the gradient part of the attack needs to be modified.

So it is a little tricky here. I notice that in patch_attacker_parallelized.py, you use the gradients relative to the input 3 channels images only. It is somehow like you just attack "part of" the model.

However, I also find that it is reasonable to perturb the first 3 channels only. If you perturb all 6 channels, the result image may not follow the "encoding rule".

It may be better to do an experiment for "undefended baseline" (Fig7. In the original paper) using "double channel " encoding trick also.

This is only a suggestion... To be honest I am quite confused now.

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.