Trusted-AI / adversarial-robustness-toolbox

Adversarial Robustness Toolbox (ART) - Python Library for Machine Learning Security - Evasion, Poisoning, Extraction, Inference - Red and Blue Teams
https://adversarial-robustness-toolbox.readthedocs.io/en/latest/
MIT License
4.84k stars 1.16k forks source link

detection_adversarial_samples_cifar10.ipynb is not working correctly on nbviewer. The reason is tf version. #770

Open YacratesWyh opened 3 years ago

YacratesWyh commented 3 years ago

It's easy to reproduce this error through the tutorial of nbviewer, and the problem is the tf version on the server is lower than expected 2.2.0(I found the same error on my server and solved by updating tf).

Just a piece of advice to add a comment on the notebook to remind the following user how to solve this.

UnknownError Traceback (most recent call last)

in ----> 1 x_test_pred = np.argmax(classifier.predict(x_test[:100]), axis=1) 2 nb_correct_pred = np.sum(x_test_pred == np.argmax(y_test[:100], axis=1)) 3 4 print("Original test data (first 100 images):") 5 print("Correctly classified: {}".format(nb_correct_pred)) ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/art/estimators/classification/classifier.py in replacement_function(self, *args, **kwargs) 62 if len(args) > 0: 63 args = tuple(lst) ---> 64 return fdict[func_name](self, *args, **kwargs) 65 66 replacement_function.__doc__ = fdict[func_name].__doc__ ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/art/estimators/classification/keras.py in predict(self, x, batch_size, **kwargs) 391 for batch_index in range(int(np.ceil(x_preprocessed.shape[0] / float(batch_size)))): 392 begin, end = batch_index * batch_size, min((batch_index + 1) * batch_size, x_preprocessed.shape[0]) --> 393 predictions[begin:end] = self._model.predict([x_preprocessed[begin:end]]) 394 395 # Apply postprocessing ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing) 1460 verbose=verbose, 1461 steps=steps, -> 1462 callbacks=callbacks) 1463 1464 def train_on_batch(self, x, y, ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/keras/engine/training_arrays.py in predict_loop(model, f, ins, batch_size, verbose, steps, callbacks) 322 batch_logs = {'batch': batch_index, 'size': len(batch_ids)} 323 callbacks._call_batch_hook('predict', 'begin', batch_index, batch_logs) --> 324 batch_outs = f(ins_batch) 325 batch_outs = to_list(batch_outs) 326 if batch_index == 0: ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/tensorflow/python/keras/backend.py in __call__(self, inputs) 3790 value = math_ops.cast(value, tensor.dtype) 3791 converted_inputs.append(value) -> 3792 outputs = self._graph_fn(*converted_inputs) 3793 3794 # EagerTensor.numpy() will often make a copy to ensure memory safety. ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/tensorflow/python/eager/function.py in __call__(self, *args, **kwargs) 1603 TypeError: For invalid positional/keyword argument combinations. 1604 """ -> 1605 return self._call_impl(args, kwargs) 1606 1607 def _call_impl(self, args, kwargs, cancellation_manager=None): ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _call_impl(self, args, kwargs, cancellation_manager) 1643 raise TypeError("Keyword arguments {} unknown. Expected {}.".format( 1644 list(kwargs.keys()), list(self._arg_keywords))) -> 1645 return self._call_flat(args, self.captured_inputs, cancellation_manager) 1646 1647 def _filtered_call(self, args, kwargs): ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _call_flat(self, args, captured_inputs, cancellation_manager) 1744 # No tape is watching; skip to running the function. 1745 return self._build_call_outputs(self._inference_function.call( -> 1746 ctx, args, cancellation_manager=cancellation_manager)) 1747 forward_backward = self._select_forward_and_backward_functions( 1748 args, ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/tensorflow/python/eager/function.py in call(self, ctx, args, cancellation_manager) 596 inputs=args, 597 attrs=attrs, --> 598 ctx=ctx) 599 else: 600 outputs = execute.execute_with_cancellation( ~/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name) 58 ctx.ensure_initialized() 59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, ---> 60 inputs, attrs, num_outputs) 61 except core._NotOkStatusException as e: 62 if name is not None: UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [[node conv2d_1/convolution (defined at /home/beat/codes/anaconda3/envs/py37_tf220/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_32692] Function call stack: keras_scratch_graph
YacratesWyh commented 3 years ago

The requirement of this package upgraded somewhile before? I guess. And this nb notebook isn't following.

beat-buesser commented 3 years ago

Hi @YacratesWyh Thank you very much for using ART and raising this issue! I think your proposal makes sense. We also have plans to better define the dependencies of all our notebooks in the near future.