self._optimizer = optimizer
// Store the logit layer
self._logit_layer = len(list(model.modules())) - 2 if use_logits else len(list(model.modules())) - 3
// Use GPU if possible
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
After Change
super(PyTorchClassifier, self).__init__(clip_values, defences)
//self._nb_classes = list(model.modules())[-1 if use_logits else -2].out_features
self._nb_classes = output_shape[0]
self._input_shape = input_shape
self._model = model
self._loss = loss
self._optimizer = optimizer