Skip to content

Commit 43890d1

Browse files
committed
Apply review comments
Signed-off-by: Hessel Tuinhof <[email protected]>
1 parent b65f173 commit 43890d1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

art/attacks/evasion/imperceptible_asr/imperceptible_asr.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
from tensorflow.compat.v1 import Tensor
4141
from torch import Tensor as PTensor
4242

43+
from art.utils import SPEECH_RECOGNIZER_TYPE
44+
4345
logger = logging.getLogger(__name__)
4446

4547

@@ -65,7 +67,7 @@ class ImperceptibleASR(EvasionAttack):
6567

6668
def __init__(
6769
self,
68-
estimator: Union["PyTorchEstimator", "TensorFlowV2Estimator"],
70+
estimator: "SPEECH_RECOGNIZER_TYPE",
6971
masker: "PsychoacousticMasker",
7072
eps: float = 2000.0,
7173
learning_rate_1: float = 100.0,
@@ -349,7 +351,7 @@ def _loss_gradient_masking_threshold(
349351

350352
def _loss_gradient_masking_threshold_tf(
351353
self, perturbation: "Tensor", psd_maximum_stabilized: "Tensor", masking_threshold_stabilized: "Tensor"
352-
) -> "Tensor":
354+
) -> Union["Tensor", "Tensor"]:
353355
"""
354356
Compute loss gradient of the masking threshold loss in TensorFlow.
355357
@@ -471,7 +473,6 @@ def _approximate_power_spectral_density_torch(
471473
psd_matrix_approximated = pow(10.0, 9.6) / torch.unsqueeze(psd_maximum_stabilized, 1) * psd_matrix
472474

473475
# return PSD matrix such that shape is (batch_size, window_size // 2 + 1, frame_length)
474-
# return torch.transpose(psd_matrix_approximated, 1, 2)
475476
return psd_matrix_approximated
476477

477478
def _check_params(self) -> None:

art/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
from art.estimators.object_detection.pytorch_faster_rcnn import PyTorchFasterRCNN
9494
from art.estimators.object_detection.tensorflow_faster_rcnn import TensorFlowFasterRCNN
9595

96+
from art.estimators.speech_recognition.pytorch_deep_speech import PyTorchDeepSpeech
97+
from art.estimators.speech_recognition.tensorflow_lingvo import TensorFlowLingvoAsr
98+
9699
CLASSIFIER_TYPE = Union[
97100
Classifier,
98101
BlackBoxClassifier,
@@ -172,6 +175,10 @@
172175
ObjectDetector, PyTorchFasterRCNN, TensorFlowFasterRCNN,
173176
]
174177

178+
SPEECH_RECOGNIZER_TYPE = Union[
179+
PyTorchDeepSpeech,
180+
TensorFlowLingvoAsr,
181+
]
175182

176183
# --------------------------------------------------------------------------------------------------------- DEPRECATION
177184

tests/attacks/evasion/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def audio_batch_padded():
6969
def asr_dummy_estimator(framework):
7070
def _asr_dummy_estimator(**kwargs):
7171
asr_dummy = None
72-
if framework == "tensorflow2":
72+
if framework == "tensorflow2v1":
7373

7474
class TensorFlowV2AsrDummy(TensorFlowV2Estimator, SpeechRecognizerMixin):
7575
def get_activations():

0 commit comments

Comments
 (0)