Skip to content

Commit f45b268

Browse files
committed
Update workflows for TensorFlow/Keras 2.14
Signed-off-by: Beat Buesser <[email protected]>
1 parent 68bc1cc commit f45b268

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

tests/attacks/test_adversarial_patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def test_4_pytorch(self):
301301

302302
self.assertAlmostEqual(patch_adv[0, 8, 8], 0.5, delta=0.05)
303303
self.assertAlmostEqual(patch_adv[0, 14, 14], 0.5, delta=0.05)
304-
self.assertAlmostEqual(float(np.sum(patch_adv)), 371.88014772999827, delta=4.0)
304+
self.assertAlmostEqual(float(np.sum(patch_adv)), 367.6218066346819, delta=4.0)
305305

306306
mask = np.ones((1, 28, 28)).astype(bool)
307307
attack_ap.apply_patch(x=x_train, scale=0.1, mask=mask)

tests/classifiersFrameworks/test_tensorflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_binary_keras_instantiation_and_attack_pgd(art_warning):
239239
]
240240
)
241241
model.summary()
242-
model.compile(optimizer=tf.optimizers.Adam(), loss="binary_crossentropy", metrics=["accuracy"])
242+
model.compile(optimizer=tf.optimizers.legacy.Adam(), loss="binary_crossentropy", metrics=["accuracy"])
243243
classifier = KerasClassifier(model=model)
244244
classifier.fit(train_x, train_y, nb_epochs=5)
245245
pred = classifier.predict(test_x)
@@ -268,7 +268,7 @@ def test_binary_keras_instantiation_and_attack_pgd(art_warning):
268268
# ]
269269
# )
270270
# model.summary()
271-
# model.compile(optimizer=tf.optimizers.Adam(), loss="binary_crossentropy", metrics=["accuracy"])
271+
# model.compile(optimizer=tf.optimizers.legacy.Adam(), loss="binary_crossentropy", metrics=["accuracy"])
272272
# classifier = art.estimators.classification.TensorFlowV2Classifier(model=model)
273273
# classifier.fit(train_x, train_y, nb_epochs=5)
274274
# pred = classifier.predict(test_x)

tests/defences/trainer/test_adversarial_trainer_awp_pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_adversarial_trainer_awppgd_pytorch_fit_and_predict(get_adv_trainer_awpp
124124
else:
125125
accuracy = np.sum(predictions == y_test_mnist) / x_test_mnist.shape[0]
126126

127-
trainer.fit(x_train_mnist, y_train_mnist, nb_epochs=20)
127+
trainer.fit(x_train_mnist, y_train_mnist, nb_epochs=40)
128128
predictions_new = np.argmax(trainer.predict(x_test_mnist), axis=1)
129129

130130
if label_format == "one_hot":

tests/estimators/certification/test_macer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _get_classifier():
5757
import tensorflow as tf
5858

5959
classifier, _ = get_image_classifier_tf()
60-
optimizer = tf.keras.optimizers.SGD(learning_rate=0.01, momentum=0.9, name="SGD", decay=5e-4)
60+
optimizer = tf.keras.optimizers.legacy.SGD(learning_rate=0.01, momentum=0.9, name="SGD", decay=5e-4)
6161
scheduler = tf.keras.optimizers.schedules.PiecewiseConstantDecay([250, 400], [0.01, 0.001, 0.0001])
6262
rs = TensorFlowV2MACER(
6363
model=classifier.model,

tests/estimators/certification/test_smooth_adv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _get_classifier():
5757
import tensorflow as tf
5858

5959
classifier, _ = get_image_classifier_tf()
60-
optimizer = tf.keras.optimizers.SGD(learning_rate=0.01, momentum=0.9, name="SGD", decay=1e-4)
60+
optimizer = tf.keras.optimizers.legacy.SGD(learning_rate=0.01, momentum=0.9, name="SGD", decay=1e-4)
6161
scheduler = tf.keras.optimizers.schedules.PiecewiseConstantDecay([50, 100], [0.01, 0.001, 0.0001])
6262
rs = TensorFlowV2SmoothAdv(
6363
model=classifier.model,

tests/estimators/classification/test_scikitlearn.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ def test_class_gradient_none_2(self):
300300

301301
def test_class_gradient_int_1(self):
302302
grad_predicted = self.classifier.class_gradient(self.x_test_iris[0:1], label=1)
303-
grad_expected = [[[-0.56322294, -0.70427608, -0.98874801, -0.67053026]]]
303+
grad_expected = [[[-0.56322294, -0.70493763, -0.98874801, -0.67053026]]]
304304

305305
for i_shape in range(4):
306+
print(grad_predicted[0, 0, i_shape])
306307
self.assertAlmostEqual(grad_predicted[0, 0, i_shape], grad_expected[0][0][i_shape], 3)
307308

308309
def test_class_gradient_int_2(self):
@@ -311,13 +312,16 @@ def test_class_gradient_int_2(self):
311312
[[-0.56322294, -0.70427608, -0.98874801, -0.67053026]],
312313
[[-0.50528532, -0.71700042, -0.82467848, -0.59614766]],
313314
]
315+
print("grad_predicted")
316+
print(grad_predicted)
314317
np.testing.assert_array_almost_equal(grad_predicted, grad_expected, decimal=4)
315318

316319
def test_class_gradient_list_1(self):
317320
grad_predicted = self.classifier.class_gradient(self.x_test_iris[0:1], label=[1])
318321
grad_expected = [[[-0.56322294, -0.70427608, -0.98874801, -0.67053026]]]
319322

320323
for i_shape in range(4):
324+
print(grad_predicted[0, 0, i_shape])
321325
self.assertAlmostEqual(grad_predicted[0, 0, i_shape], grad_expected[0][0][i_shape], 3)
322326

323327
def test_class_gradient_list_2(self):
@@ -326,6 +330,8 @@ def test_class_gradient_list_2(self):
326330
[[-0.56322294, -0.70427608, -0.98874801, -0.67053026]],
327331
[[0.70875132, 0.25104877, 1.70929277, 0.88410652]],
328332
]
333+
print("grad_predicted")
334+
print(grad_predicted)
329335
np.testing.assert_array_almost_equal(grad_predicted, grad_expected, decimal=4)
330336

331337
def test_class_gradient_label_wrong_type(self):
@@ -340,6 +346,8 @@ def test_class_gradient_label_wrong_type(self):
340346
def test_loss_gradient(self):
341347
grad_predicted = self.classifier.loss_gradient(self.x_test_iris[0:1], self.y_test_iris[0:1])
342348
grad_expected = np.asarray([[-0.21693791, -0.08792436, -0.51507443, -0.26990796]])
349+
print("grad_predicted")
350+
print(grad_predicted)
343351
np.testing.assert_array_almost_equal(grad_predicted, grad_expected, decimal=4)
344352

345353
def test_save(self):

0 commit comments

Comments
 (0)