-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache audio triggers #2053
Cache audio triggers #2053
Conversation
…ers can be cached instead of loaded repeatedly Signed-off-by: Sterling <sterling.suggs@twosixtech.com>
Signed-off-by: Sterling <sterling.suggs@twosixtech.com>
@Swanand-Kadhe @beat-buesser Let me know if anything should be changed in formatting, style, documentation, or anything else, since this is my first pr into ART. |
Co-authored-by: Beat Buesser <49047826+beat-buesser@users.noreply.github.com>
Signed-off-by: Sterling <sterling.suggs@twosixtech.com>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## dev_1.14.0 #2053 +/- ##
==============================================
+ Coverage 80.90% 81.08% +0.17%
==============================================
Files 294 294
Lines 26223 26212 -11
Branches 4800 4797 -3
==============================================
+ Hits 21216 21254 +38
+ Misses 3801 3792 -9
+ Partials 1206 1166 -40
|
Hi @swsuggs - thank you very much for this PR! I am happy to take a look. |
Signed-off-by: Sterling <sterling.suggs@twosixtech.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for the PR. It looks good to me. I just have a couple of minor suggestions regarding docstrings as mentioned below.
…l-robustness-toolbox into cache-audio-perturbations
Signed-off-by: Sterling <sterling.suggs@twosixtech.com>
@Swanand-Kadhe Thanks for your suggestions, I have implemented them and also reformatted the docstrings a bit to match what it looks like in other ART classes. Please let me know if there is anything else. |
@swsuggs @Swanand-Kadhe Thank you very much! |
for a notebook update, https://nbviewer.org/github/Trusted-AI/adversarial-robustness-toolbox/blob/main/notebooks/poisoning_attack_backdoor_audio.ipynb# you can do this, everything works fine, I hope it helps ! Thanks ! import numpy as np
from art.attacks.poisoning import PoisoningAttackBackdoor
from art.attacks.poisoning.perturbations.audio_perturbations import CacheToneTrigger, CacheAudioTrigger
# define the poison function
def poison_func(x_audio):
return CacheToneTrigger(sampling_rate=16000, shift=True, scale=0.25).insert(x=x_audio)
# define the target label for the poisoned samples
target_label = np.array(['down'])
target_label = np.expand_dims(target_label, axis=0)
# create a poisoning attack object using the poison function
backdoor_attack = PoisoningAttackBackdoor(poison_func)
poisoned_x, poisoned_y = backdoor_attack.poison(x_audio, target_label, broadcast=True)
try:
poisoned_x, poisoned_y = backdoor_attack.poison(x_audio, target_label, broadcast=True)
except ValueError as e:
print("Error:", e)
except Exception as e:
print("Unknown error:", e) # import necessary libraries
from art.attacks.poisoning import PoisoningAttackBackdoor
import numpy as np
# define the poison function
def poison_func(x):
# insert a cough trigger backdoor into the input audio
return CacheAudioTrigger( sampling_rate = 16000, duration =0.6, backdoor_path = '../utils/data/backdoors/cough_trigger.wav',scale =0.1).insert(x=x_audio)
# define the target label for the trigger samples
target_label = np.array('stop')
target_label = np.expand_dims(target_label, axis=0)
# create a poisoning attack object using the poison function
backdoor_attack = PoisoningAttackBackdoor(poison_func)
poisoned_x, poisoned_y = backdoor_attack.poison(x_audio, target_label, broadcast=True)
try:
poisoned_x, poisoned_y = backdoor_attack.poison(x_audio, target_label, broadcast=True)
except Exception as e:
print("Error during poisoning:", e)
poisoned_x, poisoned_y = None, None |
Thank you @OrsonTyphanel93, I had indeed forgotten to update the demo notebook. An update is on the way. It looks like you figured out how to use the class, but let me know if you have any other questions! |
Thanks, I can confirm that it works! I'm actually thinking about how to detect it, thanks again! |
Hello Dear @Swanand-Kadhe, thank you very much ! for the update, I just discovered that you have created a new function def poison_loader_tone():
trigger = CacheToneTrigger(
sampling_rate=16000,
frequency=440,
duration=0.1,
shift = 8000,
scale = 0.25
)
def poison_func(x_audio):
return trigger.insert(x_audio)
return PoisoningAttackBackdoor(poison_func)
backdoor_attack = poison_loader_tone() |
Description
Calling
librosa.load()
for every sample to be poisoned can take hours. This PR uses a class instead of pure functions so that the loaded trigger can be stored.Fixes #2052
Type of change
Please check all relevant options.
Testing
Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.
Checklist