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?

4

2 回答 2

2

可能目标文件的路径不正确

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
于 2019-04-17T23:23:04.973 回答
1

你应该:

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

sess一个在哪里tf.session

于 2021-03-24T14:46:22.090 回答