MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / _encode_image

Function _encode_image

diffusers/examples/community/stable_unclip.py:18–36  ·  view source on GitHub ↗
(self, image, device, num_images_per_prompt, do_classifier_free_guidance)

Source from the content-addressed store, hash-verified

16
17
18def _encode_image(self, image, device, num_images_per_prompt, do_classifier_free_guidance):
19 image = image.to(device=device)
20 image_embeddings = image # take image as image_embeddings
21 image_embeddings = image_embeddings.unsqueeze(1)
22
23 # duplicate image embeddings for each generation per prompt, using mps friendly method
24 bs_embed, seq_len, _ = image_embeddings.shape
25 image_embeddings = image_embeddings.repeat(1, num_images_per_prompt, 1)
26 image_embeddings = image_embeddings.view(bs_embed * num_images_per_prompt, seq_len, -1)
27
28 if do_classifier_free_guidance:
29 uncond_embeddings = torch.zeros_like(image_embeddings)
30
31 # For classifier free guidance, we need to do two forward passes.
32 # Here we concatenate the unconditional and text embeddings into a single batch
33 # to avoid doing two forward passes
34 image_embeddings = torch.cat([uncond_embeddings, image_embeddings])
35
36 return image_embeddings
37
38
39class StableUnCLIPPipeline(DiffusionPipeline):

Callers

nothing calls this directly

Calls 1

toMethod · 0.45

Tested by

no test coverage detected