import{S as Tl,i as Il,s as Cl,e as a,k as p,w as f,t as i,M as Zl,c as n,d as s,m as c,a as o,x as h,h as r,b as m,G as t,g as d,y as g,q as _,o as b,B as v,v as zl,L as ql}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as mt}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as S}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Q}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as El}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Nl(ut){let w,T,y,x,j;return x=new S({props:{code:`import requests
import torch

from diffusers import DDIMScheduler, StableDiffusionPix2PixZeroPipeline


def download(embedding_url, local_filepath):
    r = requests.get(embedding_url)
    with open(local_filepath, "wb") as f:
        f.write(r.content)


model_ckpt = "CompVis/stable-diffusion-v1-4"
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.to("cuda")

prompt = "a high resolution painting of a cat in the style of van gough"
source_emb_url = "https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/cat.pt"
target_emb_url = "https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/dog.pt"

for url in [source_emb_url, target_emb_url]:
    download(url, url.split("/")[-1])

src_embeds = torch.load(source_emb_url.split("/")[-1])
target_embeds = torch.load(target_emb_url.split("/")[-1])
images = pipeline(
    prompt,
    source_embeds=src_embeds,
    target_embeds=target_embeds,
    num_inference_steps=50,
    cross_attention_guidance_amount=0.15,
).images

images[0].save("edited_image_dog.png")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPix2PixZeroPipeline


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">download</span>(<span class="hljs-params">embedding_url, local_filepath</span>):
<span class="hljs-meta">... </span>    r = requests.get(embedding_url)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(local_filepath, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> f:
<span class="hljs-meta">... </span>        f.write(r.content)


<span class="hljs-meta">&gt;&gt;&gt; </span>model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;a high resolution painting of a cat in the style of van gough&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>source_emb_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/cat.pt&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>target_emb_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/dog.pt&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> [source_emb_url, target_emb_url]:
<span class="hljs-meta">... </span>    download(url, url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>src_embeds = torch.load(source_emb_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>target_embeds = torch.load(target_emb_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>images = pipeline(
<span class="hljs-meta">... </span>    prompt,
<span class="hljs-meta">... </span>    source_embeds=src_embeds,
<span class="hljs-meta">... </span>    target_embeds=target_embeds,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
<span class="hljs-meta">... </span>).images

<span class="hljs-meta">&gt;&gt;&gt; </span>images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),{c(){w=a("p"),T=i("Examples:"),y=p(),f(x.$$.fragment)},l(u){w=n(u,"P",{});var k=o(w);T=r(k,"Examples:"),k.forEach(s),y=c(u),h(x.$$.fragment,u)},m(u,k){d(u,w,k),t(w,T),d(u,y,k),g(x,u,k),j=!0},p:ql,i(u){j||(_(x.$$.fragment,u),j=!0)},o(u){b(x.$$.fragment,u),j=!1},d(u){u&&s(w),u&&s(y),v(x,u)}}}function Ll(ut){let w,T,y,x,j;return x=new S({props:{code:`import torch
from transformers import BlipForConditionalGeneration, BlipProcessor
from diffusers import DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

import requests
from PIL import Image

captioner_id = "Salesforce/blip-image-captioning-base"
processor = BlipProcessor.from_pretrained(captioner_id)
model = BlipForConditionalGeneration.from_pretrained(
    captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=True
)

sd_model_ckpt = "CompVis/stable-diffusion-v1-4"
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    sd_model_ckpt,
    caption_generator=model,
    caption_processor=processor,
    torch_dtype=torch.float16,
    safety_checker=None,
)

pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_model_cpu_offload()

img_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png"

raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB").resize((512, 512))
# generate caption
caption = pipeline.generate_caption(raw_image)

# "a photography of a cat with flowers and dai dai daie - daie - daie kasaii"
inv_latents = pipeline.invert(caption, image=raw_image).latents
# we need to generate source and target embeds

source_prompts = ["a cat sitting on the street", "a cat playing in the field", "a face of a cat"]

target_prompts = ["a dog sitting on the street", "a dog playing in the field", "a face of a dog"]

source_embeds = pipeline.get_embeds(source_prompts)
target_embeds = pipeline.get_embeds(target_prompts)
# the latents can then be used to edit a real image

image = pipeline(
    caption,
    source_embeds=source_embeds,
    target_embeds=target_embeds,
    num_inference_steps=50,
    cross_attention_guidance_amount=0.15,
    generator=generator,
    latents=inv_latents,
    negative_prompt=caption,
).images[0]
image.save("edited_image.png")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-meta">&gt;&gt;&gt; </span>captioner_id = <span class="hljs-string">&quot;Salesforce/blip-image-captioning-base&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = BlipProcessor.from_pretrained(captioner_id)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = BlipForConditionalGeneration.from_pretrained(
<span class="hljs-meta">... </span>    captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>sd_model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
<span class="hljs-meta">... </span>    sd_model_ckpt,
<span class="hljs-meta">... </span>    caption_generator=model,
<span class="hljs-meta">... </span>    caption_processor=processor,
<span class="hljs-meta">... </span>    torch_dtype=torch.float16,
<span class="hljs-meta">... </span>    safety_checker=<span class="hljs-literal">None</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.enable_model_cpu_offload()

<span class="hljs-meta">&gt;&gt;&gt; </span>img_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>raw_image = Image.<span class="hljs-built_in">open</span>(requests.get(img_url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># generate caption</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>caption = pipeline.generate_caption(raw_image)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># &quot;a photography of a cat with flowers and dai dai daie - daie - daie kasaii&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inv_latents = pipeline.invert(caption, image=raw_image).latents
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># we need to generate source and target embeds</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>source_prompts = [<span class="hljs-string">&quot;a cat sitting on the street&quot;</span>, <span class="hljs-string">&quot;a cat playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a cat&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>target_prompts = [<span class="hljs-string">&quot;a dog sitting on the street&quot;</span>, <span class="hljs-string">&quot;a dog playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a dog&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>source_embeds = pipeline.get_embeds(source_prompts)
<span class="hljs-meta">&gt;&gt;&gt; </span>target_embeds = pipeline.get_embeds(target_prompts)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># the latents can then be used to edit a real image</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipeline(
<span class="hljs-meta">... </span>    caption,
<span class="hljs-meta">... </span>    source_embeds=source_embeds,
<span class="hljs-meta">... </span>    target_embeds=target_embeds,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
<span class="hljs-meta">... </span>    generator=generator,
<span class="hljs-meta">... </span>    latents=inv_latents,
<span class="hljs-meta">... </span>    negative_prompt=caption,
<span class="hljs-meta">... </span>).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),{c(){w=a("p"),T=i("Examples:"),y=p(),f(x.$$.fragment)},l(u){w=n(u,"P",{});var k=o(w);T=r(k,"Examples:"),k.forEach(s),y=c(u),h(x.$$.fragment,u)},m(u,k){d(u,w,k),t(w,T),d(u,y,k),g(x,u,k),j=!0},p:ql,i(u){j||(_(x.$$.fragment,u),j=!0)},o(u){b(x.$$.fragment,u),j=!1},d(u){u&&s(w),u&&s(y),v(x,u)}}}function Al(ut){let w,T,y,x,j,u,k,Ft,Qa,Fs,G,ee,Bt,be,en,Ut,tn,Bs,ve,xe,sn,an,Us,ft,nn,Hs,ht,Ht,on,Rs,gt,rn,Ws,C,_t,we,ln,pn,cn,bt,Pe,dn,mn,un,vt,ye,fn,hn,Vs,O,te,Rt,$e,gn,Wt,_n,Ks,D,Vt,bn,vn,E,xn,Kt,wn,Pn,Xt,yn,$n,Yt,kn,jn,Jt,Dn,Sn,En,F,qn,Qt,Tn,In,es,Cn,Zn,zn,xt,Nn,ke,B,Ln,ts,An,Mn,ss,Gn,On,Fn,as,Bn,Un,je,Hn,De,Rn,Wn,Xs,U,se,ns,Se,Vn,os,Kn,Ys,ae,is,H,rs,Xn,Yn,ls,Jn,Qn,wt,eo,to,ps,R,cs,Ee,so,ao,ds,ms,no,oo,Pt,io,Js,W,ne,us,qe,ro,fs,lo,Qs,V,oe,hs,Te,po,gs,co,ea,Ie,ta,K,ie,_s,Ce,mo,bs,uo,sa,re,fo,vs,ho,go,aa,yt,_o,na,Ze,oa,$t,bo,ia,ze,ra,kt,vo,la,Ne,pa,jt,xo,ca,Le,da,X,le,xs,Ae,wo,ws,Po,ma,I,yo,Me,$o,ko,Ge,jo,Do,Oe,So,Eo,ua,Fe,Ps,qo,To,fa,Be,ha,Ue,ys,Io,Co,ga,He,_a,Dt,Zo,ba,Re,$s,zo,No,va,St,Lo,xa,We,wa,Et,Ao,Pa,Ve,ya,Z,Mo,ks,Go,Oo,Ke,Fo,Bo,$a,Xe,js,Uo,Ho,ka,qt,Ro,ja,Ye,Da,Je,Ds,Wo,Vo,Sa,Qe,Ea,pe,Ko,et,Xo,Yo,qa,Tt,Jo,Ta,tt,Ia,Y,ce,Ss,st,Qo,Es,ei,Ca,P,at,ti,qs,si,ai,nt,ni,It,oi,ii,ri,z,ot,li,Ts,pi,ci,de,di,me,it,mi,Is,ui,fi,ue,rt,hi,q,gi,Cs,_i,bi,Zs,vi,xi,zs,wi,Pi,Ns,yi,$i,ki,fe,lt,ji,J,Di,Ls,Si,Ei,As,qi,Ti,Ii,he,pt,Ci,Ms,Zi,zi,N,ct,Ni,Gs,Li,Ai,ge,Za;return u=new Q({}),be=new Q({}),$e=new Q({}),Se=new Q({}),qe=new Q({}),Te=new Q({}),Ie=new S({props:{code:`import requests
import torch

from diffusers import DDIMScheduler, StableDiffusionPix2PixZeroPipeline


def download(embedding_url, local_filepath):
    r = requests.get(embedding_url)
    with open(local_filepath, "wb") as f:
        f.write(r.content)


model_ckpt = "CompVis/stable-diffusion-v1-4"
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    model_ckpt, conditions_input_image=False, torch_dtype=torch.float16
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.to("cuda")

prompt = "a high resolution painting of a cat in the style of van gough"
src_embs_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/cat.pt"
target_embs_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/dog.pt"

for url in [src_embs_url, target_embs_url]:
    download(url, url.split("/")[-1])

src_embeds = torch.load(src_embs_url.split("/")[-1])
target_embeds = torch.load(target_embs_url.split("/")[-1])

images = pipeline(
    prompt,
    source_embeds=src_embeds,
    target_embeds=target_embeds,
    num_inference_steps=50,
    cross_attention_guidance_amount=0.15,
).images
images[0].save("edited_image_dog.png")`,highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPix2PixZeroPipeline


<span class="hljs-keyword">def</span> <span class="hljs-title function_">download</span>(<span class="hljs-params">embedding_url, local_filepath</span>):
    r = requests.get(embedding_url)
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(local_filepath, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> f:
        f.write(r.content)


model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    model_ckpt, conditions_input_image=<span class="hljs-literal">False</span>, torch_dtype=torch.float16
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;a high resolution painting of a cat in the style of van gough&quot;</span>
src_embs_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/cat.pt&quot;</span>
target_embs_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/dog.pt&quot;</span>

<span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> [src_embs_url, target_embs_url]:
    download(url, url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

src_embeds = torch.load(src_embs_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
target_embeds = torch.load(target_embs_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

images = pipeline(
    prompt,
    source_embeds=src_embeds,
    target_embeds=target_embeds,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),Ce=new Q({}),Ze=new S({props:{code:`import torch
from transformers import BlipForConditionalGeneration, BlipProcessor
from diffusers import DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

captioner_id = "Salesforce/blip-image-captioning-base"
processor = BlipProcessor.from_pretrained(captioner_id)
model = BlipForConditionalGeneration.from_pretrained(captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=True)

sd_model_ckpt = "CompVis/stable-diffusion-v1-4"
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    sd_model_ckpt,
    caption_generator=model,
    caption_processor=processor,
    torch_dtype=torch.float16,
    safety_checker=None,
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_model_cpu_offload()`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

captioner_id = <span class="hljs-string">&quot;Salesforce/blip-image-captioning-base&quot;</span>
processor = BlipProcessor.from_pretrained(captioner_id)
model = BlipForConditionalGeneration.from_pretrained(captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=<span class="hljs-literal">True</span>)

sd_model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    sd_model_ckpt,
    caption_generator=model,
    caption_processor=processor,
    torch_dtype=torch.float16,
    safety_checker=<span class="hljs-literal">None</span>,
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_model_cpu_offload()`}}),ze=new S({props:{code:`import requests
from PIL import Image

img_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png"
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB").resize((512, 512))
caption = pipeline.generate_caption(raw_image)`,highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

img_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png&quot;</span>
raw_image = Image.<span class="hljs-built_in">open</span>(requests.get(img_url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
caption = pipeline.generate_caption(raw_image)`}}),Ne=new S({props:{code:`generator = torch.manual_seed(0)
inv_latents = pipeline.invert(caption, image=raw_image, generator=generator).latents`,highlighted:`generator = torch.manual_seed(<span class="hljs-number">0</span>)
inv_latents = pipeline.invert(caption, image=raw_image, generator=generator).latents`}}),Le=new S({props:{code:`# See the "Generating source and target embeddings" section below to
# automate the generation of these captions with a pre-trained model like Flan-T5 as explained below.
source_prompts = ["a cat sitting on the street", "a cat playing in the field", "a face of a cat"]
target_prompts = ["a dog sitting on the street", "a dog playing in the field", "a face of a dog"]

source_embeds = pipeline.get_embeds(source_prompts, batch_size=2)
target_embeds = pipeline.get_embeds(target_prompts, batch_size=2)


image = pipeline(
    caption,
    source_embeds=source_embeds,
    target_embeds=target_embeds,
    num_inference_steps=50,
    cross_attention_guidance_amount=0.15,
    generator=generator,
    latents=inv_latents,
    negative_prompt=caption,
).images[0]
image.save("edited_image.png")`,highlighted:`<span class="hljs-comment"># See the &quot;Generating source and target embeddings&quot; section below to</span>
<span class="hljs-comment"># automate the generation of these captions with a pre-trained model like Flan-T5 as explained below.</span>
source_prompts = [<span class="hljs-string">&quot;a cat sitting on the street&quot;</span>, <span class="hljs-string">&quot;a cat playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a cat&quot;</span>]
target_prompts = [<span class="hljs-string">&quot;a dog sitting on the street&quot;</span>, <span class="hljs-string">&quot;a dog playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a dog&quot;</span>]

source_embeds = pipeline.get_embeds(source_prompts, batch_size=<span class="hljs-number">2</span>)
target_embeds = pipeline.get_embeds(target_prompts, batch_size=<span class="hljs-number">2</span>)


image = pipeline(
    caption,
    source_embeds=source_embeds,
    target_embeds=target_embeds,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
    generator=generator,
    latents=inv_latents,
    negative_prompt=caption,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),Ae=new Q({}),Be=new S({props:{code:`import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-xl")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-xl", device_map="auto", torch_dtype=torch.float16)`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, T5ForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/flan-t5-xl&quot;</span>)
model = T5ForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;google/flan-t5-xl&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>, torch_dtype=torch.float16)`}}),He=new S({props:{code:`source_concept = "cat"
target_concept = "dog"

source_text = f"Provide a caption for images containing a {source_concept}. "
"The captions should be in English and should be no longer than 150 characters."

target_text = f"Provide a caption for images containing a {target_concept}. "
"The captions should be in English and should be no longer than 150 characters."`,highlighted:`source_concept = <span class="hljs-string">&quot;cat&quot;</span>
target_concept = <span class="hljs-string">&quot;dog&quot;</span>

source_text = <span class="hljs-string">f&quot;Provide a caption for images containing a <span class="hljs-subst">{source_concept}</span>. &quot;</span>
<span class="hljs-string">&quot;The captions should be in English and should be no longer than 150 characters.&quot;</span>

target_text = <span class="hljs-string">f&quot;Provide a caption for images containing a <span class="hljs-subst">{target_concept}</span>. &quot;</span>
<span class="hljs-string">&quot;The captions should be in English and should be no longer than 150 characters.&quot;</span>`}}),We=new S({props:{code:`def generate_captions(input_prompt):
    input_ids = tokenizer(input_prompt, return_tensors="pt").input_ids.to("cuda")

    outputs = model.generate(
        input_ids, temperature=0.8, num_return_sequences=16, do_sample=True, max_new_tokens=128, top_k=10
    )
    return tokenizer.batch_decode(outputs, skip_special_tokens=True)`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_captions</span>(<span class="hljs-params">input_prompt</span>):
    input_ids = tokenizer(input_prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids.to(<span class="hljs-string">&quot;cuda&quot;</span>)

    outputs = model.generate(
        input_ids, temperature=<span class="hljs-number">0.8</span>, num_return_sequences=<span class="hljs-number">16</span>, do_sample=<span class="hljs-literal">True</span>, max_new_tokens=<span class="hljs-number">128</span>, top_k=<span class="hljs-number">10</span>
    )
    <span class="hljs-keyword">return</span> tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),Ve=new S({props:{code:`source_captions = generate_captions(source_text)
target_captions = generate_captions(target_concept)`,highlighted:`source_captions = generate_captions(source_text)
target_captions = generate_captions(target_concept)`}}),Ye=new S({props:{code:`from diffusers import StableDiffusionPix2PixZeroPipeline 

pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16
)
pipeline = pipeline.to("cuda")
tokenizer = pipeline.tokenizer
text_encoder = pipeline.text_encoder`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPix2PixZeroPipeline 

pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, torch_dtype=torch.float16
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)
tokenizer = pipeline.tokenizer
text_encoder = pipeline.text_encoder`}}),Qe=new S({props:{code:`import torch 

def embed_captions(sentences, tokenizer, text_encoder, device="cuda"):
    with torch.no_grad():
        embeddings = []
        for sent in sentences:
            text_inputs = tokenizer(
                sent,
                padding="max_length",
                max_length=tokenizer.model_max_length,
                truncation=True,
                return_tensors="pt",
            )
            text_input_ids = text_inputs.input_ids
            prompt_embeds = text_encoder(text_input_ids.to(device), attention_mask=None)[0]
            embeddings.append(prompt_embeds)
    return torch.concatenate(embeddings, dim=0).mean(dim=0).unsqueeze(0)

source_embeddings = embed_captions(source_captions, tokenizer, text_encoder)
target_embeddings = embed_captions(target_captions, tokenizer, text_encoder)`,highlighted:`<span class="hljs-keyword">import</span> torch 

<span class="hljs-keyword">def</span> <span class="hljs-title function_">embed_captions</span>(<span class="hljs-params">sentences, tokenizer, text_encoder, device=<span class="hljs-string">&quot;cuda&quot;</span></span>):
    <span class="hljs-keyword">with</span> torch.no_grad():
        embeddings = []
        <span class="hljs-keyword">for</span> sent <span class="hljs-keyword">in</span> sentences:
            text_inputs = tokenizer(
                sent,
                padding=<span class="hljs-string">&quot;max_length&quot;</span>,
                max_length=tokenizer.model_max_length,
                truncation=<span class="hljs-literal">True</span>,
                return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
            )
            text_input_ids = text_inputs.input_ids
            prompt_embeds = text_encoder(text_input_ids.to(device), attention_mask=<span class="hljs-literal">None</span>)[<span class="hljs-number">0</span>]
            embeddings.append(prompt_embeds)
    <span class="hljs-keyword">return</span> torch.concatenate(embeddings, dim=<span class="hljs-number">0</span>).mean(dim=<span class="hljs-number">0</span>).unsqueeze(<span class="hljs-number">0</span>)

source_embeddings = embed_captions(source_captions, tokenizer, text_encoder)
target_embeddings = embed_captions(target_captions, tokenizer, text_encoder)`}}),tt=new S({props:{code:`from diffusers import DDIMScheduler

pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)

images = pipeline(
    prompt,
    source_embeds=source_embeddings,
    target_embeds=target_embeddings,
    num_inference_steps=50,
    cross_attention_guidance_amount=0.15,
).images
images[0].save("edited_image_dog.png")`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler

pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)

images = pipeline(
    prompt,
    source_embeds=source_embeddings,
    target_embeds=target_embeddings,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),st=new Q({}),at=new mt({props:{name:"class diffusers.StableDiffusionPix2PixZeroPipeline",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": typing.Union[diffusers.schedulers.scheduling_ddpm.DDPMScheduler, diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteScheduler, diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler]"},{name:"feature_extractor",val:": CLIPFeatureExtractor"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"inverse_scheduler",val:": DDIMInverseScheduler"},{name:"caption_generator",val:": BlipForConditionalGeneration"},{name:"caption_processor",val:": BlipProcessor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Stable Diffusion uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a>, specifically
the <a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a> variant.`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/main/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, <a href="/docs/diffusers/main/en/api/schedulers/euler_ancestral#diffusers.EulerAncestralDiscreteScheduler">EulerAncestralDiscreteScheduler</a>, or <a href="/docs/diffusers/main/en/api/schedulers/ddpm#diffusers.DDPMScheduler">DDPMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.safety_checker",description:`<strong>safety_checker</strong> (<code>StableDiffusionSafetyChecker</code>) &#x2014;
Classification module that estimates whether generated images could be considered offensive or harmful.
Please, refer to the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">model card</a> for details.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>CLIPFeatureExtractor</code>) &#x2014;
Model that extracts features from generated images to be used as inputs for the <code>safety_checker</code>.`,name:"feature_extractor"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.requires_safety_checker",description:`<strong>requires_safety_checker</strong> (bool) &#x2014;
Whether the pipeline requires a safety checker. We recommend setting it to True if you&#x2019;re using the
pipeline publicly.`,name:"requires_safety_checker"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L274"}}),ot=new mt({props:{name:"__call__",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image, NoneType] = None"},{name:"source_embeds",val:": Tensor = None"},{name:"target_embeds",val:": Tensor = None"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attention_guidance_amount",val:": float = 0.1"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.source_embeds",description:`<strong>source_embeds</strong> (<code>torch.Tensor</code>) &#x2014;
Source concept embeddings. Generation of the embeddings as per the <a href="https://arxiv.org/abs/2302.03027" rel="nofollow">original
paper</a>. Used in discovering the edit direction.`,name:"source_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.target_embeds",description:`<strong>target_embeds</strong> (<code>torch.Tensor</code>) &#x2014;
Target concept embeddings. Generation of the embeddings as per the <a href="https://arxiv.org/abs/2302.03027" rel="nofollow">original
paper</a>. Used in discovering the edit direction.`,name:"target_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code>. instead. If not defined, one has to pass <code>negative_prompt_embeds</code>. instead.
Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.cross_attention_guidance_amount",description:`<strong>cross_attention_guidance_amount</strong> (<code>float</code>, defaults to 0.1) &#x2014;
Amount of guidance needed from the reference cross-attention maps.`,name:"cross_attention_guidance_amount"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L754",returnDescription:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of </code>bool<code>s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the </code>safety_checker\`.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),de=new El({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.example",$$slots:{default:[Nl]},$$scope:{ctx:ut}}}),it=new mt({props:{name:"construct_direction",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.construct_direction",parameters:[{name:"embs_source",val:": Tensor"},{name:"embs_target",val:": Tensor"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L670"}}),rt=new mt({props:{name:"enable_model_cpu_offload",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L381"}}),lt=new mt({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L360"}}),pt=new mt({props:{name:"generate_caption",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.generate_caption",parameters:[{name:"images",val:""}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L650"}}),ct=new mt({props:{name:"invert",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert",parameters:[{name:"prompt",val:": typing.Optional[str] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attention_guidance_amount",val:": float = 0.1"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"},{name:"lambda_auto_corr",val:": float = 20.0"},{name:"lambda_kl",val:": float = 20.0"},{name:"num_reg_steps",val:": int = 5"},{name:"num_auto_corr_rolls",val:": int = 5"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.image",description:`<strong>image</strong> (<code>PIL.Image.Image</code>, <em>optional</em>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be used for conditioning.`,name:"image"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.cross_attention_guidance_amount",description:`<strong>cross_attention_guidance_amount</strong> (<code>float</code>, defaults to 0.1) &#x2014;
Amount of guidance needed from the reference cross-attention maps.`,name:"cross_attention_guidance_amount"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.lambda_auto_corr",description:`<strong>lambda_auto_corr</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Lambda parameter to control auto correction`,name:"lambda_auto_corr"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.lambda_kl",description:`<strong>lambda_kl</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Lambda parameter to control Kullback&#x2013;Leibler divergence output`,name:"lambda_kl"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_reg_steps",description:`<strong>num_reg_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of regularization loss steps`,name:"num_reg_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_auto_corr_rolls",description:`<strong>num_auto_corr_rolls</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of auto correction roll steps`,name:"num_auto_corr_rolls"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L1031",returnDescription:`
<p><code>Pix2PixInversionPipelineOutput</code> or
<code>tuple</code>:
<code>Pix2PixInversionPipelineOutput</code> if
<code>return_dict</code> is True, otherwise a \`tuple. When returning a tuple, the first element is the inverted
latents tensor and then second is the corresponding decoded image.</p>
`}}),ge=new El({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.example",$$slots:{default:[Ll]},$$scope:{ctx:ut}}}),{c(){w=a("meta"),T=p(),y=a("h1"),x=a("a"),j=a("span"),f(u.$$.fragment),k=p(),Ft=a("span"),Qa=i("Zero-shot Image-to-Image Translation"),Fs=p(),G=a("h2"),ee=a("a"),Bt=a("span"),f(be.$$.fragment),en=p(),Ut=a("span"),tn=i("Overview"),Bs=p(),ve=a("p"),xe=a("a"),sn=i("Zero-shot Image-to-Image Translation"),an=i("."),Us=p(),ft=a("p"),nn=i("The abstract of the paper is the following:"),Hs=p(),ht=a("p"),Ht=a("em"),on=i("Large-scale text-to-image generative models have shown their remarkable ability to synthesize diverse and high-quality images. However, it is still challenging to directly apply these models for editing real images for two reasons. First, it is hard for users to come up with a perfect text prompt that accurately describes every visual detail in the input image. Second, while existing models can introduce desirable changes in certain regions, they often dramatically alter the input content and introduce unexpected changes in unwanted regions. In this work, we propose pix2pix-zero, an image-to-image translation method that can preserve the content of the original image without manual prompting. We first automatically discover editing directions that reflect desired edits in the text embedding space. To preserve the general content structure after editing, we further propose cross-attention guidance, which aims to retain the cross-attention maps of the input image throughout the diffusion process. In addition, our method does not need additional training for these edits and can directly use the existing pre-trained text-to-image diffusion model. We conduct extensive experiments and show that our method outperforms existing and concurrent works for both real and synthetic image editing."),Rs=p(),gt=a("p"),rn=i("Resources:"),Ws=p(),C=a("ul"),_t=a("li"),we=a("a"),ln=i("Project Page"),pn=i("."),cn=p(),bt=a("li"),Pe=a("a"),dn=i("Paper"),mn=i("."),un=p(),vt=a("li"),ye=a("a"),fn=i("Original Code"),hn=i("."),Vs=p(),O=a("h2"),te=a("a"),Rt=a("span"),f($e.$$.fragment),gn=p(),Wt=a("span"),_n=i("Tips"),Ks=p(),D=a("ul"),Vt=a("li"),bn=i("The pipeline can be conditioned on real input images. Check out the code examples below to know more."),vn=p(),E=a("li"),xn=i("The pipeline exposes two arguments namely "),Kt=a("code"),wn=i("source_embeds"),Pn=i(" and "),Xt=a("code"),yn=i("target_embeds"),$n=i(`
that let you control the direction of the semantic edits in the final image to be generated. Let\u2019s say,
you wanted to translate from \u201Ccat\u201D to \u201Cdog\u201D. In this case, the edit direction will be \u201Ccat -> dog\u201D. To reflect
this in the pipeline, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),Yt=a("code"),kn=i("source_embeds"),jn=i(" and \u201Cdog\u201D to "),Jt=a("code"),Dn=i("target_embeds"),Sn=i(". Refer to the code example below for more details."),En=p(),F=a("li"),qn=i("When you\u2019re using this pipeline from a prompt, specify the "),Qt=a("em"),Tn=i("source"),In=i(` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),es=a("strong"),Cn=i("cat"),Zn=i(" in the style of van gough\u201D."),zn=p(),xt=a("li"),Nn=i("If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),ke=a("ul"),B=a("li"),Ln=i("Swap the "),ts=a("code"),An=i("source_embeds"),Mn=i(" and "),ss=a("code"),Gn=i("target_embeds"),On=i("."),Fn=p(),as=a("li"),Bn=i("Change the input prompt to include \u201Cdog\u201D."),Un=p(),je=a("li"),Hn=i("To learn more about how the source and target embeddings are generated, refer to the "),De=a("a"),Rn=i(`original
paper`),Wn=i(". Below, we also provide some directions on how to generate the embeddings."),Xs=p(),U=a("h2"),se=a("a"),ns=a("span"),f(Se.$$.fragment),Vn=p(),os=a("span"),Kn=i("Available Pipelines:"),Ys=p(),ae=a("table"),is=a("thead"),H=a("tr"),rs=a("th"),Xn=i("Pipeline"),Yn=p(),ls=a("th"),Jn=i("Tasks"),Qn=p(),wt=a("th"),eo=i("Demo"),to=p(),ps=a("tbody"),R=a("tr"),cs=a("td"),Ee=a("a"),so=i("StableDiffusionPix2PixZeroPipeline"),ao=p(),ds=a("td"),ms=a("em"),no=i("Text-Based Image Editing"),oo=p(),Pt=a("td"),io=i("[\u{1F917} Space] (soon)"),Js=p(),W=a("h2"),ne=a("a"),us=a("span"),f(qe.$$.fragment),ro=p(),fs=a("span"),lo=i("Usage example"),Qs=p(),V=a("h3"),oe=a("a"),hs=a("span"),f(Te.$$.fragment),po=p(),gs=a("span"),co=i("Based on an image generated with the input prompt"),ea=p(),f(Ie.$$.fragment),ta=p(),K=a("h3"),ie=a("a"),_s=a("span"),f(Ce.$$.fragment),mo=p(),bs=a("span"),uo=i("Based on an input image"),sa=p(),re=a("p"),fo=i(`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),vs=a("code"),ho=i("DDIMInverseScheduler"),go=i(` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),aa=p(),yt=a("p"),_o=i("First, let\u2019s load our pipeline:"),na=p(),f(Ze.$$.fragment),oa=p(),$t=a("p"),bo=i("Then, we load an input image for conditioning and obtain a suitable caption for it:"),ia=p(),f(ze.$$.fragment),ra=p(),kt=a("p"),vo=i("Then we employ the generated caption and the input image to get the inverted noise:"),la=p(),f(Ne.$$.fragment),pa=p(),jt=a("p"),xo=i("Now, generate the image with edit directions:"),ca=p(),f(Le.$$.fragment),da=p(),X=a("h2"),le=a("a"),xs=a("span"),f(Ae.$$.fragment),wo=p(),ws=a("span"),Po=i("Generating source and target embeddings"),ma=p(),I=a("p"),yo=i("The authors originally used the "),Me=a("a"),$o=i("GPT-3 API"),ko=i(` to generate the source and target captions for discovering
edit directions. However, we can also leverage open source and public models for the same purpose.
Below, we provide an end-to-end example with the `),Ge=a("a"),jo=i("Flan-T5"),Do=i(` model
for generating captions and `),Oe=a("a"),So=i("CLIP"),Eo=i(` for
computing embeddings on the generated captions.`),ua=p(),Fe=a("p"),Ps=a("strong"),qo=i("1. Load the generation model"),To=i(":"),fa=p(),f(Be.$$.fragment),ha=p(),Ue=a("p"),ys=a("strong"),Io=i("2. Construct a starting prompt"),Co=i(":"),ga=p(),f(He.$$.fragment),_a=p(),Dt=a("p"),Zo=i("Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),ba=p(),Re=a("p"),$s=a("strong"),zo=i("3. Generate captions"),No=i(":"),va=p(),St=a("p"),Lo=i("We can use a utility like so for this purpose."),xa=p(),f(We.$$.fragment),wa=p(),Et=a("p"),Ao=i("And then we just call it to generate our captions:"),Pa=p(),f(Ve.$$.fragment),ya=p(),Z=a("p"),Mo=i(`We encourage you to play around with the different parameters supported by the
`),ks=a("code"),Go=i("generate()"),Oo=i(" method ("),Ke=a("a"),Fo=i("documentation"),Bo=i(") for the generation quality you are looking for."),$a=p(),Xe=a("p"),js=a("strong"),Uo=i("4. Load the embedding model"),Ho=i(":"),ka=p(),qt=a("p"),Ro=i("Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),ja=p(),f(Ye.$$.fragment),Da=p(),Je=a("p"),Ds=a("strong"),Wo=i("5. Compute embeddings"),Vo=i(":"),Sa=p(),f(Qe.$$.fragment),Ea=p(),pe=a("p"),Ko=i("And you\u2019re done! "),et=a("a"),Xo=i("Here"),Yo=i(" is a Colab Notebook that you can use to interact with the entire process."),qa=p(),Tt=a("p"),Jo=i("Now, you can use these embeddings directly while calling the pipeline:"),Ta=p(),f(tt.$$.fragment),Ia=p(),Y=a("h2"),ce=a("a"),Ss=a("span"),f(st.$$.fragment),Qo=p(),Es=a("span"),ei=i("StableDiffusionPix2PixZeroPipeline"),Ca=p(),P=a("div"),f(at.$$.fragment),ti=p(),qs=a("p"),si=i("Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),ai=p(),nt=a("p"),ni=i("This model inherits from "),It=a("a"),oi=i("DiffusionPipeline"),ii=i(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),ri=p(),z=a("div"),f(ot.$$.fragment),li=p(),Ts=a("p"),pi=i("Function invoked when calling the pipeline for generation."),ci=p(),f(de.$$.fragment),di=p(),me=a("div"),f(it.$$.fragment),mi=p(),Is=a("p"),ui=i("Constructs the edit direction to steer the image generation process semantically."),fi=p(),ue=a("div"),f(rt.$$.fragment),hi=p(),q=a("p"),gi=i(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Cs=a("code"),_i=i("enable_sequential_cpu_offload"),bi=i(", this method moves one whole model at a time to the GPU when its "),Zs=a("code"),vi=i("forward"),xi=i(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),zs=a("code"),wi=i("enable_sequential_cpu_offload"),Pi=i(", but performance is much better due to the iterative execution of the "),Ns=a("code"),yi=i("unet"),$i=i("."),ki=p(),fe=a("div"),f(lt.$$.fragment),ji=p(),J=a("p"),Di=i(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Ls=a("code"),Si=i("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Ei=i("forward"),As=a("code"),qi=i("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Ti=i("enable_model_cpu_offload`, but performance is lower."),Ii=p(),he=a("div"),f(pt.$$.fragment),Ci=p(),Ms=a("p"),Zi=i("Generates caption for a given image."),zi=p(),N=a("div"),f(ct.$$.fragment),Ni=p(),Gs=a("p"),Li=i("Function used to generate inverted latents given a prompt and image."),Ai=p(),f(ge.$$.fragment),this.h()},l(e){const l=Zl('[data-svelte="svelte-1phssyn"]',document.head);w=n(l,"META",{name:!0,content:!0}),l.forEach(s),T=c(e),y=n(e,"H1",{class:!0});var dt=o(y);x=n(dt,"A",{id:!0,class:!0,href:!0});var Os=o(x);j=n(Os,"SPAN",{});var Ki=o(j);h(u.$$.fragment,Ki),Ki.forEach(s),Os.forEach(s),k=c(dt),Ft=n(dt,"SPAN",{});var Xi=o(Ft);Qa=r(Xi,"Zero-shot Image-to-Image Translation"),Xi.forEach(s),dt.forEach(s),Fs=c(e),G=n(e,"H2",{class:!0});var za=o(G);ee=n(za,"A",{id:!0,class:!0,href:!0});var Yi=o(ee);Bt=n(Yi,"SPAN",{});var Ji=o(Bt);h(be.$$.fragment,Ji),Ji.forEach(s),Yi.forEach(s),en=c(za),Ut=n(za,"SPAN",{});var Qi=o(Ut);tn=r(Qi,"Overview"),Qi.forEach(s),za.forEach(s),Bs=c(e),ve=n(e,"P",{});var Mi=o(ve);xe=n(Mi,"A",{href:!0,rel:!0});var er=o(xe);sn=r(er,"Zero-shot Image-to-Image Translation"),er.forEach(s),an=r(Mi,"."),Mi.forEach(s),Us=c(e),ft=n(e,"P",{});var tr=o(ft);nn=r(tr,"The abstract of the paper is the following:"),tr.forEach(s),Hs=c(e),ht=n(e,"P",{});var sr=o(ht);Ht=n(sr,"EM",{});var ar=o(Ht);on=r(ar,"Large-scale text-to-image generative models have shown their remarkable ability to synthesize diverse and high-quality images. However, it is still challenging to directly apply these models for editing real images for two reasons. First, it is hard for users to come up with a perfect text prompt that accurately describes every visual detail in the input image. Second, while existing models can introduce desirable changes in certain regions, they often dramatically alter the input content and introduce unexpected changes in unwanted regions. In this work, we propose pix2pix-zero, an image-to-image translation method that can preserve the content of the original image without manual prompting. We first automatically discover editing directions that reflect desired edits in the text embedding space. To preserve the general content structure after editing, we further propose cross-attention guidance, which aims to retain the cross-attention maps of the input image throughout the diffusion process. In addition, our method does not need additional training for these edits and can directly use the existing pre-trained text-to-image diffusion model. We conduct extensive experiments and show that our method outperforms existing and concurrent works for both real and synthetic image editing."),ar.forEach(s),sr.forEach(s),Rs=c(e),gt=n(e,"P",{});var nr=o(gt);rn=r(nr,"Resources:"),nr.forEach(s),Ws=c(e),C=n(e,"UL",{});var Ct=o(C);_t=n(Ct,"LI",{});var Gi=o(_t);we=n(Gi,"A",{href:!0,rel:!0});var or=o(we);ln=r(or,"Project Page"),or.forEach(s),pn=r(Gi,"."),Gi.forEach(s),cn=c(Ct),bt=n(Ct,"LI",{});var Oi=o(bt);Pe=n(Oi,"A",{href:!0,rel:!0});var ir=o(Pe);dn=r(ir,"Paper"),ir.forEach(s),mn=r(Oi,"."),Oi.forEach(s),un=c(Ct),vt=n(Ct,"LI",{});var Fi=o(vt);ye=n(Fi,"A",{href:!0,rel:!0});var rr=o(ye);fn=r(rr,"Original Code"),rr.forEach(s),hn=r(Fi,"."),Fi.forEach(s),Ct.forEach(s),Vs=c(e),O=n(e,"H2",{class:!0});var Na=o(O);te=n(Na,"A",{id:!0,class:!0,href:!0});var lr=o(te);Rt=n(lr,"SPAN",{});var pr=o(Rt);h($e.$$.fragment,pr),pr.forEach(s),lr.forEach(s),gn=c(Na),Wt=n(Na,"SPAN",{});var cr=o(Wt);_n=r(cr,"Tips"),cr.forEach(s),Na.forEach(s),Ks=c(e),D=n(e,"UL",{});var L=o(D);Vt=n(L,"LI",{});var dr=o(Vt);bn=r(dr,"The pipeline can be conditioned on real input images. Check out the code examples below to know more."),dr.forEach(s),vn=c(L),E=n(L,"LI",{});var A=o(E);xn=r(A,"The pipeline exposes two arguments namely "),Kt=n(A,"CODE",{});var mr=o(Kt);wn=r(mr,"source_embeds"),mr.forEach(s),Pn=r(A," and "),Xt=n(A,"CODE",{});var ur=o(Xt);yn=r(ur,"target_embeds"),ur.forEach(s),$n=r(A,`
that let you control the direction of the semantic edits in the final image to be generated. Let\u2019s say,
you wanted to translate from \u201Ccat\u201D to \u201Cdog\u201D. In this case, the edit direction will be \u201Ccat -> dog\u201D. To reflect
this in the pipeline, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),Yt=n(A,"CODE",{});var fr=o(Yt);kn=r(fr,"source_embeds"),fr.forEach(s),jn=r(A," and \u201Cdog\u201D to "),Jt=n(A,"CODE",{});var hr=o(Jt);Dn=r(hr,"target_embeds"),hr.forEach(s),Sn=r(A,". Refer to the code example below for more details."),A.forEach(s),En=c(L),F=n(L,"LI",{});var Zt=o(F);qn=r(Zt,"When you\u2019re using this pipeline from a prompt, specify the "),Qt=n(Zt,"EM",{});var gr=o(Qt);Tn=r(gr,"source"),gr.forEach(s),In=r(Zt,` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),es=n(Zt,"STRONG",{});var _r=o(es);Cn=r(_r,"cat"),_r.forEach(s),Zn=r(Zt," in the style of van gough\u201D."),Zt.forEach(s),zn=c(L),xt=n(L,"LI",{});var Bi=o(xt);Nn=r(Bi,"If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),ke=n(Bi,"UL",{});var La=o(ke);B=n(La,"LI",{});var zt=o(B);Ln=r(zt,"Swap the "),ts=n(zt,"CODE",{});var br=o(ts);An=r(br,"source_embeds"),br.forEach(s),Mn=r(zt," and "),ss=n(zt,"CODE",{});var vr=o(ss);Gn=r(vr,"target_embeds"),vr.forEach(s),On=r(zt,"."),zt.forEach(s),Fn=c(La),as=n(La,"LI",{});var xr=o(as);Bn=r(xr,"Change the input prompt to include \u201Cdog\u201D."),xr.forEach(s),La.forEach(s),Bi.forEach(s),Un=c(L),je=n(L,"LI",{});var Aa=o(je);Hn=r(Aa,"To learn more about how the source and target embeddings are generated, refer to the "),De=n(Aa,"A",{href:!0,rel:!0});var wr=o(De);Rn=r(wr,`original
paper`),wr.forEach(s),Wn=r(Aa,". Below, we also provide some directions on how to generate the embeddings."),Aa.forEach(s),L.forEach(s),Xs=c(e),U=n(e,"H2",{class:!0});var Ma=o(U);se=n(Ma,"A",{id:!0,class:!0,href:!0});var Pr=o(se);ns=n(Pr,"SPAN",{});var yr=o(ns);h(Se.$$.fragment,yr),yr.forEach(s),Pr.forEach(s),Vn=c(Ma),os=n(Ma,"SPAN",{});var $r=o(os);Kn=r($r,"Available Pipelines:"),$r.forEach(s),Ma.forEach(s),Ys=c(e),ae=n(e,"TABLE",{});var Ga=o(ae);is=n(Ga,"THEAD",{});var kr=o(is);H=n(kr,"TR",{});var Nt=o(H);rs=n(Nt,"TH",{});var jr=o(rs);Xn=r(jr,"Pipeline"),jr.forEach(s),Yn=c(Nt),ls=n(Nt,"TH",{});var Dr=o(ls);Jn=r(Dr,"Tasks"),Dr.forEach(s),Qn=c(Nt),wt=n(Nt,"TH",{align:!0});var Sr=o(wt);eo=r(Sr,"Demo"),Sr.forEach(s),Nt.forEach(s),kr.forEach(s),to=c(Ga),ps=n(Ga,"TBODY",{});var Er=o(ps);R=n(Er,"TR",{});var Lt=o(R);cs=n(Lt,"TD",{});var qr=o(cs);Ee=n(qr,"A",{href:!0,rel:!0});var Tr=o(Ee);so=r(Tr,"StableDiffusionPix2PixZeroPipeline"),Tr.forEach(s),qr.forEach(s),ao=c(Lt),ds=n(Lt,"TD",{});var Ir=o(ds);ms=n(Ir,"EM",{});var Cr=o(ms);no=r(Cr,"Text-Based Image Editing"),Cr.forEach(s),Ir.forEach(s),oo=c(Lt),Pt=n(Lt,"TD",{align:!0});var Zr=o(Pt);io=r(Zr,"[\u{1F917} Space] (soon)"),Zr.forEach(s),Lt.forEach(s),Er.forEach(s),Ga.forEach(s),Js=c(e),W=n(e,"H2",{class:!0});var Oa=o(W);ne=n(Oa,"A",{id:!0,class:!0,href:!0});var zr=o(ne);us=n(zr,"SPAN",{});var Nr=o(us);h(qe.$$.fragment,Nr),Nr.forEach(s),zr.forEach(s),ro=c(Oa),fs=n(Oa,"SPAN",{});var Lr=o(fs);lo=r(Lr,"Usage example"),Lr.forEach(s),Oa.forEach(s),Qs=c(e),V=n(e,"H3",{class:!0});var Fa=o(V);oe=n(Fa,"A",{id:!0,class:!0,href:!0});var Ar=o(oe);hs=n(Ar,"SPAN",{});var Mr=o(hs);h(Te.$$.fragment,Mr),Mr.forEach(s),Ar.forEach(s),po=c(Fa),gs=n(Fa,"SPAN",{});var Gr=o(gs);co=r(Gr,"Based on an image generated with the input prompt"),Gr.forEach(s),Fa.forEach(s),ea=c(e),h(Ie.$$.fragment,e),ta=c(e),K=n(e,"H3",{class:!0});var Ba=o(K);ie=n(Ba,"A",{id:!0,class:!0,href:!0});var Or=o(ie);_s=n(Or,"SPAN",{});var Fr=o(_s);h(Ce.$$.fragment,Fr),Fr.forEach(s),Or.forEach(s),mo=c(Ba),bs=n(Ba,"SPAN",{});var Br=o(bs);uo=r(Br,"Based on an input image"),Br.forEach(s),Ba.forEach(s),sa=c(e),re=n(e,"P",{});var Ua=o(re);fo=r(Ua,`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),vs=n(Ua,"CODE",{});var Ur=o(vs);ho=r(Ur,"DDIMInverseScheduler"),Ur.forEach(s),go=r(Ua,` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),Ua.forEach(s),aa=c(e),yt=n(e,"P",{});var Hr=o(yt);_o=r(Hr,"First, let\u2019s load our pipeline:"),Hr.forEach(s),na=c(e),h(Ze.$$.fragment,e),oa=c(e),$t=n(e,"P",{});var Rr=o($t);bo=r(Rr,"Then, we load an input image for conditioning and obtain a suitable caption for it:"),Rr.forEach(s),ia=c(e),h(ze.$$.fragment,e),ra=c(e),kt=n(e,"P",{});var Wr=o(kt);vo=r(Wr,"Then we employ the generated caption and the input image to get the inverted noise:"),Wr.forEach(s),la=c(e),h(Ne.$$.fragment,e),pa=c(e),jt=n(e,"P",{});var Vr=o(jt);xo=r(Vr,"Now, generate the image with edit directions:"),Vr.forEach(s),ca=c(e),h(Le.$$.fragment,e),da=c(e),X=n(e,"H2",{class:!0});var Ha=o(X);le=n(Ha,"A",{id:!0,class:!0,href:!0});var Kr=o(le);xs=n(Kr,"SPAN",{});var Xr=o(xs);h(Ae.$$.fragment,Xr),Xr.forEach(s),Kr.forEach(s),wo=c(Ha),ws=n(Ha,"SPAN",{});var Yr=o(ws);Po=r(Yr,"Generating source and target embeddings"),Yr.forEach(s),Ha.forEach(s),ma=c(e),I=n(e,"P",{});var _e=o(I);yo=r(_e,"The authors originally used the "),Me=n(_e,"A",{href:!0,rel:!0});var Jr=o(Me);$o=r(Jr,"GPT-3 API"),Jr.forEach(s),ko=r(_e,` to generate the source and target captions for discovering
edit directions. However, we can also leverage open source and public models for the same purpose.
Below, we provide an end-to-end example with the `),Ge=n(_e,"A",{href:!0,rel:!0});var Qr=o(Ge);jo=r(Qr,"Flan-T5"),Qr.forEach(s),Do=r(_e,` model
for generating captions and `),Oe=n(_e,"A",{href:!0,rel:!0});var el=o(Oe);So=r(el,"CLIP"),el.forEach(s),Eo=r(_e,` for
computing embeddings on the generated captions.`),_e.forEach(s),ua=c(e),Fe=n(e,"P",{});var Ui=o(Fe);Ps=n(Ui,"STRONG",{});var tl=o(Ps);qo=r(tl,"1. Load the generation model"),tl.forEach(s),To=r(Ui,":"),Ui.forEach(s),fa=c(e),h(Be.$$.fragment,e),ha=c(e),Ue=n(e,"P",{});var Hi=o(Ue);ys=n(Hi,"STRONG",{});var sl=o(ys);Io=r(sl,"2. Construct a starting prompt"),sl.forEach(s),Co=r(Hi,":"),Hi.forEach(s),ga=c(e),h(He.$$.fragment,e),_a=c(e),Dt=n(e,"P",{});var al=o(Dt);Zo=r(al,"Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),al.forEach(s),ba=c(e),Re=n(e,"P",{});var Ri=o(Re);$s=n(Ri,"STRONG",{});var nl=o($s);zo=r(nl,"3. Generate captions"),nl.forEach(s),No=r(Ri,":"),Ri.forEach(s),va=c(e),St=n(e,"P",{});var ol=o(St);Lo=r(ol,"We can use a utility like so for this purpose."),ol.forEach(s),xa=c(e),h(We.$$.fragment,e),wa=c(e),Et=n(e,"P",{});var il=o(Et);Ao=r(il,"And then we just call it to generate our captions:"),il.forEach(s),Pa=c(e),h(Ve.$$.fragment,e),ya=c(e),Z=n(e,"P",{});var At=o(Z);Mo=r(At,`We encourage you to play around with the different parameters supported by the
`),ks=n(At,"CODE",{});var rl=o(ks);Go=r(rl,"generate()"),rl.forEach(s),Oo=r(At," method ("),Ke=n(At,"A",{href:!0,rel:!0});var ll=o(Ke);Fo=r(ll,"documentation"),ll.forEach(s),Bo=r(At,") for the generation quality you are looking for."),At.forEach(s),$a=c(e),Xe=n(e,"P",{});var Wi=o(Xe);js=n(Wi,"STRONG",{});var pl=o(js);Uo=r(pl,"4. Load the embedding model"),pl.forEach(s),Ho=r(Wi,":"),Wi.forEach(s),ka=c(e),qt=n(e,"P",{});var cl=o(qt);Ro=r(cl,"Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),cl.forEach(s),ja=c(e),h(Ye.$$.fragment,e),Da=c(e),Je=n(e,"P",{});var Vi=o(Je);Ds=n(Vi,"STRONG",{});var dl=o(Ds);Wo=r(dl,"5. Compute embeddings"),dl.forEach(s),Vo=r(Vi,":"),Vi.forEach(s),Sa=c(e),h(Qe.$$.fragment,e),Ea=c(e),pe=n(e,"P",{});var Ra=o(pe);Ko=r(Ra,"And you\u2019re done! "),et=n(Ra,"A",{href:!0,rel:!0});var ml=o(et);Xo=r(ml,"Here"),ml.forEach(s),Yo=r(Ra," is a Colab Notebook that you can use to interact with the entire process."),Ra.forEach(s),qa=c(e),Tt=n(e,"P",{});var ul=o(Tt);Jo=r(ul,"Now, you can use these embeddings directly while calling the pipeline:"),ul.forEach(s),Ta=c(e),h(tt.$$.fragment,e),Ia=c(e),Y=n(e,"H2",{class:!0});var Wa=o(Y);ce=n(Wa,"A",{id:!0,class:!0,href:!0});var fl=o(ce);Ss=n(fl,"SPAN",{});var hl=o(Ss);h(st.$$.fragment,hl),hl.forEach(s),fl.forEach(s),Qo=c(Wa),Es=n(Wa,"SPAN",{});var gl=o(Es);ei=r(gl,"StableDiffusionPix2PixZeroPipeline"),gl.forEach(s),Wa.forEach(s),Ca=c(e),P=n(e,"DIV",{class:!0});var $=o(P);h(at.$$.fragment,$),ti=c($),qs=n($,"P",{});var _l=o(qs);si=r(_l,"Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),_l.forEach(s),ai=c($),nt=n($,"P",{});var Va=o(nt);ni=r(Va,"This model inherits from "),It=n(Va,"A",{href:!0});var bl=o(It);oi=r(bl,"DiffusionPipeline"),bl.forEach(s),ii=r(Va,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Va.forEach(s),ri=c($),z=n($,"DIV",{class:!0});var Mt=o(z);h(ot.$$.fragment,Mt),li=c(Mt),Ts=n(Mt,"P",{});var vl=o(Ts);pi=r(vl,"Function invoked when calling the pipeline for generation."),vl.forEach(s),ci=c(Mt),h(de.$$.fragment,Mt),Mt.forEach(s),di=c($),me=n($,"DIV",{class:!0});var Ka=o(me);h(it.$$.fragment,Ka),mi=c(Ka),Is=n(Ka,"P",{});var xl=o(Is);ui=r(xl,"Constructs the edit direction to steer the image generation process semantically."),xl.forEach(s),Ka.forEach(s),fi=c($),ue=n($,"DIV",{class:!0});var Xa=o(ue);h(rt.$$.fragment,Xa),hi=c(Xa),q=n(Xa,"P",{});var M=o(q);gi=r(M,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Cs=n(M,"CODE",{});var wl=o(Cs);_i=r(wl,"enable_sequential_cpu_offload"),wl.forEach(s),bi=r(M,", this method moves one whole model at a time to the GPU when its "),Zs=n(M,"CODE",{});var Pl=o(Zs);vi=r(Pl,"forward"),Pl.forEach(s),xi=r(M,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),zs=n(M,"CODE",{});var yl=o(zs);wi=r(yl,"enable_sequential_cpu_offload"),yl.forEach(s),Pi=r(M,", but performance is much better due to the iterative execution of the "),Ns=n(M,"CODE",{});var $l=o(Ns);yi=r($l,"unet"),$l.forEach(s),$i=r(M,"."),M.forEach(s),Xa.forEach(s),ki=c($),fe=n($,"DIV",{class:!0});var Ya=o(fe);h(lt.$$.fragment,Ya),ji=c(Ya),J=n(Ya,"P",{});var Gt=o(J);Di=r(Gt,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Ls=n(Gt,"CODE",{});var kl=o(Ls);Si=r(kl,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),kl.forEach(s),Ei=r(Gt,"forward"),As=n(Gt,"CODE",{});var jl=o(As);qi=r(jl,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),jl.forEach(s),Ti=r(Gt,"enable_model_cpu_offload`, but performance is lower."),Gt.forEach(s),Ya.forEach(s),Ii=c($),he=n($,"DIV",{class:!0});var Ja=o(he);h(pt.$$.fragment,Ja),Ci=c(Ja),Ms=n(Ja,"P",{});var Dl=o(Ms);Zi=r(Dl,"Generates caption for a given image."),Dl.forEach(s),Ja.forEach(s),zi=c($),N=n($,"DIV",{class:!0});var Ot=o(N);h(ct.$$.fragment,Ot),Ni=c(Ot),Gs=n(Ot,"P",{});var Sl=o(Gs);Li=r(Sl,"Function used to generate inverted latents given a prompt and image."),Sl.forEach(s),Ai=c(Ot),h(ge.$$.fragment,Ot),Ot.forEach(s),$.forEach(s),this.h()},h(){m(w,"name","hf:doc:metadata"),m(w,"content",JSON.stringify(Ml)),m(x,"id","zeroshot-imagetoimage-translation"),m(x,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(x,"href","#zeroshot-imagetoimage-translation"),m(y,"class","relative group"),m(ee,"id","overview"),m(ee,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ee,"href","#overview"),m(G,"class","relative group"),m(xe,"href","https://arxiv.org/abs/2302.03027"),m(xe,"rel","nofollow"),m(we,"href","https://pix2pixzero.github.io/"),m(we,"rel","nofollow"),m(Pe,"href","https://arxiv.org/abs/2302.03027"),m(Pe,"rel","nofollow"),m(ye,"href","https://github.com/pix2pixzero/pix2pix-zero"),m(ye,"rel","nofollow"),m(te,"id","tips"),m(te,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(te,"href","#tips"),m(O,"class","relative group"),m(De,"href","https://arxiv.org/abs/2302.03027"),m(De,"rel","nofollow"),m(se,"id","available-pipelines"),m(se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(se,"href","#available-pipelines"),m(U,"class","relative group"),m(wt,"align","center"),m(Ee,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py"),m(Ee,"rel","nofollow"),m(Pt,"align","center"),m(ne,"id","usage-example"),m(ne,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ne,"href","#usage-example"),m(W,"class","relative group"),m(oe,"id","based-on-an-image-generated-with-the-input-prompt"),m(oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(oe,"href","#based-on-an-image-generated-with-the-input-prompt"),m(V,"class","relative group"),m(ie,"id","based-on-an-input-image"),m(ie,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ie,"href","#based-on-an-input-image"),m(K,"class","relative group"),m(le,"id","generating-source-and-target-embeddings"),m(le,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(le,"href","#generating-source-and-target-embeddings"),m(X,"class","relative group"),m(Me,"href","https://openai.com/api/"),m(Me,"rel","nofollow"),m(Ge,"href","https://huggingface.co/docs/transformers/model_doc/flan-t5"),m(Ge,"rel","nofollow"),m(Oe,"href","https://huggingface.co/docs/transformers/model_doc/clip"),m(Oe,"rel","nofollow"),m(Ke,"href","https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.generation_tf_utils.TFGenerationMixin.generate"),m(Ke,"rel","nofollow"),m(et,"href","https://colab.research.google.com/drive/1tz2C1EdfZYAPlzXXbTnf-5PRBiR8_R1F?usp=sharing"),m(et,"rel","nofollow"),m(ce,"id","diffusers.StableDiffusionPix2PixZeroPipeline"),m(ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ce,"href","#diffusers.StableDiffusionPix2PixZeroPipeline"),m(Y,"class","relative group"),m(It,"href","/docs/diffusers/main/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),m(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(me,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(ue,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(fe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(he,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,l){t(document.head,w),d(e,T,l),d(e,y,l),t(y,x),t(x,j),g(u,j,null),t(y,k),t(y,Ft),t(Ft,Qa),d(e,Fs,l),d(e,G,l),t(G,ee),t(ee,Bt),g(be,Bt,null),t(G,en),t(G,Ut),t(Ut,tn),d(e,Bs,l),d(e,ve,l),t(ve,xe),t(xe,sn),t(ve,an),d(e,Us,l),d(e,ft,l),t(ft,nn),d(e,Hs,l),d(e,ht,l),t(ht,Ht),t(Ht,on),d(e,Rs,l),d(e,gt,l),t(gt,rn),d(e,Ws,l),d(e,C,l),t(C,_t),t(_t,we),t(we,ln),t(_t,pn),t(C,cn),t(C,bt),t(bt,Pe),t(Pe,dn),t(bt,mn),t(C,un),t(C,vt),t(vt,ye),t(ye,fn),t(vt,hn),d(e,Vs,l),d(e,O,l),t(O,te),t(te,Rt),g($e,Rt,null),t(O,gn),t(O,Wt),t(Wt,_n),d(e,Ks,l),d(e,D,l),t(D,Vt),t(Vt,bn),t(D,vn),t(D,E),t(E,xn),t(E,Kt),t(Kt,wn),t(E,Pn),t(E,Xt),t(Xt,yn),t(E,$n),t(E,Yt),t(Yt,kn),t(E,jn),t(E,Jt),t(Jt,Dn),t(E,Sn),t(D,En),t(D,F),t(F,qn),t(F,Qt),t(Qt,Tn),t(F,In),t(F,es),t(es,Cn),t(F,Zn),t(D,zn),t(D,xt),t(xt,Nn),t(xt,ke),t(ke,B),t(B,Ln),t(B,ts),t(ts,An),t(B,Mn),t(B,ss),t(ss,Gn),t(B,On),t(ke,Fn),t(ke,as),t(as,Bn),t(D,Un),t(D,je),t(je,Hn),t(je,De),t(De,Rn),t(je,Wn),d(e,Xs,l),d(e,U,l),t(U,se),t(se,ns),g(Se,ns,null),t(U,Vn),t(U,os),t(os,Kn),d(e,Ys,l),d(e,ae,l),t(ae,is),t(is,H),t(H,rs),t(rs,Xn),t(H,Yn),t(H,ls),t(ls,Jn),t(H,Qn),t(H,wt),t(wt,eo),t(ae,to),t(ae,ps),t(ps,R),t(R,cs),t(cs,Ee),t(Ee,so),t(R,ao),t(R,ds),t(ds,ms),t(ms,no),t(R,oo),t(R,Pt),t(Pt,io),d(e,Js,l),d(e,W,l),t(W,ne),t(ne,us),g(qe,us,null),t(W,ro),t(W,fs),t(fs,lo),d(e,Qs,l),d(e,V,l),t(V,oe),t(oe,hs),g(Te,hs,null),t(V,po),t(V,gs),t(gs,co),d(e,ea,l),g(Ie,e,l),d(e,ta,l),d(e,K,l),t(K,ie),t(ie,_s),g(Ce,_s,null),t(K,mo),t(K,bs),t(bs,uo),d(e,sa,l),d(e,re,l),t(re,fo),t(re,vs),t(vs,ho),t(re,go),d(e,aa,l),d(e,yt,l),t(yt,_o),d(e,na,l),g(Ze,e,l),d(e,oa,l),d(e,$t,l),t($t,bo),d(e,ia,l),g(ze,e,l),d(e,ra,l),d(e,kt,l),t(kt,vo),d(e,la,l),g(Ne,e,l),d(e,pa,l),d(e,jt,l),t(jt,xo),d(e,ca,l),g(Le,e,l),d(e,da,l),d(e,X,l),t(X,le),t(le,xs),g(Ae,xs,null),t(X,wo),t(X,ws),t(ws,Po),d(e,ma,l),d(e,I,l),t(I,yo),t(I,Me),t(Me,$o),t(I,ko),t(I,Ge),t(Ge,jo),t(I,Do),t(I,Oe),t(Oe,So),t(I,Eo),d(e,ua,l),d(e,Fe,l),t(Fe,Ps),t(Ps,qo),t(Fe,To),d(e,fa,l),g(Be,e,l),d(e,ha,l),d(e,Ue,l),t(Ue,ys),t(ys,Io),t(Ue,Co),d(e,ga,l),g(He,e,l),d(e,_a,l),d(e,Dt,l),t(Dt,Zo),d(e,ba,l),d(e,Re,l),t(Re,$s),t($s,zo),t(Re,No),d(e,va,l),d(e,St,l),t(St,Lo),d(e,xa,l),g(We,e,l),d(e,wa,l),d(e,Et,l),t(Et,Ao),d(e,Pa,l),g(Ve,e,l),d(e,ya,l),d(e,Z,l),t(Z,Mo),t(Z,ks),t(ks,Go),t(Z,Oo),t(Z,Ke),t(Ke,Fo),t(Z,Bo),d(e,$a,l),d(e,Xe,l),t(Xe,js),t(js,Uo),t(Xe,Ho),d(e,ka,l),d(e,qt,l),t(qt,Ro),d(e,ja,l),g(Ye,e,l),d(e,Da,l),d(e,Je,l),t(Je,Ds),t(Ds,Wo),t(Je,Vo),d(e,Sa,l),g(Qe,e,l),d(e,Ea,l),d(e,pe,l),t(pe,Ko),t(pe,et),t(et,Xo),t(pe,Yo),d(e,qa,l),d(e,Tt,l),t(Tt,Jo),d(e,Ta,l),g(tt,e,l),d(e,Ia,l),d(e,Y,l),t(Y,ce),t(ce,Ss),g(st,Ss,null),t(Y,Qo),t(Y,Es),t(Es,ei),d(e,Ca,l),d(e,P,l),g(at,P,null),t(P,ti),t(P,qs),t(qs,si),t(P,ai),t(P,nt),t(nt,ni),t(nt,It),t(It,oi),t(nt,ii),t(P,ri),t(P,z),g(ot,z,null),t(z,li),t(z,Ts),t(Ts,pi),t(z,ci),g(de,z,null),t(P,di),t(P,me),g(it,me,null),t(me,mi),t(me,Is),t(Is,ui),t(P,fi),t(P,ue),g(rt,ue,null),t(ue,hi),t(ue,q),t(q,gi),t(q,Cs),t(Cs,_i),t(q,bi),t(q,Zs),t(Zs,vi),t(q,xi),t(q,zs),t(zs,wi),t(q,Pi),t(q,Ns),t(Ns,yi),t(q,$i),t(P,ki),t(P,fe),g(lt,fe,null),t(fe,ji),t(fe,J),t(J,Di),t(J,Ls),t(Ls,Si),t(J,Ei),t(J,As),t(As,qi),t(J,Ti),t(P,Ii),t(P,he),g(pt,he,null),t(he,Ci),t(he,Ms),t(Ms,Zi),t(P,zi),t(P,N),g(ct,N,null),t(N,Ni),t(N,Gs),t(Gs,Li),t(N,Ai),g(ge,N,null),Za=!0},p(e,[l]){const dt={};l&2&&(dt.$$scope={dirty:l,ctx:e}),de.$set(dt);const Os={};l&2&&(Os.$$scope={dirty:l,ctx:e}),ge.$set(Os)},i(e){Za||(_(u.$$.fragment,e),_(be.$$.fragment,e),_($e.$$.fragment,e),_(Se.$$.fragment,e),_(qe.$$.fragment,e),_(Te.$$.fragment,e),_(Ie.$$.fragment,e),_(Ce.$$.fragment,e),_(Ze.$$.fragment,e),_(ze.$$.fragment,e),_(Ne.$$.fragment,e),_(Le.$$.fragment,e),_(Ae.$$.fragment,e),_(Be.$$.fragment,e),_(He.$$.fragment,e),_(We.$$.fragment,e),_(Ve.$$.fragment,e),_(Ye.$$.fragment,e),_(Qe.$$.fragment,e),_(tt.$$.fragment,e),_(st.$$.fragment,e),_(at.$$.fragment,e),_(ot.$$.fragment,e),_(de.$$.fragment,e),_(it.$$.fragment,e),_(rt.$$.fragment,e),_(lt.$$.fragment,e),_(pt.$$.fragment,e),_(ct.$$.fragment,e),_(ge.$$.fragment,e),Za=!0)},o(e){b(u.$$.fragment,e),b(be.$$.fragment,e),b($e.$$.fragment,e),b(Se.$$.fragment,e),b(qe.$$.fragment,e),b(Te.$$.fragment,e),b(Ie.$$.fragment,e),b(Ce.$$.fragment,e),b(Ze.$$.fragment,e),b(ze.$$.fragment,e),b(Ne.$$.fragment,e),b(Le.$$.fragment,e),b(Ae.$$.fragment,e),b(Be.$$.fragment,e),b(He.$$.fragment,e),b(We.$$.fragment,e),b(Ve.$$.fragment,e),b(Ye.$$.fragment,e),b(Qe.$$.fragment,e),b(tt.$$.fragment,e),b(st.$$.fragment,e),b(at.$$.fragment,e),b(ot.$$.fragment,e),b(de.$$.fragment,e),b(it.$$.fragment,e),b(rt.$$.fragment,e),b(lt.$$.fragment,e),b(pt.$$.fragment,e),b(ct.$$.fragment,e),b(ge.$$.fragment,e),Za=!1},d(e){s(w),e&&s(T),e&&s(y),v(u),e&&s(Fs),e&&s(G),v(be),e&&s(Bs),e&&s(ve),e&&s(Us),e&&s(ft),e&&s(Hs),e&&s(ht),e&&s(Rs),e&&s(gt),e&&s(Ws),e&&s(C),e&&s(Vs),e&&s(O),v($e),e&&s(Ks),e&&s(D),e&&s(Xs),e&&s(U),v(Se),e&&s(Ys),e&&s(ae),e&&s(Js),e&&s(W),v(qe),e&&s(Qs),e&&s(V),v(Te),e&&s(ea),v(Ie,e),e&&s(ta),e&&s(K),v(Ce),e&&s(sa),e&&s(re),e&&s(aa),e&&s(yt),e&&s(na),v(Ze,e),e&&s(oa),e&&s($t),e&&s(ia),v(ze,e),e&&s(ra),e&&s(kt),e&&s(la),v(Ne,e),e&&s(pa),e&&s(jt),e&&s(ca),v(Le,e),e&&s(da),e&&s(X),v(Ae),e&&s(ma),e&&s(I),e&&s(ua),e&&s(Fe),e&&s(fa),v(Be,e),e&&s(ha),e&&s(Ue),e&&s(ga),v(He,e),e&&s(_a),e&&s(Dt),e&&s(ba),e&&s(Re),e&&s(va),e&&s(St),e&&s(xa),v(We,e),e&&s(wa),e&&s(Et),e&&s(Pa),v(Ve,e),e&&s(ya),e&&s(Z),e&&s($a),e&&s(Xe),e&&s(ka),e&&s(qt),e&&s(ja),v(Ye,e),e&&s(Da),e&&s(Je),e&&s(Sa),v(Qe,e),e&&s(Ea),e&&s(pe),e&&s(qa),e&&s(Tt),e&&s(Ta),v(tt,e),e&&s(Ia),e&&s(Y),v(st),e&&s(Ca),e&&s(P),v(at),v(ot),v(de),v(it),v(rt),v(lt),v(pt),v(ct),v(ge)}}}const Ml={local:"zeroshot-imagetoimage-translation",sections:[{local:"overview",title:"Overview"},{local:"tips",title:"Tips "},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",sections:[{local:"based-on-an-image-generated-with-the-input-prompt",title:"Based on an image generated with the input prompt"},{local:"based-on-an-input-image",title:"Based on an input image"}],title:"Usage example"},{local:"generating-source-and-target-embeddings",title:"Generating source and target embeddings "},{local:"diffusers.StableDiffusionPix2PixZeroPipeline",title:"StableDiffusionPix2PixZeroPipeline"}],title:"Zero-shot Image-to-Image Translation"};function Gl(ut){return zl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Rl extends Tl{constructor(w){super();Il(this,w,Gl,Al,Cl,{})}}export{Rl as default,Ml as metadata};
