Skip to content

Commit 1e6a660

Browse files
committed
Resolve review comments
1 parent 1388987 commit 1e6a660

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/defences/local_spatial_smoothing.py renamed to src/defences/spatial_smoothing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import absolute_import, division, print_function, unicode_literals
22

3-
import numpy as np
43
from scipy import ndimage
54

65
from src.defences.preprocessor import Preprocessor
76

87

9-
class LocalSpatialSmoothing(Preprocessor):
8+
class SpatialSmoothing(Preprocessor):
109
"""
1110
Implement the local spatial smoothing defence approach.
1211
Defence method from https://arxiv.org/abs/1704.01155.
@@ -50,7 +49,7 @@ def set_params(self, **kwargs):
5049
:param window_size: (int) The size of the sliding window.
5150
"""
5251
# Save attack-specific parameters
53-
super(LocalSpatialSmoothing, self).set_params(**kwargs)
52+
super(SpatialSmoothing, self).set_params(**kwargs)
5453

5554
if type(self.window_size) is not int or self.window_size <= 0:
5655
raise ValueError("Sliding window size must be a positive integer")

src/defences/local_spatial_smoothing_unittest.py renamed to src/defences/spatial_smoothing_unittest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66

7-
from src.defences.local_spatial_smoothing import LocalSpatialSmoothing
7+
from src.defences.spatial_smoothing import SpatialSmoothing
88

99

1010
class TestLocalSpatialSmoothing(unittest.TestCase):
@@ -15,29 +15,30 @@ def test_ones(self):
1515
# Start to test
1616
for window_size in range(1, 20):
1717
with self.subTest("Sliding window size = {}".format(window_size)):
18-
preprocess = LocalSpatialSmoothing()
18+
preprocess = SpatialSmoothing()
1919
smoothed_x = preprocess(x, window_size)
2020
self.assertTrue((smoothed_x == 1).all())
2121

2222
def test_fix(self):
23-
x = np.array([[[[1],[2],[3]],[[7],[8],[9]],[[4],[5],[6]]]])
23+
x = np.array([[[[1], [2], [3]], [[7], [8], [9]], [[4], [5], [6]]]])
2424

2525
# Start to test
26-
preprocess = LocalSpatialSmoothing()
26+
preprocess = SpatialSmoothing()
2727
smoothed_x = preprocess(x, 3)
2828
self.assertTrue((smoothed_x==np.array(
29-
[[[[2],[3],[3]],[[4],[5],[6]],[[5],[6],[6]]]])).all())
29+
[[[[2], [3], [3]], [[4], [5], [6]], [[5], [6], [6]]]])).all())
3030

3131
smoothed_x = preprocess(x, 1)
3232
self.assertTrue((smoothed_x==x).all())
3333

3434
smoothed_x = preprocess(x, 2)
3535
self.assertTrue((smoothed_x==np.array(
36-
[[[[1],[2],[3]],[[7],[7],[8]],[[7],[7],[8]]]])).all())
36+
[[[[1], [2], [3]], [[7], [7], [8]], [[7], [7], [8]]]])).all())
3737

3838

3939
if __name__ == '__main__':
4040
unittest.main()
4141

4242

4343

44+

0 commit comments

Comments
 (0)