攻击模型:Inception v3 数据集:ImageNet 原有预分类模型:TF-slim图像分类库
接论文
synthesizing-robust-adversarial-examples https://arxiv.org/abs/1707.07397
(综合强大的对抗样本)
代码:
http://www.anishathalye.com/media/2017/07/25/adversarial.ipynb(本文讲解)
https://github.com/prabhant/synthesizing-robust-adversarial-examples
参考:https://www.jiqizhixin.com/articles/2017-08-11-9
代码在jupyter notebook中可以直接打开,本文主要添加部分代码注释。
攻击模型:Inception v3 数据集:ImageNet 原有预分类模型:TF-slim图像分类库
import tensorflow as tf
import tensorflow.contrib.slim as slim
import tensorflow.contrib.slim.nets as nets
tf.logging.set_verbosity(tf.logging.ERROR)
sess = tf.InteractiveSession()
image = tf.Variable(tf.zeros((299, 299, 3)))
#设置输入图像:tf.Variable
instead of a tf.placeholder
可训练
#tf.Variable:声明变量并赋值,tf.placeholder对声明的变量长期使用,节省内存
def inception(image, reuse):
preprocessed = tf.multiply(tf.subtract(tf.expand_dims(image, 0), 0.5), 2.0)
arg_scope = nets.inception.inception_v3_arg_scope(weight_decay=0.0)
with slim.arg_scope(arg_scope):
logits, _ = nets.inception.inception_v3(
preprocessed, 1001, is_training=False, reuse=reuse)
#299,299,3,1001是inceptionV3的标准参数
logits = logits[:,1:] # ignore background class
probs = tf.nn.softmax(logits) # probabilities
return logits, probs
logits, probs = inception(image, reuse=False)
(一)正确分类
加载Inception v3模型后,用自己的一张照片来正确分类
然后生成对抗样本:
旋转后才有PGD保持对抗样本的攻击性: