Code Monkey home page Code Monkey logo

avc_nips_2018's Introduction

NIPS 2018 Adversarial Vision Challenge

Code to reproduce the attacks and defenses for the entries "JeromeR" in the NIPS 2018 Adversarial Vision Challenge (1st place on Untargeted attacks, 3rd place on Robust models and Targeted attacks)

Team name: LIVIA - ETS Montreal

Team members: Jérôme Rony, Luiz Gustavo Hafemann

Overview

Defense: We trained a robust model with a new iterative gradient-based L2 attack that we propose (Decoupled Direction and Norm — DDN), that is fast enough to be used during training. In each training step, we find an adversarial example (using DDN) that is close to the decision boundary, and minimize the cross-entropy of this example. There is no change to the model architecture, nor any impact on inference time.

Attacks: Our attack is based on a collection of surrogate models (including robust models trained with DDN). For each model, we select two directions to attack: the gradient of the cross entropy loss for the original class, and the direction given by running the DDN attack. For each direction, we do a binary search on the norm to find the decision boundary. We take the best attack and refine it with a Boundary attack.

For more information on the DDN attack, refer to the paper, and implementation:

[1]Jérôme Rony, Luiz G. Hafemann, Luiz S. Oliveira, Ismail Ben Ayed, Robert Sabourin and Eric Granger "Decoupling Direction and Norm for Efficient Gradient-Based L2 Adversarial Attacks and Defenses", arXiv:1811.09600

Installation

Clone this repository and install the dependencies by running pip install -r requirements.txt

Download the TinyImagenet dataset:

wget https://storage.googleapis.com/luizgh-datasets/avc_models/tiny-imagenet-pytorch.tar.gz
tar xvf tiny-imagenet-pytorch.tar.gz -C data

Optional: download trained models: resnext50_ddn (our robust model), resnet18_clean (not adversarially trained):

wget https://storage.googleapis.com/luizgh-datasets/avc_models/resnet18_clean.pt
wget https://storage.googleapis.com/luizgh-datasets/avc_models/resnext50_32x4d_ddn.pt
wget https://storage.googleapis.com/luizgh-datasets/avc_models/resnext50_32x4d_imagenet.pth

Training a model

Adversarially training a model (using the DDN attack):

python train_tiny_imagenet_ddn.py data --sf tiny_ddn --adv --max-norm 2.5 --arch resnext50_32x4d --pretrained

For monitoring training, you can start a visdom server, and then add the argument --visdom-port <port> to the command above:

python -m visdom.server -port <port>

Running the attack

See "attack_example.py" for an example of the attack. If you downloaded the models from the Installation section, you can run the following code:

python attack_example.py --m resnet18_clean.pt --sm resnext50_32x4d_ddn.pt

This will create an attack against a resnet18 model, using an adversarially trained surrogate model.

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.