adversarial-robustness-toolbox icon indicating copy to clipboard operation
adversarial-robustness-toolbox copied to clipboard

Error in cell 5 in notebooks/detection_adversarial_samples_cifar10.ipynb

Open ckadner opened this issue 3 years ago • 2 comments

Describe the bug

There is an error in cell 5 in notebooks/detection_adversarial_samples_cifar10.ipynb

https://github.com/Trusted-AI/adversarial-robustness-toolbox/blame/main/notebooks/detection_adversarial_samples_cifar10.ipynb#L405-L407

In [5]:

x_test_pred = np.argmax(classifier.predict(x_test[:100]), axis=1)
nb_correct_pred = np.sum(x_test_pred == np.argmax(y_test[:100], axis=1))

print("Original test data (first 100 images):")
print("Correctly classified: {}".format(nb_correct_pred))
print("Incorrectly classified: {}".format(100-nb_correct_pred))

Out [5]:

---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
<ipython-input-5-91f9a98aaa5a> in <module>
----> 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

Related issues

https://github.com/machine-learning-exchange/katalog/issues/24

ckadner avatar Sep 04 '21 23:09 ckadner

@drewbuttlerbb4

ckadner avatar Sep 04 '21 23:09 ckadner

Hi @ckadner Thank you very much for opening this issue. The notebook itself does not contain a bug, but it looks like it has been run with TensorFlow v2 the last time instead of TensorFlow v1. Could you please run it again and open a pull request?

beat-buesser avatar Sep 06 '21 11:09 beat-buesser