MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / log_video

Method log_video

sat/diffusion_video.py:336–399  ·  view source on GitHub ↗
(
        self,
        batch: Dict,
        N: int = 8,
        ucg_keys: List[str] = None,
        only_log_video_latents=False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

334
335 @torch.no_grad()
336 def log_video(
337 self,
338 batch: Dict,
339 N: int = 8,
340 ucg_keys: List[str] = None,
341 only_log_video_latents=False,
342 **kwargs,
343 ) -> Dict:
344 conditioner_input_keys = [e.input_key for e in self.conditioner.embedders]
345 if ucg_keys:
346 assert all(map(lambda x: x in conditioner_input_keys, ucg_keys)), (
347 "Each defined ucg key for sampling must be in the provided conditioner input keys,"
348 f"but we have {ucg_keys} vs. {conditioner_input_keys}"
349 )
350 else:
351 ucg_keys = conditioner_input_keys
352 log = dict()
353
354 x = self.get_input(batch)
355
356 # ucg_keys: ['txt', 'fut_traj']
357 c, uc = self.conditioner.get_unconditional_conditioning(
358 batch,
359 force_uc_zero_embeddings=ucg_keys if len(self.conditioner.embedders) > 0 else [],
360 )
361
362 sampling_kwargs = {}
363
364 N = min(x.shape[0], N)
365 x = x.to(self.device)[:N]
366 if not self.latent_input:
367 log["inputs"] = x.to(torch.float32)
368 x = x.permute(0, 2, 1, 3, 4).contiguous()
369
370
371 z = self.encode_first_stage(x, batch)
372 # [1, 16, 13, 60, 90]
373
374 if not only_log_video_latents:
375 log["reconstructions"] = self.decode_first_stage(z).to(torch.float32)
376 log["reconstructions"] = log["reconstructions"].permute(0, 2, 1, 3, 4).contiguous()
377 z = z.permute(0, 2, 1, 3, 4).contiguous()
378
379 # z: torch.Size([1, 13, 16, 64, 112]) b t c h w
380
381 if self.cond_inds is not None:
382 sampling_kwargs['prefix'] = z[:, self.cond_inds]
383
384 log.update(self.log_conditionings(batch, N))
385
386 for k in c:
387 if isinstance(c[k], torch.Tensor):
388 c[k], uc[k] = map(lambda y: y[k][:N].to(self.device), (c, uc))
389
390 samples = self.sample(c, shape=z.shape[1:], uc=uc, batch_size=N, **sampling_kwargs) # b t c h w
391 samples = samples.permute(0, 2, 1, 3, 4).contiguous()
392 if only_log_video_latents:
393 latents = 1.0 / self.scale_factor * samples

Callers 1

log_videoFunction · 0.80

Calls 8

get_inputMethod · 0.95
encode_first_stageMethod · 0.95
decode_first_stageMethod · 0.95
log_conditioningsMethod · 0.95
sampleMethod · 0.95
toMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected