cihangxie / DI-2-FGSM

Improving Transferability of Adversarial Examples with Input Diversity
MIT License
161 stars 38 forks source link

complete code #1

Closed sun201711 closed 5 years ago

sun201711 commented 5 years ago

Can you give me the complete code, the current code can't be verified.Thank you!

cihangxie commented 5 years ago

which part you cannot verify?

sun201711 commented 5 years ago

I want to generate adversarial examples using multi-model fusion method, but when I input the transformed images into the inception resnetV2 network, I get the following error. Traceback (most recent call last): File "target_attack.py", line 284, in tf.app.run() File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "target_attack.py", line 253, in main xadv, , , , , = tf.while_loop(stop_large, graph_large, [x_input, target_class_input, i, x_max, x_min, grad]) File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2623, in while_loop result = context.BuildLoop(cond, body, loop_vars, shape_invariants) File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2456, in BuildLoop pred, body, original_loop_vars, loop_vars, shape_invariants) File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2406, in _BuildLoop body_result = body(packed_vars_for_body) File "target_attack.py", line 147, in graph_large input_diversity(x), num_classes=num_classes, is_training=False, scope='EnsAdvInceptionResnetV2') File "/home/user/sun/Targeted-Adversarial-Attack/nets/inception_resnet_v2.py", line 307, in inception_resnet_v2 padding='VALID', scope='Conv2d_2a_5x5') File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 181, in func_with_args return func(args, current_args) File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 917, in convolution _reuse=reuse) File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/convolutional.py", line 420, in init name=name, kwargs) File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/convolutional.py", line 104, in init self.kernel_size = utils.normalize_tuple(kernel_size, rank, 'kernel_size') File "/home/user/dsp/software/anaconda2/lib/python2.7/site-packages/tensorflow/python/layers/utils.py", line 87, in normalize_tuple int(single_value) TypeError: int returned non-int (type NoneType)

So, can you give me the code to attack an ensemble of multiple networks.

cihangxie commented 5 years ago

I use this code for ensemble

https://github.com/dongyp13/Non-Targeted-Adversarial-Attacks

sun201711 commented 5 years ago

Yeah,I also use this code,but when I input the input_diversity(x) into the InceptionV4 or Inception ResnetV2,it will have the above error.

sun201711 commented 5 years ago

I just made the following changes to this code. Have you made any other changes?

with slim.arg_scope(inception_v3.inception_v3_arg_scope()): logits_ens3_adv_v3, end_points_ens3_adv_v3 = inception_v3.inception_v3( input_diversity(x), num_classes=num_classes, is_training=False, scope='Ens3AdvInceptionV3')

with slim.arg_scope(inception_v3.inception_v3_arg_scope()): logits_ens4_adv_v3, end_points_ens4_adv_v3 = inception_v3.inception_v3( input_diversity(x), num_classes=num_classes, is_training=False, scope='Ens4AdvInceptionV3')

with slim.arg_scope(inception_v4.inception_v4_arg_scope()): logits_v4, end_points_v4 = inception_v4.inception_v4( input_diversity(x), num_classes=num_classes, is_training=False)

with slim.arg_scope(inception_resnet_v2.inception_resnet_v2_arg_scope()): logits_res_v2, end_points_res_v2 = inception_resnet_v2.inception_resnet_v2( input_diversity(x), num_classes=num_classes, is_training=False)

cihangxie commented 5 years ago

Oh, i see your problem. You should take care of the tensor shape now, i.e., you should make some changes to the net files of inceptionv4 and inceptionresnetv2, to make sure the shape info is properly got.

For example, https://github.com/cihangxie/NIPS2017_adv_challenge_defense/blob/master/inception_resnet_v2.py

sun201711 commented 5 years ago

Can you give me the tarined models and the net files for the ensemble models attack ?Thank you very much !!!

cihangxie commented 5 years ago

all models are available here https://github.com/tensorflow/models/tree/master/research/slim