Skip to content

Commit 2082451

Browse files
author
Beat Buesser
committed
Merge remote-tracking branch 'origin/dev_1.7.0' into development_feature_adversaries
2 parents 2b71848 + 02fdc8d commit 2082451

File tree

6 files changed

+615
-11
lines changed

6 files changed

+615
-11
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
- AGH University of Science and Technology
1515
- Rensselaer Polytechnic Institute (RPI)
1616
- IMT Atlantique
17+
- Johns Hopkins University
1718
- Troj.AI

art/attacks/evasion/fast_gradient.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,22 @@ def _compute_perturbation(
409409
)
410410

411411
# Check for NaN before normalisation an replace with 0
412-
if np.isnan(grad).any():
412+
if grad.dtype != np.object and np.isnan(grad).any():
413413
logger.warning("Elements of the loss gradient are NaN and have been replaced with 0.0.")
414414
grad = np.where(np.isnan(grad), 0.0, grad)
415+
else:
416+
for i, _ in enumerate(grad):
417+
grad_i_array = grad[i].astype(np.float32)
418+
if np.isnan(grad_i_array).any():
419+
grad[i] = np.where(np.isnan(grad_i_array), 0.0, grad_i_array).astype(np.object)
415420

416421
# Apply mask
417422
if mask is not None:
418423
grad = np.where(mask == 0.0, 0.0, grad)
419424

420425
# Apply norm bound
421426
def _apply_norm(grad, object_type=False):
422-
if np.isinf(grad).any():
427+
if (grad.dtype != np.object and np.isinf(grad).any()) or np.isnan(grad.astype(np.float32)).any():
423428
logger.info("The loss gradient array contains at least one positive or negative infinity.")
424429

425430
if self.norm in [np.inf, "inf"]:
@@ -454,7 +459,16 @@ def _apply_perturbation(
454459
) -> np.ndarray:
455460

456461
perturbation_step = eps_step * perturbation
457-
perturbation_step[np.isnan(perturbation_step)] = 0
462+
if perturbation_step.dtype != np.object:
463+
perturbation_step[np.isnan(perturbation_step)] = 0
464+
else:
465+
for i, _ in enumerate(perturbation_step):
466+
perturbation_step_i_array = perturbation_step[i].astype(np.float32)
467+
if np.isnan(perturbation_step_i_array).any():
468+
perturbation_step[i] = np.where(
469+
np.isnan(perturbation_step_i_array), 0.0, perturbation_step_i_array
470+
).astype(np.object)
471+
458472
batch = batch + perturbation_step
459473
if self.estimator.clip_values is not None:
460474
clip_min, clip_max = self.estimator.clip_values

art/attacks/evasion/imperceptible_asr/imperceptible_asr_pytorch.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import scipy
3232

3333
from art.attacks.attack import EvasionAttack
34-
from art.estimators.estimator import BaseEstimator, LossGradientsMixin, NeuralNetworkMixin
3534
from art.estimators.pytorch import PyTorchEstimator
3635
from art.estimators.speech_recognition.pytorch_deep_speech import PyTorchDeepSpeech
3736
from art.estimators.speech_recognition.speech_recognizer import SpeechRecognizerMixin
@@ -78,13 +77,9 @@ class ImperceptibleASRPyTorch(EvasionAttack):
7877
]
7978

8079
_estimator_requirements = (
81-
BaseEstimator,
82-
LossGradientsMixin,
83-
NeuralNetworkMixin,
84-
SpeechRecognizerMixin,
8580
PytorchSpeechRecognizerMixin,
81+
SpeechRecognizerMixin,
8682
PyTorchEstimator,
87-
PyTorchDeepSpeech,
8883
)
8984

9085
def __init__(

art/estimators/speech_recognition/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
from art.estimators.speech_recognition.speech_recognizer import SpeechRecognizerMixin
55

66
from art.estimators.speech_recognition.pytorch_deep_speech import PyTorchDeepSpeech
7+
from art.estimators.speech_recognition.pytorch_espresso import PyTorchEspresso
78
from art.estimators.speech_recognition.tensorflow_lingvo import TensorFlowLingvoASR

art/estimators/speech_recognition/pytorch_deep_speech.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
from art import config
3030
from art.estimators.pytorch import PyTorchEstimator
31-
from art.estimators.speech_recognition.speech_recognizer import SpeechRecognizerMixin
32-
from art.estimators.speech_recognition.speech_recognizer import PytorchSpeechRecognizerMixin
31+
from art.estimators.speech_recognition.speech_recognizer import SpeechRecognizerMixin, PytorchSpeechRecognizerMixin
3332
from art.utils import get_file
3433

3534
if TYPE_CHECKING:

0 commit comments

Comments
 (0)