text stringlengths 0 5.54k |
|---|
filename = "__assets__/pix2pix video/camel.mp4" |
repo_id = "PAIR/Text2Video-Zero" |
video_path = hf_hub_download(repo_type="space", repo_id=repo_id, filename=filename) Read video from path Copied from PIL import Image |
import imageio |
reader = imageio.get_reader(video_path, "ffmpeg") |
frame_count = 8 |
video = [Image.fromarray(reader.get_data(i)) for i in range(frame_count)] Run StableDiffusionInstructPix2PixPipeline with our custom attention processor Copied import torch |
from diffusers import StableDiffusionInstructPix2PixPipeline |
from diffusers.pipelines.text_to_video_synthesis.pipeline_text_to_video_zero import CrossFrameAttnProcessor |
model_id = "timbrooks/instruct-pix2pix" |
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda") |
pipe.unet.set_attn_processor(CrossFrameAttnProcessor(batch_size=3)) |
prompt = "make it Van Gogh Starry Night style" |
result = pipe(prompt=[prompt] * len(video), image=video).images |
imageio.mimsave("edited_video.mp4", result, fps=4) DreamBooth specialization Methods Text-To-Video, Text-To-Video with Pose Control and Text-To-Video with Edge Control |
can run with custom DreamBooth models, as shown below for |
Canny edge ControlNet model and |
Avatar style DreamBooth model: Download a demo video Copied from huggingface_hub import hf_hub_download |
filename = "__assets__/canny_videos_mp4/girl_turning.mp4" |
repo_id = "PAIR/Text2Video-Zero" |
video_path = hf_hub_download(repo_type="space", repo_id=repo_id, filename=filename) Read video from path Copied from PIL import Image |
import imageio |
reader = imageio.get_reader(video_path, "ffmpeg") |
frame_count = 8 |
canny_edges = [Image.fromarray(reader.get_data(i)) for i in range(frame_count)] Run StableDiffusionControlNetPipeline with custom trained DreamBooth model Copied import torch |
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel |
from diffusers.pipelines.text_to_video_synthesis.pipeline_text_to_video_zero import CrossFrameAttnProcessor |
# set model id to custom model |
model_id = "PAIR/text2video-zero-controlnet-canny-avatar" |
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16) |
pipe = StableDiffusionControlNetPipeline.from_pretrained( |
model_id, controlnet=controlnet, torch_dtype=torch.float16 |
).to("cuda") |
# Set the attention processor |
pipe.unet.set_attn_processor(CrossFrameAttnProcessor(batch_size=2)) |
pipe.controlnet.set_attn_processor(CrossFrameAttnProcessor(batch_size=2)) |
# fix latents for all frames |
latents = torch.randn((1, 4, 64, 64), device="cuda", dtype=torch.float16).repeat(len(canny_edges), 1, 1, 1) |
prompt = "oil painting of a beautiful girl avatar style" |
result = pipe(prompt=[prompt] * len(canny_edges), image=canny_edges, latents=latents).images |
imageio.mimsave("video.mp4", result, fps=4) You can filter out some available DreamBooth-trained models with this link. Make sure to check out the Schedulers guide to learn how to explore the tradeoff between scheduler speed and quality, and see the reuse components across pipelines section to learn how to efficiently load the same components into multiple pipelines. TextToVideoZeroPipeline class diffusers.TextToVideoZeroPipeline < source > ( vae: AutoencoderKL text_encoder: CLIPTextModel tokenizer: CLIPTokenizer unet: UNet2DConditionModel scheduler: KarrasDiffusionSchedulers safety_checker: StableDiffusionSafetyChecker feature_extractor: CLIPImageProcessor requires_safety_checker: bool = True ) Parameters vae (AutoencoderKL) β |
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations. text_encoder (CLIPTextModel) β |
Frozen text-encoder (clip-vit-large-patch14). tokenizer (CLIPTokenizer) β |
A CLIPTokenizer to tokenize text. unet (UNet2DConditionModel) β |
A UNet3DConditionModel to denoise the encoded video latents. scheduler (SchedulerMixin) β |
A scheduler to be used in combination with unet to denoise the encoded image latents. Can be one of |
DDIMScheduler, LMSDiscreteScheduler, or PNDMScheduler. safety_checker (StableDiffusionSafetyChecker) β |
Classification module that estimates whether generated images could be considered offensive or harmful. |
Please refer to the model card for more details |
about a modelβs potential harms. feature_extractor (CLIPImageProcessor) β |
A CLIPImageProcessor to extract features from generated images; used as inputs to the safety_checker. Pipeline for zero-shot text-to-video generation using Stable Diffusion. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods |
implemented for all pipelines (downloading, saving, running on a particular device, etc.). __call__ < source > ( prompt: Union video_length: Optional = 8 height: Optional = None width: Optional = None num_inference_steps: int = 50 guidance_scale: float = 7.5 negative_prompt: Union = None num_videos_per_prompt: Optional = 1 eta: float = 0.0 generator: Union = None latents: Optional = None motion_field_strength_x: float = 12 motion_field_strength_y: float = 12 output_type: Optional = 'tensor' return_dict: bool = True callback: Optional = None callback_steps: Optional = 1 t0: int = 44 t1: int = 47 frame_ids: Optional = None ) β TextToVideoPipelineOutput 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 DDIM paper. Only applies |
to the DDIMScheduler, and is ignored in other schedulers. generator (torch.Generator or List[torch.Generator], optional) β |
A torch.Generator 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 |
TextToVideoPipelineOutput 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 paper, |
Sect. 3.3.1. motion_field_strength_y (float, optional, defaults to 12) β |
Strength of motion in generated video along y-axis. See the paper, |
Sect. 3.3.1. t0 (int, optional, defaults to 44) β |
Timestep t0. Should be in the range [0, num_inference_steps - 1]. See the |
paper, 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 |
paper, 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 |
TextToVideoPipelineOutput |
The output contains a ndarray of the generated video, when output_type != "latent", otherwise a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.