在Cleverhans示例中: cleverhans/examples/test_imagenet_attacks.py
他们使用sess=None实现了SPSA攻击。
但在克利夫汉斯攻击库中,有很多方法不能将sess设置为None,如CW、DeepFool、BFGS等。
如何使用sess更改代码并使用这些方法生成对抗性示例?
链接:https://github.com/tensorflow/cleverhans/blob/master/examples/test_imagenet_attacks.py
一个ImagNet上SPSA攻击的代码聚合:
attack = SPSA(model)
x_adv = attack.generate(x_input, ...)
logits = model.get_logits(x_adv)
acc = _top_1_accuracy(logits, y_label)
saver = tf.train.Saver(slim.get_model_variables())
session_creator = tf.train.ChiefSessionCreator(...)
with tf.train.MonitoredSession(session_creator) as sess:
for i in xrange(num_images):
feed_dict_i = {x_input, y_label}
acc_val = sess.run(acc, feed_dict=feed_dict_i)但是对于DeepFool,我们不能写attack =SPSA(模型),因为它必须是attack =DeepFool(模型,会话)。
发布于 2019-08-22 00:32:30
如果你想传递一个会话给攻击对象,你可以在实例化它的时候这样做:
attack = SPSA(model, sess=sess)
attack = LBFGS(model, sess)https://stackoverflow.com/questions/57496919
复制相似问题