MCPcopy Create free account
hub / github.com/OpenImagingLab/4DSloMo / __call__

Method __call__

FixModel.py:217–306  ·  view source on GitHub ↗
(
        self,
        prompt,
        negative_prompt="",
        input_image=None,
        input_video=None,
        denoising_strength=1.0,
        seed=None,
        rand_device="cpu",
        height=1024,
        width=1024,
        cam_id=0,
        num_frames=81,
        cfg_scale=5.0,
        num_inference_steps=50,
        sigma_shift=5.0,
        tiled=True,
        tile_size=(30, 52),
        tile_stride=(15, 26),
        tea_cache_l1_thresh=None,
        tea_cache_model_id="",
        progress_bar_cmd=tqdm,
        progress_bar_st=None,
    )

Source from the content-addressed store, hash-verified

215
216 @torch.no_grad()
217 def __call__(
218 self,
219 prompt,
220 negative_prompt="",
221 input_image=None,
222 input_video=None,
223 denoising_strength=1.0,
224 seed=None,
225 rand_device="cpu",
226 height=1024,
227 width=1024,
228 cam_id=0,
229 num_frames=81,
230 cfg_scale=5.0,
231 num_inference_steps=50,
232 sigma_shift=5.0,
233 tiled=True,
234 tile_size=(30, 52),
235 tile_stride=(15, 26),
236 tea_cache_l1_thresh=None,
237 tea_cache_model_id="",
238 progress_bar_cmd=tqdm,
239 progress_bar_st=None,
240 ):
241 # Parameter check
242 height, width = self.check_resize_height_width(height, width)
243 if num_frames % 4 != 1:
244 num_frames = (num_frames + 2) // 4 * 4 + 1
245 print(f"Only `num_frames % 4 != 1` is acceptable. We round it up to {num_frames}.")
246
247 # Tiler parameters
248 tiler_kwargs = {"tiled": tiled, "tile_size": tile_size, "tile_stride": tile_stride}
249
250 # Scheduler
251 self.scheduler.set_timesteps(num_inference_steps, denoising_strength=denoising_strength, shift=sigma_shift)
252
253 # Initialize noise
254 noise = self.generate_noise((1, 16, (num_frames - 1) // 4 + 1, height//8, width//8), seed=seed, device=rand_device, dtype=torch.float32)
255 noise = noise.to(dtype=self.torch_dtype, device=self.device)
256 latents = noise
257
258 # Encode prompts
259 self.load_models_to_device(["text_encoder"])
260 prompt_emb_posi = self.encode_prompt(prompt, positive=True)
261 if cfg_scale != 1.0:
262 prompt_emb_nega = self.encode_prompt(negative_prompt, positive=False)
263
264 # Encode image
265 # import pdb; pdb.set_trace()
266 if input_image is not None and self.image_encoder is not None:
267 self.load_models_to_device(["image_encoder", "vae"])
268 # inter_frame = []
269 # for frame_id in [2,4,6]:
270 # inter_frame.append(input_video[frame_id])
271
272 image_emb = self.encode_image_condition(input_image, input_video, num_frames, height, width, cam_id)
273 else:
274 image_emb = {}

Callers

nothing calls this directly

Calls 7

encode_promptMethod · 0.95
prepare_extra_inputMethod · 0.95
decode_videoMethod · 0.95
tensor2videoMethod · 0.95
TeaCacheClass · 0.85
model_fn_wan_videoFunction · 0.85

Tested by

no test coverage detected