Skip to content

MuseTalk: Real-Time High Quality Lip Synchorization with Latent Space Inpainting

License

Notifications You must be signed in to change notification settings

YankeeMarco/MuseTalk-docker

 
 

Repository files navigation

MuseTalk In Docker Container

MuseTalk: Real-Time High Quality Lip Synchronization with Latent Space Inpainting
Yue Zhang *, Minhao Liu*, Zhaokang Chen, Bin Wu, Yubin Zeng, Chao Zhan, Yingjie He, Junxin Huang, Wenjiang Zhou (*Equal Contribution, Corresponding Author, benbinwu@tencent.com)

Lyra Lab, Tencent Music Entertainment

github huggingface space Technical report

We introduce MuseTalk, a real-time high quality lip-syncing model (30fps+ on an NVIDIA Tesla V100). MuseTalk can be applied with input videos, e.g., generated by MuseV, as a complete virtual human solution.

🆕 Update: We are thrilled to announce that MusePose has been released. MusePose is an image-to-video generation framework for virtual human under control signal like pose. Together with MuseV and MuseTalk, we hope the community can join us and march towards the vision where a virtual human can be generated end2end with native ability of full body movement and interaction.

Overview

MuseTalk is a real-time high quality audio-driven lip-syncing model trained in the latent space of ft-mse-vae, which

  1. modifies an unseen face according to the input audio, with a size of face region of 256 x 256.
  2. supports audio in various languages, such as Chinese, English, and Japanese.
  3. supports real-time inference with 30fps+ on an NVIDIA Tesla V100.
  4. supports modification of the center point of the face region proposes, which SIGNIFICANTLY affects generation results.
  5. checkpoint available trained on the HDTF dataset.
  6. training codes (comming soon).

News

  • [04/02/2024] Release MuseTalk project and pretrained models.
  • [04/16/2024] Release Gradio demo on HuggingFace Spaces (thanks to HF team for their community grant)
  • [04/17/2024] : We release a pipeline that utilizes MuseTalk for real-time inference.
  • [10/18/2024] 📣 We release the technical report. Our report details a superior model to the open-source L1 loss version. It includes GAN and perceptual losses for improved clarity, and sync loss for enhanced performance.

Model

Model Structure MuseTalk was trained in latent spaces, where the images were encoded by a freezed VAE. The audio was encoded by a freezed whisper-tiny model. The architecture of the generation network was borrowed from the UNet of the stable-diffusion-v1-4, where the audio embeddings were fused to the image embeddings by cross-attention.

Note that although we use a very similar architecture as Stable Diffusion, MuseTalk is distinct in that it is NOT a diffusion model. Instead, MuseTalk operates by inpainting in the latent space with a single step.

these weights should be organized in models as follows:

./models/
├── musetalk
│   └── musetalk.json
│   └── pytorch_model.bin
├── dwpose
│   └── dw-ll_ucoco_384.pth
├── face-parse-bisent
│   ├── 79999_iter.pth
│   └── resnet18-5c106cde.pth
├── sd-vae-ft-mse
│   ├── config.json
│   └── diffusion_pytorch_model.bin
└── whisper
    └── tiny.pt

Docker container with docker-compose

Please note that this repository employs a temporary solution for handling model files. We recommend that you customize this approach to suit your needs, potentially by mounting external volumes containing the actual model files. In this context, we are treating the Docker image as an independent function to facilitate easier deployment.

To build the image: 
docker-compose -f Docker-compose.cuda.yml build

To run: 
docker-compose -f Docker-compose.cuda.yml up

To stop the container: 
docker-compose -f Docker-compose.cuda.yml down

To test in the container with interactive mode:
docker run musetalk-docker_musetalk -v ./:/app -p 7866:7866 -it /bin/bash



Quickstart

Inference

Here, we provide the inference script.

python -m scripts.inference --inference_config configs/inference/test.yaml 

configs/inference/test.yaml is the path to the inference configuration file, including video_path and audio_path. The video_path should be either a video file, an image file or a directory of images.

You are recommended to input video with 25fps, the same fps used when training the model. If your video is far less than 25fps, you are recommended to apply frame interpolation or directly convert the video to 25fps using ffmpeg.

Use of bbox_shift to have adjustable results

🔎 We have found that upper-bound of the mask has an important impact on mouth openness. Thus, to control the mask region, we suggest using the bbox_shift parameter. Positive values (moving towards the lower half) increase mouth openness, while negative values (moving towards the upper half) decrease mouth openness.

You can start by running with the default configuration to obtain the adjustable value range, and then re-run the script within this range.

For example, in the case of Xinying Sun, after running the default configuration, it shows that the adjustable value rage is [-9, 9]. Then, to decrease the mouth openness, we set the value to be -7.

python -m scripts.inference --inference_config configs/inference/test.yaml --bbox_shift -7 

📌 More technical details can be found in bbox_shift.

Combining MuseV and MuseTalk

As a complete solution to virtual human generation, you are suggested to first apply MuseV to generate a video (text-to-video, image-to-video or pose-to-video) by referring this. Frame interpolation is suggested to increase frame rate. Then, you can use MuseTalk to generate a lip-sync video by referring this.

🆕 Real-time inference

Here, we provide the inference script. This script first applies necessary pre-processing such as face detection, face parsing and VAE encode in advance. During inference, only UNet and the VAE decoder are involved, which makes MuseTalk real-time.

python -m scripts.realtime_inference --inference_config configs/inference/realtime.yaml --batch_size 4

configs/inference/realtime.yaml is the path to the real-time inference configuration file, including preparation, video_path , bbox_shift and audio_clips.

  1. Set preparation to True in realtime.yaml to prepare the materials for a new avatar. (If the bbox_shift has changed, you also need to re-prepare the materials.)
  2. After that, the avatar will use an audio clip selected from audio_clips to generate video.
    Inferring using: data/audio/yongen.wav
    
  3. While MuseTalk is inferring, sub-threads can simultaneously stream the results to the users. The generation process can achieve 30fps+ on an NVIDIA Tesla V100.
  4. Set preparation to False and run this script if you want to genrate more videos using the same avatar.
Note for Real-time inference
  1. If you want to generate multiple videos using the same avatar/video, you can also use this script to SIGNIFICANTLY expedite the generation process.
  2. In the previous script, the generation time is also limited by I/O (e.g. saving images). If you just want to test the generation speed without saving the images, you can run
python -m scripts.realtime_inference --inference_config configs/inference/realtime.yaml --skip_save_images

Acknowledgement

  1. We thank open-source components like whisper, dwpose, face-alignment, face-parsing, S3FD.
  2. MuseTalk has referred much to diffusers and isaacOnline/whisper.
  3. MuseTalk has been built on HDTF datasets.

Thanks for open-sourcing!

Limitations

  • Resolution: Though MuseTalk uses a face region size of 256 x 256, which make it better than other open-source methods, it has not yet reached the theoretical resolution bound. We will continue to deal with this problem.
    If you need higher resolution, you could apply super resolution models such as GFPGAN in combination with MuseTalk.

  • Identity preservation: Some details of the original face are not well preserved, such as mustache, lip shape and color.

  • Jitter: There exists some jitter as the current pipeline adopts single-frame generation.

Citation

@article{musetalk,
  title={MuseTalk: Real-Time High Quality Lip Synchorization with Latent Space Inpainting},
  author={Zhang, Yue and Liu, Minhao and Chen, Zhaokang and Wu, Bin and Zeng, Yubin and Zhan, Chao and He, Yingjie and Huang, Junxin and Zhou, Wenjiang},
  journal={arxiv},
  year={2024}
}

Disclaimer/License

  1. code: The code of MuseTalk is released under the MIT License. There is no limitation for both academic and commercial usage.
  2. model: The trained model are available for any purpose, even commercially.
  3. other opensource model: Other open-source models used must comply with their license, such as whisper, ft-mse-vae, dwpose, S3FD, etc..
  4. The testdata are collected from internet, which are available for non-commercial research purposes only.
  5. AIGC: This project strives to impact the domain of AI-driven video generation positively. Users are granted the freedom to create videos using this tool, but they are expected to comply with local laws and utilize it responsibly. The developers do not assume any responsibility for potential misuse by users.

About

MuseTalk: Real-Time High Quality Lip Synchorization with Latent Space Inpainting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.9%
  • Shell 0.1%