1919import pytest
2020
2121import numpy as np
22+ import tensorflow as tf
2223
2324from art .attacks .evasion import ShadowAttack
2425from art .estimators .estimator import BaseEstimator , LossGradientsMixin
@@ -34,18 +35,15 @@ def fix_get_mnist_subset(get_mnist_dataset):
3435 (x_train_mnist , y_train_mnist ), (x_test_mnist , y_test_mnist ) = get_mnist_dataset
3536 n_train = 100
3637 n_test = 11
37- yield ( x_train_mnist [:n_train ], y_train_mnist [:n_train ], x_test_mnist [:n_test ], y_test_mnist [:n_test ])
38+ yield x_train_mnist [:n_train ], y_train_mnist [:n_train ], x_test_mnist [:n_test ], y_test_mnist [:n_test ]
3839
3940
40- @pytest .mark .only_with_platform ("pytorch" )
41+ @pytest .mark .skipif (tf .__version__ [0 ] == "1" , reason = "Skip for TensorFlow 1.x" )
42+ @pytest .mark .skipMlFramework ("keras" , "scikitlearn" )
4143def test_generate (fix_get_mnist_subset , get_image_classifier_list_for_attack ):
4244
4345 classifier_list = get_image_classifier_list_for_attack (ShadowAttack )
4446
45- if classifier_list is None :
46- logging .warning ("Couldn't perform this test because no classifier is defined" )
47- return
48-
4947 for classifier in classifier_list :
5048 attack = ShadowAttack (
5149 estimator = classifier ,
@@ -61,15 +59,13 @@ def test_generate(fix_get_mnist_subset, get_image_classifier_list_for_attack):
6159
6260 (x_train_mnist , y_train_mnist , x_test_mnist , y_test_mnist ) = fix_get_mnist_subset
6361
64- if attack .framework == "pytorch" :
65- x_train_mnist = x_train_mnist .transpose ((0 , 3 , 1 , 2 ))
66-
6762 x_train_mnist_adv = attack .generate (x = x_train_mnist [0 :1 ], y = y_train_mnist [0 :1 ])
6863
69- assert np .max (np .abs (x_train_mnist_adv - x_train_mnist [0 :1 ])) == pytest .approx (0.34966960549354553 , 0.06 )
64+ assert np .max (np .abs (x_train_mnist_adv - x_train_mnist [0 :1 ])) == pytest .approx (0.34966960549354553 , abs = 0.06 )
7065
7166
72- @pytest .mark .only_with_platform ("pytorch" )
67+ @pytest .mark .skipif (tf .__version__ [0 ] == "1" , reason = "Skip for TensorFlow 1.x" )
68+ @pytest .mark .skipMlFramework ("keras" , "scikitlearn" )
7369def test_get_regularisation_loss_gradients (fix_get_mnist_subset , get_image_classifier_list_for_attack ):
7470
7571 classifier_list = get_image_classifier_list_for_attack (ShadowAttack )
@@ -90,9 +86,6 @@ def test_get_regularisation_loss_gradients(fix_get_mnist_subset, get_image_class
9086
9187 (x_train_mnist , _ , _ , _ ) = fix_get_mnist_subset
9288
93- if attack .framework == "pytorch" :
94- x_train_mnist = x_train_mnist .transpose ((0 , 3 , 1 , 2 ))
95-
9689 gradients = attack ._get_regularisation_loss_gradients (x_train_mnist [0 :1 ])
9790
9891 gradients_expected = np .array (
0 commit comments