INNER CODE UNIT · Python
mapped_img
wenhaochai/StableVideo · app.py:210
mapped_img = np.array(mapped_img).astype(np.float32) / 255.0
mapped_img = mapped_img[None].transpose(0, 3, 1, 2)
mapped_img = torch.from_numpy(mapped_img).cuda()
mapped_img = 2. * mapped_img - 1.
latent = self.canny_model.get_first_stage_encoding(self.canny_model.encode_first_stage(mapped_img))
t_enc = int(ddim_steps * s)
latent = self.canny_ddim_sampler.stochastic_encode(latent, torch.tensor([t_enc]).to("cuda"))
samples = self.canny_ddim_sampler.decode(x_latent=latent,
cond=cond,
t_start=t_enc,
unconditional_guidance_scale=scale,
unconditional_conditioning=un_cond)
x_samples = self.canny_model.decode_first_stage(samples)
result = (einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
result = Image.fromarray(result[0])