46ad98c1b619502c926c657c1a4c4276d2fd1f79,art/defences/adversarial_trainer_unittest.py,TestAdversarialTrainer,test_shared_model_mnist,#TestAdversarialTrainer#,110

Before Change


        // Create and fit classifier
        params = {"epochs": 5, "batch_size": BATCH_SIZE}
        classifier = CNN(im_shape, dataset="mnist")
        classifier.compile({"loss": "categorical_crossentropy", "optimizer": "adam", "metrics": ["accuracy"]})
        classifier.fit(x_train, y_train, **params)

        // Create FGSM attacker
        adv = FastGradientMethod(classifier, session)

After Change



        // Create and fit classifier
        params = {"nb_epochs": 2, "batch_size": BATCH_SIZE}
        classifier = self.classifier_k

        // Create FGSM attacker
        adv = FastGradientMethod(classifier)
        x_adv = adv.generate(x_test)
        preds = classifier.predict(x_adv)
        acc = np.sum(np.argmax(preds, axis=1) == np.argmax(y_test, axis=1)) / y_test.shape[0]

        // Perform adversarial training
        adv_trainer = AdversarialTrainer(classifier, adv)
        adv_trainer.fit(x_train, y_train, **params)

        // Evaluate that accuracy on adversarial sample has improved
        preds_adv_trained = adv_trainer.classifier.predict(x_adv)
        acc_adv_trained = np.sum(np.argmax(preds_adv_trained, axis=1) == np.argmax(y_test, axis=1)) / y_test.shape[0]
        print("\nAccuracy before adversarial training: %.2f%%" % (acc * 100))
        print("\nAccuracy after adversarial training: %.2f%%" % (acc_adv_trained * 100))

    @staticmethod
    def _cnn_mnist_tf(input_shape):
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: IBM/adversarial-robustness-toolbox
Commit Name: 46ad98c1b619502c926c657c1a4c4276d2fd1f79
Time: 2018-05-01
Author: Maria-Irina.Nicolae@ibm.com
File Name: art/defences/adversarial_trainer_unittest.py
Class Name: TestAdversarialTrainer
Method Name: test_shared_model_mnist


Project Name: GPflow/GPflow
Commit Name: dec3dcf7b86168234e38e4f40059abecd3245c44
Time: 2017-10-29
Author: art.art.v@gmail.com
File Name: testing/test_profiling.py
Class Name: TestProfiling
Method Name: test_profile


Project Name: osmr/imgclsmob
Commit Name: 09e4a76102ff4a06a835180237ea171eb475985c
Time: 2018-09-19
Author: osemery@gmail.com
File Name: keras_/models/mobilenet.py
Class Name:
Method Name: _test