Giter Club home page Giter Club logo

fgsm-learn's Introduction

学习FGSM(Fast Gradient Sign Method)

$$ \boxed{注:\text{Github}渲染公式不正常,建议下载仓库中的\text{pdf}进行查看。} $$

Classify文件夹内实现了一个分类识别的神经网络,训练完成后得到权重文件才可进行FGSM攻击。

attack文件夹中有FGSM的实现,可运行代码查看效果

FGSM效果

下表为使用FGSM对抗攻击后的前后对比效果。

原始图片效果 攻击后的图片效果

iFGSM效果

除了有FGSM的实现,代码还实现了iFGSM,即多次迭代FGSM。

下表为两种方法的对比效果,此处的条件为$\epsilon_{\mathrm{FGSM}} = i*\epsilon_{\mathrm{iFGSM}}$,$i$为迭代次数。

FGSM iFGSM(迭代10次)

Targeted iFGSM效果

Target is wrench Targeted is dragonfly

原理

FGSM原理

$$ x^{\prime}=x+\epsilon\cdot\mathrm{sign}(\nabla_{x}J(\theta,x,y)) $$

iFGSM原理

$$ x^{(0)}=x

\x^{(i+1)}=\mathrm{Clip}{x,\epsilon}\left(x^{(i)}+\epsilon\cdot\mathrm{sign}(\nabla{x}J(\theta,x^{(i)},y))\right) $$

有目标的FGSM实现原理

对于无目标FGSM,我们的想法是:

$$ \operatorname{maxmize}J(\theta,x^{\prime},y), \quad \text{s.t.}|x^{\prime}-x|_{\infty} < \epsilon, $$

而对于有目标的FGSM,我们的想法则是:

$$ \operatorname{minimize }J(\theta,x^{\prime},y^{\prime}),\quad\text{s.t.}|x^{\prime}-x|_{\infty} < \epsilon $$

其中,$x$ 为原始图像,$x^{\prime}$ 为对抗攻击后的图像,$y$ 为真实的标签,$y^{\prime}$ 为对抗攻击中的目标标签。

所以它的实现公式为: $$ x^{\prime}=x{\color{red}-}\epsilon\cdot\mathrm{sign}(\nabla_{x}J(\theta,x,y^{\prime})) $$ 此处与FGSM相比只有微小的区别。

参考:

https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html

https://colab.research.google.com/github/ashishpatel26/Awesome-Pytorch-Tutorials/blob/main/17.Pytorch Transfer learning with Caltech101.ipynb

https://github.com/Harry24k/FGSM-pytorch

https://github.com/1Konny/FGSM

fgsm-learn's People

Contributors

eptansuo avatar

Stargazers

jiaxing avatar  avatar  avatar

Watchers

 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.