Skip to content

Commit eadbbde

Browse files
authored
Merge pull request #1147 from Trusted-AI/dev_1.7.0
Update to ART 1.7.0
2 parents 24a616b + 17e633f commit eadbbde

File tree

112 files changed

+11370
-1011
lines changed

Some content is hidden

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

112 files changed

+11370
-1011
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 clean all \
21+
&& rm -r /var/lib/apt/lists/*
22+
23+
RUN /opt/conda/bin/conda install --yes \
24+
astropy \
25+
matplotlib \
26+
pandas \
27+
scikit-learn \
28+
scikit-image
29+
30+
# Install necessary libraries for deepspeech v3
31+
RUN pip install torch
32+
RUN pip install tensorflow
33+
RUN pip install torchaudio==0.6.0
34+
RUN pip install --no-build-isolation fairscale
35+
36+
RUN git clone https://github.com/SeanNaren/deepspeech.pytorch.git
37+
RUN cd deepspeech.pytorch && pip install -r requirements.txt
38+
RUN cd deepspeech.pytorch && pip install -e .
39+
40+
RUN pip install numba==0.50.0
41+
RUN pip install pytest-cov
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Test DeepSpeech v3'
2+
description: 'Run tests for DeepSpeech v3'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- run: $GITHUB_ACTION_PATH/run.sh
7+
shell: bash
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh -l
2+
3+
exit_code=0
4+
5+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/speech_recognition/test_pytorch_deep_speech.py --framework=pytorch --skip_travis=True --durations=0
6+
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed estimators/speech_recognition/test_pytorch_deep_speech tests"; fi
7+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/attacks/evasion/test_imperceptible_asr_pytorch.py --framework=pytorch --skip_travis=True --durations=0
8+
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed attacks/evasion/test_imperceptible_asr_pytorch tests"; fi
9+
10+
exit ${exit_code}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI PyTorchDeepSpeech v3
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_deepspeech_v3:
23+
name: PyTorchDeepSpeech v3
24+
runs-on: ubuntu-latest
25+
container: minhitbk/art_testing_envs:deepspeech_v3
26+
steps:
27+
- name: Checkout Repo
28+
uses: actions/[email protected]
29+
- name: Run Test Action
30+
uses: ./.github/actions/deepspeech-v3
31+
- name: Upload coverage to Codecov
32+
uses: codecov/[email protected]

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ ENV/
9696
*.jpg
9797
demo/pics/*
9898

99-
# ignore local config
100-
*config.ini
101-
10299
# Things TF might pull when testing
103100
*.gz
104101
*.npy

AUTHORS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
- Intel Corporation
1111
- University of Chicago
1212
- The MITRE Corporation
13+
- General Motors Company
14+
- AGH University of Science and Technology
15+
- Rensselaer Polytechnic Institute (RPI)
16+
- IMT Atlantique
17+
- Johns Hopkins University
18+
- Troj.AI

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ RUN pip3 install lightgbm==2.3.1
3131
RUN pip3 install xgboost==1.1.1
3232
RUN pip3 install kornia==0.3.1
3333

34+
RUN pip3 install lief==0.11.4
35+
3436
RUN pip3 install pytest==5.4.1 pytest-pep8==1.0.6 pytest-mock==3.2.0 codecov==2.1.8 requests==2.24.0
3537

3638
RUN mkdir /project; mkdir /project/TMP

art/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
from art import attacks
88
from art import defences
99
from art import estimators
10+
from art import evaluations
1011
from art import metrics
11-
from art import wrappers
12+
from art import preprocessing
1213

1314
# Semantic Version
14-
__version__ = "1.6.2"
15+
__version__ = "1.7.0-dev"
1516

1617
# pylint: disable=C0103
1718

art/attacks/attack.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,18 @@ class Attack(abc.ABC, metaclass=InputFilter):
9393
attack_params: List[str] = list()
9494
_estimator_requirements: Optional[Union[Tuple[Any, ...], Tuple[()]]] = None
9595

96-
def __init__(self, estimator):
96+
def __init__(
97+
self,
98+
estimator,
99+
tensor_board: Union[str, bool] = False,
100+
):
97101
"""
98102
:param estimator: An estimator.
103+
:param tensor_board: Activate summary writer for TensorBoard: Default is `False` and deactivated summary writer.
104+
If `True` save runs/CURRENT_DATETIME_HOSTNAME in current directory. Provide `path` in type
105+
`str` to save in path/CURRENT_DATETIME_HOSTNAME.
106+
Use hierarchical folder structure to compare between runs easily. e.g. pass in ‘runs/exp1’,
107+
‘runs/exp2’, etc. for each new experiment to compare across them.
99108
"""
100109
super().__init__()
101110

@@ -106,6 +115,19 @@ def __init__(self, estimator):
106115
raise EstimatorError(self.__class__, self.estimator_requirements, estimator)
107116

108117
self._estimator = estimator
118+
self.tensor_board = tensor_board
119+
120+
if tensor_board:
121+
from tensorboardX import SummaryWriter
122+
123+
if isinstance(tensor_board, str):
124+
self.summary_writer = SummaryWriter(tensor_board)
125+
else:
126+
self.summary_writer = SummaryWriter()
127+
else:
128+
self.summary_writer = None
129+
130+
Attack._check_params(self)
109131

110132
@property
111133
def estimator(self):
@@ -129,7 +151,9 @@ def set_params(self, **kwargs) -> None:
129151
self._check_params()
130152

131153
def _check_params(self) -> None:
132-
pass
154+
155+
if not isinstance(self.tensor_board, (bool, str)):
156+
raise ValueError("The argument `tensor_board` has to be either of type bool or str.")
133157

134158

135159
class EvasionAttack(Attack):
@@ -305,12 +329,12 @@ def __init__(self, estimator):
305329
@abc.abstractmethod
306330
def infer(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> np.ndarray:
307331
"""
308-
Infer sensitive properties (attributes, membership training records) from the targeted estimator. This method
332+
Infer sensitive attributes from the targeted estimator. This method
309333
should be overridden by all concrete inference attack implementations.
310334
311335
:param x: An array with reference inputs to be used in the attack.
312336
:param y: Labels for `x`. This parameter is only used by some of the attacks.
313-
:return: An array holding the inferred properties.
337+
:return: An array holding the inferred attribute values.
314338
"""
315339
raise NotImplementedError
316340

@@ -334,12 +358,41 @@ def __init__(self, estimator, attack_feature: Union[int, slice] = 0):
334358
@abc.abstractmethod
335359
def infer(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> np.ndarray:
336360
"""
337-
Infer sensitive properties (attributes, membership training records) from the targeted estimator. This method
361+
Infer sensitive attributes from the targeted estimator. This method
362+
should be overridden by all concrete inference attack implementations.
363+
364+
:param x: An array with reference inputs to be used in the attack.
365+
:param y: Labels for `x`. This parameter is only used by some of the attacks.
366+
:return: An array holding the inferred attribute values.
367+
"""
368+
raise NotImplementedError
369+
370+
371+
class MembershipInferenceAttack(InferenceAttack):
372+
"""
373+
Abstract base class for membership inference attack classes.
374+
"""
375+
376+
def __init__(self, estimator: Union["CLASSIFIER_TYPE"]):
377+
"""
378+
:param estimator: A trained estimator targeted for inference attack.
379+
:type estimator: :class:`.art.estimators.estimator.BaseEstimator`
380+
:param attack_feature: The index of the feature to be attacked.
381+
"""
382+
super().__init__(estimator)
383+
384+
@abc.abstractmethod
385+
def infer(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> np.ndarray:
386+
"""
387+
Infer membership status of samples from the target estimator. This method
338388
should be overridden by all concrete inference attack implementations.
339389
340390
:param x: An array with reference inputs to be used in the attack.
341391
:param y: Labels for `x`. This parameter is only used by some of the attacks.
342-
:return: An array holding the inferred properties.
392+
:param probabilities: a boolean indicating whether to return the predicted probabilities per class, or just
393+
the predicted class.
394+
:return: An array holding the inferred membership status (1 indicates member of training set,
395+
0 indicates non-member) or class probabilities.
343396
"""
344397
raise NotImplementedError
345398

art/attacks/evasion/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@
1010
from art.attacks.evasion.auto_projected_gradient_descent import AutoProjectedGradientDescent
1111
from art.attacks.evasion.brendel_bethge import BrendelBethgeAttack
1212
from art.attacks.evasion.boundary import BoundaryAttack
13-
from art.attacks.evasion.carlini import CarliniL2Method, CarliniLInfMethod
13+
from art.attacks.evasion.carlini import CarliniL2Method, CarliniLInfMethod, CarliniL0Method
1414
from art.attacks.evasion.decision_tree_attack import DecisionTreeAttack
1515
from art.attacks.evasion.deepfool import DeepFool
1616
from art.attacks.evasion.dpatch import DPatch
1717
from art.attacks.evasion.dpatch_robust import RobustDPatch
1818
from art.attacks.evasion.elastic_net import ElasticNet
1919
from art.attacks.evasion.fast_gradient import FastGradientMethod
2020
from art.attacks.evasion.frame_saliency import FrameSaliencyAttack
21-
from art.attacks.evasion.feature_adversaries import FeatureAdversaries
21+
from art.attacks.evasion.feature_adversaries.feature_adversaries_numpy import FeatureAdversariesNumpy
22+
from art.attacks.evasion.feature_adversaries.feature_adversaries_pytorch import FeatureAdversariesPyTorch
23+
from art.attacks.evasion.feature_adversaries.feature_adversaries_tensorflow import FeatureAdversariesTensorFlowV2
24+
from art.attacks.evasion.geometric_decision_based_attack import GeoDA
2225
from art.attacks.evasion.hclu import HighConfidenceLowUncertainty
2326
from art.attacks.evasion.hop_skip_jump import HopSkipJump
2427
from art.attacks.evasion.imperceptible_asr.imperceptible_asr import ImperceptibleASR
2528
from art.attacks.evasion.imperceptible_asr.imperceptible_asr_pytorch import ImperceptibleASRPyTorch
2629
from art.attacks.evasion.iterative_method import BasicIterativeMethod
30+
from art.attacks.evasion.lowprofool import LowProFool
2731
from art.attacks.evasion.newtonfool import NewtonFool
32+
from art.attacks.evasion.pe_malware_attack import MalwareGDTensorFlow
2833
from art.attacks.evasion.pixel_threshold import PixelAttack
2934
from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent import ProjectedGradientDescent
3035
from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent_numpy import (
@@ -36,6 +41,7 @@
3641
from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent_tensorflow_v2 import (
3742
ProjectedGradientDescentTensorFlowV2,
3843
)
44+
from art.attacks.evasion.over_the_air_flickering.over_the_air_flickering_pytorch import OverTheAirFlickeringPyTorch
3945
from art.attacks.evasion.saliency_map import SaliencyMapMethod
4046
from art.attacks.evasion.shadow_attack import ShadowAttack
4147
from art.attacks.evasion.shapeshifter import ShapeShifter

0 commit comments

Comments
 (0)