Skip to content

Commit ae0194c

Browse files
authored
Merge pull request #1321 from Trusted-AI/dev_1.8.0
Update to ART 1.8.0
2 parents 20fb7ef + caa9c2a commit ae0194c

File tree

86 files changed

+6347
-1567
lines changed

Some content is hidden

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

86 files changed

+6347
-1567
lines changed

.github/actions/goturn/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Get base from a pytorch image
2+
FROM pytorch/pytorch:1.6.0-cuda10.1-cudnn7-runtime
3+
4+
# Set to install things in non-interactive mode
5+
ENV DEBIAN_FRONTEND noninteractive
6+
7+
# Install system wide softwares
8+
RUN apt-get update \
9+
&& apt-get install -y \
10+
libgl1-mesa-glx \
11+
libx11-xcb1 \
12+
git \
13+
gcc \
14+
mono-mcs \
15+
libavcodec-extra \
16+
ffmpeg \
17+
curl \
18+
libsndfile-dev \
19+
libsndfile1 \
20+
&& apt-get install -y libsm6 libxext6 \
21+
&& apt-get install -y libxrender-dev \
22+
&& apt-get clean all \
23+
&& rm -r /var/lib/apt/lists/*
24+
25+
RUN /opt/conda/bin/conda install --yes \
26+
astropy \
27+
matplotlib \
28+
pandas \
29+
scikit-learn \
30+
scikit-image
31+
32+
# Install necessary libraries for goturn
33+
RUN pip install torch==1.4
34+
RUN pip install tensorflow==2.1.4
35+
RUN pip install torchaudio==0.5.0
36+
RUN pip install pytest
37+
RUN pip install numba
38+
RUN pip install scikit-learn==0.20
39+
RUN pip install pytest-cov
40+
RUN pip install gdown
41+
42+
RUN git clone https://github.com/nrupatunga/goturn-pytorch.git /tmp/goturn-pytorch
43+
RUN cd /tmp/goturn-pytorch && pip install -r requirements.txt
44+
45+
RUN pip install numpy==1.20.3
46+
47+
ENV PYTHONPATH "${PYTHONPATH}:/tmp/goturn-pytorch/src"
48+
ENV PYTHONPATH "${PYTHONPATH}:/tmp/goturn-pytorch/src/scripts"
49+
50+
RUN mkdir /tmp/goturn-pytorch/src/goturn/models/checkpoints
51+
RUN cd /tmp/goturn-pytorch/src/goturn/models/checkpoints && gdown https://drive.google.com/uc?id=1GouImhqpcoDtV_eLrD2wra-qr3vkAMY4

.github/actions/goturn/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Test GOTURN'
2+
description: 'Run tests for GOTURN'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- run: $GITHUB_ACTION_PATH/run.sh
7+
shell: bash

.github/actions/goturn/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
exit_code=0
4+
5+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_tracking/test_pytorch_goturn.py --framework=pytorch --durations=0
6+
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/object_tracking/test_pytorch_goturn tests"; fi
7+
8+
exit ${exit_code}

.github/workflows/ci-goturn.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI PyTorchGoturn
2+
on:
3+
# Run on manual trigger
4+
workflow_dispatch:
5+
6+
# Run on pull requests
7+
pull_request:
8+
paths-ignore:
9+
- '*.md'
10+
11+
# Run when pushing to main or dev branches
12+
push:
13+
branches:
14+
- main
15+
- dev*
16+
17+
# Run scheduled CI flow daily
18+
schedule:
19+
- cron: '0 8 * * 0'
20+
21+
jobs:
22+
test_pytorch_goturn:
23+
name: PyTorchGoturn
24+
runs-on: ubuntu-latest
25+
container: adversarialrobustnesstoolbox/art_testing_envs:goturn
26+
steps:
27+
- name: Checkout Repo
28+
uses: actions/[email protected]
29+
- name: Run Test Action
30+
uses: ./.github/actions/goturn
31+
- name: Upload coverage to Codecov
32+
uses: codecov/[email protected]

.github/workflows/ci-legacy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020

2121
jobs:
2222
test:
23-
runs-on: ubuntu-16.04
23+
runs-on: ubuntu-20.04
2424
strategy:
2525
fail-fast: false
2626
matrix:

.github/workflows/ci-mxnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020

2121
jobs:
2222
test:
23-
runs-on: ubuntu-16.04
23+
runs-on: ubuntu-18.04
2424
strategy:
2525
fail-fast: false
2626
matrix:

.github/workflows/ci-pytorch-fasterrcnn.yml renamed to .github/workflows/ci-pytorch-object-detectors.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI PyTorchFasterRCNN
1+
name: CI PyTorchObjectDetectors
22
on:
33
# Run on manual trigger
44
workflow_dispatch:
@@ -20,7 +20,7 @@ on:
2020

2121
jobs:
2222
test_pytorch_fasterrcnn:
23-
name: PyTorchFasterRCNN
23+
name: PyTorchObjectDetectors
2424
runs-on: ubuntu-20.04
2525
strategy:
2626
fail-fast: false
@@ -43,7 +43,9 @@ jobs:
4343
pip install torch==1.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
4444
pip install torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
4545
pip install torchaudio==0.6.0 -f https://download.pytorch.org/whl/torch_stable.html
46-
- name: Run Test Action
46+
- name: Run Test Action - test_pytorch_object_detector
47+
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_pytorch_object_detector.py --framework=pytorch --durations=0
48+
- name: Run Test Action - test_pytorch_faster_rcnn
4749
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/object_detection/test_pytorch_faster_rcnn.py --framework=pytorch --durations=0
4850
- name: Upload coverage to Codecov
4951
uses: codecov/[email protected]

.github/workflows/ci-style-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
run: mypy art
5252
- name: pytest-flake8
5353
if: ${{ always() }}
54-
run: pytest --flake8 -v -m flake8
54+
run: pytest --flake8 -v -m flake8 --ignore=contrib
5555
- name: black
5656
if: ${{ always() }}
5757
run: |

art/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from art import preprocessing
1313

1414
# Semantic Version
15-
__version__ = "1.7.2"
15+
__version__ = "1.8.0.dev0"
1616

1717
# pylint: disable=C0103
1818

art/attacks/attack.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,16 @@ def replacement_function(self, *args, **kwargs):
8585
setattr(cls, item, new_function)
8686

8787

88-
class Attack(abc.ABC, metaclass=InputFilter):
88+
class Attack(abc.ABC):
8989
"""
9090
Abstract base class for all attack abstract base classes.
9191
"""
9292

9393
attack_params: List[str] = list()
94+
# The _estimator_requirements define the requirements an estimator must satisfy to be used as a target for an
95+
# attack. They should be a tuple of requirements, where each requirement is either a class the estimator must
96+
# inherit from, or a tuple of classes which define a union, i.e. the estimator must inherit from at least one class
97+
# in the requirement tuple.
9498
_estimator_requirements: Optional[Union[Tuple[Any, ...], Tuple[()]]] = None
9599

96100
def __init__(
@@ -111,7 +115,7 @@ def __init__(
111115
if self.estimator_requirements is None:
112116
raise ValueError("Estimator requirements have not been defined in `_estimator_requirements`.")
113117

114-
if not all(t in type(estimator).__mro__ for t in self.estimator_requirements):
118+
if not self.is_estimator_valid(estimator):
115119
raise EstimatorError(self.__class__, self.estimator_requirements, estimator)
116120

117121
self._estimator = estimator
@@ -155,6 +159,24 @@ def _check_params(self) -> None:
155159
if not isinstance(self.tensor_board, (bool, str)):
156160
raise ValueError("The argument `tensor_board` has to be either of type bool or str.")
157161

162+
def is_estimator_valid(self, estimator) -> bool:
163+
"""
164+
Checks if the given estimator satisfies the requirements for this attack.
165+
166+
:param estimator: The estimator to check.
167+
:return: True if the estimator is valid for the attack.
168+
"""
169+
170+
for req in self.estimator_requirements:
171+
# A requirement is either a class which the estimator must inherit from, or a tuple of classes and the
172+
# estimator is required to inherit from at least one of the classes
173+
if isinstance(req, tuple):
174+
if all(p not in type(estimator).__mro__ for p in req):
175+
return False
176+
elif req not in type(estimator).__mro__:
177+
return False
178+
return True
179+
158180

159181
class EvasionAttack(Attack):
160182
"""
@@ -175,7 +197,7 @@ def generate( # lgtm [py/inheritance/incorrect-overridden-signature]
175197
176198
:param x: An array with the original inputs to be attacked.
177199
:param y: Correct labels or target labels for `x`, depending if the attack is targeted
178-
or not. This parameter is only used by some of the attacks.
200+
or not. This parameter is only used by some of the attacks.
179201
:return: An array holding the adversarial examples.
180202
"""
181203
raise NotImplementedError
@@ -373,7 +395,7 @@ class MembershipInferenceAttack(InferenceAttack):
373395
Abstract base class for membership inference attack classes.
374396
"""
375397

376-
def __init__(self, estimator: Union["CLASSIFIER_TYPE"]):
398+
def __init__(self, estimator):
377399
"""
378400
:param estimator: A trained estimator targeted for inference attack.
379401
:type estimator: :class:`.art.estimators.estimator.BaseEstimator`

0 commit comments

Comments
 (0)