close

Deepfakes 簡介
Deepfakes 是人工智能生成的任何人或名人的合成視頻,它冒充真實的人,並讓他們採取行動或說出他們從未做過的任何事情。
Deepfake 的創建過程在技術上很複雜,通常需要大量數據,然後將這些數據輸入神經網絡以訓練和生成合成視頻。
Deepfakes 的影響
Deepfakes 和 AI 虛擬形象可能會產生不同的影響,具體取決於其使用方式。雖然 deepfake 的負面影響可能令人恐懼,但它在其他情況下會很有用。
Deepfakes 的優點
Deepfakes 可以作為一種藝術形式,讓過去的人們重獲新生。例如,一幅蒙娜麗莎的畫可以用來生成一個會說話的蒙娜麗莎的合成圖像。
Deepfake 技術可用於在訓練視頻中創建 AI 頭像。在疫情期間,總部位於倫敦的 Synthesia 等初創公司越來越受到企業界的關注,因為封鎖和健康問題使涉及真人的視頻拍攝變得更加困難。
Deepfakes 可用於創建個人頭像,可以用於試穿衣服或新髮型。
Deepfakes 還可用於調查新聞報道、金融等各個領域的身份保護和匿名化。
Deepfakes 的缺點
Deepfakes 可用於通過名人的換臉視頻傳播假新聞。
Deepfakes 也可能被誤用於在社交媒體上發起錯誤信息宣傳活動,從而改變公眾輿論並導致負面後果。
創建 Deepfakes
儘管可以通過多種方式使用或誤用Deepfakes,但隨着 AI 日新月異的進步,創建它們變得越來越容易。
我們現在可以用一個人的小視頻源創建一個Deepfakes。是的,隨着神經網絡的最新進展,這現在很容易實現。
讓我們將解決方案分解為兩部分
聲音克隆
視頻口型同步
Deepfakes 的語音克隆部分
SV2TTS 是一個深度學習框架,可以通過訓練將音頻量化並以數字和參數的形式表現出來,這些數字和參數的基礎是一個人的聲音的一小段音頻。
語音樣本的這種數字描述可用於指導和訓練一個從文本到語音的模型,以使用任何文本數據作為輸入,生成具有相同語音的新音頻。因此,使用從樣本源視頻中提取的音頻,可以使用 SV2TTS 輕鬆創建語音克隆。

圖:SV2TTS 工作流程
SV2TTS 工作流程
揚聲器編碼器接收從源視頻中提取的目標人物的音頻,並將帶有嵌入的編碼輸出傳遞給合成器。
合成器根據目標音頻和成對的文本記錄進行訓練,併合成輸入
神經聲碼器將合成器產生的頻譜圖轉換為輸出波形
Deepfakes 的視頻口形同步部分
Wav2lip 是一種口型同步 GAN,它以人說話的音頻樣本和等長視頻樣本作為輸入,並將人的口型與輸入音頻同步。因此,它會生成同一個人說出輸入音頻的合成視頻,而不是原始樣本視頻中的實際音頻。
圖:Wav2Lip 工作流程
視頻口型同步工作流程
生成器使用身份編碼器、語音編碼器和面部解碼器來生成視頻幀
判別器在訓練過程中因生成不準確而懲罰生成器
生成器-鑑別器的對抗訓練導致最終輸出視頻具有儘可能高的準確度
示例合成視頻
這是我製作的奧巴馬與我們交談的合成視頻!用於創建語音克隆音頻的文字記錄顯示:「Hey guys, this is Barack Obama. As you can see, this is not a real video. My creator, Suvojit, generated this synthetic video with Generative Adversarial Networks….」
https://youtu.be/5BpxgU-0vbc
深入了解 SV2TTS 的步驟和代碼
讓我們深入了解 SV2TTS 和 Wav2Lip 的步驟和代碼。
源視頻
選擇源視頻——視頻可以是任意長度,並且應該只有目標角色在前面發言,並儘可能少的中斷。
請注意,生成的最終合成視頻將與輸入視頻的大小相同,因此你可以根據需要裁剪視頻。
音頻提取
從源視頻中提取音頻。該音頻將作為 SV2TTS 生成語音克隆的訓練數據。
導入庫
對於 SV2TTS,在Notebook中導入必要的庫。
#importingallthenecessarylibraries
importosfromos.pathimportexists,join,basename,splitextimportsysfromIPython.displayimportdisplay,Audio,clear_outputfromIPython.utilsimportioimportipywidgetsaswidgetsimportnumpyasnpfromdl_colab_notebooks.audioimportrecord_audio,upload_audiofromsynthesizer.inferenceimportSynthesizerfromencoderimportinferenceasencoderfromvocoderimportinferenceasvocoderfrompathlibimportPath
克隆 SV2TTS 存儲庫
克隆基於SV2TTS的實時語音克隆repo並安裝requirements。
sys.path.append(name_of_proj)
#urlofsvt2ttsgit_repo_url='https://github.com/CorentinJ/Real-Time-Voice-Cloning.git'name_of_proj=splitext(basename(git_repo_url))[0]
#clonereporecursivelyandinstalldependencies
ifnotexists(name_of_proj):#cloneandinstall!gitclone-q--recursive{git_repo_url}#installdependencies!cd{name_of_proj}
!pipinstall-q-rrequirements.txt!pipinstall-qgdown!apt-getinstall-qqlibportaudio2!pipinstall-qhttps://github.com/tugstugi/dl-colab-notebooks/archive/colab_utils.zip
加載預訓練模型
下載並加載預訓練的模型和合成器。
#loadpretrainedmodelencoder.load_model(project_name/Path("encoder/saved_models/pretrained.pt"))#createsynthesizerobjectsynthesizer=Synthesizer(project_name/Path("synthesizer/saved_models/pretrained/pretrained.pt"))#loadmodeltovocodervocoder.load_model(project_name/Path("vocoder/saved_models/pretrained/pretrained.pt"))
上傳音頻和計算嵌入
設置採樣率,編碼器嵌入,以及上傳或記錄音頻的選項。在這種情況下,我們將上傳音頻。
#chooseappropriatesamplerateSAMPLE_RATE=22050#createoptiontouploadorrecordaudio,enteraudiodurationrec_upl="Upld(.mp3or.wav)"#@param["Recrd","Upld(.mp3or.wav)"]record_seconds=600#@param{type:"number",min:1,max:10,step:1}embedding=None#computeembeddingsdef_compute_embedding(audio):display(Audio(audio,rate=SAMPLE_RATE,autoplay=True))globalembeddingembedding=Noneembedding=encoder.embed_utterance(encoder.preprocess_wav(audio,SAMPLE_RATE))#functionforrecordingyourownvoiceandcomputingembeddingsdef_record_audio(b):clear_output()audio=record_audio(record_seconds,sample_rate=SAMPLE_RATE)_compute_embedding(audio)#functionforuploadingaudioandcomputingembeddingsdef_upload_audio(b):clear_output()audio=upload_audio(sample_rate=SAMPLE_RATE)_compute_embedding(audio)ifrecord_or_upload=="Record":button=widgets.Button(description="RecordYourVoice")button.on_click(_record_audio)display(button)else:#button=widgets.Button(description="UploadVoiceFile")#button.on_click(_upload_audio)_upload_audio("")
生成語音克隆
最後,合成音頻並生成輸出波形
#textforthevoiceclonetoreadoutinthesyntheticallygeneratedaudiotext="HeyguysthisisBarackObama.Asyoucansee,thisisnotarealvideo.Mycreator,SuvojitgeneratedthissyntheticvideowithGenerativeAdversarialNetworks.Likeandsharethisvideo,andmessageSuvojitifyouwanttoknowmoredetails.Bye"#@param{type:"string"}defsynthesize(embed,text):print("Synthesizingnewaudio...")#synthesizethespectrogramsspecs=synthesizer.synthesize_spectrograms([text],)generated_wav=vocoder.infer_waveform(specs[0])#generateoutputwaveformgenerated_wav=np.pad(generated_wav,(0,synthesizer.sample_rate),mode="constant")clear_output()display(Audio(generated_wav,rate=synthesizer.sample_rate,autoplay=True))ifembeddingisNone:print(「uploadtheaudio」)else:synthesize(embedding,text)
唇形同步:克隆 Wav2Lip Repo
現在是生成口型同步視頻的時候了。克隆 Wav2Lip 存儲庫並下載預訓練模型以實現高度準確的唇形同步。掛載 Google 驅動器並上傳和複製內容。
#download:https://github.com/Rudrabha/Wav2Lip#training-on-datasets-other-than-lrs2!gitclonehttps://github.com/Rudrabha/Wav2Lip.git#copycheckpointsfromgoogledrivetosessionstorage!cp-ri"/content/gdrive/MyDrive/Files/Wav2lip/wav2lip_gan.pth"/content/Wav2Lip/checkpoints/!cp-ri"/content/gdrive/MyDrive/Files/Wav2lip/wav2lip.pth"/content/Wav2Lip/checkpoints/!cdWav2Lip&&pipinstall-rrequirements.txt!wget"https://www.adrianbulat.com/downloads/python-fan/s3fd-619a316812.pth"-O"Wav2Lip/face_detection/detection/sfd/s3fd.pth"
預處理音頻和視頻數據
現在設置要處理的文件。
%cdsample_data/%rminput_audio.wav%rminput_video.mp4fromgoogle.colabimportfilesuploaded=files.upload()%cd..!cdWav2Lip&&pythoninference.py--checkpoint_pathcheckpoints/wav2lip_gan.pth--face"/content/sample_data/input_video.mp4"--audio"/content/sample_data/input_audio.wav"fromgoogle.colabimportfiles#downloadthevoicegeneratedinpreviousstepstosessionstoragefiles.download('/content/Wav2Lip/results/result_voice.mp4')fromIPython.displayimportHTMLfrombase64importb64encode#readbinaryoftheaudiofilemp4=open('/content/Wav2Lip/results/result_voice.mp4','rb').read()data_url="data:video/mp4;base64,"+b64encode(mp4).decode()HTML(f"""<videowidth="50%"height="50%"controls><sourcesrc="{data_url}"type="video/mp4"></video>""")
上傳 Wav2Lip 的輸入文件
上傳 input_vide o.mp4 & input_audio.wav 文件。輸入音頻是在上一步從 SV2TTS 生成的。
%cdsample_data/fromgoogle.colabimportfilesuploaded=files.upload()%cd..
生成口型同步視頻
使用預訓練模型創建 wav2lip 視頻。
#settheargsforcheckpointandinputfilesandgeneratethelipsyncvideo!cdWav2Lip&&pythoninference.py--checkpoint_pathcheckpoints/wav2lip_gan.pth
將 Deepfake 下載到你的 PC
就是這樣!現在你可以將 deepfake 下載到你的谷歌驅動器和你的電腦上。
files.download('/content/Wav2Lip/results/result_voice.mp4')
因此,音頻克隆和唇形同步 GAN 的組合可用於製作一個deepfake ,從一個人的 10 秒短視頻中生成任何人所說的任意內容(自定義內容)。
參考
SV2TTS 論文: https://arxiv.org/pdf/1806.04558.pdf
Wav2Lip 論文: https://arxiv.org/pdf/2008.10010.pdf

☆ END ☆
如果看到這裡,說明你喜歡這篇文章,請轉發、點讚。微信搜索「uncle_pn」,歡迎添加小編微信「 woshicver」,每日朋友圈更新一篇高質量博文。
↓掃描二維碼添加小編↓

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 鑽石舞台 的頭像
    鑽石舞台

    鑽石舞台

    鑽石舞台 發表在 痞客邦 留言(0) 人氣()