(
self,
input_image=None,
input_video=None,
mask_frames=[],
mask_frame_ids=[],
min_cfg_scale=1.0,
max_cfg_scale=3.0,
denoising_strength=1.0,
num_frames=25,
height=576,
width=1024,
fps=7,
motion_bucket_id=127,
noise_aug_strength=0.02,
num_inference_steps=20,
post_normalize=True,
contrast_enhance_scale=1.2,
seed=None,
progress_bar_cmd=tqdm,
progress_bar_st=None,
)
| 109 | |
| 110 | @torch.no_grad() |
| 111 | def __call__( |
| 112 | self, |
| 113 | input_image=None, |
| 114 | input_video=None, |
| 115 | mask_frames=[], |
| 116 | mask_frame_ids=[], |
| 117 | min_cfg_scale=1.0, |
| 118 | max_cfg_scale=3.0, |
| 119 | denoising_strength=1.0, |
| 120 | num_frames=25, |
| 121 | height=576, |
| 122 | width=1024, |
| 123 | fps=7, |
| 124 | motion_bucket_id=127, |
| 125 | noise_aug_strength=0.02, |
| 126 | num_inference_steps=20, |
| 127 | post_normalize=True, |
| 128 | contrast_enhance_scale=1.2, |
| 129 | seed=None, |
| 130 | progress_bar_cmd=tqdm, |
| 131 | progress_bar_st=None, |
| 132 | ): |
| 133 | height, width = self.check_resize_height_width(height, width) |
| 134 | |
| 135 | # Prepare scheduler |
| 136 | self.scheduler.set_timesteps(num_inference_steps, denoising_strength=denoising_strength) |
| 137 | |
| 138 | # Prepare latent tensors |
| 139 | noise = self.generate_noise((num_frames, 4, height//8, width//8), seed=seed, device=self.device, dtype=self.torch_dtype) |
| 140 | if denoising_strength == 1.0: |
| 141 | latents = noise.clone() |
| 142 | else: |
| 143 | latents = self.encode_video_with_vae(input_video) |
| 144 | latents = self.scheduler.add_noise(latents, noise, self.scheduler.timesteps[0]) |
| 145 | |
| 146 | # Prepare mask frames |
| 147 | if len(mask_frames) > 0: |
| 148 | mask_latents = self.encode_video_with_vae(mask_frames) |
| 149 | |
| 150 | # Encode image |
| 151 | image_emb_clip_posi = self.encode_image_with_clip(input_image) |
| 152 | image_emb_clip_nega = torch.zeros_like(image_emb_clip_posi) |
| 153 | image_emb_vae_posi = repeat(self.encode_image_with_vae(input_image, noise_aug_strength, seed=seed), "B C H W -> (B T) C H W", T=num_frames) |
| 154 | image_emb_vae_nega = torch.zeros_like(image_emb_vae_posi) |
| 155 | |
| 156 | # Prepare classifier-free guidance |
| 157 | cfg_scales = torch.linspace(min_cfg_scale, max_cfg_scale, num_frames) |
| 158 | cfg_scales = cfg_scales.reshape(num_frames, 1, 1, 1).to(device=self.device, dtype=self.torch_dtype) |
| 159 | |
| 160 | # Prepare positional id |
| 161 | add_time_id = torch.tensor([[fps-1, motion_bucket_id, noise_aug_strength]], device=self.device) |
| 162 | |
| 163 | # Denoise |
| 164 | for progress_id, timestep in enumerate(progress_bar_cmd(self.scheduler.timesteps)): |
| 165 | |
| 166 | # Mask frames |
| 167 | for frame_id, mask_frame_id in enumerate(mask_frame_ids): |
| 168 | latents[mask_frame_id] = self.scheduler.add_noise(mask_latents[frame_id], noise[mask_frame_id], timestep) |
nothing calls this directly
no test coverage detected