Skip to content

Commit

Permalink
Merge pull request #2296 from Trusted-AI/dev_1.16.0
Browse files Browse the repository at this point in the history
Update to ART 1.16.0
  • Loading branch information
beat-buesser authored Sep 22, 2023
2 parents 75b38a1 + ad7520c commit 2d486e5
Show file tree
Hide file tree
Showing 102 changed files with 12,030 additions and 1,458 deletions.
5 changes: 4 additions & 1 deletion .github/actions/yolo/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
exit_code=0

pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_pytorch_yolo.py --framework=pytorch --durations=0
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/speech_recognition/test_pytorch_yolo tests"; fi
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/object_detection/test_pytorch_yolo tests"; fi

pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_object_seeker_yolo.py --framework=pytorch --durations=0
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/object_detection/test_object_seeker_yolo tests"; fi

exit ${exit_code}
65 changes: 65 additions & 0 deletions .github/workflows/ci-huggingface.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI Huggingface
on:
# Run on manual trigger
workflow_dispatch:

# Run on pull requests
pull_request:
paths-ignore:
- '*.md'

# Run on merge queue
merge_group:

# Run when pushing to main or dev branches
push:
branches:
- main
- dev*

# Run scheduled CI flow daily
schedule:
- cron: '0 8 * * 0'

jobs:
test:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- name: Huggingface 4.30
framework: huggingface
python: 3.9
torch: 1.13.1+cpu
torchvision: 0.14.1+cpu
torchaudio: 0.13.1
transformers: 4.30.2

name: ${{ matrix.name }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Dependencies
run: |
sudo apt-get update
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
pip install transformers==${{ matrix.transformers }}
pip list
- name: Run Tests
run: ./run_tests.sh ${{ matrix.framework }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .github/workflows/ci-lingvo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 -q -r <(sed '/^scipy/d;/^matplotlib/d;/^pandas/d;/^statsmodels/d;/^numba/d;/^jax/d;/^h5py/d;/^Pillow/d;/^pytest/d;/^pytest-mock/d;/^torch/d;/^torchaudio/d;/^torchvision/d;/^xgboost/d;/^requests/d;/^tensorflow/d;/^keras/d;/^kornia/d;/^librosa/d;/^tqdm/d' requirements_test.txt)
pip install -q -r <(sed '/^scipy/d;/^matplotlib/d;/^pandas/d;/^statsmodels/d;/^numba/d;/^jax/d;/^h5py/d;/^Pillow/d;/^pytest/d;/^pytest-mock/d;/^torch/d;/^torchaudio/d;/^torchvision/d;/^xgboost/d;/^requests/d;/^tensorflow/d;/^keras/d;/^kornia/d;/^librosa/d;/^tqdm/d;/^timm/d' requirements_test.txt)
pip install scipy==1.5.4
pip install matplotlib==3.3.4
pip install pandas==1.1.5
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci-pytorch-object-detectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_pytorch_faster_rcnn.py --framework=pytorch --durations=0
- name: Run Test Action - test_pytorch_detection_transformer
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_pytorch_detection_transformer.py --framework=pytorch --durations=0
- name: Run Test Action - test_pytorch_object_seeker_faster_rcnn
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_object_seeker_faster_rcnn.py --framework=pytorch --durations=0
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
15 changes: 15 additions & 0 deletions art/attacks/attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def set_params(self, **kwargs) -> None:
for key, value in kwargs.items():
if key in self.attack_params:
setattr(self, key, value)
else:
raise ValueError(f'The attribute "{key}" cannot be set for this attack.')
self._check_params()

def _check_params(self) -> None:
Expand Down Expand Up @@ -186,6 +188,19 @@ def is_estimator_valid(estimator, estimator_requirements) -> bool:
return False
return True

def __repr__(self):
"""
Returns a string describing the attack class and attack_params
"""
param_str = ""
for param in self.attack_params:
if hasattr(self, param):
param_str += f"{param}={getattr(self, param)}, "
elif hasattr(self, "_attack"):
if hasattr(self._attack, param):
param_str += f"{param}={getattr(self._attack, param)}, "
return f"{type(self).__name__}({param_str})"


class EvasionAttack(Attack):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ def _random_overlay(
name=None,
)

pad_h_before = int((self.image_shape[self.i_h] - image_mask.shape[self.i_h_patch + 1]) / 2)
pad_h_before = int((self.image_shape[self.i_h] - image_mask.shape.as_list()[self.i_h_patch + 1]) / 2)
pad_h_after = int(self.image_shape[self.i_h] - pad_h_before - image_mask.shape[self.i_h_patch + 1])

pad_w_before = int((self.image_shape[self.i_w] - image_mask.shape[self.i_w_patch + 1]) / 2)
pad_w_before = int((self.image_shape[self.i_w] - image_mask.shape.as_list()[self.i_w_patch + 1]) / 2)
pad_w_after = int(self.image_shape[self.i_w] - pad_w_before - image_mask.shape[self.i_w_patch + 1])

image_mask = tf.pad( # pylint: disable=E1123
Expand Down Expand Up @@ -323,10 +323,10 @@ def _random_overlay(

if mask is None:
padding_after_scaling_h = (
self.image_shape[self.i_h] - im_scale * padded_patch.shape[self.i_h + 1]
self.image_shape[self.i_h] - im_scale * padded_patch.shape.as_list()[self.i_h + 1]
) / 2.0
padding_after_scaling_w = (
self.image_shape[self.i_w] - im_scale * padded_patch.shape[self.i_w + 1]
self.image_shape[self.i_w] - im_scale * padded_patch.shape.as_list()[self.i_w + 1]
) / 2.0
x_shift = np.random.uniform(-padding_after_scaling_w, padding_after_scaling_w)
y_shift = np.random.uniform(-padding_after_scaling_h, padding_after_scaling_h)
Expand Down
Loading

0 comments on commit 2d486e5

Please sign in to comment.