Skip to content

Commit 2b24bdb

Browse files
Irina NicolaeIrina Nicolae
authored andcommitted
Change defenses to defences for consistency
1 parent 857c871 commit 2b24bdb

File tree

8 files changed

+16
-17
lines changed

8 files changed

+16
-17
lines changed

art/attacks/carlini.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class CarliniL2Method(Attack):
1313
"""
1414
The L_2 optimized attack of Carlini and Wagner (2016). This attack is the most efficient and should be used as the
15-
primary attack to evaluate potential defenses (wrt the L_0 and L_inf attacks). This implementation is inspired by
15+
primary attack to evaluate potential defences (wrt the L_0 and L_inf attacks). This implementation is inspired by
1616
the one in Cleverhans, which reproduces the authors' original code (https://github.com/carlini/nn_robust_attacks).
1717
Paper link: https://arxiv.org/pdf/1608.04644.pdf
1818
"""
@@ -160,7 +160,7 @@ def generate(self, x, **kwargs):
160160

161161
# No labels provided, use model prediction as correct class
162162
if y is None:
163-
y = np.argmax(self.classifier.predict(inputs=x, logits=False), axis=1)
163+
y = np.argmax(self.classifier.predict(x, logits=False), axis=1)
164164
y = to_categorical(y, self.classifier.nb_classes)
165165

166166
# Images to be attacked:

art/attacks/carlini_unittest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_tfclassifier(self):
4646
self._sess.run(tf.global_variables_initializer())
4747

4848
# Get MNIST
49-
batch_size, nb_train, nb_test = 100, 1000, 10
49+
batch_size, nb_train, nb_test = 100, 500, 5
5050
(x_train, y_train), (x_test, y_test), _, _ = load_mnist()
5151
x_train, y_train = x_train[:nb_train], y_train[:nb_train]
5252
x_test, y_test = x_test[:nb_test], y_test[:nb_test]
@@ -57,7 +57,7 @@ def test_tfclassifier(self):
5757
tfc.fit(x_train, y_train, batch_size=batch_size, nb_epochs=2)
5858

5959
# First attack
60-
cl2m = CarliniL2Method(classifier=tfc, targeted=True, max_iter=100, binary_search_steps=10,
60+
cl2m = CarliniL2Method(classifier=tfc, targeted=True, max_iter=10, binary_search_steps=10,
6161
learning_rate=2e-2, initial_const=3, decay=1e-2)
6262
params = {'y': random_targets(y_test, tfc.nb_classes)}
6363
x_test_adv = cl2m.generate(x_test, **params)
@@ -67,7 +67,7 @@ def test_tfclassifier(self):
6767
self.assertTrue((target == y_pred_adv).all())
6868

6969
# Second attack
70-
cl2m = CarliniL2Method(classifier=tfc, targeted=False, max_iter=100, binary_search_steps=10,
70+
cl2m = CarliniL2Method(classifier=tfc, targeted=False, max_iter=10, binary_search_steps=10,
7171
learning_rate=2e-2, initial_const=3, decay=1e-2)
7272
params = {'y': random_targets(y_test, tfc.nb_classes)}
7373
x_test_adv = cl2m.generate(x_test, **params)
@@ -77,7 +77,7 @@ def test_tfclassifier(self):
7777
self.assertTrue((target != y_pred_adv).all())
7878

7979
# Third attack
80-
cl2m = CarliniL2Method(classifier=tfc, targeted=False, max_iter=100, binary_search_steps=10,
80+
cl2m = CarliniL2Method(classifier=tfc, targeted=False, max_iter=10, binary_search_steps=10,
8181
learning_rate=2e-2, initial_const=3, decay=1e-2)
8282
params = {}
8383
x_test_adv = cl2m.generate(x_test, **params)
@@ -96,7 +96,7 @@ def test_krclassifier(self):
9696
k.set_session(session)
9797

9898
# Get MNIST
99-
batch_size, nb_train, nb_test = 100, 1000, 10
99+
batch_size, nb_train, nb_test = 100, 500, 5
100100
(x_train, y_train), (x_test, y_test), _, _ = load_mnist()
101101
x_train, y_train = x_train[:nb_train], y_train[:nb_train]
102102
x_test, y_test = x_test[:nb_test], y_test[:nb_test]
@@ -116,7 +116,7 @@ def test_krclassifier(self):
116116
krc.fit(x_train, y_train, batch_size=batch_size, nb_epochs=2)
117117

118118
# First attack
119-
cl2m = CarliniL2Method(classifier=krc, targeted=True, max_iter=100, binary_search_steps=10,
119+
cl2m = CarliniL2Method(classifier=krc, targeted=True, max_iter=10, binary_search_steps=10,
120120
learning_rate=2e-2, initial_const=3, decay=1e-2)
121121
params = {'y': random_targets(y_test, krc.nb_classes)}
122122
x_test_adv = cl2m.generate(x_test, **params)
@@ -126,7 +126,7 @@ def test_krclassifier(self):
126126
self.assertTrue((target == y_pred_adv).any())
127127

128128
# Second attack
129-
cl2m = CarliniL2Method(classifier=krc, targeted=False, max_iter=100, binary_search_steps=10,
129+
cl2m = CarliniL2Method(classifier=krc, targeted=False, max_iter=10, binary_search_steps=10,
130130
learning_rate=2e-2, initial_const=3, decay=1e-2)
131131
params = {'y': random_targets(y_test, krc.nb_classes)}
132132
x_test_adv = cl2m.generate(x_test, **params)
@@ -136,7 +136,7 @@ def test_krclassifier(self):
136136
self.assertTrue((target != y_pred_adv).all())
137137

138138
# Third attack
139-
cl2m = CarliniL2Method(classifier=krc, targeted=False, max_iter=100, binary_search_steps=10,
139+
cl2m = CarliniL2Method(classifier=krc, targeted=False, max_iter=10, binary_search_steps=10,
140140
learning_rate=2e-2, initial_const=3, decay=1e-2)
141141
params = {}
142142
x_test_adv = cl2m.generate(x_test, **params)

art/defences/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Module implementing multiple types of defenses against adversarial attacks.
2+
Module implementing multiple types of defences against adversarial attacks.
33
"""
44
from art.defences.adversarial_trainer import AdversarialTrainer
55
from art.defences.feature_squeezing import FeatureSqueezing

art/defences/feature_squeezing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def fit(self, x, y=None, **kwargs):
4545
pass
4646

4747
def set_params(self, **kwargs):
48-
"""Take in a dictionary of parameters and applies defense-specific checks before saving them as attributes.
48+
"""Take in a dictionary of parameters and applies defence-specific checks before saving them as attributes.
4949
5050
Defense-specific parameters:
5151
:param bit_depth: The number of bits to encode data on

art/defences/gaussian_augmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def fit(self, x, y=None, **kwargs):
7272

7373
def set_params(self, **kwargs):
7474
"""
75-
Take in a dictionary of parameters and applies defense-specific checks before saving them as attributes.
75+
Take in a dictionary of parameters and applies defence-specific checks before saving them as attributes.
7676
7777
:param sigma: Standard deviation of Gaussian noise to be added.
7878
:type sigma: `float`

art/defences/label_smoothing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def fit(self, x, y=None, **kwargs):
5050
pass
5151

5252
def set_params(self, **kwargs):
53-
"""Take in a dictionary of parameters and applies defense-specific checks before saving them as attributes.
53+
"""Take in a dictionary of parameters and applies defence-specific checks before saving them as attributes.
5454
5555
Defense-specific parameters:
5656
:param max_value: Value to affect to correct label

art/defences/preprocessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class Preprocessor(ABC):
1414
"""
15-
Abstract base class for defenses performing model hardening by preprocessing data.
15+
Abstract base class for defences performing model hardening by preprocessing data.
1616
"""
1717
params = []
1818

art/defences/spatial_smoothing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def fit(self, x, y=None, **kwargs):
4949

5050
def set_params(self, **kwargs):
5151
"""
52-
Take in a dictionary of parameters and applies defense-specific checks
53-
before saving them as attributes.
52+
Take in a dictionary of parameters and applies defence-specific checks before saving them as attributes.
5453
5554
:param window_size: The size of the sliding window.
5655
:type window_size: `int`

0 commit comments

Comments
 (0)