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

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.