@@ -31,7 +31,7 @@ def forward(self, x):
3131 logit_output = self .fc (x )
3232 output = F .softmax (logit_output , dim = 1 )
3333
34- return ( logit_output , output )
34+ return logit_output , output
3535
3636
3737class TestCarliniL2 (unittest .TestCase ):
@@ -113,7 +113,7 @@ def test_tfclassifier(self):
113113 self ._sess .run (tf .global_variables_initializer ())
114114
115115 # Get MNIST
116- batch_size , nb_train , nb_test = 100 , 1000 , 10
116+ batch_size , nb_train , nb_test = 100 , 500 , 5
117117 (x_train , y_train ), (x_test , y_test ), _ , _ = load_mnist ()
118118 x_train , y_train = x_train [:nb_train ], y_train [:nb_train ]
119119 x_test , y_test = x_test [:nb_test ], y_test [:nb_test ]
@@ -124,7 +124,7 @@ def test_tfclassifier(self):
124124 tfc .fit (x_train , y_train , batch_size = batch_size , nb_epochs = 2 )
125125
126126 # First attack
127- cl2m = CarliniL2Method (classifier = tfc , targeted = True , max_iter = 100 , binary_search_steps = 10 ,
127+ cl2m = CarliniL2Method (classifier = tfc , targeted = True , max_iter = 10 , binary_search_steps = 10 ,
128128 learning_rate = 2e-2 , initial_const = 3 , decay = 1e-2 )
129129 params = {'y' : random_targets (y_test , tfc .nb_classes )}
130130 x_test_adv = cl2m .generate (x_test , ** params )
@@ -137,7 +137,7 @@ def test_tfclassifier(self):
137137 self .assertTrue ((target == y_pred_adv ).all ())
138138
139139 # Second attack
140- cl2m = CarliniL2Method (classifier = tfc , targeted = False , max_iter = 100 , binary_search_steps = 10 ,
140+ cl2m = CarliniL2Method (classifier = tfc , targeted = False , max_iter = 10 , binary_search_steps = 10 ,
141141 learning_rate = 2e-2 , initial_const = 3 , decay = 1e-2 )
142142 params = {'y' : random_targets (y_test , tfc .nb_classes )}
143143 x_test_adv = cl2m .generate (x_test , ** params )
@@ -149,7 +149,7 @@ def test_tfclassifier(self):
149149 self .assertTrue ((target != y_pred_adv ).all ())
150150
151151 # Third attack
152- cl2m = CarliniL2Method (classifier = tfc , targeted = False , max_iter = 100 , binary_search_steps = 10 ,
152+ cl2m = CarliniL2Method (classifier = tfc , targeted = False , max_iter = 10 , binary_search_steps = 10 ,
153153 learning_rate = 2e-2 , initial_const = 3 , decay = 1e-2 )
154154 params = {}
155155 x_test_adv = cl2m .generate (x_test , ** params )
@@ -170,7 +170,7 @@ def test_krclassifier(self):
170170 k .set_session (session )
171171
172172 # Get MNIST
173- batch_size , nb_train , nb_test = 100 , 1000 , 10
173+ batch_size , nb_train , nb_test = 100 , 500 , 5
174174 (x_train , y_train ), (x_test , y_test ), _ , _ = load_mnist ()
175175 x_train , y_train = x_train [:nb_train ], y_train [:nb_train ]
176176 x_test , y_test = x_test [:nb_test ], y_test [:nb_test ]
@@ -190,7 +190,7 @@ def test_krclassifier(self):
190190 krc .fit (x_train , y_train , batch_size = batch_size , nb_epochs = 2 )
191191
192192 # First attack
193- cl2m = CarliniL2Method (classifier = krc , targeted = True , max_iter = 100 , binary_search_steps = 10 ,
193+ cl2m = CarliniL2Method (classifier = krc , targeted = True , max_iter = 10 , binary_search_steps = 10 ,
194194 learning_rate = 2e-2 , initial_const = 3 , decay = 1e-2 )
195195 params = {'y' : random_targets (y_test , krc .nb_classes )}
196196 x_test_adv = cl2m .generate (x_test , ** params )
@@ -202,7 +202,7 @@ def test_krclassifier(self):
202202 self .assertTrue ((target == y_pred_adv ).any ())
203203
204204 # Second attack
205- cl2m = CarliniL2Method (classifier = krc , targeted = False , max_iter = 100 , binary_search_steps = 10 ,
205+ cl2m = CarliniL2Method (classifier = krc , targeted = False , max_iter = 10 , binary_search_steps = 10 ,
206206 learning_rate = 2e-2 , initial_const = 3 , decay = 1e-2 )
207207 params = {'y' : random_targets (y_test , krc .nb_classes )}
208208 x_test_adv = cl2m .generate (x_test , ** params )
@@ -214,7 +214,7 @@ def test_krclassifier(self):
214214 self .assertTrue ((target != y_pred_adv ).all ())
215215
216216 # Third attack
217- cl2m = CarliniL2Method (classifier = krc , targeted = False , max_iter = 100 , binary_search_steps = 10 ,
217+ cl2m = CarliniL2Method (classifier = krc , targeted = False , max_iter = 10 , binary_search_steps = 10 ,
218218 learning_rate = 2e-2 , initial_const = 3 , decay = 1e-2 )
219219 params = {}
220220 x_test_adv = cl2m .generate (x_test , ** params )
@@ -289,7 +289,3 @@ def test_ptclassifier(self):
289289
290290if __name__ == '__main__' :
291291 unittest .main ()
292-
293-
294-
295-
0 commit comments