MCPcopy
hub / github.com/vladmandic/sdnext / create_latents

Function create_latents

modules/processing_vae.py:15–34  ·  view source on GitHub ↗
(image, p, dtype=None, device=None)

Source from the content-addressed store, hash-verified

13
14
15def create_latents(image, p, dtype=None, device=None):
16 from modules.processing import create_random_tensors
17 from PIL import Image
18 if image is None:
19 return image
20 elif isinstance(image, Image.Image):
21 latents = vae_encode(image, model=shared.sd_model, vae_type=p.vae_type)
22 elif isinstance(image, list):
23 latents = [vae_encode(i, model=shared.sd_model, vae_type=p.vae_type).squeeze(dim=0) for i in image]
24 latents = torch.stack(latents, dim=0).to(shared.device)
25 else:
26 log.warning(f'Latents: input type: {type(image)} {image}')
27 return image
28 noise = p.denoising_strength * create_random_tensors(latents.shape[1:], seeds=p.all_seeds, subseeds=p.all_subseeds, subseed_strength=p.subseed_strength, p=p)
29 latents = (1 - p.denoising_strength) * latents + noise
30 if dtype is not None:
31 latents = latents.to(dtype=dtype)
32 if device is not None:
33 latents = latents.to(device=device)
34 return latents
35
36
37def full_vqgan_decode(latents, model):

Callers

nothing calls this directly

Calls 3

create_random_tensorsFunction · 0.90
vae_encodeFunction · 0.70
toMethod · 0.45

Tested by

no test coverage detected