cleverhans-lab / cleverhans

An adversarial example library for constructing attacks, building defenses, and benchmarking both
MIT License
6.18k stars 1.39k forks source link

Error in FGSM with keras #1198

Closed ForeverRuri closed 3 years ago

ForeverRuri commented 3 years ago

Describe the bug When i try to use FGSM in keras, i meet up with the error same as https://stackoverflow.com/questions/58254353/error-when-implementing-fgsm-in-keras-with-cleverhans

To Reproduce Steps to reproduce the behavior:

fgsm = FastGradientMethod(KerasModelWrapper(model), sess=sess)
model_input = tf.placeholder(tf.float32, shape=(1, 299, 299, 3))
x_adv = fgsm.generate(model_input, **fgsm_params)
adv_images = sess.run(x_adv, feed_dict={model_input: img})

error at the last line

System configuration

alkaet commented 3 years ago

I'm not familiar with the TF1 implementation and we have discontinued support for TF1. I think that we will not fix this problem. @jonasguan Your opinion on this? @ForeverRuri Is there a specific reason you need to use TF1 rather than TF2? I'm happy to help you with setting up the MNIST tutorial for TF2

ForeverRuri commented 3 years ago

@ForeverRuri Is there a specific reason you need to use TF1 rather than TF2? I'm happy to help you with setting up the MNIST tutorial for TF2

For we have done some work in advance in TF1, or could u tell me with which version of cleverhans can i run the code above? or how could i use a keras pretrained model to generate some adv pics?

alkaet commented 3 years ago

Version 4.0 of Cleverhans (current version) implements the TF2 FGSM attack. TF2 uses keras as it's high level API. You should not have too much trouble porting Keras code to TF2. I would recommend that solution as TF1 is no longer supported by google afaik.