MCPcopy
hub / github.com/Picsart-AI-Research/Text2Video-Zero

github.com/Picsart-AI-Research/Text2Video-Zero @main sqlite

repository ↗ · DeepWiki ↗
2,169 symbols 6,428 edges 354 files 968 documented · 45%
README

Text2Video-Zero

This repository is the official implementation of Text2Video-Zero.

Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Generators

Levon Khachatryan, Andranik Movsisyan, Vahram Tadevosyan, Roberto Henschel, Zhangyang Wang, Shant Navasardyan, Humphrey Shi

Paper | Video | Hugging Face Spaces | Project

Our method Text2Video-Zero enables zero-shot video generation using (i) a textual prompt (see rows 1, 2), (ii) a prompt combined with guidance from poses or edges (see lower right), and (iii) Video Instruct-Pix2Pix, i.e., instruction-guided video editing (see lower left). Results are temporally consistent and follow closely the guidance and textual prompts.

News

  • [03/23/2023] Paper Text2Video-Zero released!
  • [03/25/2023] The first version of our huggingface demo (containing zero-shot text-to-video generation and Video Instruct Pix2Pix) released!
  • [03/27/2023] The full version of our huggingface demo released! Now also included: text and pose conditional video generation, text and edge conditional video generation, and text, edge and dreambooth conditional video generation.
  • [03/28/2023] Code for all our generation methods released! We added a new low-memory setup. Minimum required GPU VRAM is currently 12 GB. It will be further reduced in the upcoming releases.
  • [03/29/2023] Improved Huggingface demo! (i) For text-to-video generation, any base model for stable diffusion and any dreambooth model hosted on huggingface can now be loaded! (ii) We improved the quality of Video Instruct-Pix2Pix. (iii) We added two longer examples for Video Instruct-Pix2Pix.
  • [03/30/2023] New code released! It includes all improvements of our latest huggingface iteration. See the news update from 03/29/2023. In addition, generated videos (text-to-video) can have arbitrary length.
  • [04/06/2023] We integrated Token Merging into our code. When the highest compression is used and chunk size set to 2, our code can run with less than 7 GB VRAM.
  • [04/11/2023] New code and Huggingface demo released! We integrated depth control, based on MiDaS.
  • [04/13/2023] Our method has been integrad into 🧨 Diffusers!

Contribute

We are on a journey to democratize AI and empower the creativity of everyone, and we believe Text2Video-Zero is a great research direction to unleash the zero-shot video generation and editing capacity of the amazing text-to-image models!

To achieve this goal, all contributions are welcome. Please check out these external implementations and extensions of Text2Video-Zero. We thank the authors for their efforts and contributions: * https://github.com/JiauZhang/Text2Video-Zero * https://github.com/camenduru/text2video-zero-colab * https://github.com/SHI-Labs/Text2Video-Zero-sd-webui

Setup

  1. Clone this repository and enter:
git clone https://github.com/Picsart-AI-Research/Text2Video-Zero.git
cd Text2Video-Zero/
  1. Install requirements using Python 3.9 and CUDA >= 11.6
virtualenv --system-site-packages -p python3.9 venv
source venv/bin/activate
pip install -r requirements.txt

Inference API

To run inferences create an instance of Model class

import torch
from model import Model

model = Model(device = "cuda", dtype = torch.float16)

Text-To-Video

To directly call our text-to-video generator, run this python command which stores the result in tmp/text2video/A_horse_galloping_on_a_street.mp4 :

prompt = "A horse galloping on a street"
params = {"t0": 44, "t1": 47 , "motion_field_strength_x" : 12, "motion_field_strength_y" : 12, "video_length": 8}

out_path, fps = f"./text2video_{prompt.replace(' ','_')}.mp4", 4
model.process_text2video(prompt, fps = fps, path = out_path, **params)

To use a different stable diffusion base model run this python command:

from hf_utils import get_model_list
model_list = get_model_list()
for idx, name in enumerate(model_list):
  print(idx, name)
idx = int(input("Select the model by the listed number: ")) # select the model of your choice
model.process_text2video(prompt, model_name = model_list[idx], fps = fps, path = out_path, **params)

Hyperparameters (Optional)

You can define the following hyperparameters: * Motion field strength: motion_field_strength_x = $\delta_x$ and motion_field_strength_y = $\delta_y$ (see our paper, Sect. 3.3.1). Default: motion_field_strength_x=motion_field_strength_y= 12. * $T$ and $T'$ (see our paper, Sect. 3.3.1). Define values t0 and t1 in the range {0,...,50}. Default: t0=44, t1=47 (DDIM steps). Corresponds to timesteps 881 and 941, respectively. * Video length: Define the number of frames video_length to be generated. Default: video_length=8.


Text-To-Video with Pose Control

To directly call our text-to-video generator with pose control, run this python command:

prompt = 'an astronaut dancing in outer space'
motion_path = '__assets__/poses_skeleton_gifs/dance1_corr.mp4'
out_path = f"./text2video_pose_guidance_{prompt.replace(' ','_')}.gif"
model.process_controlnet_pose(motion_path, prompt=prompt, save_path=out_path)

Text-To-Video with Edge Control

To directly call our text-to-video generator with edge control, run this python command:

prompt = 'oil painting of a deer, a high-quality, detailed, and professional photo'
video_path = '__assets__/canny_videos_mp4/deer.mp4'
out_path = f'./text2video_edge_guidance_{prompt}.mp4'
model.process_controlnet_canny(video_path, prompt=prompt, save_path=out_path)

Hyperparameters

You can define the following hyperparameters for Canny edge detection: * low threshold. Define value low_threshold in the range $(0, 255)$. Default: low_threshold=100. * high threshold. Define value high_threshold in the range $(0, 255)$. Default: high_threshold=200. Make sure that high_threshold > low_threshold.

You can give hyperparameters as arguments to model.process_controlnet_canny


Text-To-Video with Edge Guidance and Dreambooth specialization

Load a dreambooth model then proceed as described in Text-To-Video with Edge Guidance


prompt = 'your prompt'
video_path = 'path/to/your/video'
dreambooth_model_path = 'path/to/your/dreambooth/model'
out_path = f'./text2video_edge_db_{prompt}.gif'
model.process_controlnet_canny_db(dreambooth_model_path, video_path, prompt=prompt, save_path=out_path)

The value video_path can be the path to a mp4 file. To use one of the example videos provided, set video_path="woman1", video_path="woman2", video_path="woman3", or video_path="man1".

The value dreambooth_model_path can either be a link to a diffuser model file, or the name of one of the dreambooth models provided. To this end, set dreambooth_model_path = "Anime DB", dreambooth_model_path = "Avatar DB", dreambooth_model_path = "GTA-5 DB", or dreambooth_model_path = "Arcane DB". The corresponding keywords are: 1girl (for Anime DB), arcane style (for Arcane DB) avatar style (for Avatar DB) and gtav style (for GTA-5 DB).

Custom Dreambooth Models

To load custom Dreambooth models, transfer control to the custom model and convert it to diffuser format. Then, the value of dreambooth_model_path must link to the folder containing the diffuser file. Dreambooth models can be obtained, for instance, from CIVITAI.


Video Instruct-Pix2Pix

To perform pix2pix video editing, run this python command:

prompt = 'make it Van Gogh Starry Night'
video_path = '__assets__/pix2pix video/camel.mp4'
out_path = f'./video_instruct_pix2pix_{prompt}.mp4'
model.process_pix2pix(video_path, prompt=prompt, save_path=out_path)

Text-To-Video with Depth Control

To directly call our text-to-video generator with depth control, run this python command:

prompt = 'oil painting of a deer, a high-quality, detailed, and professional photo'
video_path = '__assets__/depth_videos/deer.mp4'
out_path = f'./text2video_depth_control_{prompt}.mp4'
model.process_controlnet_depth(video_path, prompt=prompt, save_path=out_path)

Low Memory Inference

Each of the above introduced interface can be run in a low memory setup. In the minimal setup, a GPU with 12 GB VRAM is sufficient.

To reduce the memory usage, add chunk_size=k as additional parameter when calling one of the above defined inference APIs. The integer value k must be in the range {2,...,video_length}. It defines the number of frames that are processed at once (without any loss in quality). The lower the value the less memory is needed.

When using the gradio app, set chunk_size in the Advanced options.

Thanks to the great work of Token Merging, the memory usage can be further reduced. It can be configured using the merging_ratio parameter with values in [0,1]. The higher the value, the more compression is applied (leading to faster inference and less memory requirements). Be aware that too high values will decrease the image quality.

We plan to continue optimizing our code to enable even lower memory consumption.


Ablation Study

To replicate the ablation study, add additional parameters when calling the above defined inference APIs. * To deactivate cross-frame attention: Add use_cf_attn=False to the parameter list. * To deactivate enriching latent codes with motion dynamics: Add use_motion_field=False to the parameter list.

Note: Adding smooth_bg=True activates background smoothing. However, our code does not include the salient object detector necessary to run that code.


Inference using Gradio

Click to see details.

From the project root folder, run this shell command:

python app.py

Then access the app locally with a browser.

To access the app remotely, run this shell command:

python app.py --public_access

For security information about public access we refer to the documentation of gradio.


Results

Text-To-Video

"A cat is running on the grass" "A panda is playing guitar on times square" "A man is running in the snow" "An astronaut is skiing down the hill"
"A panda surfing on a wakeboard" "A bear dancing on times square" "A man is riding a bicycle in the sunshine" "A horse galloping on a street"
"A tiger walking alone down the street" "A panda surfing on a wakeboard" "A horse galloping on a street" "A cute cat running in a beautiful meadow"
"A horse galloping on a street" "A panda walking alone down the street" "A dog is walking down the street" "An astronaut is waving his hands on the moon"

Text-To-Video with Pose Guidance

Core symbols most depended-on inside this repo

size
called by 241
annotator/uniformer/mmcv/video/io.py
get
called by 79
annotator/uniformer/mmcv/video/io.py
update
called by 54
annotator/uniformer/mmcv/runner/log_buffer.py
build_norm_layer
called by 38
annotator/uniformer/mmcv/cnn/bricks/norm.py
constant_init
called by 34
annotator/uniformer/mmcv/cnn/utils/weight_init.py
dim
called by 34
annotator/uniformer/mmcv/parallel/data_container.py
build_conv_layer
called by 33
annotator/uniformer/mmcv/cnn/bricks/conv.py
digit_version
called by 32
annotator/uniformer/mmcv/utils/version_utils.py

Shape

Method 1,293
Function 495
Class 380
Route 1

Languages

Python100%

Modules by API surface

annotator/uniformer/mmcv/fileio/file_client.py70 symbols
annotator/uniformer/mmseg/datasets/pipelines/transforms.py63 symbols
annotator/uniformer/mmcv/cnn/utils/weight_init.py56 symbols
annotator/uniformer/mmcv/runner/hooks/lr_updater.py46 symbols
annotator/uniformer/mmcv/utils/config.py39 symbols
annotator/uniformer/mmcv/runner/base_runner.py33 symbols
annotator/uniformer/mmseg/models/backbones/uniformer.py32 symbols
annotator/uniformer/mmcv/video/io.py32 symbols
annotator/uniformer/mmcv/cnn/utils/flops_counter.py32 symbols
annotator/uniformer/mmseg/models/backbones/resnet.py29 symbols
annotator/uniformer/mmcv/runner/checkpoint.py28 symbols
annotator/uniformer/mmcv/runner/hooks/momentum_updater.py26 symbols

Dependencies from manifests, versioned

Pillow9.4.0 · 1×
accelerate0.16.0 · 1×
addict2.4.0 · 1×
albumentations1.3.0 · 1×
basicsr1.4.2 · 1×
decord0.6.0 · 1×
diffusers0.14.0 · 1×
einops0.6.0 · 1×
gradio3.23.0 · 1×
imageio2.9.0 · 1×
imageio-ffmpeg0.4.2 · 1×

For agents

$ claude mcp add Text2Video-Zero \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact