Nicholas Carlini是文章Audio Adversarial Examples: Targeted Attacks on Speech-to-Text的作者,他将自己的代码放在github上,地址为https://github.com/carlini/audio_adversarial_examples
本文介绍Nicholas Carlini的audio_adversarial_examples源码安装方法,写这篇文章的原因是因为其github库的readme安装有一些问题,不能完成安装,因此我安装自己的安装过程重新写下,亲测可用。
步骤如下:
1. 安装依赖:
安装git LFS,便于后期大文件下载:
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
$ sudo apt-get install git-lfs
$ git lfs install
方法来自于https://blog.csdn.net/u014454538/article/details/81282369
安装ds-ctcdecoder:
pip install ds-ctcdecoder
安装其他依赖库:
pip3 install tensorflow-gpu==1.14 progressbar numpy scipy pandas python_speech_features tables attrdict pyxdg
2. 准备源码:
下载Nicholas Carlini的代码到本地:
git clone https://github.com/carlini/audio_adversarial_examples.git
进入audio_adversarial_examples文件夹:
cd audio_adversarial_examples
下一步需要下载DeepSpeech代码,但是audio_adversarial_examples使用的是DeepSpeech0.4.1版本,不建议使用Nicholas Carlini提供的先下载github库后checkout版本的方法,我遇到了bug
建议直接打开https://github.com/mozilla/DeepSpeech/tree/v0.4.1,下载压缩包,解压后放到audio_adversarial_examples文件夹中
记得重命名为DeepSpeech!删除后面的-0.4.1方便代码引用
进入DeepSpeech文件夹中,注释掉DeepSpeech.py中的第21行代码:
from tensorflow.contrib.lite.python import tflite_convert
下载DeepSpeech模型,本步需要很长时间:
wget https://github.com/mozilla/DeepSpeech/releases/download/v0.4.1/deepspeech-0.4.1-checkpoint.tar.gz
tar -xzf deepspeech-0.4.1-checkpoint.tar.gz
到此为止,源码安装结束,可以开始测试:
产生恶意样本:
python3 attack.py --in sample-000000.wav --target "this is a test" --out adv.wav --iterations 1000 --restore_path deepspeech-0.4.1-checkpoint/model.v0.4.1
输出很多warning,可忽略
最终输出如下:
without the datasete the article asusedless
--------------------------w-i-thh-----outt- -the--- -d-a-t---a-------s-e----te-- the- --arrtt-i--c--le- --a------s-uu---see-------l-e---s-ss-----------------
188.785 188.785
138.291 138.291
74.535 74.535
71.442 71.442
59.933 59.933
47.739 47.739
39.142 39.142
36.828 36.828
32.526 32.526
27.466 27.466
thasas was sist
......
计算成功率:
python3 attack.py --in adv.wav --restore_path deepspeech-0.4.1-checkpoint/model.v0.4.1