Skip to content

Commit

Permalink
Merge branch 'master' into api-e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcarter23 committed Dec 4, 2024
2 parents 6a2cfc7 + 6aae231 commit c1b469c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions adversarial_attack/fgsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ def standard_attack(
orig_pred = model(tensor)

if orig_pred.argmax().item() != truth.item():
raise ValueError(
f"Model prediction {orig_pred.argmax().item()} does not match true class {truth.item()}.",
f"It is therefore pointless to perform an attack.",
warnings.warn(
(
f"Model prediction {orig_pred.argmax().item()} does not match true class {truth.item()}."
f"It is therefore pointless to perform an attack."
),
RuntimeWarning,
)
return None

# make a copy of the input tensor
adv_tensor = tensor.clone().detach()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_fgsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_standard_attack_failure(model):
epsilon = 0.1
max_iter = 50

with pytest.raises(ValueError, match="does not match true class"):
standard_attack(model=model, tensor=tensor, truth=truth, epsilon=epsilon, max_iter=max_iter)
with pytest.warns(RuntimeWarning):
assert standard_attack(model=model, tensor=tensor, truth=truth, epsilon=epsilon, max_iter=max_iter) is None


def test_standard_attack_no_change(model):
Expand Down

0 comments on commit c1b469c

Please sign in to comment.