bdaa0a7126f3b5e72b9df7c4b58413ced4f40a18,tests/attacks/test_fast_gradient.py,TestFastGradientMethodImages,test_targeted_attack_images,#TestFastGradientMethodImages#,165

Before Change


        self.assertFalse((self.x_test_mnist == x_test_adv).all())

    def test_targeted_attack_images(self):
        classifier = utils_test.get_image_classifier()

        attack = FastGradientMethod(classifier, eps=1.0, targeted=True)

        y_test_pred_sort = classifier.predict(self.x_test_mnist).argsort(axis=1)

After Change


            self.assertFalse((self.x_test_mnist == x_test_adv).all())

    def test_targeted_attack_images(self):
        classifier_list = utils_test.get_image_classifiers()

        // TODO this if statement must be removed once we have a classifier for both image and tabular data
        if classifier_list is None:
            logging.warning("Couldn"t perform  this test because no classifier is defined")
            return

        for classifier in classifier_list:
            attack = FastGradientMethod(classifier, eps=1.0, targeted=True)

            y_test_pred_sort = classifier.predict(self.x_test_mnist).argsort(axis=1)
            targets = np.zeros((self.x_test_mnist.shape[0], 10))
            for i in range(self.x_test_mnist.shape[0]):
                targets[i, y_test_pred_sort[i, -2]] = 1.0

            attack_params = {"minimal": True, "eps_step": 0.01, "eps": 1.0}
            attack.set_params(**attack_params)

            x_test_adv = attack.generate(self.x_test_mnist, y=targets)
            self.assertFalse((self.x_test_mnist == x_test_adv).all())

            y_test_pred_adv = get_labels_np_array(classifier.predict(x_test_adv))

            self.assertEqual(targets.shape, y_test_pred_adv.shape)
            self.assertGreaterEqual((targets == y_test_pred_adv).sum(), self.x_test_mnist.shape[0] // 2)

    def test_targeted_attack_tabular(self):
        classifier_list = utils_test.get_tabular_classifiers()

        for classifier in classifier_list:
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 11

Instances


Project Name: IBM/adversarial-robustness-toolbox
Commit Name: bdaa0a7126f3b5e72b9df7c4b58413ced4f40a18
Time: 2020-01-31
Author: killian.levacher@gmail.com
File Name: tests/attacks/test_fast_gradient.py
Class Name: TestFastGradientMethodImages
Method Name: test_targeted_attack_images


Project Name: IBM/adversarial-robustness-toolbox
Commit Name: bdaa0a7126f3b5e72b9df7c4b58413ced4f40a18
Time: 2020-01-31
Author: killian.levacher@gmail.com
File Name: tests/attacks/test_fast_gradient.py
Class Name: TestFastGradientMethodImages
Method Name: test_minimal_perturbations_images


Project Name: IBM/adversarial-robustness-toolbox
Commit Name: bdaa0a7126f3b5e72b9df7c4b58413ced4f40a18
Time: 2020-01-31
Author: killian.levacher@gmail.com
File Name: tests/attacks/test_fast_gradient.py
Class Name: TestFastGradientMethodImages
Method Name: test_no_norm_images