def test_emp_robustness_mnist(self): (x_train, y_train), (_, _), _, _ = load_mnist() x_train, y_train = x_train[:NB_TRAIN], y_train[:NB_TRAIN] # Get classifier classifier = self._cnn_mnist_k([28, 28, 1]) classifier.fit(x_train, y_train, batch_size=BATCH_SIZE, nb_epochs=2, verbose=0) # Compute minimal perturbations params = {"eps_step": 1.1} emp_robust = empirical_robustness(classifier, x_train, str("fgsm"), params) self.assertEqual(emp_robust, 0.0) params = {"eps_step": 1.0, "eps": 1.0} emp_robust = empirical_robustness(classifier, x_train, str("fgsm"), params) self.assertAlmostEqual(emp_robust, 1.000369094488189, 4) params = {"eps_step": 0.1, "eps": 0.2} emp_robust = empirical_robustness(classifier, x_train, str("fgsm"), params) self.assertLessEqual(emp_robust, 0.65)
def test_emp_robustness_mnist(self): (x_train, y_train), (_, _), _, _ = load_mnist() x_train, y_train = x_train[:NB_TRAIN], y_train[:NB_TRAIN] # Get classifier classifier = self._cnn_mnist_k([28, 28, 1]) classifier.fit(x_train, y_train, batch_size=BATCH_SIZE, nb_epochs=2) # Compute minimal perturbations params = {"eps_step": 1.1} emp_robust = empirical_robustness(classifier, x_train, str('fgsm'), params) self.assertEqual(emp_robust, 0.) params = {"eps_step": 1., "eps": 1.} emp_robust = empirical_robustness(classifier, x_train, str('fgsm'), params) self.assertAlmostEqual(emp_robust, 0.5006149157681419, 3) params = {"eps_step": 0.1, "eps": 0.2} emp_robust = empirical_robustness(classifier, x_train, str('fgsm'), params) self.assertLessEqual(emp_robust, 0.65)