Skip to content

Commit

Permalink
Merge branch 'dev_1.17.0' into hf_model_wrapper_update
Browse files Browse the repository at this point in the history
  • Loading branch information
beat-buesser authored Nov 30, 2023
2 parents 49acd32 + ab389e7 commit e896821
Show file tree
Hide file tree
Showing 81 changed files with 332 additions and 250 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-huggingface.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip3 install -r requirements_test.txt
pip install tensorflow==2.10.1
pip install keras==2.10.0
pip install tensorflow==2.14.0
pip install keras==2.14.0
pip install torch==${{ matrix.torch }} -f https://download.pytorch.org/whl/cpu/torch_stable.html
pip install torchvision==${{ matrix.torchvision }} -f https://download.pytorch.org/whl/cpu/torch_stable.html
pip install torchaudio==${{ matrix.torchaudio }} -f https://download.pytorch.org/whl/cpu/torch_stable.html
Expand Down
38 changes: 16 additions & 22 deletions .github/workflows/ci-keras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,24 @@ jobs:
fail-fast: false
matrix:
include:
- name: Keras 2.9.0 (TensorFlow 2.9.2 Python 3.9)
- name: Keras 2.13.1 (TensorFlow 2.13.1 Python 3.10)
framework: keras
python: 3.9
tensorflow: 2.9.2
keras: 2.9.0
tf_addons: 0.17.0
- name: TensorFlow-Keras 2.9.2 (Keras 2.9.0 Python 3.9)
framework: kerastf
python: 3.9
tensorflow: 2.9.2
keras: 2.9.0
tf_addons: 0.17.0
- name: Keras 2.10.0 (TensorFlow 2.10.1 Python 3.9)
python: '3.10'
tensorflow: 2.13.1
keras: 2.13.1
tf_addons: 0.19.0
- name: Keras 2.14.0 (TensorFlow 2.14.0 Python 3.10)
framework: keras
python: 3.9
tensorflow: 2.10.1
keras: 2.10.0
tf_addons: 0.18.0
- name: TensorFlow-Keras 2.10.1 (Keras 2.10.0 Python 3.9)
python: '3.10'
tensorflow: 2.14.0
keras: 2.14.0
tf_addons: 0.20.0
- name: TensorFlow-Keras 2.14.0 (Keras 2.14.0 Python 3.10)
framework: kerastf
python: 3.9
tensorflow: 2.10.1
keras: 2.10.0
tf_addons: 0.18.0
python: '3.10'
tensorflow: 2.14.0
keras: 2.14.0
tf_addons: 0.20.0

name: ${{ matrix.name }}
steps:
Expand All @@ -66,7 +60,7 @@ jobs:
sudo apt-get update
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements_test.txt
pip install -q -r <(sed '/^tensorflow/d;/^keras/d;/^tensorflow-addons/d' requirements_test.txt)
pip install tensorflow==${{ matrix.tensorflow }}
pip install keras==${{ matrix.keras }}
pip install tensorflow-addons==${{ matrix.tf_addons }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ jobs:
matrix:
module: [attacks_1, attacks_2, estimators, defences, metrics, art]
include:
- name: legacy (TensorFlow 2.10.1 Keras 2.10.0 PyTorch 1.13.1 scikit-learn 1.1.3 Python 3.9)
- name: legacy (TensorFlow 2.14.0 Keras 2.14.0 PyTorch 1.13.1 scikit-learn 1.1.3 Python 3.9)
framework: legacy
python: 3.9
tensorflow: 2.10.1
keras: 2.10.0
python: '3.10'
tensorflow: 2.14.0
keras: 2.14.0
torch: 1.13.1+cpu
torchvision: 0.14.1+cpu
torchaudio: 0.13.1+cpu
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-lingvo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
pip install tqdm==4.64.1
pip list
- name: Run ${{ matrix.name }} Tests
run: ./run_tests.sh ${{ matrix.framework }}
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/speech_recognition/test_tensorflow_lingvo.py --framework=${{ matrix.framework }} --durations=0
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ci-mxnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: mxnet (Python 3.8)
- name: mxnet (Python 3.9)
framework: mxnet
python: 3.8
python: 3.9

name: Run ${{ matrix.name }} Tests
steps:
Expand All @@ -45,8 +45,6 @@ jobs:
sudo apt-get update
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip install tensorflow==2.4.1
pip install keras==2.4.3
pip3 install -q -r requirements_test.txt
pip list
- name: Run ${{ matrix.name }} ${{ matrix.module }} Tests
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/ci-pytorch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: PyTorch 1.11.0 (Python 3.9)
framework: pytorch
python: 3.8
torch: 1.11.0+cpu
torchvision: 0.12.0+cpu
torchaudio: 0.11.0
- name: PyTorch 1.12.1 (Python 3.9)
framework: pytorch
python: 3.8
python: 3.9
torch: 1.12.1+cpu
torchvision: 0.13.1+cpu
torchaudio: 0.12.1
Expand Down Expand Up @@ -67,8 +61,6 @@ jobs:
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip3 install -r requirements_test.txt
pip install tensorflow==2.10.1
pip install keras==2.10.0
pip install torch==${{ matrix.torch }} -f https://download.pytorch.org/whl/cpu/torch_stable.html
pip install torchvision==${{ matrix.torchvision }} -f https://download.pytorch.org/whl/cpu/torch_stable.html
pip install torchaudio==${{ matrix.torchaudio }} -f https://download.pytorch.org/whl/cpu/torch_stable.html
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-scikit-learn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ jobs:
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements_test.txt
pip install tensorflow==2.10.1
pip install keras==2.10.0
pip install scikit-learn==${{ matrix.scikit-learn }}
pip list
- name: Run Tests
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-style-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -q pylint==2.12.2 mypy==0.931 pycodestyle==2.8.0 black==21.12b0
pip install -q -r requirements_test.txt
pip install -q -r <(sed '/^numpy/d;/^pluggy/d;/^tensorflow/d;/^keras/d' requirements_test.txt)
pip install numpy==1.22.4
pip install pluggy==0.13.1
pip install tensorflow==2.7.0
pip install keras==2.7.0
pip install tensorflow==2.13.1
pip install keras==2.13.1
pip install types-six
pip install types-PyYAML
pip install types-setuptools
pip install click==8.0.2
pip install numpy==1.21.6
pip list
- name: pycodestyle
run: pycodestyle --ignore=C0330,C0415,E203,E231,W503 --max-line-length=120 art
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci-tensorflow-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ jobs:
sudo apt-get update
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip install -q -r <(sed '/^pandas/d;/^scipy/d;/^matplotlib/d;/^xgboost/d;/^jax/d' requirements_test.txt)
pip install -q -r <(sed '/^pandas/d;/^scipy/d;/^matplotlib/d;/^xgboost/d;/^tensorflow/d;/^keras/d;/^jax/d' requirements_test.txt)
pip install pandas==1.3.5
pip install scipy==1.7.2
pip install matplotlib==3.5.3
pip install xgboost==1.6.2
pip install protobuf==3.20.1
pip install tensorflow==${{ matrix.tensorflow }}
pip install keras==${{ matrix.keras }}
pip install jax[cpu]==0.3.25
pip install numpy==1.20
pip list
- name: Run Tests
run: ./run_tests.sh ${{ matrix.framework }}
Expand Down
37 changes: 15 additions & 22 deletions .github/workflows/ci-tensorflow-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,27 @@ jobs:
fail-fast: false
matrix:
include:
- name: TensorFlow 2.9.2 (Keras 2.9.0 Python 3.9)
- name: TensorFlow 2.13.1 (Keras 2.13.1 Python 3.10)
framework: tensorflow
python: 3.9
tensorflow: 2.9.2
python: '3.10'
tensorflow: 2.13.1
tf_version: v2
keras: 2.9.0
tf_addons: 0.17.1
- name: TensorFlow 2.10.1v1 (Keras 2.10.0 Python 3.9)
keras: 2.13.1
tf_addons: 0.21.0
- name: TensorFlow 2.14.0v1 (Keras 2.14.0 Python 3.10)
framework: tensorflow2v1
python: 3.9
tensorflow: 2.10.1
tf_version: v2
keras: 2.10.0
tf_addons: 0.18.0
- name: TensorFlow 2.10.1 (Keras 2.10.0 Python 3.9)
framework: tensorflow
python: 3.9
tensorflow: 2.10.1
python: '3.10'
tensorflow: 2.14.0
tf_version: v2
keras: 2.10.0
tf_addons: 0.18.0
- name: TensorFlow 2.10.1 (Keras 2.10.0 Python 3.10)
keras: 2.14.0
tf_addons: 0.21.0
- name: TensorFlow 2.14.0 (Keras 2.14.0 Python 3.10)
framework: tensorflow
python: '3.10'
tensorflow: 2.10.1
tensorflow: 2.14.0
tf_version: v2
keras: 2.10.0
tf_addons: 0.18.0
keras: 2.14.0
tf_addons: 0.21.0

name: ${{ matrix.name }}
steps:
Expand All @@ -70,7 +63,7 @@ jobs:
sudo apt-get update
sudo apt-get -y -q install ffmpeg libavcodec-extra
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements_test.txt
pip install -q -r <(sed '/^tensorflow/d;/^keras/d;/^tensorflow-addons/d' requirements_test.txt)
pip install tensorflow==${{ matrix.tensorflow }}
pip install keras==${{ matrix.keras }}
pip install tensorflow-addons==${{ matrix.tf_addons }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: .
push: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import logging
import math
from typing import Optional, Tuple, Union, TYPE_CHECKING
from typing import Any, Optional, Tuple, Union, TYPE_CHECKING

import numpy as np
from tqdm.auto import trange
Expand Down Expand Up @@ -270,15 +270,15 @@ def _get_circular_patch_mask(self, nb_samples: int, sharpness: int = 40) -> "tor
y = np.linspace(-1, 1, diameter)
x_grid, y_grid = np.meshgrid(x, y, sparse=True)
z_grid = (x_grid ** 2 + y_grid ** 2) ** sharpness
image_mask = 1 - np.clip(z_grid, -1, 1)
image_mask: Union[int, np.ndarray[Any, np.dtype[Any]]] = 1 - np.clip(z_grid, -1, 1)
elif self.patch_type == "square":
image_mask = np.ones((diameter, diameter))

image_mask = np.expand_dims(image_mask, axis=0)
image_mask = np.broadcast_to(image_mask, self.patch_shape)
image_mask = torch.Tensor(np.array(image_mask)).to(self.estimator.device)
image_mask = torch.stack([image_mask] * nb_samples, dim=0)
return image_mask
image_mask_tensor = torch.Tensor(np.array(image_mask)).to(self.estimator.device)
image_mask_tensor = torch.stack([image_mask_tensor] * nb_samples, dim=0)
return image_mask_tensor

def _random_overlay(
self,
Expand Down
10 changes: 5 additions & 5 deletions art/attacks/evasion/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
from typing import Optional, Tuple, TYPE_CHECKING
from typing import List, Optional, Tuple, TYPE_CHECKING

import numpy as np
from tqdm.auto import tqdm, trange
Expand Down Expand Up @@ -268,14 +268,14 @@ def _attack(
for _ in trange(self.max_iter, desc="Boundary attack - iterations", disable=not self.verbose):
# Trust region method to adjust delta
for _ in range(self.num_trial):
potential_advs = []
potential_advs_list: List[np.ndarray] = []
for _ in range(self.sample_size):
potential_adv = x_adv + self._orthogonal_perturb(self.curr_delta, x_adv, original_sample)
potential_adv = np.clip(potential_adv, clip_min, clip_max)
potential_advs.append(potential_adv)
potential_advs_list.append(potential_adv)

preds = np.argmax(
self.estimator.predict(np.array(potential_advs), batch_size=self.batch_size),
self.estimator.predict(np.array(potential_advs_list), batch_size=self.batch_size),
axis=1,
)

Expand All @@ -292,7 +292,7 @@ def _attack(
self.curr_delta /= self.step_adapt

if delta_ratio > 0:
x_advs = np.array(potential_advs)[np.where(satisfied)[0]]
x_advs = np.array(potential_advs_list)[np.where(satisfied)[0]]
break
else: # pragma: no cover
logger.warning("Adversarial example found but not optimal.")
Expand Down
8 changes: 4 additions & 4 deletions art/attacks/evasion/brendel_bethge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ def generate(
return best_advs.astype(config.ART_NUMPY_DTYPE)

def norms(self, x: np.ndarray) -> np.ndarray:
order = self.norm if self.norm != "inf" else np.inf
order = float(self.norm) if self.norm != "inf" else np.inf
norm = np.linalg.norm(x=x.reshape(x.shape[0], -1), ord=order, axis=1)
return norm

Expand Down Expand Up @@ -2542,15 +2542,15 @@ def _binary_search(
"""
# First set upper and lower bounds as well as the threshold for the binary search
if norm == 2:
(upper_bound, lower_bound) = (1, 0)
(upper_bound, lower_bound) = (np.array(1.0), np.array(0.0))

if threshold is None:
threshold = self.theta

else:
(upper_bound, lower_bound) = (
np.max(abs(original_sample - current_sample)),
0,
np.array(0.0),
)

if threshold is None:
Expand Down Expand Up @@ -2580,7 +2580,7 @@ def _binary_search(
result = self._interpolate(
current_sample=current_sample,
original_sample=original_sample,
alpha=upper_bound,
alpha=float(upper_bound),
norm=norm,
)

Expand Down
2 changes: 1 addition & 1 deletion art/attacks/evasion/carlini.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(
self._tanh_smoother = 0.999999

def _loss(
self, x: np.ndarray, x_adv: np.ndarray, target: np.ndarray, c_weight: float
self, x: np.ndarray, x_adv: np.ndarray, target: np.ndarray, c_weight: np.ndarray
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Compute the objective function value.
Expand Down
4 changes: 2 additions & 2 deletions art/attacks/evasion/dpatch_robust.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ def _untransform_gradients(
gradients = transforms["brightness"] * gradients

# Undo rotations:
rot90 = (4 - transforms["rot90"]) % 4
gradients = np.rot90(gradients, rot90, (1, 2))
rot90 = int((4 - transforms["rot90"]) % 4)
gradients = np.rot90(gradients, k=rot90, axes=(1, 2))

# Account for cropping when considering the upper left point of the patch:
x_1 = self.patch_location[0] - int(transforms["crop_x"])
Expand Down
Loading

0 comments on commit e896821

Please sign in to comment.