Skip to content

Commit 38976aa

Browse files
author
Beat Buesser
committed
Update test
Signed-off-by: Beat Buesser <[email protected]>
1 parent 0845d57 commit 38976aa

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

art/attacks/evasion/adversarial_patch/adversarial_patch_tensorflow.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ def _probabilities(self, images: "tf.Tensor") -> "tf.Tensor":
177177
patched_input, clip_value_min=self.estimator.clip_values[0], clip_value_max=self.estimator.clip_values[1],
178178
)
179179

180-
# from matplotlib import pyplot as plt
181-
# plt.matshow(patched_input[0, :, :, 0])
182-
# plt.show()
183-
184180
probabilities = self.estimator._predict_framework(patched_input)
185181

186182
return probabilities
@@ -350,7 +346,7 @@ def generate(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> T
350346

351347
for _ in trange(self.max_iter, desc="Adversarial Patch TensorFlow v2"):
352348
for images, target in ds:
353-
loss = self._train_step(images=images, target=target)
349+
_ = self._train_step(images=images, target=target)
354350

355351
return (
356352
self._patch.numpy(),

tests/attacks/test_adversarial_patch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ def test_tensorflow_v2_framework(self):
100100
scale_max=0.41,
101101
learning_rate=5.0,
102102
batch_size=10,
103-
max_iter=5,
103+
max_iter=10,
104104
patch_shape=(28, 28, 1),
105105
)
106106

107107
target = np.zeros(self.x_train_mnist.shape[0])
108108
patch_adv, _ = attack_ap.generate(self.x_train_mnist, target, shuffle=False)
109109

110-
self.assertAlmostEqual(patch_adv[8, 8, 0], 0.123679265, delta=0.05)
111-
self.assertAlmostEqual(patch_adv[14, 14, 0], 0.0, delta=0.05)
112-
self.assertAlmostEqual(float(np.sum(patch_adv)), 411.5689392089844, delta=1.0)
110+
self.assertAlmostEqual(patch_adv[8, 8, 0], 0.21282613, delta=0.05)
111+
self.assertAlmostEqual(patch_adv[14, 14, 0], 0.5411238, delta=0.05)
112+
self.assertAlmostEqual(float(np.sum(patch_adv)), 378.3399658203125, delta=1.0)
113113

114114
@unittest.skipIf(
115115
int(keras.__version__.split(".")[0]) == 2 and int(keras.__version__.split(".")[1]) < 3,

0 commit comments

Comments
 (0)