I try to use the code to attack models implemented in Keras. There is no problem when using fgsm. However, when I use deepfool, I get an error:
Traceback (most recent call last):
File "attack_mnist_keras.py", line 136, in
main()
File "attack_mnist_keras.py", line 127, in main
x_deepfool = deepfool(classifier_attack, x, epochs=3)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 50, in deepfool
name='deepfool')
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
swap_memory=swap_memory)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 413, in compute
packed_fn_values = fn(packed_values)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 46, in _f
clip_max=clip_max, min_prob=min_prob)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 165, in _deepfoolx
name='_deepfoolx', back_prop=False)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 144, in _body
for i in range(ydim)]
TypeError: 'NoneType' object cannot be interpreted as an integer
I found that in the deepfool.py, line 120 get y0 with shape (?, 10) rather than (1, 10). I have tried to ignore this and set ydim = 1, but I get another error:
Traceback (most recent call last):
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call
return fn(*args)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 1 of dimension 0 out of bounds.
[[Node: deepfool/while/_deepfoolx/strided_slice_4 = StridedSlice[Index=DT_INT64, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/device:GPU:0"](deepfool/while/_deepfoolx/stack, deepfool/while/_deepfoolx/strided_slice_4/stack/_147, deepfool/while/_deepfoolx/strided_slice_4/stack_1/_149, deepfool/while/_deepfoolx/strided_slice_4/Cast/_151)]]
[[Node: clip_by_value/_165 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_781_clip_by_value", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "attack_mnist_keras.py", line 136, in
main()
File "attack_mnist_keras.py", line 129, in main
x_adv = make_deepfool(sess, x_deepfool, x, epochs, X_test, 3)
File "attack_mnist_keras.py", line 61, in make_deepfool
K.learning_phase(): 0})
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
run_metadata_ptr)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
feed_dict_tensor, options, run_metadata)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
run_metadata)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 1 of dimension 0 out of bounds.
[[Node: deepfool/while/_deepfoolx/strided_slice_4 = StridedSlice[Index=DT_INT64, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/device:GPU:0"](deepfool/while/_deepfoolx/stack, deepfool/while/_deepfoolx/strided_slice_4/stack/_147, deepfool/while/_deepfoolx/strided_slice_4/stack_1/_149, deepfool/while/_deepfoolx/strided_slice_4/Cast/_151)]]
[[Node: clip_by_value/_165 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_781_clip_by_value", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'deepfool/while/_deepfoolx/strided_slice_4', defined at:
File "attack_mnist_keras.py", line 136, in
main()
File "attack_mnist_keras.py", line 127, in main
x_deepfool = deepfool(classifier_attack, x, epochs=3)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 50, in deepfool
name='deepfool')
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
swap_memory=swap_memory)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 413, in compute
packed_fn_values = fn(packed_values)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 46, in _f
clip_max=clip_max, min_prob=min_prob)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 166, in _deepfoolx
name='_deepfoolx', back_prop=False)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 149, in _body
gk, go = g[k0], tf.concat((g[:k0], g[(k0+1):]), axis=0)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 597, in _slice_helper
name=name)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 763, in strided_slice
shrink_axis_mask=shrink_axis_mask)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 8148, in strided_slice
name=name)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): slice index 1 of dimension 0 out of bounds.
[[Node: deepfool/while/_deepfoolx/strided_slice_4 = StridedSlice[Index=DT_INT64, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/device:GPU:0"](deepfool/while/_deepfoolx/stack, deepfool/while/_deepfoolx/strided_slice_4/stack/_147, deepfool/while/_deepfoolx/strided_slice_4/stack_1/_149, deepfool/while/_deepfoolx/strided_slice_4/Cast/_151)]]
[[Node: clip_by_value/_165 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_781_clip_by_value", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
I wonder if you could help me solve this problem. Thanks very much.
I try to use the code to attack models implemented in Keras. There is no problem when using fgsm. However, when I use deepfool, I get an error: Traceback (most recent call last): File "attack_mnist_keras.py", line 136, in
main()
File "attack_mnist_keras.py", line 127, in main
x_deepfool = deepfool(classifier_attack, x, epochs=3)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 50, in deepfool
name='deepfool')
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
swap_memory=swap_memory)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 413, in compute
packed_fn_values = fn(packed_values)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 46, in _f
clip_max=clip_max, min_prob=min_prob)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 165, in _deepfoolx
name='_deepfoolx', back_prop=False)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 144, in _body
for i in range(ydim)]
TypeError: 'NoneType' object cannot be interpreted as an integer
I found that in the deepfool.py, line 120 get y0 with shape (?, 10) rather than (1, 10). I have tried to ignore this and set ydim = 1, but I get another error: Traceback (most recent call last): File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call return fn(*args) File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 1 of dimension 0 out of bounds. [[Node: deepfool/while/_deepfoolx/strided_slice_4 = StridedSlice[Index=DT_INT64, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/device:GPU:0"](deepfool/while/_deepfoolx/stack, deepfool/while/_deepfoolx/strided_slice_4/stack/_147, deepfool/while/_deepfoolx/strided_slice_4/stack_1/_149, deepfool/while/_deepfoolx/strided_slice_4/Cast/_151)]] [[Node: clip_by_value/_165 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_781_clip_by_value", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "attack_mnist_keras.py", line 136, in
main()
File "attack_mnist_keras.py", line 129, in main
x_adv = make_deepfool(sess, x_deepfool, x, epochs, X_test, 3)
File "attack_mnist_keras.py", line 61, in make_deepfool
K.learning_phase(): 0})
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
run_metadata_ptr)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
feed_dict_tensor, options, run_metadata)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
run_metadata)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 1 of dimension 0 out of bounds.
[[Node: deepfool/while/_deepfoolx/strided_slice_4 = StridedSlice[Index=DT_INT64, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/device:GPU:0"](deepfool/while/_deepfoolx/stack, deepfool/while/_deepfoolx/strided_slice_4/stack/_147, deepfool/while/_deepfoolx/strided_slice_4/stack_1/_149, deepfool/while/_deepfoolx/strided_slice_4/Cast/_151)]]
[[Node: clip_by_value/_165 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_781_clip_by_value", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'deepfool/while/_deepfoolx/strided_slice_4', defined at: File "attack_mnist_keras.py", line 136, in
main()
File "attack_mnist_keras.py", line 127, in main
x_deepfool = deepfool(classifier_attack, x, epochs=3)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 50, in deepfool
name='deepfool')
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 423, in map_fn
swap_memory=swap_memory)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/functional_ops.py", line 413, in compute
packed_fn_values = fn(packed_values)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 46, in _f
clip_max=clip_max, min_prob=min_prob)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 166, in _deepfoolx
name='_deepfoolx', back_prop=False)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 3224, in while_loop
result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2956, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2893, in _BuildLoop
body_result = body(packed_vars_for_body)
File "/home/wangxiaosen/attack_gan/attack_keras/deepfool.py", line 149, in _body
gk, go = g[k0], tf.concat((g[:k0], g[(k0+1):]), axis=0)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 597, in _slice_helper
name=name)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 763, in strided_slice
shrink_axis_mask=shrink_axis_mask)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 8148, in strided_slice
name=name)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op
op_def=op_def)
File "/opt/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1718, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): slice index 1 of dimension 0 out of bounds. [[Node: deepfool/while/_deepfoolx/strided_slice_4 = StridedSlice[Index=DT_INT64, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1, _device="/job:localhost/replica:0/task:0/device:GPU:0"](deepfool/while/_deepfoolx/stack, deepfool/while/_deepfoolx/strided_slice_4/stack/_147, deepfool/while/_deepfoolx/strided_slice_4/stack_1/_149, deepfool/while/_deepfoolx/strided_slice_4/Cast/_151)]] [[Node: clip_by_value/_165 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_781_clip_by_value", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
I wonder if you could help me solve this problem. Thanks very much.