1

My code is:

i = 0
fgsm = FastGradientMethod(wrap)
adv = fgsm.generate(x_test_tensor, **fgsm_params)

for adv_x in tf.unstack(adv):
    img = tf.cast(adv_x, dtype=tf.uint8)
    tf_image = tf.image.encode_jpeg(img)
    tf.write_file('adversarial_examples/' + str(i) + '.jpg', tf_image)
    i += 1

Where FastGradientMethod is from cleverhans. This runs without an error, but the jpg's don't exist in my folder. What's missing?

Shamoon
  • 41,293
  • 91
  • 306
  • 570

2 Answers2

2

may the path of the destination file is not correct

import os

for adv_x in tf.unstack(adv):
    img = tf.cast(adv_x, dtype=tf.uint8)
    tf_image = tf.image.encode_jpeg(img)
    pth = os.path.join('adversarial_examples', '%s.jpg'%i)
    tf.write_file(pth, tf_image)
    i += 1
1

you should:

op = tf.write_file(pth, tf_image)
sess.run(op)

Where sess is a tf.session.

Robert
  • 7,394
  • 40
  • 45
  • 64