Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ActivationDefense and SpectralSignatures expected flattened bug #2327

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion art/defences/detector/poison/activation_defence.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ def _get_activations(self, x_train: Optional[np.ndarray] = None) -> np.ndarray:

# wrong way to get activations activations = self.classifier.predict(self.x_train)
if isinstance(activations, np.ndarray):
nodes_last_layer = np.shape(activations)[1]
# flatten activations across batch
activations = np.reshape(activations, (activations.shape[0], -1))
nodes_last_layer = activations.shape[1]
else:
raise ValueError("activations is None or tensor.")

Expand Down
2 changes: 2 additions & 0 deletions art/defences/detector/poison/spectral_signature_defense.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def detect_poison(self, **kwargs) -> Tuple[dict, List[int]]:
raise ValueError("Wrong type detected.")

if features_x_poisoned is not None:
# flatten activations across batch
features_x_poisoned = np.reshape(features_x_poisoned, (features_x_poisoned.shape[0], -1))
features_split = segment_by_class(features_x_poisoned, self.y_train, self.classifier.nb_classes)
else:
raise ValueError("Activation are `None`.")
Expand Down