Skip to content

Commit 857c04c

Browse files
[Pix2Pix0] Add utility function to get edit vector (open-mmlab#2383)
uP
1 parent 2e7a286 commit 857c04c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,20 @@ def construct_direction(self, embs_source: torch.Tensor, embs_target: torch.Tens
542542
"""Constructs the edit direction to steer the image generation process semantically."""
543543
return (embs_target.mean(0) - embs_source.mean(0)).unsqueeze(0)
544544

545+
@torch.no_grad()
546+
def get_embeds(self, prompt: List[str]) -> torch.FloatTensor:
547+
input_ids = self.tokenizer(
548+
prompt,
549+
padding="max_length",
550+
max_length=self.tokenizer.model_max_length,
551+
truncation=True,
552+
return_tensors="pt",
553+
).input_ids
554+
555+
embeds = self.text_encoder(input_ids)[0]
556+
557+
return embeds.mean(0)[None]
558+
545559
@torch.no_grad()
546560
@replace_example_docstring(EXAMPLE_DOC_STRING)
547561
def __call__(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy