Split FGS generate_np test to 3 tests for distance metrics
@@ -131,11 +131,10 @@ class TestFastGradientMethod(CleverHansTest):
self.model = my_model
self.attack = FastGradientMethod(self.model, sess=self.sess)
- def test_generate_np_gives_adversarial_example(self):
+ def help_test_generate_np_gives_adversarial_example(self, ord):
x_val = np.random.rand(100, 2)
x_val = np.array(x_val, dtype=np.float32)
- for ord in [np.inf, 1, 2]:
x_adv = self.attack.generate_np(x_val, eps=.5, ord=ord,
clip_min=-5, clip_max=5)
if ord == np.inf:
@@ -148,9 +147,17 @@ class TestFastGradientMethod(CleverHansTest):
orig_labs = np.argmax(self.sess.run(self.model(x_val)), axis=1)
new_labs = np.argmax(self.sess.run(self.model(x_adv)), axis=1)
-
self.assertTrue(np.mean(orig_labs == new_labs) < 0.5)
+ def test_generate_np_gives_adversarial_example_linfinity(self):
+ self.help_test_generate_np_gives_adversarial_example(np.infty)
+
+ def test_generate_np_gives_adversarial_example_l1(self):
+ self.help_test_generate_np_gives_adversarial_example(1)
+
+ def test_generate_np_gives_adversarial_example_l2(self):
+ self.help_test_generate_np_gives_adversarial_example(2)
+
def test_generate_np_can_be_called_with_different_eps(self):
x_val = np.random.rand(100, 2)
x_val = np.array(x_val, dtype=np.float32)
