Skip to content

Commit c9dab59

Browse files
authored
Merge pull request #968 from Trusted-AI/development_maintenance_160
General format updates for dev_1.6.0
2 parents ab26b12 + fc7b8a4 commit c9dab59

File tree

64 files changed

+582
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+582
-608
lines changed

art/attacks/evasion/adversarial_asr.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class CarliniWagnerASR(ImperceptibleASR):
4747
"learning_rate",
4848
"max_iter",
4949
"batch_size",
50+
"decrease_factor_eps",
51+
"num_iter_decrease_eps",
5052
]
5153

5254
def __init__(
@@ -55,6 +57,8 @@ def __init__(
5557
eps: float = 2000.0,
5658
learning_rate: float = 100.0,
5759
max_iter: int = 1000,
60+
decrease_factor_eps: float = 0.8,
61+
num_iter_decrease_eps: int = 10,
5862
batch_size: int = 16,
5963
):
6064
"""
@@ -64,6 +68,8 @@ def __init__(
6468
:param eps: Initial max norm bound for adversarial perturbation.
6569
:param learning_rate: Learning rate of attack.
6670
:param max_iter: Number of iterations.
71+
:param decrease_factor_eps: Decrease factor for epsilon (Paper default: 0.8).
72+
:param num_iter_decrease_eps: Iterations after which to decrease epsilon if attack succeeds (Paper default: 10).
6773
:param batch_size: Batch size.
6874
"""
6975
# pylint: disable=W0231
@@ -76,14 +82,14 @@ def __init__(
7682
self.max_iter_1 = max_iter
7783
self.max_iter_2 = 0
7884
self._targeted = True
85+
self.decrease_factor_eps = decrease_factor_eps
86+
self.num_iter_decrease_eps = num_iter_decrease_eps
7987
self.batch_size = batch_size
8088

8189
# set remaining stage 2 params to some random values
8290
self.alpha = 0.1
8391
self.learning_rate_2 = 0.1
8492
self.loss_theta_min = 0.0
85-
self.decrease_factor_eps: float = 1.0
86-
self.num_iter_decrease_eps: int = 1
8793
self.increase_factor_alpha: float = 1.0
8894
self.num_iter_increase_alpha: int = 1
8995
self.decrease_factor_alpha: float = 1.0

art/attacks/evasion/adversarial_patch/adversarial_patch_pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(
8686
:param scale_min: The minimum scaling applied to random patches. The value should be in the range `[0, 1]`,
8787
but less than `scale_max`.
8888
:param scale_max: The maximum scaling applied to random patches. The value should be in the range `[0, 1]`, but
89-
larger than `scale_min.`
89+
larger than `scale_min`.
9090
:param distortion_scale_max: The maximum distortion scale for perspective transformation in range `[0, 1]`. If
9191
distortion_scale_max=0.0 the perspective transformation sampling will be disabled.
9292
:param learning_rate: The learning rate of the optimization.

art/attacks/evasion/adversarial_patch/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1616
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1717
# SOFTWARE.
18+
"""
19+
This module implements utility functions for adversarial patch attacks.
20+
"""
1821
import numpy as np
1922

2023

@@ -56,14 +59,14 @@ def insert_transformed_patch(x: np.ndarray, patch: np.ndarray, image_coords: np.
5659
)
5760

5861
# calculate homography
59-
h, status = cv2.findHomography(patch_coords, image_coords)
62+
height, _ = cv2.findHomography(patch_coords, image_coords)
6063

6164
# warp patch to destination coordinates
62-
x_out = cv2.warpPerspective(patch, h, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC)
65+
x_out = cv2.warpPerspective(patch, height, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC)
6366

6467
# mask to aid with insertion
6568
mask = np.ones(patch.shape)
66-
mask_out = cv2.warpPerspective(mask, h, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC)
69+
mask_out = cv2.warpPerspective(mask, height, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC)
6770

6871
# save image before adding shadows
6972
x_neg_patch = np.copy(x)

art/attacks/evasion/auto_projected_gradient_descent.py

Lines changed: 118 additions & 119 deletions
Large diffs are not rendered by default.

art/attacks/evasion/dpatch_robust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def _check_params(self) -> None:
384384
raise ValueError("The first element of the brightness range must be less or equal to the second one.")
385385

386386
if not isinstance(self.rotation_weights, (tuple, list)) or not all(
387-
isinstance(s, float) or isinstance(s, int) for s in self.rotation_weights
387+
isinstance(s, (float, int)) for s in self.rotation_weights
388388
):
389389
raise ValueError("The rotation sampling weights must be provided as tuple or list of float or int values.")
390390
if len(self.rotation_weights) != 4:

art/attacks/evasion/frame_saliency.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def generate(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> n
112112
if self.method == "one_shot":
113113
if y is None:
114114
return self.attacker.generate(x)
115-
else:
116-
return self.attacker.generate(x, y)
115+
116+
return self.attacker.generate(x, y)
117117

118118
if y is None:
119119
# Throw error if attack is targeted, but no targets are provided

0 commit comments

Comments
 (0)