查看原文
其他

算法|Tensorflow实现了四个对抗图像制作算法

2017-05-15 全球人工智能

全球人工智能:专注为AI开发者提供全球最新AI技术动态和社群交流。用户来源包括:北大、清华、中科院、复旦、麻省理工、卡内基梅隆、斯坦福、哈佛、牛津、剑桥等世界名校的AI技术硕士、博士和教授;以及谷歌、腾讯、百度、脸谱、微软、华为、阿里、海康威视、滴滴、英伟达等全球名企的AI开发者和AI科学家。


文章来源:Github


Four adversarial image crafting algorithms are implemented with  Tensorflow.  The four attacking algorithms can be found in attacks  folder.  The implementation adheres to the principle tensor-in,  tensor-out.  They all return a Tensorflow operation which could be  run through sess.run(...).


API:

  • Fast Gradient Sign Method (FGSM) basic/iterative

    fgsm(model, x, eps=0.01, epochs=1, clip_min=0.0, clip_max=1.0)


https://arxiv.org/abs/1412.6572/

https://arxiv.org/abs/1607.02533


  • Target class Gradient Sign Method (TGSM)

    tgsm(model, x, y=None, eps=0.01, epochs=1, clip_min=0.0, clip_max=1.0)    
  1. When y=None, this implements the least-likely class method.

  2. If y is an integer or a list of integers, the source image is        modified towards label y.


https://arxiv.org/abs/1607.02533


  • Jacobian-based Saliency Map Approach (JSMA)

    jsma(model, x, y, epochs=1.0, eps=1., clip_min=0.0, clip_max=1.0, pair=False, min_proba=0.0)    

    y is the target label, could be an integer or a list.  when      epochs is a floating number in the range [0, 1], it denotes the      maximum percentage distortion allowed and epochs is automatically      deduced.  min_proba denotes the minimum confidence of target      image.  If pair=True, then modifies two pixels at a time.


https://arxiv.org/abs/1511.07528


  • Saliency map difference approach (SMDA)

    smda(model, x, y, epochs=1.0, eps=1., clip_min=0.0, clip_max=1.0, min_proba=0.0)

    Interface is the same as jsma.  This algorithm differs from the      JSMA in how the saliency score is calculated.  In JSMA, saliency      score is calculated as dt/dx * (-do/dx), while in SMDA, the      saliency score is dt/dx - do/dx, thus the name “saliency map      difference”.


The model

Notice that we have model as the first parameter for every method.  The model is a wrapper function.  It should have the following  signature


def model(x, logits=False):    
   # x is the input to the network, usually a tensorflow placeholder    y = your_model(x)    logits_ = ...               # get the logits before softmax    if logits:    
      return y, logits    
   return y


We need the logits because some algorithms (FGSM and TGSM) rely on the  logits to compute the loss.


How to Use

Implementation of each attacking method is self-contained, and depends  only on tensorflow.  Copy the attacking method file to the same  folder as your source code and import it.


The implementation should work on any framework that is compatible  with Tensorflow.  I provide example code for Tensorflow and Keras in  the folder tf_example and keras_example, respectively.  Each  code example is also self-contained.


https://github.com/gongzhitaao/tensorflow-adversarial/blob/master/tf_example

https://github.com/gongzhitaao/tensorflow-adversarial/blob/master/keras_example


And example code with the same file name implements the same function.  For example, tf_example/ex_00.py and keras_example/ex_00.py  implement exactly the same function, the only difference is that the  former uses Tensorflow platform while the latter uses Keras platform.


https://github.com/gongzhitaao/tensorflow-adversarial/blob/master/tf_example/ex_00.py

https://github.com/gongzhitaao/tensorflow-adversarial/blob/master/keras_example/ex_00.py


Results

  • ex_00.py trains a simple CNN on MNIST.  Then craft adversarial    samples from test data vis FGSM.  The original label for the    following digits are 0 through 9 originally, and the predicted label    with probability are shown below each digit.



  • ex_01.py creates cross label adversarial images via saliency map    approach (JSMA).  For each row, the digit in green box is the clean    image.  Other images on the same row are created from it.




  • ex_02.py creates cross label adversarial images via target class    gradient sign method (TGSM).




  • ex_03.py creates digits from blank images via saliency different    algorithm (SMDA).


  • These images look weird.  And I have no idea why I could not      reproduce the result in the original paper.  My guess is that

    However various experiments seem to suggest that my implementation      work properly.  I have to try more examples to figure out what is      going wrong here.

  1. either my model is too simple to catch the features of the        dataset, or

  2. there is a flaw in my implementation.


  • ex_04.py creates digits from blank images via paired saliency map    algorithm, i.e., modify two pixels at one time (refer to the    original paper for rational http://arxiv.org/abs/1511.07528).



  • ex_05.py trains a simple CNN on MNIST and then crafts adversarial    samples via LLCM.  The original label for the following digits are 0    through 9 originally, and the predicted label with probability are    shown below each digit.



  • ex_06.py trains a CNN on CIFAR10 and then crafts adversarial image    via FGSM.



Related Work

  • openai/cleverhans

https://github.com/openai/cleverhans



热门文章推荐

应用|亚洲首个全自动码头,中国这个港口被机器人承包了!

AIJob|深大70万+年薪招聘大数据人才,另享“孔雀计划”160-300万元补贴

最新|超级计算机之父Cray:宣布推出全新的AI超级计算机!

重磅|英伟达:10万AI开发者计划打造万亿美元市值的商业帝国!

重磅|Facebook开源最新CNN机器翻译项目Fairseq,速度是谷歌9倍!

最新|李飞飞团队新成果:提出视频字幕密集型事件描述新模型(附资源)

推荐|CMU开源:价值百万美元的多目标人体关键点实时检测

报告|25所高产大学:源源不断为硅谷顶尖科技公司输送科技人才


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存