AI與生活應用
AI多人換臉教學
務必先閱讀以下資訊
AI服務為我們帶來很多方便但是也多了很多風險,任何的AI應用請朝正向、正面的角度去做學習,否則就失去了學習的意義。
換臉模型可能涉及違法的風險,僅做教育用途,請勿用來進行違法的事情
Deepfake(深偽),是深度學習(deep learning)與偽造(fake)的一種組合,主要意指應用人工智慧深度學習的技術,合成某個(不一定存在的)人的圖像或影片、甚至聲音。 (非指合成成人影片,我們譴責這樣誤用AI的人,新聞)
STEP 1:
螢幕錄影(ApowerREC)
使用區域錄影方式進行錄影,因為免費版只有一分鐘,喜歡的可以自行購買,輸出畫質有1080P。
影片截圖(小畫家+printscreen)
按鍵盤的PrtScr,開啟小畫家,ctrl+V貼上,做"剪裁",只裁看得清楚的頭部
Google colab
下載圖片(要置換的照片頭部,不需要"高清",不是高清就會成功,愈模糊愈容易成功而且還超像本人)
檔案下載
下載Refacer_colab,ipynb,上傳到自己的colab裡。
Google Colab 歡迎使用 Colaboratory - Colaboratory (google.com)
男女主角換臉前
換臉後(挖屋...年輕的五百)
學生用範例檔案
課堂作業上傳區(22023/10/30)
先建立自己名字的資料夾
https://drive.google.com/drive/folders/1oosHa-_YlacLqKMs1sN75BkSwEaiIYjw?usp=drive_link
需要其他的工具軟體:
螢幕錄影(ApowerREC)、影片截圖、Google colab
AI換臉服務教學 https://www.youtube.com/watch?v=VQtrF62tuEE
多人換臉 Refacer Colab 使用教學 + 詳細步驟
https://www.youtube.com/watch?v=_fLsVoMfJiQ
Refacer Github: https://github.com/xaviviro/refacer
程式碼替換部分的連結(僅供教學故不公開)
另一種修復方式可以參考(僅供教學故不公開)
mark原來的!wget的那一行,新增一行
!gdown --id 從共用連接當中複製貼上id那一段
id取得在雲端硬碟onnx檔案共用的連結中擷取出來
Refacer安裝於Windows的教學(強烈建議安裝在有GPU的顯卡)
以下是針對有GPU的電腦(請事先確認您的nvidia顯卡有沒有支援h264,否則也是無法work!!!!)
本機端部署Refacer,可以安裝Anaconda,create一個環境
(Refacer has been tested and is known to work with Python 3.10.9, but it is likely to work with other Python versions as well)
先安裝FFMEPG (需要先安裝),可以參考下面的連結去安裝
上網下載安裝Git,不適安裝Github喔!
再安裝 Microsoft build tools https://aka.ms/vs/17/release/vs_BuildTools.exe (需要先安裝)
mkdir refacer(略)
conda create --name refacer python=3.10.9 anaconda
然後按y
安裝完成後 下指令 git clone https://github.com/xaviviro/refacer.git 下載需要的資料倒refacer資料夾,同時會建立一個refacer資料夾
本機端需要先安裝git 電腦版,否則會出現git不是內部指令的問題
cd refacer 切換目錄
ls 檢查是否有資料
conda activate refacer 啟動虛擬
下載 inswapper_128.onnx 到資料夾裡(這裡就不公開了!這檔案連創作者都不公開提供下載)
更新pip 下 python -m pip install --upgrade pip
安裝必要的套件(看自己電腦的狀況選擇指令)
For CPU (compatible with Windows, MacOSX, and Linux):
pip install -r requirements.txt
For GPU (compatible with Windows and Linux only, requires a NVIDIA GPU with CUDA and its libraries):
pip install -r requirements-GPU.txt
For CoreML (compatible with MacOSX, requires Silicon architecture):
pip install -r requirements-COREML.txt
有關"Could not build wheels for insightface, which is required to install pyproject.toml-based projects"的錯誤訊息,可以參考 https://stackoverflow.com/questions/76739044/how-to-fix-this-issue-error-failed-building-wheel-for-insightface 做解決
安裝完成之後下 python app.py
然後連線到本機的網頁
安裝FFMPEG(參考教學 https://vocus.cc/article/64701a2cfd897800014daed0 )
以下為GPU版本的錯誤訊息
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
gensim 4.3.0 requires FuzzyTM>=0.4.0, which is not installed.
numba 0.56.4 requires numpy<1.24,>=1.18, but you have numpy 1.24.3 which is incompatible.
需要在文字檔中更新找到適合的版本
Anaconda 環境安裝設定參考文件
環境建置:安裝Anaconda、Tensorflow、Keras與openCV(Windows篇)
VALLE本機部署
教學影片 https://www.youtube.com/watch?v=D8tFRIF92WY
Github https://github.com/Plachtaa/VALL-E-X/blob/master/README-ZH.md
create --name VALLE python=3.10 anaconda
git clone https://github.com/Plachtaa/VALL-E-X.git
cd VALL-E-X
pip install -r requirements.txt
如果需要制作prompt,需要安装 ffmpeg 并将其所在文件夹加入到环境变量PATH中 (這個參考Refacer部屬裡FFMEPG的教學)
執行 python -X utf8 launch-ui.py
會跳出一個網頁視窗
=================================
如果要使用GPU,必須要下指令
移除 pip uninstall torch torchvision torchaudio
安裝 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu
118 這裡是安裝cudua 11.8版本(支援11.7以上)
執行 python -X utf8 launch-ui.py
====================
中文的話要繁中轉簡中唷
除掉背景音的軟體 UVR5