In Cleverhans example: cleverhans/examples/test_imagenet_attacks.py
They implement SPSA attack with sess=None.
But in Cleverhans attacks repo, there are a lot of methods cannot set sess as None, for example, CW, DeepFool, BFGS...
How to change the code with a sess and to generate adversarial examples with these methods?
Link: https://github.com/tensorflow/cleverhans/blob/master/examples/test_imagenet_attacks.py
A code fregment of SPSA attack on ImagNet:
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)
But for DeepFool, we cannot write attack = SPSA(model) as it must be attack = DeepFool(model, sess).