Skip to content
Open
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: 2 additions & 2 deletions src/secmlt/adv/evasion/advlib_attacks/advlib_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _run(
samples: torch.Tensor,
labels: torch.Tensor,
) -> torch.Tensor:
if not isinstance(model, BasePytorchClassifier):
if not isinstance(model, BasePytorchClassifier) and not isinstance(model, EnsembleModel):
msg = "Model type not supported."
raise NotImplementedError(msg)
device = model._get_device()
Expand All @@ -74,7 +74,7 @@ def _run(
model=model,
inputs=samples,
labels=labels,
ε=self.epsilon,
eps=self.epsilon,
targeted=(self.y_target is not None),
loss_function=self.loss_function,
)
Expand Down
12 changes: 6 additions & 6 deletions src/secmlt/adv/evasion/modular_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ def _run(

# keep perturbation with highest loss
best_delta.data = torch.where(
atleast_kd(losses.detach().cpu() < best_losses, len(samples.shape)),
delta.data,
best_delta.data,
atleast_kd(losses.detach().cpu() < best_losses.detach().cpu(), len(samples.shape)),
delta.detach().cpu().data,
best_delta.detach().cpu().data,
)
best_losses.data = torch.where(
losses.detach().cpu() < best_losses,
losses.detach().cpu() < best_losses.detach().cpu(),
losses.detach().cpu(),
best_losses.data,
best_losses.detach().cpu().data,
)
x_adv, _ = self.manipulation_function(samples.data, best_delta.data)
x_adv, _ = self.manipulation_function(samples.detach().cpu().data, best_delta.data)
return x_adv, best_delta
4 changes: 4 additions & 0 deletions src/secmlt/trackers/trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def get(self) -> torch.Tensor:
torch.Tensor
History of tracked parameters.
"""
# Dropout of the last batch element if there is a size mismatch
reference_size = self.tracked[0].size()
if self.tracked[-1].size() != reference_size:
self.tracked.pop()
return torch.stack(self.tracked, -1)

def get_last_tracked(self) -> Union[None, torch.Tensor]:
Expand Down