|
18 | 18 | from __future__ import absolute_import, division, print_function, unicode_literals |
19 | 19 |
|
20 | 20 | import logging |
21 | | -# import unittest |
| 21 | + |
| 22 | +import unittest |
| 23 | + |
22 | 24 | # import numpy as np |
23 | | -# import pandas as pd |
24 | | -# |
| 25 | +import pandas as pd |
| 26 | + |
25 | 27 | # from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent import ProjectedGradientDescent |
26 | 28 | # from art.estimators.classification.keras import KerasClassifier |
27 | 29 | # from art.estimators.estimator import BaseEstimator, LossGradientsMixin |
28 | | -# from art.utils import load_dataset, get_labels_np_array |
29 | | -# |
30 | | -# from tests.utils import get_image_classifier_tf, get_image_classifier_pt |
| 30 | +from art.utils import load_dataset # , get_labels_np_array |
| 31 | + |
| 32 | +# from tests.utils import get_image_classifier_tf, get_image_classifier_pt, get_tabular_classifier_pt |
31 | 33 | # from tests.utils import get_tabular_classifier_tf, get_tabular_classifier_kr |
32 | | -# from tests.utils import get_tabular_classifier_pt, master_seed |
| 34 | +from tests.utils import master_seed |
| 35 | + |
33 | 36 | # from tests.attacks.utils import backend_test_classifier_type_check_fail |
34 | 37 |
|
35 | 38 | logger = logging.getLogger(__name__) |
|
39 | 42 | NB_TEST = 11 |
40 | 43 |
|
41 | 44 |
|
42 | | -# class TestInputFilter(unittest.TestCase): |
43 | | -# """ |
44 | | -# A unittest class for testing the input filtering using |
45 | | -# PGD tests. |
46 | | -# """ |
47 | | -# |
48 | | -# @classmethod |
49 | | -# def setUpClass(cls): |
50 | | -# # MNIST |
51 | | -# (x_train, y_train), (x_test, y_test), _, _ = load_dataset("mnist") |
52 | | -# x_train = list(x_train[:NB_TRAIN]) |
53 | | -# y_train = list(y_train[:NB_TRAIN]) |
54 | | -# x_test = list(x_test[:NB_TEST]) |
55 | | -# y_test = list(y_test[:NB_TEST]) |
56 | | -# cls.mnist = (x_train, y_train), (x_test, y_test) |
57 | | -# |
58 | | -# # Iris |
59 | | -# (x_train, y_train), (x_test, y_test), _, _ = load_dataset("iris") |
60 | | -# x_train = pd.DataFrame(x_train) |
61 | | -# y_train = pd.DataFrame(y_train) |
62 | | -# x_test = pd.DataFrame(x_test) |
63 | | -# y_test = pd.DataFrame(y_test) |
64 | | -# cls.iris = (x_train, y_train), (x_test, y_test) |
65 | | -# |
66 | | -# def setUp(self): |
67 | | -# master_seed(1234) |
68 | | -# |
69 | | -# def test_2_tensorflow_mnist(self): |
| 45 | +class TestInputFilter(unittest.TestCase): |
| 46 | + """ |
| 47 | + A unittest class for testing the input filtering using |
| 48 | + PGD tests. |
| 49 | + """ |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def setUpClass(cls): |
| 53 | + # MNIST |
| 54 | + (x_train, y_train), (x_test, y_test), _, _ = load_dataset("mnist") |
| 55 | + x_train = list(x_train[:NB_TRAIN]) |
| 56 | + y_train = list(y_train[:NB_TRAIN]) |
| 57 | + x_test = list(x_test[:NB_TEST]) |
| 58 | + y_test = list(y_test[:NB_TEST]) |
| 59 | + cls.mnist = (x_train, y_train), (x_test, y_test) |
| 60 | + |
| 61 | + # Iris |
| 62 | + (x_train, y_train), (x_test, y_test), _, _ = load_dataset("iris") |
| 63 | + x_train = pd.DataFrame(x_train) |
| 64 | + y_train = pd.DataFrame(y_train) |
| 65 | + x_test = pd.DataFrame(x_test) |
| 66 | + y_test = pd.DataFrame(y_test) |
| 67 | + cls.iris = (x_train, y_train), (x_test, y_test) |
| 68 | + |
| 69 | + def setUp(self): |
| 70 | + master_seed(1234) |
| 71 | + |
| 72 | + def test_2_tensorflow_mnist(self): |
| 73 | + pass |
| 74 | + |
| 75 | + |
70 | 76 | # (x_train, y_train), (x_test, y_test) = self.mnist |
71 | 77 | # classifier, sess = get_image_classifier_tf() |
72 | 78 | # |
|
140 | 146 | # logger.info("Accuracy on adversarial test examples with 3 random initialisations: %.2f%%", acc * 100) |
141 | 147 | # |
142 | 148 | # # Check that x_test has not been modified by attack and classifier |
143 | | -# self.assertAlmostEqual(float(np.max(np.abs(np.array(x_test_original) - np.array(x_test)))), 0.0, delta=0.00001) |
| 149 | +# self.assertAlmostEqual(float(np.max(np.abs(np.array(x_test_original) - np.array(x_test)))), 0.0, |
| 150 | +# delta=0.00001) |
144 | 151 | # |
145 | 152 | # def test_1_classifier_type_check_fail(self): |
146 | 153 | # backend_test_classifier_type_check_fail(ProjectedGradientDescent, [BaseEstimator, LossGradientsMixin]) |
|
0 commit comments