0

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).

1 Answers1

0

If you'd like to pass a session to the attack object, you can do so when you instantiate it:

attack = SPSA(model, sess=sess)
attack = LBFGS(model, sess)
  • Thanks for the author's reply. I know we can pass a session when init. I have solved this problem by using other sess objects. My above question is focus on test_imagenet_attacks.py, this file as ImageNet attack demo, but it seems cannot change to SPSA(model, sess=sess) or LBFGS(model, sess) easily as tf.train.MonitoredSession(session_creator) seems cannot be passed at init an attack object. – George.Zhao Aug 30 '19 at 07:07