Docker 環境檢查
執行docker info
查看環境種是否有安裝docker,否則首先安裝好docker 運行環境。在線環境安裝執行執行兩條指令即可
sudo apt install docker
sudo apt-get install docker-ce
sudo apt-get install docker-composesudo systemctl restart docker
GPU環境檢查
沒有GPU環境忽略該步驟,但后面的所有過程跑起來可能就不會那么流暢。
nvidia-smi --query-gpu=name,memory.total,memory.free --format=csv,noheader
NVIDIA Container Toolkit 安裝
為確保能用上nvidia的gpu,需要安裝改toolkit。詳細參見
【安裝NVIDIA Container Toolkit】
自定義創建容器鏡像
下載Dockerfile文件及地址:
https://gitee.com/qingplus/qingcloud-platform/blob/develop/qingcloud-deploy/standard/AIGC/SadTalker/Dockerfile
FROM python:3.8.16-bullseye
ARG DEBIAN_FRONTEND=noninteractiveRUN echo > /etc/apt/sources.list
RUN echo "deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib"> /etc/apt/sources.list
RUN echo "deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib">> /etc/apt/sources.list
RUN echo "deb https://mirrors.aliyun.com/debian-security/ bullseye-security main">> /etc/apt/sources.list
RUN echo "deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main">> /etc/apt/sources.list
RUN echo "deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib">> /etc/apt/sources.list
RUN echo "deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib">> /etc/apt/sources.list
RUN echo "deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib">> /etc/apt/sources.list
RUN echo "deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib">> /etc/apt/sources.listRUN apt-get updateRUN apt-get install -y --no-install-recommends \software-properties-common \wget \git \build-essential \libgl1 \libssl-dev \libffi-dev \libxml2-dev \libxslt1-dev \zlib1g-dev \libjpeg-dev \libpng-dev \unzip \ffmpegWORKDIR /appCOPY SadTalker /app/SadTalker/
WORKDIR /app/SadTalker
RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple
RUN pip config set install.trusted-host mirrors.aliyun.com
RUN pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
RUN pip install dlib-bin
RUN pip install --verbose --use-pep517 -r requirements.txtENTRYPOINT ["python3", "inference.py"]
注意:
1、網上很多教程都會讓安裝conda,主要是因為安裝的目標并不是在容器中,這里是容器化部署,環境單一,并不存在多個虛擬環境的情況,所以直接pip 安裝即可。
2、網絡原因,請務必做好鏡像源的配置。 這里包括apt-get 的source 。和pip的國內安裝源,大部分錯誤都源于此處。
3、--verbose --use-pep517
我的環境build時出錯,根據錯誤提示添加這兩參數解決問題。為了方便糾錯,把–verbose 加上方便顯示更多的提示信息
4、默認鏡像源為清華源的時候,會有一個報錯,此處改為阿里源解決問題。
生存image
進入到Dockerfile所在目錄,執行:
docker build -t qingcloudtech/sadtalker:v1.0 .
當然如果不想自己build 的也可以直接運行啟動命名:但需要把鏡像名稱改為:
registry.cn-hangzhou.aliyuncs.com/qingcloudtech/sadtalker:v1.0
啟動命令
docker run -it --gpus all \ -v ./checkpoints:/app/SadTalker/checkpoints \ -v ./gfpgan/weights:/app/SadTalker/gfpgan/weights \ -v ./results:/app/SadTalker/results \ -v ./data:/app/SadTalker/sample \ qingcloudtech/sadtalker:v1.0 \ --driven_audio /app/SadTalker/examples/driven_audio/chinese_news.wav \ --source_image /app/SadTalker/examples/source_image/art_0.png \ --expression_scale 1.0 \ --result_dir /app/SadTalker/results \
備注:
/app/SadTalker/checkpoints
容器內該目錄不能改變
/app/SadTalker/gfpgan/weights
容器內該地址不能改變
checkpoinits 和weights 文件都放在宿主機上,方便更新和下載。
運行結果文件放在掛在到本地方便讀取結果文件的容器路徑需要與--result_dir
一致。
需要操作的音頻文件和image樣例文件也掛在到宿主機上。
高級設置
inference.py 文件中高級配置選項說明
姓名 | 配置 | 默認 | 說明 |
---|---|---|---|
增強模式 | –enhancer | None | gfpgan或RestoreFormer |
確保已經安裝: | |||
pip install gfpgan | |||
背景增強器 | –background_enhancer | None | realesrgan:增強完整視頻。 |
確保已經安裝: | |||
pip install realesrgan | |||
靜止模式 | –still | false | 使用與原始圖像相同的姿勢參數,減少頭部運動。 |
表現模式 | –expression_scale | 1.0 | 值越大,表情運動越強。 |
保存路徑 | –result_dir | ./results | 該文件將保存在較新的位置。 |
預處理 | –preprocess | crop | crop: 運行并在裁剪后的輸入圖像中生成結果 |
resize: 圖像將調整為特定分辨率。 | |||
full :運行完整圖像動畫, | |||
使用–still可以獲得更好的效果。 | |||
參考模式 | |||
(眼睛) | –ref_eyeblink | None | 視頻路徑,我們借用此參考視頻中的眨眼來提供更自然的眉毛運動。 |
參考模式 | |||
(姿勢) | –ref_pose | None | 視頻路徑,我們從頭部參考視頻中借用姿勢。 |
3D模式 | –face3dvis | false | 需要額外安裝。生成 3D 臉部的更多詳細信息可以在此處 |
找到。 | |||
自由觀看模式 | –input_yaw, | ||
–input_pitch, | |||
–input_roll | None | 從單個圖像生成新穎的視圖或自由視圖 4D 頭部說話。更多詳細信息可以在這里 | |
找到。 |
從音頻和單個圖像生成 4D 自由視圖
我們使用input_yaw, input_pitch,input_roll來控制頭部姿勢。例如,–input_yaw -20 30 10表示輸入頭偏航度從-20變為30,然后從30變為10。
docker run -it --gpus all \ -v ./checkpoints:/app/SadTalker/checkpoints \ -v ./gfpgan/weights:/app/SadTalker/gfpgan/weights \ -v ./results:/app/SadTalker/results \ -v ./data:/app/SadTalker/sample \ qingcloudtech/sadtalker:v1.0 \ --driven_audio /app/SadTalker/examples/driven_audio/chinese_news.wav \ --source_image /app/SadTalker/examples/source_image/art_0.png \ --expression_scale 1.0 \ --result_dir /app/SadTalker/results \ --input_yaw -20 30 10
【Qinghub Studio 】更適合開發人員的低代碼開源開發平臺
【QingHub企業級應用統一部署】
【QingHub企業級應用開發管理】
【QingHub** 演示】**
【https://qingplus.cn】