GitHub - bytedance/LatentSync: Taming Stable Diffusion for Lip Sync! (original) (raw)

LatentSync

arXiv arXiv arXiv Replicate

🔥 Updates

📖 Introduction

We present LatentSync, an end-to-end lip-sync method based on audio-conditioned latent diffusion models without any intermediate motion representation, diverging from previous diffusion-based lip-sync methods based on pixel-space diffusion or two-stage generation. Our framework can leverage the powerful capabilities of Stable Diffusion to directly model complex audio-visual correlations.

🏗️ Framework

LatentSync uses the Whisper to convert melspectrogram into audio embeddings, which are then integrated into the U-Net via cross-attention layers. The reference and masked frames are channel-wise concatenated with noised latents as the input of U-Net. In the training process, we use a one-step method to get estimated clean latents from predicted noises, which are then decoded to obtain the estimated clean frames. The TREPA, LPIPS and SyncNet losses are added in the pixel space.

🎬 Demo

Original video Lip-synced video
demo1_video.mp4 demo1_output.mp4
demo2_video.mp4 demo2_output.mp4
demo3_video.mp4 demo3_output.mp4
demo4_video.mp4 demo4_output.mp4
demo5_video.mp4 demo5_output.mp4

(Photorealistic videos are filmed by contracted models, and anime videos are from VASA-1 and EMO)

📑 Open-source Plan

🔧 Setting up the Environment

Install the required packages and download the checkpoints via:

If the download is successful, the checkpoints should appear as follows:

./checkpoints/
|-- latentsync_unet.pt
|-- whisper
|   `-- tiny.pt

Or you can download latentsync_unet.pt and tiny.pt manually from our HuggingFace repo

🚀 Inference

Minimum VRAM for inference:

There are two ways to perform inference:

1. Gradio App

Run the Gradio app for inference:

2. Command Line Interface

Run the script for inference:

You can try adjusting the following inference parameters to achieve better results:

🔄 Data Processing Pipeline

The complete data processing pipeline includes the following steps:

  1. Remove the broken video files.
  2. Resample the video FPS to 25, and resample the audio to 16000 Hz.
  3. Scene detect via PySceneDetect.
  4. Split each video into 5-10 second segments.
  5. Affine transform the faces according to the landmarks detected by InsightFace, then resize to 256 times\timestimes 256.
  6. Remove videos with sync confidence score lower than 3, and adjust the audio-visual offset to 0.
  7. Calculate hyperIQA score, and remove videos with scores lower than 40.

Run the script to execute the data processing pipeline:

./data_processing_pipeline.sh

You should change the parameter input_dir in the script to specify the data directory to be processed. The processed videos will be saved in the high_visual_quality directory. Each step will generate a new directory to prevent the need to redo the entire pipeline in case the process is interrupted by an unexpected error.

🏋️‍♂️ Training U-Net

Before training, you should process the data as described above. We released a pretrained SyncNet with 94% accuracy on both VoxCeleb2 and HDTF datasets for the supervision of U-Net training. You can execute the following command to download this SyncNet checkpoint:

huggingface-cli download ByteDance/LatentSync-1.6 stable_syncnet.pt --local-dir checkpoints

If all the preparations are complete, you can train the U-Net with the following script:

We prepared several UNet configuration files in the configs/unet directory, each corresponding to a specific training setup:

Also remember to change the parameters in U-Net config file to specify the data directory, checkpoint save path, and other training hyperparameters. For convenience, we prepared a script for writing a data files list. Run the following command:

python -m tools.write_fileslist

🏋️‍♂️ Training SyncNet

In case you want to train SyncNet on your own datasets, you can run the following script. The data processing pipeline for SyncNet is the same as U-Net.

After validations_steps training, the loss charts will be saved in train_output_dir. They contain both the training and validation loss. If you want to customize the architecture of SyncNet for different image resolutions and input frame lengths, please follow the guide.

📊 Evaluation

You can evaluate the sync confidence score of a generated video by running the following script:

You can evaluate the accuracy of SyncNet on a dataset by running the following script:

./eval/eval_syncnet_acc.sh

Note that our released SyncNet is trained on data processed through our data processing pipeline, which includes special operations such as affine transformation and audio-visual adjustment. Therefore, before evaluation, the test data must first be processed using the provided pipeline.

🙏 Acknowledgement

Thanks for their generous contributions to the open-source community!

📖 Citation

If you find our repo useful for your research, please consider citing our paper:

@article{li2024latentsync, title={LatentSync: Taming Audio-Conditioned Latent Diffusion Models for Lip Sync with SyncNet Supervision}, author={Li, Chunyu and Zhang, Chao and Xu, Weikai and Lin, Jingyu and Xie, Jinghui and Feng, Weiguo and Peng, Bingyue and Chen, Cunjian and Xing, Weiwei}, journal={arXiv preprint arXiv:2412.09262}, year={2024} }