-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NeuralChat] add optimized SadTalker to Video plugin in NeuralChat (#564
) Signed-off-by: Sihan Chen <39623753+Spycsh@users.noreply.github.com> Co-authored-by: VincyZhang <wenxin.zhang@intel.com> Co-authored-by: chen, suyue <suyue.chen@intel.com>
- Loading branch information
1 parent
9d90e1d
commit 7f24c79
Showing
82 changed files
with
7,619 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
intel_extension_for_transformers/neural_chat/examples/plugins/video/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Face Animation | ||
|
||
We optimize SadTalker on Intel Xeon CPU and integrate its face animation functionalities into the video plugin of NeuralChat. | ||
|
||
## Prepare Environment | ||
|
||
``` | ||
conda install ffmpeg | ||
pip install ffmpeg-python | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Prepare Models | ||
|
||
``` | ||
bash download_models.sh checkpoints gfpgan/weights | ||
``` | ||
|
||
## Usage | ||
|
||
### Simply run the test script | ||
``` | ||
python main.py | ||
``` | ||
|
||
### Deploy it as a server | ||
|
||
``` | ||
neuralchat_server start --config_file face_animation.yaml | ||
``` | ||
|
||
## Acknowledgements | ||
|
||
This plugin is mostly adapted from [SadTalker](https://github.com/OpenTalker/SadTalker). We thank the related authors for their great work! |
35 changes: 35 additions & 0 deletions
35
intel_extension_for_transformers/neural_chat/examples/plugins/video/download_models.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
mkdir ./checkpoints | ||
|
||
wget -nc https://github.com/OpenTalker/SadTalker/releases/download/v0.0.2-rc/mapping_00109-model.pth.tar -O ./checkpoints/mapping_00109-model.pth.tar | ||
wget -nc https://github.com/OpenTalker/SadTalker/releases/download/v0.0.2-rc/mapping_00229-model.pth.tar -O ./checkpoints/mapping_00229-model.pth.tar | ||
wget -nc https://github.com/OpenTalker/SadTalker/releases/download/v0.0.2-rc/SadTalker_V0.0.2_256.safetensors -O ./checkpoints/SadTalker_V0.0.2_256.safetensors | ||
wget -nc https://github.com/OpenTalker/SadTalker/releases/download/v0.0.2-rc/SadTalker_V0.0.2_512.safetensors -O ./checkpoints/SadTalker_V0.0.2_512.safetensors | ||
|
||
|
||
# wget -nc https://github.com/Winfredy/SadTalker/releases/download/v0.0.2/BFM_Fitting.zip -O ./checkpoints/BFM_Fitting.zip | ||
# unzip -n ./checkpoints/BFM_Fitting.zip -d ./checkpoints/ | ||
|
||
mkdir -p ./gfpgan/weights | ||
wget -c https://github.com/xinntao/facexlib/releases/download/v0.1.0/alignment_WFLW_4HG.pth -O ./gfpgan/weights/alignment_WFLW_4HG.pth | ||
wget -c https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth -O ./gfpgan/weights/detection_Resnet50_Final.pth | ||
wget -nc https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -O ./gfpgan/weights/GFPGANv1.4.pth | ||
wget -nc https://github.com/xinntao/facexlib/releases/download/v0.2.2/parsing_parsenet.pth -O ./gfpgan/weights/parsing_parsenet.pth | ||
|
46 changes: 46 additions & 0 deletions
46
intel_extension_for_transformers/neural_chat/examples/plugins/video/face_animation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This is the parameter configuration file for NeuralChat Serving. | ||
|
||
################################################################################# | ||
# SERVER SETTING # | ||
################################################################################# | ||
host: 0.0.0.0 | ||
port: 9001 | ||
|
||
model_name_or_path: "facebook/opt-125m" | ||
device: "cpu" | ||
|
||
tts: | ||
enable: true | ||
args: | ||
device: "cpu" | ||
voice: "default" | ||
stream_mode: false | ||
output_audio_path: "./output_audio.wav" | ||
|
||
face_animation: | ||
enable: true | ||
args: | ||
device: "cpu" | ||
bf16: true | ||
p_num: 4 | ||
enhancer: "gfpgan" | ||
|
||
# task choices = ['textchat', 'voicechat', 'retrieval', 'text2image', 'finetune'] | ||
tasks_list: ['faceanimation'] |
39 changes: 39 additions & 0 deletions
39
intel_extension_for_transformers/neural_chat/examples/plugins/video/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from intel_extension_for_transformers.neural_chat.pipeline.plugins.video.face_animation.sadtalker import SadTalker | ||
import requests | ||
import torch | ||
|
||
|
||
sample_audio_url = "https://github.com/intel/intel-extension-for-transformers/raw/main/intel_extension_for_transformers/neural_chat/assets/audio/welcome.wav" | ||
sample_img_url = "https://raw.githubusercontent.com/OpenTalker/SadTalker/main/examples/source_image/full_body_2.png" | ||
img_data = requests.get(sample_img_url).content | ||
source_image = "sample_img.jpg" | ||
driven_audio = "sample_audio.wav" | ||
with open(source_image, 'wb') as f: | ||
f.write(img_data) | ||
audio_data = requests.get(sample_audio_url).content | ||
with open(driven_audio, 'wb') as f: | ||
f.write(audio_data) | ||
output_video_path = "response.mp4" | ||
checkpoint_dir = "checkpoints" | ||
device = "cuda" if torch.cuda.is_available() else "cpu" | ||
sadtalker = SadTalker(device=device, checkpoint_dir=checkpoint_dir, bf16=True, p_num=4, enhancer=None, output_video_path=output_video_path) | ||
|
||
sadtalker.convert(source_image=source_image, driven_audio=driven_audio) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
intel_extension_for_transformers/neural_chat/pipeline/plugins/video/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
30 changes: 30 additions & 0 deletions
30
...on_for_transformers/neural_chat/pipeline/plugins/video/face_animation/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Face Animation | ||
|
||
We optimize SadTalker on Intel Xeon CPU and integrate its face animation functionalities into the video plugin of NeuralChat. | ||
|
||
## Prepare Environment | ||
|
||
``` | ||
cd intel-extension-for-transformers/intel_extension_for_transformers/neural_chat/pipeline/plugins/video/face_animation | ||
conda install ffmpeg | ||
pip install ffmpeg-python | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
from sadtalker import SadTalker | ||
device = "cuda" if torch.cuda.is_available() else "cpu" | ||
sadtalker = SadTalker(device=device) | ||
# without enhancer | ||
sadtalker.convert(source_image=source_image, driven_audio=driven_audio, output_video_path="./response.mp4", | ||
bf16=True, result_dir="./results", p_num=4, enhancer=None) | ||
# with enhancer | ||
sadtalker.convert(source_image=source_image, driven_audio=driven_audio, output_video_path="./response.mp4", | ||
bf16=True, result_dir="./results", p_num=4, enhancer='gfpgan') | ||
``` | ||
|
||
## Acknowledgements | ||
|
||
This plugin is mostly adapted from [SadTalker](https://github.com/OpenTalker/SadTalker). We thank the related authors for their great work! |
Oops, something went wrong.