Text2Video-Zero

Text2Video-Zero

Text2Video-Zero: Text-to-Image Diffusion Models are Zero-Shot Video Generatorsarrow-up-right is by Levon Khachatryan, Andranik Movsisyan, Vahram Tadevosyan, Roberto Henschel, Zhangyang Wangarrow-up-right, Shant Navasardyan, Humphrey Shiarrow-up-right.

Text2Video-Zero enables zero-shot video generation using either:

  1. A textual prompt

  2. A prompt combined with guidance from poses or edges

  3. Video Instruct-Pix2Pix (instruction-guided video editing)

Results are temporally consistent and closely follow the guidance and textual prompts.

teaser-img

The abstract from the paper is:

Recent text-to-video generation approaches rely on computationally heavy training and require large-scale video datasets. In this paper, we introduce a new task of zero-shot text-to-video generation and propose a low-cost approach (without any training or optimization) by leveraging the power of existing text-to-image synthesis methods (e.g., Stable Diffusion), making them suitable for the video domain. Our key modifications include (i) enriching the latent codes of the generated frames with motion dynamics to keep the global scene and the background time consistent; and (ii) reprogramming frame-level self-attention using a new cross-frame attention of each frame on the first frame, to preserve the context, appearance, and identity of the foreground object. Experiments show that this leads to low overhead, yet high-quality and remarkably consistent video generation. Moreover, our approach is not limited to text-to-video synthesis but is also applicable to other tasks such as conditional and content-specialized video generation, and Video Instruct-Pix2Pix, i.e., instruction-guided video editing. As experiments show, our method performs comparably or sometimes better than recent approaches, despite not being trained on additional video data.

You can find additional information about Text-to-Video Zero on the project pagearrow-up-right, paperarrow-up-right, and original codebasearrow-up-right.

Usage example

Text-To-Video

To generate a video from prompt, run the following python command

Copied

You can change these parameters in the pipeline call:

  • Motion field strength (see the paperarrow-up-right, Sect. 3.3.1):

    • motion_field_strength_x and motion_field_strength_y. Default: motion_field_strength_x=12, motion_field_strength_y=12

  • T and T' (see the paperarrow-up-right, Sect. 3.3.1)

    • t0 and t1 in the range {0, ..., num_inference_steps}. Default: t0=45, t1=48

  • Video length:

    • video_length, the number of frames video_length to be generated. Default: video_length=8

We an also generate longer videos by doing the processing in a chunk-by-chunk manner:

Copied

Text-To-Video with Pose Control

To generate a video from prompt with additional pose control

  1. Download a demo video

    Copied

  2. Read video containing extracted pose images

    Copied

    To extract pose from actual video, read ControlNet documentationarrow-up-right.

  3. Run StableDiffusionControlNetPipeline with our custom attention processor

    Copied

Text-To-Video with Edge Control

To generate a video from prompt with additional pose control, follow the steps described above for pose-guided generation using Canny edge ControlNet modelarrow-up-right.

Video Instruct-Pix2Pix

To perform text-guided video editing (with InstructPix2Pixarrow-up-right):

  1. Download a demo video

    Copied

  2. Read video from path

    Copied

  3. Run StableDiffusionInstructPix2PixPipeline with our custom attention processor

    Copied

DreamBooth specialization

Methods Text-To-Video, Text-To-Video with Pose Control and Text-To-Video with Edge Control can run with custom DreamBootharrow-up-right models, as shown below for Canny edge ControlNet modelarrow-up-right and Avatar style DreamBootharrow-up-right model

  1. Download a demo video

    Copied

  2. Read video from path

    Copied

  3. Run StableDiffusionControlNetPipeline with custom trained DreamBooth model

    Copied

You can filter out some available DreamBooth-trained models with this linkarrow-up-right.

TextToVideoZeroPipeline

class diffusers.TextToVideoZeroPipeline

<source>arrow-up-right

( vae: AutoencoderKLtext_encoder: CLIPTextModeltokenizer: CLIPTokenizerunet: UNet2DConditionModelscheduler: KarrasDiffusionSchedulerssafety_checker: StableDiffusionSafetyCheckerfeature_extractor: CLIPImageProcessorrequires_safety_checker: bool = True )

Parameters

Pipeline for zero-shot text-to-video generation using Stable Diffusion.

This model inherits from DiffusionPipelinearrow-up-right. Check the superclass documentation for the generic methods implemented for all pipelines (downloading, saving, running on a particular device, etc.).

__call__

<source>arrow-up-right

( prompt: typing.Union[str, typing.List[str]]video_length: typing.Optional[int] = 8height: typing.Optional[int] = Nonewidth: typing.Optional[int] = Nonenum_inference_steps: int = 50guidance_scale: float = 7.5negative_prompt: typing.Union[str, typing.List[str], NoneType] = Nonenum_videos_per_prompt: typing.Optional[int] = 1eta: float = 0.0generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = Nonelatents: typing.Optional[torch.FloatTensor] = Nonemotion_field_strength_x: float = 12motion_field_strength_y: float = 12output_type: typing.Optional[str] = 'tensor'return_dict: bool = Truecallback: typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = Nonecallback_steps: typing.Optional[int] = 1t0: int = 44t1: int = 47frame_ids: typing.Optional[typing.List[int]] = None ) β†’ TextToVideoPipelineOutputarrow-up-right

Parameters

  • prompt (str or List[str], optional) β€” The prompt or prompts to guide image generation. If not defined, you need to pass prompt_embeds.

  • video_length (int, optional, defaults to 8) β€” The number of generated video frames.

  • height (int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) β€” The height in pixels of the generated image.

  • width (int, optional, defaults to self.unet.config.sample_size * self.vae_scale_factor) β€” The width in pixels of the generated image.

  • num_inference_steps (int, optional, defaults to 50) β€” The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference.

  • guidance_scale (float, optional, defaults to 7.5) β€” A higher guidance scale value encourages the model to generate images closely linked to the text prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1.

  • negative_prompt (str or List[str], optional) β€” The prompt or prompts to guide what to not include in video generation. If not defined, you need to pass negative_prompt_embeds instead. Ignored when not using guidance (guidance_scale < 1).

  • num_videos_per_prompt (int, optional, defaults to 1) β€” The number of videos to generate per prompt.

  • eta (float, optional, defaults to 0.0) β€” Corresponds to parameter eta (Ξ·) from the DDIMarrow-up-right paper. Only applies to the DDIMSchedulerarrow-up-right, and is ignored in other schedulers.

  • generator (torch.Generator or List[torch.Generator], optional) β€” A torch.Generatorarrow-up-right to make generation deterministic.

  • latents (torch.FloatTensor, optional) β€” Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for video generation. Can be used to tweak the same generation with different prompts. If not provided, a latents tensor is generated by sampling using the supplied random generator.

  • output_type (str, optional, defaults to "numpy") β€” The output format of the generated video. Choose between "latent" and "numpy".

  • return_dict (bool, optional, defaults to True) β€” Whether or not to return a TextToVideoPipelineOutputarrow-up-right instead of a plain tuple.

  • callback (Callable, optional) β€” A function that calls every callback_steps steps during inference. The function is called with the following arguments: callback(step: int, timestep: int, latents: torch.FloatTensor).

  • callback_steps (int, optional, defaults to 1) β€” The frequency at which the callback function is called. If not specified, the callback is called at every step.

  • motion_field_strength_x (float, optional, defaults to 12) β€” Strength of motion in generated video along x-axis. See the paperarrow-up-right, Sect. 3.3.1.

  • motion_field_strength_y (float, optional, defaults to 12) β€” Strength of motion in generated video along y-axis. See the paperarrow-up-right, Sect. 3.3.1.

  • t0 (int, optional, defaults to 44) β€” Timestep t0. Should be in the range [0, num_inference_steps - 1]. See the paperarrow-up-right, Sect. 3.3.1.

  • t1 (int, optional, defaults to 47) β€” Timestep t0. Should be in the range [t0 + 1, num_inference_steps - 1]. See the paperarrow-up-right, Sect. 3.3.1.

  • frame_ids (List[int], optional) β€” Indexes of the frames that are being generated. This is used when generating longer videos chunk-by-chunk.

Returns

TextToVideoPipelineOutputarrow-up-right

The output contains a ndarray of the generated video, when output_type != "latent", otherwise a latent code of generated videos and a list of bools indicating whether the corresponding generated video contains β€œnot-safe-for-work” (nsfw) content..

The call function to the pipeline for generation.

backward_loop

<source>arrow-up-right

( latentstimestepsprompt_embedsguidance_scalecallbackcallback_stepsnum_warmup_stepsextra_step_kwargscross_attention_kwargs = None ) β†’ latents

Parameters

  • callback (Callable, optional) β€” A function that calls every callback_steps steps during inference. The function is called with the following arguments: callback(step: int, timestep: int, latents: torch.FloatTensor).

  • callback_steps (int, optional, defaults to 1) β€” The frequency at which the callback function is called. If not specified, the callback is called at every step. extra_step_kwargs β€” Extra_step_kwargs. cross_attention_kwargs β€” A kwargs dictionary that if specified is passed along to the AttentionProcessor as defined in self.processorarrow-up-right. num_warmup_steps β€” number of warmup steps.

Returns

latents

Latents of backward process output at time timesteps[-1].

Perform backward process given list of time steps.

forward_loop

<source>arrow-up-right

( x_t0t0t1generator ) β†’ x_t1

Parameters

Returns

x_t1

Forward process applied to x_t0 from time t0 to t1.

Perform DDPM forward process from time t0 to t1. This is the same as adding noise with corresponding variance.

TextToVideoPipelineOutput

class diffusers.pipelines.text_to_video_synthesis.pipeline_text_to_video_zero.TextToVideoPipelineOutput

<source>arrow-up-right

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]nsfw_content_detected: typing.Optional[typing.List[bool]] )

Parameters

  • images ([List[PIL.Image.Image], np.ndarray]) β€” List of denoised PIL images of length batch_size or NumPy array of shape (batch_size, height, width, num_channels).

  • nsfw_content_detected ([List[bool]]) β€” List indicating whether the corresponding generated image contains β€œnot-safe-for-work” (nsfw) content or None if safety checking could not be performed.

Output class for zero-shot text-to-video pipeline.

Last updated