Home

Awesome

DiffusionVideoEditing

Official project repo for the paper "Speech Driven Video Editing via an Audio-Conditioned Diffusion Model"

https://github.com/DanBigioi/DiffusionVideoEditing/assets/44242832/474b1c06-daf7-4d79-ad30-247c0269b68c

network_diagram

Shoutout to https://github.com/Janspiry/Palette-Image-to-Image-Diffusion-Models ! Most of the code in this repo is taken from there. It's a really good implementation of the Palette image2image paper, so go check it out!

Additionally, make sure to check out the repo of our co-authors https://github.com/MStypulkowski/diffused-heads ! They utilise diffusion models for the related task of talking head generation.

You can check out some of our results on the project page found here: https://danbigioi.github.io/DiffusionVideoEditing/

To read our paper, click on this link: https://arxiv.org/abs/2301.04474 . Note that our paper is currently under review.

Set Up

This code was tested on using Python version 3.8.12 , and CUDA 11.0 . The listed requirements in the requirements.txt file are what we used, however one could use a more recent version of both CUDA and Pytorch, just note that you may have to deal with some dependency issues that should be easily solveable. If you run into any issues running the code, feel free to post them here.

To install the repository run the following commands:

  git clone https://github.com/DanBigioi/DiffusionVideoEditing.git

  cd DiffusionVideoEditing 

  pip install -r requirements.txt

Dataset Download

Next, from the root directory of the repo, create the following directories:

  mkdir datasets

  cd datasets

  mkdir CREMAD

  mkdir S1
  

For training/testing the multi-speaker model on the CREMA-D dataset, download the following zipped files, unzip them, and put them in the CREMAD folder:

For training/testing the single speaker model on identity S1 of the GRID dataset, download the following zipped files, unzip them, and put them in the S1 folder:

Also download the following folder called "Generated_Frames", unzip it, and place it in the datasets folder:

Its purpose is to store the frames generated during inference, and we have configured it to contain frame 0 of each video in the CREMA-D test set.

Model Weights Download

To download the pretrained model weights for our multi-speaker model, download the following zipped folder, unzip it, and place it in the weights folder:

To download the pretrained model weights for our single-speaker model, download the following .ckpt file and place it in the weights folder:

Training

In order to train your model from scratch on the preprocessed files we provide, simply run the following command:

python run.py -c config/audio_talking_heads.json -p train 

Just make sure you modify the config file to specify how many GPUs you want to use, and to point towards where you stored the train set files that you downloaded above. Additionally, modify the config file to say "resume_state": null . If you wish to resume training from the pretrained checkpoint we provide, simply modify the config to say "resume_state": "weights/multi-speaker_checkpoint/735".

Data Processing For Custom Training

To train a model from scratch on your own custom dataset, prepare the data in the following way:

Video Processing

Audio Processing

Once your data is correctly processed, you can now start training the model from scratch, just don't forget to modify the config/audio_talking_heads.json file to point towards your processed video frames and audio files.

Inference

Before running inference, make sure you download and unzip the Generated_Frames folder and placed it within the datasets folder. This folder will store the frames generated by the model.

Then, for the video you wish to modify, process it in the same way you would process the training set videos. That is, crop it, resize it, and extract the individual frames as described above. One extra step is needed though, move frame 0 into the Generated_Frames_Folder, and rename it from "ID_Caption_Emotion_Volume_000.png" to "Out_ID_Caption_Emotion_Volume_000.png". The audio is processed the same, just ensure that the name of the audio file is the same as the name of the original video ie. "ID_Caption_Emotion_Volume_000.wav".

This is necessary because our model is autoregressive and requires a "seed" frame to start the generation process. This is provided by frame 0. The "Generated_Frames" folder you unzipped should contain 820 such seed frames, each one corresponding to a video within the CREMA-D test set. Additionally, we already preprocess the videos within the CREMA-D test set for you, they can be found in the folder datasets/CREMAD/Cropped_Frames_Test.

To run inference, simply run

python run.py -c config/audio_talking_heads_inference.json -p infer 

Note that inference can only be run on a single GPU with a batch size of 1, and 0 num_workers. This is because the method is entirely autoregressive and relies on the previously generated frame to generate the following one. Make sure you modify the inference section of the json to point towards the frames you want to modify, and audio.

We are currently working on preparing an easier to use inference script, so stay tuned for updates there!

Once inference finishes running, the folder datasets/Generated_Frames will contain all the newly generated frames. To turn them into a video, use the two methods we provide in utils/make_video.py , namely the make_videos() and combine_audio_video() methods.