Skip to content

Commit 093b8fd

Browse files
authored
Merge branch 'dev_1.19.0' into development_patch_mask
2 parents 8827ce9 + cf11263 commit 093b8fd

File tree

27 files changed

+3892
-27
lines changed

27 files changed

+3892
-27
lines changed

.github/workflows/ci-tensorflow-v1.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
sudo apt-get update
4949
sudo apt-get -y -q install ffmpeg libavcodec-extra
5050
python -m pip install --upgrade pip setuptools wheel
51-
pip install -q -r <(sed '/^pandas/d;/^scipy/d;/^matplotlib/d;/^xgboost/d;/^tensorflow/d;/^keras/d;/^jax/d;/^torch/d;/^Pillow/d;/^h5py/d;/^kornia/d;/^scikit-learn/d;/^pytest-mock/d;/^GPy/d;/^lief/d;/^statsmodels/d;/^ultralytics/d;/^ipython/d;/^numba/d;/^pytest/d;/^pylint/d;/^mypy/d;/^pycodestyle/d;/^black/d;/^types-PyYAML/d;/^types-setuptools/d' requirements_test.txt)
51+
pip install -q -r <(sed '/^pandas/d;/^scipy/d;/^matplotlib/d;/^xgboost/d;/^tensorflow/d;/^keras/d;/^jax/d;/^torch/d;/^Pillow/d;/^h5py/d;/^kornia/d;/^scikit-learn/d;/^pytest-mock/d;/^GPy/d;/^lief/d;/^statsmodels/d;/^ultralytics/d;/^ipython/d;/^numba/d;/^pytest/d;/^pylint/d;/^mypy/d;/^pycodestyle/d;/^black/d;/^types-PyYAML/d;/^types-setuptools/d;/^requests/d' requirements_test.txt)
5252
pip install pandas==1.3.5
5353
pip install scipy==1.7.2
5454
pip install matplotlib==3.5.3
@@ -71,6 +71,7 @@ jobs:
7171
pip install numba==0.56.4
7272
pip install pytest==7.4.4
7373
pip install pytest-cov
74+
pip install requests==2.31.0
7475
pip list
7576
- name: Run Tests
7677
run: ./run_tests.sh ${{ matrix.framework }}

.github/workflows/dockerhub.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030

3131
- name: Extract metadata (tags, labels) for Docker
3232
id: meta
33-
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
33+
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
3434
with:
3535
images: adversarialrobustnesstoolbox/releases
3636
tags: |
3737
type=raw,value={{branch}}-1.18.2-{{sha}}
3838
type=semver,pattern={{version}}
3939
4040
- name: Build and push Docker image
41-
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
41+
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
4242
with:
4343
context: .
4444
push: true

art/attacks/evasion/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from art.attacks.evasion.auto_attack import AutoAttack
1515
from art.attacks.evasion.auto_projected_gradient_descent import AutoProjectedGradientDescent
1616
from art.attacks.evasion.auto_conjugate_gradient import AutoConjugateGradient
17+
from art.attacks.evasion.rescaling_auto_conjugate_gradient import RescalingAutoConjugateGradient
1718

1819
if importlib.util.find_spec("numba") is not None:
1920
from art.attacks.evasion.brendel_bethge import BrendelBethgeAttack
@@ -62,6 +63,7 @@
6263
from art.attacks.evasion.shapeshifter import ShapeShifter
6364
from art.attacks.evasion.simba import SimBA
6465
from art.attacks.evasion.spatial_transformation import SpatialTransformation
66+
from art.attacks.evasion.steal_now_attack_later.steal_now_attack_later import SNAL
6567
from art.attacks.evasion.square_attack import SquareAttack
6668
from art.attacks.evasion.pixel_threshold import ThresholdAttack
6769
from art.attacks.evasion.universal_perturbation import UniversalPerturbation

art/attacks/evasion/auto_attack.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878
batch_size: int = 32,
7979
estimator_orig: "CLASSIFIER_TYPE" | None = None,
8080
targeted: bool = False,
81-
parallel: bool = False,
81+
parallel_pool_size: int = 0,
8282
):
8383
"""
8484
Create a :class:`.AutoAttack` instance.
@@ -93,7 +93,8 @@ def __init__(
9393
:param estimator_orig: Original estimator to be attacked by adversarial examples.
9494
:param targeted: If False run only untargeted attacks, if True also run targeted attacks against each possible
9595
target.
96-
:param parallel: If True run attacks in parallel.
96+
:param parallel_pool_size: Number of parallel threads / pool size in multiprocessing. If parallel_pool_size=0
97+
computation runs without multiprocessing.
9798
"""
9899
super().__init__(estimator=estimator)
99100

@@ -151,7 +152,7 @@ def __init__(
151152
self.estimator_orig = estimator
152153

153154
self._targeted = targeted
154-
self.parallel = parallel
155+
self.parallel_pool_size = parallel_pool_size
155156
self.best_attacks: np.ndarray = np.array([])
156157
self._check_params()
157158

@@ -199,7 +200,7 @@ def generate(self, x: np.ndarray, y: np.ndarray | None = None, **kwargs) -> np.n
199200
if attack.targeted:
200201
attack.set_params(targeted=False)
201202

202-
if self.parallel:
203+
if self.parallel_pool_size > 0:
203204
args.append(
204205
(
205206
deepcopy(x_adv),
@@ -253,7 +254,7 @@ def generate(self, x: np.ndarray, y: np.ndarray | None = None, **kwargs) -> np.n
253254
targeted_labels[:, i], nb_classes=self.estimator.nb_classes
254255
)
255256

256-
if self.parallel:
257+
if self.parallel_pool_size > 0:
257258
args.append(
258259
(
259260
deepcopy(x_adv),
@@ -287,8 +288,8 @@ def generate(self, x: np.ndarray, y: np.ndarray | None = None, **kwargs) -> np.n
287288
except ValueError as error:
288289
logger.warning("Error completing attack: %s}", str(error))
289290

290-
if self.parallel:
291-
with multiprocess.get_context("spawn").Pool() as pool:
291+
if self.parallel_pool_size > 0:
292+
with multiprocess.get_context("spawn").Pool(processes=self.parallel_pool_size) as pool:
292293
# Results come back in the order that they were issued
293294
results = pool.starmap(run_attack, args)
294295
perturbations = []
@@ -320,15 +321,16 @@ def __repr__(self) -> str:
320321
This method returns a summary of the best performing (lowest perturbation in the parallel case) attacks
321322
per image passed to the AutoAttack class.
322323
"""
323-
if self.parallel:
324+
if self.parallel_pool_size > 0:
324325
best_attack_meta = "\n".join(
325326
[
326327
f"image {i+1}: {str(self.args[idx][3])}" if idx != 0 else f"image {i+1}: n/a"
327328
for i, idx in enumerate(self.best_attacks)
328329
]
329330
)
330331
auto_attack_meta = (
331-
f"AutoAttack(targeted={self.targeted}, parallel={self.parallel}, num_attacks={len(self.args)})"
332+
f"AutoAttack(targeted={self.targeted}, parallel_pool_size={self.parallel_pool_size}, "
333+
+ "num_attacks={len(self.args)})"
332334
)
333335
return f"{auto_attack_meta}\nBestAttacks:\n{best_attack_meta}"
334336

@@ -339,7 +341,8 @@ def __repr__(self) -> str:
339341
]
340342
)
341343
auto_attack_meta = (
342-
f"AutoAttack(targeted={self.targeted}, parallel={self.parallel}, num_attacks={len(self.attacks)})"
344+
f"AutoAttack(targeted={self.targeted}, parallel_pool_size={self.parallel_pool_size}, "
345+
+ "num_attacks={len(self.attacks)})"
343346
)
344347
return f"{auto_attack_meta}\nBestAttacks:\n{best_attack_meta}"
345348

0 commit comments

Comments
 (0)