Closed pluskid closed 6 years ago
I'm getting the following error while trying to run a code segment in the README:
import numpy as np batch_size = 32 def my_very_robust_model(images_nchw): """This function implements a valid unrestricted advex defense""" logits = np.random.randn(batch_size, 2) return logits from unrestricted_advex import eval_kit from unrestricted_advex.mnist_baselines.evaluate_tcu_mnist import iter_mnist_testset eval_kit.evaluate_tcu_mnist_model( my_very_robust_model, iter_mnist_testset( num_datapoints=batch_size, batch_size=batch_size))
error log
--------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args) 1321 try: -> 1322 return fn(*args) 1323 except errors.OpError as e: ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata) 1306 return self._call_tf_sessionrun( -> 1307 options, feed_dict, fetch_list, target_list, run_metadata) 1308 ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata) 1408 self._session, options, feed_dict, fetch_list, target_list, -> 1409 run_metadata) 1410 else: InvalidArgumentError: 0-th value returned by pyfunc_1 is double, but expects float [[Node: while/PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_1", _device="/job:localhost/replica:0/task:0/device:CPU:0"](while/add_4)]] During handling of the above exception, another exception occurred: InvalidArgumentError Traceback (most recent call last) <ipython-input-1-bc52c4bf0bb6> in <module>() 12 eval_kit.evaluate_tcu_mnist_model( 13 my_very_robust_model, iter_mnist_testset( ---> 14 num_datapoints=batch_size, batch_size=batch_size)) ~/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/eval_kit.py in evaluate_tcu_mnist_model(model_fn, dataset_iter, model_name) 123 return evaluate_tcu_model(model_fn, dataset_iter, 124 model_name=model_name, --> 125 attack_list=attack_list) 126 127 ~/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/eval_kit.py in evaluate_tcu_model(model_fn, data_iter, attack_list, model_name) 53 print("Executing attack: %s" % attack.name) 54 ---> 55 logits, labels, x_adv = run_attack(model_fn, dataset, attack) 56 57 preds = (logits[:, 0] < logits[:, 1]).astype(np.int64) ~/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/eval_kit.py in run_attack(model, data_iter, attack_fn) 29 x_np.shape) 30 ---> 31 x_adv = attack_fn(model, x_np, y_np) 32 logits = model(x_adv) 33 ~/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/attacks.py in __call__(***failed resolving arguments***) 62 x_adv_np = self.sess.run(self.x_adv, feed_dict={ 63 self.x_input: np.expand_dims(x_np[i], axis=0), ---> 64 self.y_label: np.expand_dims(y_np[i], axis=0), 65 }) 66 all_x_adv_np.append(x_adv_np) ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata) 898 try: 899 result = self._run(None, fetches, feed_dict, options_ptr, --> 900 run_metadata_ptr) 901 if run_metadata: 902 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr) ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata) 1133 if final_fetches or final_targets or (handle and feed_dict_tensor): 1134 results = self._do_run(handle, final_targets, final_fetches, -> 1135 feed_dict_tensor, options, run_metadata) 1136 else: 1137 results = [] ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata) 1314 if handle is None: 1315 return self._do_call(_run_fn, feeds, fetches, targets, options, -> 1316 run_metadata) 1317 else: 1318 return self._do_call(_prun_fn, handle, feeds, fetches) ~/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args) 1333 except KeyError: 1334 pass -> 1335 raise type(e)(node_def, op, message) 1336 1337 def _extend_graph(self): InvalidArgumentError: 0-th value returned by pyfunc_1 is double, but expects float [[Node: while/PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_1", _device="/job:localhost/replica:0/task:0/device:CPU:0"](while/add_4)]] Caused by op 'while/PyFunc', defined at: File "HOME/anaconda3/bin/ipython", line 11, in <module> sys.exit(start_ipython()) File "HOME/anaconda3/lib/python3.6/site-packages/IPython/__init__.py", line 125, in start_ipython return launch_new_instance(argv=argv, **kwargs) File "HOME/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 658, in launch_instance app.start() File "HOME/anaconda3/lib/python3.6/site-packages/IPython/terminal/ipapp.py", line 356, in start self.shell.mainloop() File "HOME/anaconda3/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 480, in mainloop self.interact() File "HOME/anaconda3/lib/python3.6/site-packages/IPython/terminal/interactiveshell.py", line 471, in interact self.run_cell(code, store_history=True) File "HOME/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2728, in run_cell interactivity=interactivity, compiler=compiler, result=result) File "HOME/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2856, in run_ast_nodes if self.run_code(code, result): File "HOME/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-1-bc52c4bf0bb6>", line 14, in <module> num_datapoints=batch_size, batch_size=batch_size)) File "HOME/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/eval_kit.py", line 114, in evaluate_tcu_mnist_model epsilon=0.3), File "HOME/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/attacks.py", line 50, in __init__ is_debug=is_debug) File "HOME/anaconda3/lib/python3.6/site-packages/cleverhans/attacks.py", line 1604, in generate is_debug=is_debug, File "HOME/anaconda3/lib/python3.6/site-packages/cleverhans/attacks_tf.py", line 1762, in pgd_attack back_prop=False) File "HOME/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 "HOME/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 "HOME/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/anaconda3/lib/python3.6/site-packages/cleverhans/attacks_tf.py", line 1739, in loop_body loss = tf.reduce_mean(wrapped_loss_fn(perturbation), axis=0) File "HOME/anaconda3/lib/python3.6/site-packages/cleverhans/attacks_tf.py", line 1736, in wrapped_loss_fn return loss_fn(input_image + x, label) File "HOME/anaconda3/lib/python3.6/site-packages/cleverhans/attacks.py", line 1594, in loss_fn logits = self.model.get_logits(x) File "HOME/anaconda3/lib/python3.6/site-packages/cleverhans/model.py", line 48, in get_logits return self.get_layer(x, 'logits') File "HOME/anaconda3/lib/python3.6/site-packages/cleverhans/model.py", line 35, in get_layer output = self.fprop(x) File "HOME/tmp/unrestricted-adversarial-examples/unrestricted-advex/unrestricted_advex/attacks.py", line 223, in fprop logits_op = tf.py_func(self.model_fn, [x], tf.float32) File "HOME/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 344, in py_func func=func, inp=inp, Tout=Tout, stateful=stateful, eager=False, name=name) File "HOME/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 241, in _internal_py_func input=inp, token=token, Tout=Tout, name=name) File "HOME/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_script_ops.py", line 128, in py_func "PyFunc", input=input, token=token, Tout=Tout, name=name) File "HOME/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "HOME/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op op_def=op_def) File "HOME/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): 0-th value returned by pyfunc_1 is double, but expects float [[Node: while/PyFunc = PyFunc[Tin=[DT_FLOAT], Tout=[DT_FLOAT], token="pyfunc_1", _device="/job:localhost/replica:0/task:0/device:CPU:0"](while/add_4)]]
Good catch. Updated the example and added an assertion
I'm getting the following error while trying to run a code segment in the README:
error log