Skip to content

Commit

Permalink
(#7) Attack: Add accuracy monitors to Progbar
Browse files Browse the repository at this point in the history
  • Loading branch information
betarixm committed May 1, 2022
1 parent 8a61c4b commit 0505104
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/typings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def attack(
) -> Tuple[tf.metrics.Accuracy, tf.metrics.Accuracy, Optional[tf.metrics.Accuracy]]:
_, test = self.dataset.dataset()

progress = keras.utils.Progbar(test.cardinality().numpy())
metrics = ["acc_normal", "acc_under_attack", "acc_with_defense"]
progress = keras.utils.Progbar(
test.cardinality().numpy(), stateful_metrics=metrics
)

for x, y in test:
x_attack = self.add_perturbation(x)
Expand All @@ -196,7 +199,17 @@ def attack(
self.accuracy_with_defense(
y, self.victim_model.predict(self.defense_model.predict(x_attack))
)
progress.add(1)
progress.add(
1,
values=zip(
metrics,
[
self.accuracy_normal.result(),
self.accuracy_under_attack.result(),
self.accuracy_with_defense.result(),
],
),
)

return (
self.accuracy_normal,
Expand Down

0 comments on commit 0505104

Please sign in to comment.