Giter VIP home page Giter VIP logo

fgsm's Introduction

FGSM(Fast Gradient Sign Method)


Overview

Simple pytorch implementation of FGSM and I-FGSM
(FGSM : explaining and harnessing adversarial examples, Goodfellow et al.)
(I-FGSM : adversarial examples in the physical world, Kurakin et al.)
overview

FGSM

FGSM

I-FGSM

IFGSM

Dependencies

python 3.6.4
pytorch 0.3.1.post2
visdom(optional)
tensorboardX(optional)
tensorflow(optional)

Usage

  1. train a simple MNIST classifier
python main.py --mode train --env_name [NAME]
  1. load trained classifier, generate adversarial examples, and then see outputs in the output directory
python main.py --mode generate --iteration 1 --epsilon 0.03 --env_name [NAME] --load_ckpt best_acc.tar
  1. for a targeted attack, indicate target class number using --target argument(default is -1 for a non-targeted attack)
python main.py --mode generate --iteration 1 --epsilon 0.03 --target 3 --env_name [NAME] --load_ckpt best_acc.tar

Results

Non-targeted attack

from the left, legitimate examples, perturbed examples, and indication of perturbed images that changed predictions of the classifier, respectively

  1. non-targeted attack, iteration : 1, epsilon : 0.03 non-targeted1
  2. non-targeted attack, iteration : 5, epsilon : 0.03 non-targeted2
  3. non-targeted attack, iteration : 1, epsilon : 0.5 non-targeted3

Targeted attack

from the left, legitimate examples, perturbed examples, and indication of perturbed images that led the classifier to predict an input as the target, respectively

  1. targeted attack(9), iteration : 1, epsilon : 0.03 targeted1
  2. targeted attack(9), iteration : 5, epsilon : 0.03 targeted2
  3. targeted attack(9), iteration : 1, epsilon : 0.5 targeted3

References

  1. explaining and harnessing adversarial examples, Goodfellow et al.
  2. adversarial examples in the physical world, Kurakin et al.

fgsm's People

Contributors

1konny avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

fgsm's Issues

Question about env_name [NAME]

Hi @1Konny Can you please give me an example how to run this code? I am confused what should I put into [NAME]? Can you provide one example. Thanks.

python main.py --mode train --env_name **[NAME]**

Need help understanding the following lines..

FGSM/solver.py

Line 291 in d5e730b

changed[:, 0, :, :] = where(changed[:, 0, :, :] == 1, 252, 91)

do you know if we can get the dimensions automatically based on the input and output shapes? It is really hard to understand what these are doing. I am trying to use the same code for attacks on different datasets and would like to have a neat way to infer these indices/repeats from the input shapes.

It would be wonderful if you could explain the four lines related to changed and where(), thanks!

question

python main.py --mode generate --iteration 1 --epsilon 0.03 --load_ckpt best_acc.tar
Traceback (most recent call last):
File "main.py", line 75, in
main(args)
File "main.py", line 39, in main
iteration=args.iteration)
File "G:\FGSM-master\solver.py", line 213, in generate
pad_value=0.5)
File "F:\anaconda\envs\cw\lib\site-packages\torchvision\utils.py", line 105, in save_image
im.save(filename)
File "F:\anaconda\envs\cw\lib\site-packages\PIL\Image.py", line 2237, in save
fp = builtins.open(filename, "w+b")
OSError: [Errno 22] Invalid argument: 'output\main\legitimate(t:-1,e:0.03,i:1).jpg'

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.