Coder Social home page Coder Social logo

xiaofanustc / pytorch-nips2017-attack-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rwightman/pytorch-nips2017-attack-example

0.0 2.0 0.0 17 KB

A PyTorch baseline attack example for the NIPS 2017 adversarial competition

Home Page: https://www.kaggle.com/c/nips-2017-targeted-adversarial-attack

License: Apache License 2.0

Python 97.08% Shell 2.92%

pytorch-nips2017-attack-example's Introduction

pytorch-nips2017-attack-example

This is a baseline targeted (or untargeted) attack that works within the Cleverhans (https://github.com/tensorflow/cleverhans) framework for the NIPS-2017 adversarial competition.

There are two types of attacks included, an iterative fast-gradient method, and a Carlini and Wagner L2 attack.

Iterative Fast-Gradient

These attacks are modeled after the 'basic iterative' / 'itarative FGSM' attack mentioned in https://arxiv.org/abs/1611.01236 and https://arxiv.org/abs/1705.07204 (among others).

The default setup is to run a targeted L-inifity norm variant of the targeted attack with 10 steps. L1 or L2 based attacks seem to require around 40-50 steps with the current code to perform a reasonable attack.

Carlini and Wagner L2

An implementation of the L2 variant of the attack described in this paper https://arxiv.org/abs/1608.04644 by Carlini and Wagner. Based on a reference implementation by Carlini at https://github.com/carlini/nn_robust_attacks and https://github.com/tensorflow/cleverhans/blob/master/cleverhans/attacks_tf.py

NOTE: I'm still verifying and experimenting with this attack. It takes MUCH longer (half a day) to run and produces much more subtle results that I'm having difficulty successfully transfering as a targeted attack to other models...

Usage

To run:

  1. Setup and verify cleverhans nips17 adversarial competition example environment
  2. Clone this repo
  3. Run ./download_checkpoint.sh to download the inceptionv3 checkpoint from torchvision model zoo
  4. Symbolic link the folder this repo was clone into into the cleverhans 'examples/nips17_adversarial_competition/sample_targeted_attacks/' folder
  5. Run run_attacks_and_defenses.sh and ensure '--gpu' flag is added

To switch between attacks and alter parameters of the attack, command line args in the run_attack.sh script need modification.

Iterative non-targeted L1:

python run_attack_iter.py \
  --input_dir="${INPUT_DIR}" \
  --output_dir="${OUTPUT_DIR}" \
  --max_epsilon="${MAX_EPSILON}" \
  --steps 50 \
  --norm 1 \
  --checkpoint_path=inception_v3_google-1a9a5a14.pth

Iterative targeted L2:

python run_attack_iter.py \
  --input_dir="${INPUT_DIR}" \
  --output_dir="${OUTPUT_DIR}" \
  --max_epsilon="${MAX_EPSILON}" \
  --steps 42 \
  --targeted \
  --norm 2 \
  --checkpoint_path=inception_v3_google-1a9a5a14.pth

Carlini and Wagner L2:

python run_attack_cwl2.py \
  --input_dir="${INPUT_DIR}" \
  --output_dir="${OUTPUT_DIR}" \
  --max_epsilon="${MAX_EPSILON}" \
  --targeted \
  --checkpoint_path=inception_v3_google-1a9a5a14.pth

pytorch-nips2017-attack-example's People

Contributors

rwightman avatar

Watchers

 avatar  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.