File: README.md
LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control
π₯ Updates
2025/06/01: π Over the past year, LivePortrait has π become an efficient portrait-animation (humans, cats and dogs) solution adopted by major video platformsβKuaishou, Douyin, Jianying, WeChat Channelsβas well as numerous startups and creators. π2025/01/01: πΆ We updated a new version of the Animals model with more data, see here.2024/10/18: β We have updated the versions of thetransformersandgradiolibraries to avoid security vulnerabilities. Details here.2024/08/29: π¦ We update the Windows one-click installer and support auto-updates, see changelog.2024/08/19: πΌοΈ We support image driven mode and regional control. For details, see here.2024/08/06: π¨ We support precise portrait editing in the Gradio interface, inspired by ComfyUI-AdvancedLivePortrait. See here.2024/08/05: π¦ Windows users can now download the one-click installer for Humans mode and Animals mode now! For details, see here.2024/08/02: πΈ We released a version of the Animals model, along with several other updates and improvements. Check out the details here!2024/07/25: π¦ Windows users can now download the package from HuggingFace. Simply unzip and double-clickrun_windows.batto enjoy!2024/07/24: π¨ We support pose editing for source portraits in the Gradio interface. Weβve also lowered the default detection threshold to increase recall. Have fun!2024/07/19: β¨ We support ποΈ portrait video editing (aka v2v)! More to see here.2024/07/17: π We support macOS with Apple Silicon, modified from jeethu's PR #143.2024/07/10: πͺ We support audio and video concatenating, driving video auto-cropping, and template making to protect privacy. More to see here.2024/07/09: π€ We released the HuggingFace Space, thanks to the HF team and Gradio!2024/07/04: π We released the initial version of the inference code and models. Continuous updates, stay tuned!2024/07/04: π₯ We released the homepage and technical report on arXiv.
Introduction π
This repo, named LivePortrait, contains the official PyTorch implementation of our paper LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control.
We are actively updating and improving this repository. If you find any bugs or have suggestions, welcome to raise issues or submit pull requests (PR) π.
Getting Started π
1. Clone the code and prepare the environment π οΈ
[!Note]
Make sure your system hasgit,conda, andFFmpeginstalled. For details on FFmpeg installation, see how to install FFmpeg.
git clone https://github.com/KlingTeam/LivePortrait
cd LivePortrait
# create env using conda
conda create -n LivePortrait python=3.10
conda activate LivePortraitFor Linux π§ or Windows πͺ Users
X-Pose, required by Animals mode, is a dependency that needs to be installed. The step of Check your CUDA versions is optional if you only want to run Humans mode.
Check your CUDA versions
Firstly, check your current CUDA version by:
nvcc -V # example versions: 11.1, 11.8, 12.1, etc.Then, install the corresponding torch version. Here are examples for different CUDA versions. Visit the PyTorch Official Website for installation commands if your CUDA version is not listed:
# for CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# for CUDA 11.8
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
# for CUDA 12.1
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
# ...Note: On Windows systems, some higher versions of CUDA (such as 12.4, 12.6, etc.) may lead to unknown issues. You may consider downgrading CUDA to version 11.8 for stability. See the downgrade guide by @dimitribarbot.
Finally, install the remaining dependencies:
pip install -r requirements.txtFor macOS ο£Ώ with Apple Silicon Users
The X-Pose dependency does not support macOS, so you can skip its installation. While Humans mode works as usual, Animals mode is not supported. Use the provided requirements file for macOS with Apple Silicon:
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt2. Download pretrained weights π₯
The easiest way to download the pretrained weights is from HuggingFace:
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"If you cannot access to Huggingface, you can use hf-mirror to download:
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"Alternatively, you can download all pretrained weights from Google Drive or Baidu Yun. Unzip and place them in ./pretrained_weights.
Ensuring the directory structure is as or contains this.
3. Inference π
Fast hands-on (humans) π€
# For Linux and Windows users
python inference.py
# For macOS users with Apple Silicon (Intel is not tested). NOTE: this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.pyIf the script runs successfully, you will get an output mp4 file named animations/s6--d0_concat.mp4. This file includes the following results: driving video, input image or video, and generated result.
Or, you can change the input by specifying the -s and -d arguments:
# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4
# source input is a video β¨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4
# more options to see
python inference.py -hFast hands-on (animals) π±πΆ
Animals mode is ONLY tested on Linux and Windows with NVIDIA GPU.
You need to build an OP named MultiScaleDeformableAttention first (refer to the Check your CUDA versions if needed), which is used by X-Pose, a general keypoint detection framework.
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # equal to cd ../../../../../../../Then
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitchingIf the script runs successfully, you will get an output mp4 file named animations/s39--wink_concat.mp4.
Driving video auto-cropping π’π’π’
[!IMPORTANT]
To use your own driving video, we recommend: β¬οΈ
- Crop it to a 1:1 aspect ratio (e.g., 512x512 or 256x256 pixels), or enable auto-cropping by
--flag_crop_driving_video.- Focus on the head area, similar to the example videos.
- Minimize shoulder movement.
- Make sure the first frame of driving video is a frontal face with neutral expression.
Below is an auto-cropping case by --flag_crop_driving_video:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_videoIf you find the results of auto-cropping is not well, you can modify the --scale_crop_driving_video, --vy_ratio_crop_driving_video options to adjust the scale and offset, or do it manually.
Motion template making
You can also use the auto-generated motion template files ending with .pkl to speed up inference, and protect privacy, such as:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing4. Gradio interface π€
We also provide a Gradio interface for a better experience, just run by:
# For Linux and Windows users (and macOS with Intel??)
python app.py # humans mode
# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py # humans modeWe also provide a Gradio interface of animals mode, which is only tested on Linux with NVIDIA GPU:
python app_animals.py # animals mode π±πΆYou can specify the --server_port, --share, --server_name arguments to satisfy your needs!
π We also provide an acceleration option --flag_do_torch_compile. The first-time inference triggers an optimization process (about one minute), making subsequent inferences 20-30% faster. Performance gains may vary with different CUDA versions.
# enable torch.compile for faster inference
python app.py --flag_do_torch_compileNote: This method is not supported on Windows and macOS.
Or, try it out effortlessly on HuggingFace π€
5. Inference speed evaluation πππ
We have also provided a script to evaluate the inference speed of each module:
# For NVIDIA GPU
python speed.pyThe results are here.
Community Resources π€
Discover the invaluable resources contributed by our community to enhance your LivePortrait experience.
Community-developed Projects
| Repo | Description | Author / Links |
|---|---|---|
| AVTR-1 | Real-time conversational talking-head model using dyadic audio conditioning and a LivePortrait-style portrait-warping renderer. | @avaturn-live |
| ditto-talkinghead | Real-time audio-driven talking head. | ArXiv, Homepage |
| FasterLivePortrait | Faster real-time version using TensorRT. | @warmshao |
| AdvancedLivePortrait-WebUI | Dedicated gradio based WebUI started from ComfyUI-AdvancedLivePortrait. | @jhj0517 |
| FacePoke | A real-time head transformation app, controlled by your mouse! | @jbilcke-hf |
| FaceFusion | FaceFusion 3.0 integregates LivePortrait as expression_restorer and face_editor processors. |
@henryruhs |
| sd-webui-live-portrait | WebUI extension of LivePortrait, adding atab to the original Stable Diffusion WebUI to benefit from LivePortrait features. | @dimitribarbot |
| ComfyUI-LivePortraitKJ | A ComfyUI node to use LivePortrait, with MediaPipe as as an alternative to Insightface. | @kijai |
| ComfyUI-AdvancedLivePortrait | A faster ComfyUI node with real-time preview that has inspired many other community-developed tools and projects. | @PowerHouseMan |
| comfyui-liveportrait | A ComfyUI node to use LivePortrait, supporting multi-faces, expression interpolation etc, with a tutorial. | @shadowcz007 |
Playgrounds, π€ HuggingFace Spaces and Others
- FacePoke Space
- Expression Editor Space
- Expression Editor Replicate
- Face Control Realtime Demo on FAL
- Replicate Playground
- Nuke can use LivePortrait through CompyUI node, details here
- LivePortrait lives on Poe
Video Tutorials
- Workflow of LivePortrait Video to Video by @curiousrefuge
- Google Colab tutorial by @Planet Ai
- Paper reading by @TwoMinutePapers
- ComfyUI Advanced LivePortrait by TutoView
- LivePortarit exploration and A deep dive into LivePortrait by TheoreticallyMedia
- LivePortrait hands-on tutorial by @AI Search
- ComfyUI tutorial by @Sebastian Kamph
- A tutorial on BiliBili
And so MANY amazing contributions from our community, too many to list them all π
Acknowledgements π
We would like to thank the contributors of FOMM, Open Facevid2vid, SPADE, InsightFace and X-Pose repositories, for their open research and contributions.
Ethics Considerations π‘οΈ
Portrait animation technologies come with social risks, particularly the potential for misuse in creating deepfakes. To mitigate these risks, itβs crucial to follow ethical guidelines and adopt responsible usage practices. At present, the synthesized results contain visual artifacts that may help in detecting deepfakes. Please note that we do not assume any legal responsibility for the use of the results generated by this project.
Citation π
If you find LivePortrait useful for your project or research, welcome to π this repo and cite our work using the following BibTeX:
@article{guo2024liveportrait,
title = {LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control},
author = {Guo, Jianzhu and Zhang, Dingyun and Liu, Xiaoqiang and Zhong, Zhizhou and Zhang, Yuan and Wan, Pengfei and Zhang, Di},
journal = {arXiv preprint arXiv:2407.03168},
year = {2024}
}Long live in arXiv.
Contact π§
Jianzhu Guo (ιε»Ίη ); [email protected]
Star History π
Click to view Star chart
File: Readme.md
LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control
π₯ Updates
2025/06/01: π Over the past year, LivePortrait has π become an efficient portrait-animation (humans, cats and dogs) solution adopted by major video platformsβKuaishou, Douyin, Jianying, WeChat Channelsβas well as numerous startups and creators. π2025/01/01: πΆ We updated a new version of the Animals model with more data, see here.2024/10/18: β We have updated the versions of thetransformersandgradiolibraries to avoid security vulnerabilities. Details here.2024/08/29: π¦ We update the Windows one-click installer and support auto-updates, see changelog.2024/08/19: πΌοΈ We support image driven mode and regional control. For details, see here.2024/08/06: π¨ We support precise portrait editing in the Gradio interface, inspired by ComfyUI-AdvancedLivePortrait. See here.2024/08/05: π¦ Windows users can now download the one-click installer for Humans mode and Animals mode now! For details, see here.2024/08/02: πΈ We released a version of the Animals model, along with several other updates and improvements. Check out the details here!2024/07/25: π¦ Windows users can now download the package from HuggingFace. Simply unzip and double-clickrun_windows.batto enjoy!2024/07/24: π¨ We support pose editing for source portraits in the Gradio interface. Weβve also lowered the default detection threshold to increase recall. Have fun!2024/07/19: β¨ We support ποΈ portrait video editing (aka v2v)! More to see here.2024/07/17: π We support macOS with Apple Silicon, modified from jeethu's PR #143.2024/07/10: πͺ We support audio and video concatenating, driving video auto-cropping, and template making to protect privacy. More to see here.2024/07/09: π€ We released the HuggingFace Space, thanks to the HF team and Gradio!2024/07/04: π We released the initial version of the inference code and models. Continuous updates, stay tuned!2024/07/04: π₯ We released the homepage and technical report on arXiv.
Introduction π
This repo, named LivePortrait, contains the official PyTorch implementation of our paper LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control.
We are actively updating and improving this repository. If you find any bugs or have suggestions, welcome to raise issues or submit pull requests (PR) π.
Getting Started π
1. Clone the code and prepare the environment π οΈ
[!Note]
Make sure your system hasgit,conda, andFFmpeginstalled. For details on FFmpeg installation, see how to install FFmpeg.
git clone https://github.com/KlingTeam/LivePortrait
cd LivePortrait
# create env using conda
conda create -n LivePortrait python=3.10
conda activate LivePortraitFor Linux π§ or Windows πͺ Users
X-Pose, required by Animals mode, is a dependency that needs to be installed. The step of Check your CUDA versions is optional if you only want to run Humans mode.
Check your CUDA versions
Firstly, check your current CUDA version by:
nvcc -V # example versions: 11.1, 11.8, 12.1, etc.Then, install the corresponding torch version. Here are examples for different CUDA versions. Visit the PyTorch Official Website for installation commands if your CUDA version is not listed:
# for CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# for CUDA 11.8
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
# for CUDA 12.1
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
# ...Note: On Windows systems, some higher versions of CUDA (such as 12.4, 12.6, etc.) may lead to unknown issues. You may consider downgrading CUDA to version 11.8 for stability. See the downgrade guide by @dimitribarbot.
Finally, install the remaining dependencies:
pip install -r requirements.txtFor macOS ο£Ώ with Apple Silicon Users
The X-Pose dependency does not support macOS, so you can skip its installation. While Humans mode works as usual, Animals mode is not supported. Use the provided requirements file for macOS with Apple Silicon:
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt2. Download pretrained weights π₯
The easiest way to download the pretrained weights is from HuggingFace:
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"If you cannot access to Huggingface, you can use hf-mirror to download:
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"Alternatively, you can download all pretrained weights from Google Drive or Baidu Yun. Unzip and place them in ./pretrained_weights.
Ensuring the directory structure is as or contains this.
3. Inference π
Fast hands-on (humans) π€
# For Linux and Windows users
python inference.py
# For macOS users with Apple Silicon (Intel is not tested). NOTE: this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.pyIf the script runs successfully, you will get an output mp4 file named animations/s6--d0_concat.mp4. This file includes the following results: driving video, input image or video, and generated result.
Or, you can change the input by specifying the -s and -d arguments:
# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4
# source input is a video β¨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4
# more options to see
python inference.py -hFast hands-on (animals) π±πΆ
Animals mode is ONLY tested on Linux and Windows with NVIDIA GPU.
You need to build an OP named MultiScaleDeformableAttention first (refer to the Check your CUDA versions if needed), which is used by X-Pose, a general keypoint detection framework.
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # equal to cd ../../../../../../../Then
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitchingIf the script runs successfully, you will get an output mp4 file named animations/s39--wink_concat.mp4.
Driving video auto-cropping π’π’π’
[!IMPORTANT]
To use your own driving video, we recommend: β¬οΈ
- Crop it to a 1:1 aspect ratio (e.g., 512x512 or 256x256 pixels), or enable auto-cropping by
--flag_crop_driving_video.- Focus on the head area, similar to the example videos.
- Minimize shoulder movement.
- Make sure the first frame of driving video is a frontal face with neutral expression.
Below is an auto-cropping case by --flag_crop_driving_video:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_videoIf you find the results of auto-cropping is not well, you can modify the --scale_crop_driving_video, --vy_ratio_crop_driving_video options to adjust the scale and offset, or do it manually.
Motion template making
You can also use the auto-generated motion template files ending with .pkl to speed up inference, and protect privacy, such as:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing4. Gradio interface π€
We also provide a Gradio interface for a better experience, just run by:
# For Linux and Windows users (and macOS with Intel??)
python app.py # humans mode
# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py # humans modeWe also provide a Gradio interface of animals mode, which is only tested on Linux with NVIDIA GPU:
python app_animals.py # animals mode π±πΆYou can specify the --server_port, --share, --server_name arguments to satisfy your needs!
π We also provide an acceleration option --flag_do_torch_compile. The first-time inference triggers an optimization process (about one minute), making subsequent inferences 20-30% faster. Performance gains may vary with different CUDA versions.
# enable torch.compile for faster inference
python app.py --flag_do_torch_compileNote: This method is not supported on Windows and macOS.
Or, try it out effortlessly on HuggingFace π€
5. Inference speed evaluation πππ
We have also provided a script to evaluate the inference speed of each module:
# For NVIDIA GPU
python speed.pyThe results are here.
Community Resources π€
Discover the invaluable resources contributed by our community to enhance your LivePortrait experience.
Community-developed Projects
| Repo | Description | Author / Links |
|---|---|---|
| AVTR-1 | Real-time conversational talking-head model using dyadic audio conditioning and a LivePortrait-style portrait-warping renderer. | @avaturn-live |
| ditto-talkinghead | Real-time audio-driven talking head. | ArXiv, Homepage |
| FasterLivePortrait | Faster real-time version using TensorRT. | @warmshao |
| AdvancedLivePortrait-WebUI | Dedicated gradio based WebUI started from ComfyUI-AdvancedLivePortrait. | @jhj0517 |
| FacePoke | A real-time head transformation app, controlled by your mouse! | @jbilcke-hf |
| FaceFusion | FaceFusion 3.0 integregates LivePortrait as expression_restorer and face_editor processors. |
@henryruhs |
| sd-webui-live-portrait | WebUI extension of LivePortrait, adding atab to the original Stable Diffusion WebUI to benefit from LivePortrait features. | @dimitribarbot |
| ComfyUI-LivePortraitKJ | A ComfyUI node to use LivePortrait, with MediaPipe as as an alternative to Insightface. | @kijai |
| ComfyUI-AdvancedLivePortrait | A faster ComfyUI node with real-time preview that has inspired many other community-developed tools and projects. | @PowerHouseMan |
| comfyui-liveportrait | A ComfyUI node to use LivePortrait, supporting multi-faces, expression interpolation etc, with a tutorial. | @shadowcz007 |
Playgrounds, π€ HuggingFace Spaces and Others
- FacePoke Space
- Expression Editor Space
- Expression Editor Replicate
- Face Control Realtime Demo on FAL
- Replicate Playground
- Nuke can use LivePortrait through CompyUI node, details here
- LivePortrait lives on Poe
Video Tutorials
- Workflow of LivePortrait Video to Video by @curiousrefuge
- Google Colab tutorial by @Planet Ai
- Paper reading by @TwoMinutePapers
- ComfyUI Advanced LivePortrait by TutoView
- LivePortarit exploration and A deep dive into LivePortrait by TheoreticallyMedia
- LivePortrait hands-on tutorial by @AI Search
- ComfyUI tutorial by @Sebastian Kamph
- A tutorial on BiliBili
And so MANY amazing contributions from our community, too many to list them all π
Acknowledgements π
We would like to thank the contributors of FOMM, Open Facevid2vid, SPADE, InsightFace and X-Pose repositories, for their open research and contributions.
Ethics Considerations π‘οΈ
Portrait animation technologies come with social risks, particularly the potential for misuse in creating deepfakes. To mitigate these risks, itβs crucial to follow ethical guidelines and adopt responsible usage practices. At present, the synthesized results contain visual artifacts that may help in detecting deepfakes. Please note that we do not assume any legal responsibility for the use of the results generated by this project.
Citation π
If you find LivePortrait useful for your project or research, welcome to π this repo and cite our work using the following BibTeX:
@article{guo2024liveportrait,
title = {LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control},
author = {Guo, Jianzhu and Zhang, Dingyun and Liu, Xiaoqiang and Zhong, Zhizhou and Zhang, Yuan and Wan, Pengfei and Zhang, Di},
journal = {arXiv preprint arXiv:2407.03168},
year = {2024}
}Long live in arXiv.
Contact π§
Jianzhu Guo (ιε»Ίη ); [email protected]
Star History π
Click to view Star chart
File: readme.md
LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control
π₯ Updates
2025/06/01: π Over the past year, LivePortrait has π become an efficient portrait-animation (humans, cats and dogs) solution adopted by major video platformsβKuaishou, Douyin, Jianying, WeChat Channelsβas well as numerous startups and creators. π2025/01/01: πΆ We updated a new version of the Animals model with more data, see here.2024/10/18: β We have updated the versions of thetransformersandgradiolibraries to avoid security vulnerabilities. Details here.2024/08/29: π¦ We update the Windows one-click installer and support auto-updates, see changelog.2024/08/19: πΌοΈ We support image driven mode and regional control. For details, see here.2024/08/06: π¨ We support precise portrait editing in the Gradio interface, inspired by ComfyUI-AdvancedLivePortrait. See here.2024/08/05: π¦ Windows users can now download the one-click installer for Humans mode and Animals mode now! For details, see here.2024/08/02: πΈ We released a version of the Animals model, along with several other updates and improvements. Check out the details here!2024/07/25: π¦ Windows users can now download the package from HuggingFace. Simply unzip and double-clickrun_windows.batto enjoy!2024/07/24: π¨ We support pose editing for source portraits in the Gradio interface. Weβve also lowered the default detection threshold to increase recall. Have fun!2024/07/19: β¨ We support ποΈ portrait video editing (aka v2v)! More to see here.2024/07/17: π We support macOS with Apple Silicon, modified from jeethu's PR #143.2024/07/10: πͺ We support audio and video concatenating, driving video auto-cropping, and template making to protect privacy. More to see here.2024/07/09: π€ We released the HuggingFace Space, thanks to the HF team and Gradio!2024/07/04: π We released the initial version of the inference code and models. Continuous updates, stay tuned!2024/07/04: π₯ We released the homepage and technical report on arXiv.
Introduction π
This repo, named LivePortrait, contains the official PyTorch implementation of our paper LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control.
We are actively updating and improving this repository. If you find any bugs or have suggestions, welcome to raise issues or submit pull requests (PR) π.
Getting Started π
1. Clone the code and prepare the environment π οΈ
[!Note]
Make sure your system hasgit,conda, andFFmpeginstalled. For details on FFmpeg installation, see how to install FFmpeg.
git clone https://github.com/KlingTeam/LivePortrait
cd LivePortrait
# create env using conda
conda create -n LivePortrait python=3.10
conda activate LivePortraitFor Linux π§ or Windows πͺ Users
X-Pose, required by Animals mode, is a dependency that needs to be installed. The step of Check your CUDA versions is optional if you only want to run Humans mode.
Check your CUDA versions
Firstly, check your current CUDA version by:
nvcc -V # example versions: 11.1, 11.8, 12.1, etc.Then, install the corresponding torch version. Here are examples for different CUDA versions. Visit the PyTorch Official Website for installation commands if your CUDA version is not listed:
# for CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
# for CUDA 11.8
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
# for CUDA 12.1
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121
# ...Note: On Windows systems, some higher versions of CUDA (such as 12.4, 12.6, etc.) may lead to unknown issues. You may consider downgrading CUDA to version 11.8 for stability. See the downgrade guide by @dimitribarbot.
Finally, install the remaining dependencies:
pip install -r requirements.txtFor macOS ο£Ώ with Apple Silicon Users
The X-Pose dependency does not support macOS, so you can skip its installation. While Humans mode works as usual, Animals mode is not supported. Use the provided requirements file for macOS with Apple Silicon:
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt2. Download pretrained weights π₯
The easiest way to download the pretrained weights is from HuggingFace:
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"If you cannot access to Huggingface, you can use hf-mirror to download:
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download KlingTeam/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"Alternatively, you can download all pretrained weights from Google Drive or Baidu Yun. Unzip and place them in ./pretrained_weights.
Ensuring the directory structure is as or contains this.
3. Inference π
Fast hands-on (humans) π€
# For Linux and Windows users
python inference.py
# For macOS users with Apple Silicon (Intel is not tested). NOTE: this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.pyIf the script runs successfully, you will get an output mp4 file named animations/s6--d0_concat.mp4. This file includes the following results: driving video, input image or video, and generated result.
Or, you can change the input by specifying the -s and -d arguments:
# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4
# source input is a video β¨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4
# more options to see
python inference.py -hFast hands-on (animals) π±πΆ
Animals mode is ONLY tested on Linux and Windows with NVIDIA GPU.
You need to build an OP named MultiScaleDeformableAttention first (refer to the Check your CUDA versions if needed), which is used by X-Pose, a general keypoint detection framework.
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # equal to cd ../../../../../../../Then
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitchingIf the script runs successfully, you will get an output mp4 file named animations/s39--wink_concat.mp4.
Driving video auto-cropping π’π’π’
[!IMPORTANT]
To use your own driving video, we recommend: β¬οΈ
- Crop it to a 1:1 aspect ratio (e.g., 512x512 or 256x256 pixels), or enable auto-cropping by
--flag_crop_driving_video.- Focus on the head area, similar to the example videos.
- Minimize shoulder movement.
- Make sure the first frame of driving video is a frontal face with neutral expression.
Below is an auto-cropping case by --flag_crop_driving_video:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_videoIf you find the results of auto-cropping is not well, you can modify the --scale_crop_driving_video, --vy_ratio_crop_driving_video options to adjust the scale and offset, or do it manually.
Motion template making
You can also use the auto-generated motion template files ending with .pkl to speed up inference, and protect privacy, such as:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing4. Gradio interface π€
We also provide a Gradio interface for a better experience, just run by:
# For Linux and Windows users (and macOS with Intel??)
python app.py # humans mode
# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py # humans modeWe also provide a Gradio interface of animals mode, which is only tested on Linux with NVIDIA GPU:
python app_animals.py # animals mode π±πΆYou can specify the --server_port, --share, --server_name arguments to satisfy your needs!
π We also provide an acceleration option --flag_do_torch_compile. The first-time inference triggers an optimization process (about one minute), making subsequent inferences 20-30% faster. Performance gains may vary with different CUDA versions.
# enable torch.compile for faster inference
python app.py --flag_do_torch_compileNote: This method is not supported on Windows and macOS.
Or, try it out effortlessly on HuggingFace π€
5. Inference speed evaluation πππ
We have also provided a script to evaluate the inference speed of each module:
# For NVIDIA GPU
python speed.pyThe results are here.
Community Resources π€
Discover the invaluable resources contributed by our community to enhance your LivePortrait experience.
Community-developed Projects
| Repo | Description | Author / Links |
|---|---|---|
| AVTR-1 | Real-time conversational talking-head model using dyadic audio conditioning and a LivePortrait-style portrait-warping renderer. | @avaturn-live |
| ditto-talkinghead | Real-time audio-driven talking head. | ArXiv, Homepage |
| FasterLivePortrait | Faster real-time version using TensorRT. | @warmshao |
| AdvancedLivePortrait-WebUI | Dedicated gradio based WebUI started from ComfyUI-AdvancedLivePortrait. | @jhj0517 |
| FacePoke | A real-time head transformation app, controlled by your mouse! | @jbilcke-hf |
| FaceFusion | FaceFusion 3.0 integregates LivePortrait as expression_restorer and face_editor processors. |
@henryruhs |
| sd-webui-live-portrait | WebUI extension of LivePortrait, adding atab to the original Stable Diffusion WebUI to benefit from LivePortrait features. | @dimitribarbot |
| ComfyUI-LivePortraitKJ | A ComfyUI node to use LivePortrait, with MediaPipe as as an alternative to Insightface. | @kijai |
| ComfyUI-AdvancedLivePortrait | A faster ComfyUI node with real-time preview that has inspired many other community-developed tools and projects. | @PowerHouseMan |
| comfyui-liveportrait | A ComfyUI node to use LivePortrait, supporting multi-faces, expression interpolation etc, with a tutorial. | @shadowcz007 |
Playgrounds, π€ HuggingFace Spaces and Others
- FacePoke Space
- Expression Editor Space
- Expression Editor Replicate
- Face Control Realtime Demo on FAL
- Replicate Playground
- Nuke can use LivePortrait through CompyUI node, details here
- LivePortrait lives on Poe
Video Tutorials
- Workflow of LivePortrait Video to Video by @curiousrefuge
- Google Colab tutorial by @Planet Ai
- Paper reading by @TwoMinutePapers
- ComfyUI Advanced LivePortrait by TutoView
- LivePortarit exploration and A deep dive into LivePortrait by TheoreticallyMedia
- LivePortrait hands-on tutorial by @AI Search
- ComfyUI tutorial by @Sebastian Kamph
- A tutorial on BiliBili
And so MANY amazing contributions from our community, too many to list them all π
Acknowledgements π
We would like to thank the contributors of FOMM, Open Facevid2vid, SPADE, InsightFace and X-Pose repositories, for their open research and contributions.
Ethics Considerations π‘οΈ
Portrait animation technologies come with social risks, particularly the potential for misuse in creating deepfakes. To mitigate these risks, itβs crucial to follow ethical guidelines and adopt responsible usage practices. At present, the synthesized results contain visual artifacts that may help in detecting deepfakes. Please note that we do not assume any legal responsibility for the use of the results generated by this project.
Citation π
If you find LivePortrait useful for your project or research, welcome to π this repo and cite our work using the following BibTeX:
@article{guo2024liveportrait,
title = {LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control},
author = {Guo, Jianzhu and Zhang, Dingyun and Liu, Xiaoqiang and Zhong, Zhizhou and Zhang, Yuan and Wan, Pengfei and Zhang, Di},
journal = {arXiv preprint arXiv:2407.03168},
year = {2024}
}Long live in arXiv.
Contact π§
Jianzhu Guo (ιε»Ίη ); [email protected]
Star History π
Click to view Star chart
File: assets/docs/changelog/2024-07-10.md
2024/07/10
First, thank you all for your attention, support, sharing, and contributions to LivePortrait! β€οΈ
The popularity of LivePortrait has exceeded our expectations. If you encounter any issues or other problems and we do not respond promptly, please accept our apologies. We are still actively updating and improving this repository.
Updates
**Audio and video concatenating: ** If the driving video contains audio, it will automatically be included in the generated video. Additionally, the generated video will maintain the same FPS as the driving video. If you run LivePortrait on Windows, you need to install
ffprobeandffmpegexe, see issue #94.**Driving video auto-cropping: ** Implemented automatic cropping for driving videos by tracking facial landmarks and calculating a global cropping box with a 1:1 aspect ratio. Alternatively, you can crop using video editing software or other tools to achieve a 1:1 ratio. Auto-cropping is not enbaled by default, you can specify it by
--flag_crop_driving_video.**Motion template making: ** Added the ability to create motion templates to protect privacy. The motion template is a
.pklfile that only contains the motions of the driving video. Theoretically, it is impossible to reconstruct the original face from the template. These motion templates can be used to generate videos without needing the original driving video. By default, the motion template will be generated and saved as a.pklfile with the same name as the driving video, e.g.,d0.mp4->d0.pkl. Once generated, you can specify it using the-dor--drivingoption.
About driving video
- For a guide on using your own driving video, see the driving video auto-cropping section.
Others
- If you encounter a black box problem, disable half-precision inference by using
--no_flag_use_half_precision, reported by issue #40, #48, #62.
File: assets/docs/changelog/2024-07-19.md
2024/07/19
Once again, we would like to express our heartfelt gratitude for your love, attention, and support for LivePortrait! π
We are excited to announce the release of an implementation of Portrait Video Editing (aka v2v) today! Special thanks to the hard work of the LivePortrait team: Dingyun Zhang, Zhizhou Zhong, and Jianzhu Guo.
Updates
Portrait video editing (v2v): Implemented a version of Portrait Video Editing (aka v2v). Ensure you have
pykalmanpackage installed, which has been added inrequirements_base.txt. You can specify the source video using the-sor--sourceoption, adjust the temporal smoothness of motion with--driving_smooth_observation_variance, enable head pose motion transfer with--flag_video_editing_head_rotation, and ensure the eye-open scalar of each source frame matches the first source frame before animation with--flag_source_video_eye_retargeting.More options in Gradio: We have upgraded the Gradio interface and added more options. These include
Cropping Options for Source Image or VideoandCropping Options for Driving Video, providing greater flexibility and control.
Community Contributions
- ONNX/TensorRT Versions of LivePortrait: Explore optimized versions of LivePortrait for faster performance:
- LivePortrait with X-Pose Detection: Check out LivePortrait by ShiJiaying for enhanced detection capabilities using X-pose, see #119.
File: assets/docs/changelog/2024-07-24.md
2024/07/24
Updates
- Portrait pose editing: You can change the
relative pitch,relative yaw, andrelative rollin the Gradio interface to adjust the pose of the source portrait. - Detection threshold: We have added a
--det_threshargument with a default value of 0.15 to increase recall, meaning more types of faces (e.g., monkeys, human-like) will be detected. You can set it to other values, e.g., 0.5, by usingpython app.py --det_thresh 0.5.
File: assets/docs/changelog/2024-08-02.md
2024/08/02
| Animals Singing Dance Monkey π€ |
|---|
π We are excited to announce the release of a new version featuring animals mode, along with several other updates. Special thanks to the dedicated efforts of the LivePortrait team. πͺ We also provided an one-click installer for Windows users, checkout the details here.
Updates on Animals mode
We are pleased to announce the release of the animals mode, which is fine-tuned on approximately 230K frames of various animals (mostly cats and dogs). The trained weights have been updated in the liveportrait_animals subdirectory, available on HuggingFace or Google Drive. You should download the weights before running. There are two ways to run this mode.
Please note that we have not trained the stitching and retargeting modules for the animals model due to several technical issues. This may be addressed in future updates. Therefore, we recommend disabling stitching by setting the
--no_flag_stitchingoption when running the model. Additionally,paste-backis also not recommended.
Install X-Pose
We have chosen X-Pose as the keypoints detector for animals. This relies on transformers==4.22.0 and pillow>=10.2.0 (which are already updated in requirements.txt) and requires building an OP named MultiScaleDeformableAttention.
Refer to the PyTorch installation for Linux and Windows users.
Next, build the OP MultiScaleDeformableAttention by running:
cd src/utils/dependencies/XPose/models/UniPose/ops
python setup.py build install
cd - # this returns to the previous directoryTo run the model, use the inference_animals.py script:
python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --no_flag_stitching --driving_multiplier 1.75Alternatively, you can use Gradio for a more user-friendly interface. Launch it with:
python app_animals.py # --server_port 8889 --server_name "0.0.0.0" --share[!WARNING]
X-Pose is only for Non-commercial Scientific Research Purposes, you should remove and replace it with other detectors if you use it for commercial purposes.
Updates on Humans mode
Driving Options: We have introduced an
expression-friendlydriving option to reduce head wobbling, now set as the default. While it may be less effective with large head poses, you can also select thepose-friendlyoption, which is the same as the previous version. This can be set using--driving_optionor selected in the Gradio interface. Additionally, we added a--driving_multiplieroption to adjust driving intensity, with a default value of 1, which can also be set in the Gradio interface.Retargeting Video in Gradio: We have implemented a video retargeting feature. You can specify a
target lip-open ratioto adjust the mouth movement in the source video. For instance, setting it to 0 will close the mouth in the source video π€.
Others
- Poe supports LivePortrait. Check out the news on X.
- ComfyUI-LivePortraitKJ (1.1K π) now includes MediaPipe as an alternative to InsightFace, ensuring the license remains under MIT and Apache 2.0.
- ComfyUI-AdvancedLivePortrait features real-time portrait pose/expression editing and animation, and is registered with ComfyUI-Manager.
Below are some screenshots of the new features and improvements:
| The Gradio Interface of Animals Mode |
| Driving Options and Multiplier |
| The Feature of Retargeting Video |
File: assets/docs/changelog/2024-08-05.md
One-click Windows Installer
Download the installer from HuggingFace
# !pip install -U "huggingface_hub[cli]"
huggingface-cli download cleardusk/LivePortrait-Windows LivePortrait-Windows-v20240806.zip --local-dir ./If you cannot access to Huggingface, you can use hf-mirror to download:
# !pip install -U "huggingface_hub[cli]"
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download cleardusk/LivePortrait-Windows LivePortrait-Windows-v20240806.zip --local-dir ./Alternatively, you can manually download it from the HuggingFace page.
Then, simply unzip the package LivePortrait-Windows-v20240806.zip and double-click run_windows_human.bat for the Humans mode, or run_windows_animal.bat for the Animals mode.
File: assets/docs/changelog/2024-08-06.md
Precise Portrait Editing
Inspired by ComfyUI-AdvancedLivePortrait (@PowerHouseMan), we have implemented a version of Precise Portrait Editing in the Gradio interface. With each adjustment of the slider, the edited image updates in real-time. You can click the π Reset button to reset all slider parameters. However, the performance may not be as fast as the ComfyUI plugin.
File: assets/docs/changelog/2024-08-19.md
Image Driven and Regional Control
You can now use an image as a driving signal to drive the source image or video! Additionally, we have refined the driving options to support expressions, pose, lips, eyes, or all (all is consistent with the previous default method), which we name it regional control. The control is becoming more and more precise! π―
Please note that image-based driving or regional control may not perform well in certain cases. Feel free to try different options, and be patient. π
[!Note]
We recognize that the project now offers more options, which have become increasingly complex, but due to our limited team capacity and resources, we havenβt fully documented them yet. We ask for your understanding and will work to improve the documentation over time. Contributions via PRs are welcome! If anyone is considering donating or sponsoring, feel free to leave a message in the GitHub Issues or Discussions. We will set up a payment account to reward the team members or support additional efforts in maintaining the project. π
CLI Usage
It's very simple to use an image as a driving reference. Just set the -d argument to the driving image:
python inference.py -s assets/examples/source/s5.jpg -d assets/examples/driving/d30.jpgTo change the animation_region option, you can use the --animation_region argument to exp, pose, lip, eyes, or all. For example, to only drive the lip region, you can run by:
# only driving the lip region
python inference.py -s assets/examples/source/s5.jpg -d assets/examples/driving/d0.mp4 --animation_region lipGradio Interface
More Detailed Explanation
flag_relative_motion:
When using an image as the driving input, setting --flag_relative_motion to true will apply the motion deformation between the driving image and its canonical form. If set to false, the absolute motion of the driving image is used, which may amplify expression driving strength but could also cause identity leakage. This option corresponds to the relative motion toggle in the Gradio interface. Additionally, if both source and driving inputs are images, the output will be an image. If the source is a video and the driving input is an image, the output will be a video, with each frame driven by the image's motion. The Gradio interface automatically saves and displays the output in the appropriate format.
animation_region:
This argument offers five options:
exp: Only the expression of the driving input influences the source.pose: Only the head pose drives the source.lip: Only lip movement drives the source.eyes: Only eye movement drives the source.all: All motions from the driving input are applied.
You can also select these options directly in the Gradio interface.
Editing the Lip Region of the Source Video to a Neutral Expression:
In response to requests for a more neutral lip region in the Retargeting Video of the Gradio interface, we've added a keeping the lip silent option. When selected, the animated video's lip region will adopt a neutral expression. However, this may cause inter-frame jitter or identity leakage, as it uses a mode similar to absolute driving. Note that the neutral expression may sometimes feature a slightly open mouth.
Others:
When both source and driving inputs are videos, the output motion may be a blend of both, due to the default setting of --flag_relative_motion. This option uses relative driving, where the motion offset of the current driving frame relative to the first driving frame is added to the source frame's motion. In contrast, --no_flag_relative_motion applies the driving frame's motion directly as the final driving motion.
For CLI usage, to retain only the driving video's motion in the output, use:
python inference.py --no_flag_relative_motionIn the Gradio interface, simply uncheck the relative motion option. Note that absolute driving may cause jitter or identity leakage in the animated video.
File: assets/docs/changelog/2025-01-01.md
2025/01/01
Weβre thrilled that cats π± are now speaking and singing across the internet! πΆ
In this update, weβve improved the Animals model with more data. While you might notice only a slight improvement for cats (if at all πΌ), dogs have gotten a slightly better upgrade. For example, the model is now better at recognizing their mouths instead of mistaking them for noses. πΆ
| Before vs. After (v1.1) |
|---|
The new version (v1.1) Animals Model has been updated on HuggingFace. The new version is enabled by default.
[!IMPORTANT]
Note: Make sure to update your weights to use the new version.
If you prefer to use the original version, simply modify the configuration in inference_config.py
version_animals = "" # old version
# version_animals = "_v1.1" # new (v1.1) versionFile: assets/docs/directory-structure.md
The directory structure of `pretrained_weights`
pretrained_weights
βββ insightface
β βββ models
β βββ buffalo_l
β βββ 2d106det.onnx
β βββ det_10g.onnx
βββ liveportrait
β βββ base_models
β β βββ appearance_feature_extractor.pth
β β βββ motion_extractor.pth
β β βββ spade_generator.pth
β β βββ warping_module.pth
β βββ landmark.onnx
β βββ retargeting_models
β βββ stitching_retargeting_module.pth
βββ liveportrait_animals
βββ base_models
β βββ appearance_feature_extractor.pth
β βββ motion_extractor.pth
β βββ spade_generator.pth
β βββ warping_module.pth
βββ retargeting_models
β βββ stitching_retargeting_module.pth
βββ xpose.pth