import{S as sp,i as ap,s as np,e as a,k as p,w as m,t as i,M as op,c as n,d as s,m as c,a as o,x as h,h as r,b as u,G as t,g as d,y as g,q as _,o as b,B as v,v as ip,L as tp}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as _t}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as S}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as ee}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ep}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function rp(bt){let w,T,y,x,D;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(),m(x.$$.fragment)},l(f){w=n(f,"P",{});var j=o(w);T=r(j,"Examples:"),j.forEach(s),y=c(f),h(x.$$.fragment,f)},m(f,j){d(f,w,j),t(w,T),d(f,y,j),g(x,f,j),D=!0},p:tp,i(f){D||(_(x.$$.fragment,f),D=!0)},o(f){b(x.$$.fragment,f),D=!1},d(f){f&&s(w),f&&s(y),v(x,f)}}}function lp(bt){let w,T,y,x,D;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
# when using Stable Diffusion 2 or other models that use v-prediction
# set \`cross_attention_guidance_amount\` to 0.01 or less to avoid input latent gradient explosion

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><span class="hljs-comment"># when using Stable Diffusion 2 or other models that use v-prediction</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># set \`cross_attention_guidance_amount\` to 0.01 or less to avoid input latent gradient explosion</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(),m(x.$$.fragment)},l(f){w=n(f,"P",{});var j=o(w);T=r(j,"Examples:"),j.forEach(s),y=c(f),h(x.$$.fragment,f)},m(f,j){d(f,w,j),t(w,T),d(f,y,j),g(x,f,j),D=!0},p:tp,i(f){D||(_(x.$$.fragment,f),D=!0)},o(f){b(x.$$.fragment,f),D=!1},d(f){f&&s(w),f&&s(y),v(x,f)}}}function pp(bt){let w,T,y,x,D,f,j,Vt,ln,Xs,O,te,Kt,we,pn,Xt,cn,Ys,Pe,ye,dn,un,Js,vt,fn,Qs,xt,Yt,mn,ea,wt,hn,ta,I,Pt,$e,gn,_n,bn,yt,je,vn,xn,wn,$t,ke,Pn,yn,$n,jt,De,jn,kn,sa,F,se,Jt,Se,Dn,Qt,Sn,aa,k,es,En,qn,E,Tn,ts,In,Cn,ss,Zn,zn,as,Nn,Ln,ns,An,Mn,Gn,B,On,os,Fn,Bn,is,Un,Hn,Rn,kt,Wn,Ee,U,Vn,rs,Kn,Xn,ls,Yn,Jn,Qn,ps,eo,to,qe,so,Te,ao,no,oo,z,io,cs,ro,lo,ds,po,co,Dt,uo,fo,na,H,ae,us,Ie,mo,fs,ho,oa,ne,ms,R,hs,go,_o,gs,bo,vo,St,xo,wo,_s,W,bs,Ce,Po,yo,vs,xs,$o,jo,Et,Ze,ko,ia,V,oe,ws,ze,Do,Ps,So,ra,K,ie,ys,Ne,Eo,$s,qo,la,Le,pa,X,re,js,Ae,To,ks,Io,ca,le,Co,Ds,Zo,zo,da,qt,No,ua,Me,fa,Tt,Lo,ma,Ge,ha,It,Ao,ga,Oe,_a,Ct,Mo,ba,Fe,va,Y,pe,Ss,Be,Go,Es,Oo,xa,C,Fo,Ue,Bo,Uo,He,Ho,Ro,Re,Wo,Vo,wa,We,qs,Ko,Xo,Pa,Ve,ya,Ke,Ts,Yo,Jo,$a,Xe,ja,Zt,Qo,ka,Ye,Is,ei,ti,Da,zt,si,Sa,Je,Ea,Nt,ai,qa,Qe,Ta,N,ni,Cs,oi,ii,et,ri,li,Ia,tt,Zs,pi,ci,Ca,Lt,di,Za,st,za,at,zs,ui,fi,Na,nt,La,ce,mi,ot,hi,gi,Aa,At,_i,Ma,it,Ga,J,de,Ns,rt,bi,Ls,vi,Oa,P,lt,xi,As,wi,Pi,pt,yi,Mt,$i,ji,ki,L,ct,Di,Ms,Si,Ei,ue,qi,fe,dt,Ti,Gs,Ii,Ci,me,ut,Zi,q,zi,Os,Ni,Li,Fs,Ai,Mi,Bs,Gi,Oi,Us,Fi,Bi,Ui,he,ft,Hi,Q,Ri,Hs,Wi,Vi,Rs,Ki,Xi,Yi,ge,mt,Ji,Ws,Qi,er,A,ht,tr,Vs,sr,ar,_e,Fa;return f=new ee({}),we=new ee({}),Se=new ee({}),Ie=new ee({}),ze=new ee({}),Ne=new ee({}),Le=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 gogh"
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 gogh&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>)`}}),Ae=new ee({}),Me=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()`}}),Ge=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)`}}),Oe=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`}}),Fe=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>)`}}),Be=new ee({}),Ve=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)`}}),Xe=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>`}}),Je=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>)`}}),Qe=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)`}}),st=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`}}),nt=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)`}}),it=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>)`}}),rt=new ee({}),lt=new _t({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:": CLIPImageProcessor"},{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/v0.16.0/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/v0.16.0/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/v0.16.0/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/v0.16.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.16.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, <a href="/docs/diffusers/v0.16.0/en/api/schedulers/euler_ancestral#diffusers.EulerAncestralDiscreteScheduler">EulerAncestralDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.16.0/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>CLIPImageProcessor</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/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L278"}}),ct=new _t({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. 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/v0.16.0/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/v0.16.0/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/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L790",returnDescription:`
<p><a
  href="/docs/diffusers/v0.16.0/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/v0.16.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),ue=new ep({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.example",$$slots:{default:[rp]},$$scope:{ctx:bt}}}),dt=new _t({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/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L686"}}),ut=new _t({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/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L389"}}),ft=new _t({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/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L364"}}),mt=new _t({props:{name:"generate_caption",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.generate_caption",parameters:[{name:"images",val:""}],source:"https://github.com/huggingface/diffusers/blob/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L666"}}),ht=new _t({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 1) &#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/v0.16.0/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/v0.16.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L1067",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>
`}}),_e=new ep({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.example",$$slots:{default:[lp]},$$scope:{ctx:bt}}}),{c(){w=a("meta"),T=p(),y=a("h1"),x=a("a"),D=a("span"),m(f.$$.fragment),j=p(),Vt=a("span"),ln=i("Zero-shot Image-to-Image Translation"),Xs=p(),O=a("h2"),te=a("a"),Kt=a("span"),m(we.$$.fragment),pn=p(),Xt=a("span"),cn=i("Overview"),Ys=p(),Pe=a("p"),ye=a("a"),dn=i("Zero-shot Image-to-Image Translation"),un=i("."),Js=p(),vt=a("p"),fn=i("The abstract of the paper is the following:"),Qs=p(),xt=a("p"),Yt=a("em"),mn=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."),ea=p(),wt=a("p"),hn=i("Resources:"),ta=p(),I=a("ul"),Pt=a("li"),$e=a("a"),gn=i("Project Page"),_n=i("."),bn=p(),yt=a("li"),je=a("a"),vn=i("Paper"),xn=i("."),wn=p(),$t=a("li"),ke=a("a"),Pn=i("Original Code"),yn=i("."),$n=p(),jt=a("li"),De=a("a"),jn=i("Demo"),kn=i("."),sa=p(),F=a("h2"),se=a("a"),Jt=a("span"),m(Se.$$.fragment),Dn=p(),Qt=a("span"),Sn=i("Tips"),aa=p(),k=a("ul"),es=a("li"),En=i("The pipeline can be conditioned on real input images. Check out the code examples below to know more."),qn=p(),E=a("li"),Tn=i("The pipeline exposes two arguments namely "),ts=a("code"),In=i("source_embeds"),Cn=i(" and "),ss=a("code"),Zn=i("target_embeds"),zn=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
`),as=a("code"),Nn=i("source_embeds"),Ln=i(" and \u201Cdog\u201D to "),ns=a("code"),An=i("target_embeds"),Mn=i(". Refer to the code example below for more details."),Gn=p(),B=a("li"),On=i("When you\u2019re using this pipeline from a prompt, specify the "),os=a("em"),Fn=i("source"),Bn=i(` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),is=a("strong"),Un=i("cat"),Hn=i(" in the style of van gough\u201D."),Rn=p(),kt=a("li"),Wn=i("If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),Ee=a("ul"),U=a("li"),Vn=i("Swap the "),rs=a("code"),Kn=i("source_embeds"),Xn=i(" and "),ls=a("code"),Yn=i("target_embeds"),Jn=i("."),Qn=p(),ps=a("li"),eo=i("Change the input prompt to include \u201Cdog\u201D."),to=p(),qe=a("li"),so=i("To learn more about how the source and target embeddings are generated, refer to the "),Te=a("a"),ao=i(`original
paper`),no=i(". Below, we also provide some directions on how to generate the embeddings."),oo=p(),z=a("li"),io=i("Note that the quality of the outputs generated with this pipeline is dependent on how good the "),cs=a("code"),ro=i("source_embeds"),lo=i(" and "),ds=a("code"),po=i("target_embeds"),co=i(" are. Please, refer to "),Dt=a("a"),uo=i("this discussion"),fo=i(" for some suggestions on the topic."),na=p(),H=a("h2"),ae=a("a"),us=a("span"),m(Ie.$$.fragment),mo=p(),fs=a("span"),ho=i("Available Pipelines:"),oa=p(),ne=a("table"),ms=a("thead"),R=a("tr"),hs=a("th"),go=i("Pipeline"),_o=p(),gs=a("th"),bo=i("Tasks"),vo=p(),St=a("th"),xo=i("Demo"),wo=p(),_s=a("tbody"),W=a("tr"),bs=a("td"),Ce=a("a"),Po=i("StableDiffusionPix2PixZeroPipeline"),yo=p(),vs=a("td"),xs=a("em"),$o=i("Text-Based Image Editing"),jo=p(),Et=a("td"),Ze=a("a"),ko=i("\u{1F917} Space"),ia=p(),V=a("h2"),oe=a("a"),ws=a("span"),m(ze.$$.fragment),Do=p(),Ps=a("span"),So=i("Usage example"),ra=p(),K=a("h3"),ie=a("a"),ys=a("span"),m(Ne.$$.fragment),Eo=p(),$s=a("span"),qo=i("Based on an image generated with the input prompt"),la=p(),m(Le.$$.fragment),pa=p(),X=a("h3"),re=a("a"),js=a("span"),m(Ae.$$.fragment),To=p(),ks=a("span"),Io=i("Based on an input image"),ca=p(),le=a("p"),Co=i(`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),Ds=a("code"),Zo=i("DDIMInverseScheduler"),zo=i(` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),da=p(),qt=a("p"),No=i("First, let\u2019s load our pipeline:"),ua=p(),m(Me.$$.fragment),fa=p(),Tt=a("p"),Lo=i("Then, we load an input image for conditioning and obtain a suitable caption for it:"),ma=p(),m(Ge.$$.fragment),ha=p(),It=a("p"),Ao=i("Then we employ the generated caption and the input image to get the inverted noise:"),ga=p(),m(Oe.$$.fragment),_a=p(),Ct=a("p"),Mo=i("Now, generate the image with edit directions:"),ba=p(),m(Fe.$$.fragment),va=p(),Y=a("h2"),pe=a("a"),Ss=a("span"),m(Be.$$.fragment),Go=p(),Es=a("span"),Oo=i("Generating source and target embeddings"),xa=p(),C=a("p"),Fo=i("The authors originally used the "),Ue=a("a"),Bo=i("GPT-3 API"),Uo=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 `),He=a("a"),Ho=i("Flan-T5"),Ro=i(` model
for generating captions and `),Re=a("a"),Wo=i("CLIP"),Vo=i(` for
computing embeddings on the generated captions.`),wa=p(),We=a("p"),qs=a("strong"),Ko=i("1. Load the generation model"),Xo=i(":"),Pa=p(),m(Ve.$$.fragment),ya=p(),Ke=a("p"),Ts=a("strong"),Yo=i("2. Construct a starting prompt"),Jo=i(":"),$a=p(),m(Xe.$$.fragment),ja=p(),Zt=a("p"),Qo=i("Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),ka=p(),Ye=a("p"),Is=a("strong"),ei=i("3. Generate captions"),ti=i(":"),Da=p(),zt=a("p"),si=i("We can use a utility like so for this purpose."),Sa=p(),m(Je.$$.fragment),Ea=p(),Nt=a("p"),ai=i("And then we just call it to generate our captions:"),qa=p(),m(Qe.$$.fragment),Ta=p(),N=a("p"),ni=i(`We encourage you to play around with the different parameters supported by the
`),Cs=a("code"),oi=i("generate()"),ii=i(" method ("),et=a("a"),ri=i("documentation"),li=i(") for the generation quality you are looking for."),Ia=p(),tt=a("p"),Zs=a("strong"),pi=i("4. Load the embedding model"),ci=i(":"),Ca=p(),Lt=a("p"),di=i("Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),Za=p(),m(st.$$.fragment),za=p(),at=a("p"),zs=a("strong"),ui=i("5. Compute embeddings"),fi=i(":"),Na=p(),m(nt.$$.fragment),La=p(),ce=a("p"),mi=i("And you\u2019re done! "),ot=a("a"),hi=i("Here"),gi=i(" is a Colab Notebook that you can use to interact with the entire process."),Aa=p(),At=a("p"),_i=i("Now, you can use these embeddings directly while calling the pipeline:"),Ma=p(),m(it.$$.fragment),Ga=p(),J=a("h2"),de=a("a"),Ns=a("span"),m(rt.$$.fragment),bi=p(),Ls=a("span"),vi=i("StableDiffusionPix2PixZeroPipeline"),Oa=p(),P=a("div"),m(lt.$$.fragment),xi=p(),As=a("p"),wi=i("Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),Pi=p(),pt=a("p"),yi=i("This model inherits from "),Mt=a("a"),$i=i("DiffusionPipeline"),ji=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.)`),ki=p(),L=a("div"),m(ct.$$.fragment),Di=p(),Ms=a("p"),Si=i("Function invoked when calling the pipeline for generation."),Ei=p(),m(ue.$$.fragment),qi=p(),fe=a("div"),m(dt.$$.fragment),Ti=p(),Gs=a("p"),Ii=i("Constructs the edit direction to steer the image generation process semantically."),Ci=p(),me=a("div"),m(ut.$$.fragment),Zi=p(),q=a("p"),zi=i(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Os=a("code"),Ni=i("enable_sequential_cpu_offload"),Li=i(", this method moves one whole model at a time to the GPU when its "),Fs=a("code"),Ai=i("forward"),Mi=i(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),Bs=a("code"),Gi=i("enable_sequential_cpu_offload"),Oi=i(", but performance is much better due to the iterative execution of the "),Us=a("code"),Fi=i("unet"),Bi=i("."),Ui=p(),he=a("div"),m(ft.$$.fragment),Hi=p(),Q=a("p"),Ri=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
`),Hs=a("code"),Wi=i("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Vi=i("forward"),Rs=a("code"),Ki=i("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Xi=i("enable_model_cpu_offload`, but performance is lower."),Yi=p(),ge=a("div"),m(mt.$$.fragment),Ji=p(),Ws=a("p"),Qi=i("Generates caption for a given image."),er=p(),A=a("div"),m(ht.$$.fragment),tr=p(),Vs=a("p"),sr=i("Function used to generate inverted latents given a prompt and image."),ar=p(),m(_e.$$.fragment),this.h()},l(e){const l=op('[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 gt=o(y);x=n(gt,"A",{id:!0,class:!0,href:!0});var Ks=o(x);D=n(Ks,"SPAN",{});var hr=o(D);h(f.$$.fragment,hr),hr.forEach(s),Ks.forEach(s),j=c(gt),Vt=n(gt,"SPAN",{});var gr=o(Vt);ln=r(gr,"Zero-shot Image-to-Image Translation"),gr.forEach(s),gt.forEach(s),Xs=c(e),O=n(e,"H2",{class:!0});var Ba=o(O);te=n(Ba,"A",{id:!0,class:!0,href:!0});var _r=o(te);Kt=n(_r,"SPAN",{});var br=o(Kt);h(we.$$.fragment,br),br.forEach(s),_r.forEach(s),pn=c(Ba),Xt=n(Ba,"SPAN",{});var vr=o(Xt);cn=r(vr,"Overview"),vr.forEach(s),Ba.forEach(s),Ys=c(e),Pe=n(e,"P",{});var nr=o(Pe);ye=n(nr,"A",{href:!0,rel:!0});var xr=o(ye);dn=r(xr,"Zero-shot Image-to-Image Translation"),xr.forEach(s),un=r(nr,"."),nr.forEach(s),Js=c(e),vt=n(e,"P",{});var wr=o(vt);fn=r(wr,"The abstract of the paper is the following:"),wr.forEach(s),Qs=c(e),xt=n(e,"P",{});var Pr=o(xt);Yt=n(Pr,"EM",{});var yr=o(Yt);mn=r(yr,"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."),yr.forEach(s),Pr.forEach(s),ea=c(e),wt=n(e,"P",{});var $r=o(wt);hn=r($r,"Resources:"),$r.forEach(s),ta=c(e),I=n(e,"UL",{});var be=o(I);Pt=n(be,"LI",{});var or=o(Pt);$e=n(or,"A",{href:!0,rel:!0});var jr=o($e);gn=r(jr,"Project Page"),jr.forEach(s),_n=r(or,"."),or.forEach(s),bn=c(be),yt=n(be,"LI",{});var ir=o(yt);je=n(ir,"A",{href:!0,rel:!0});var kr=o(je);vn=r(kr,"Paper"),kr.forEach(s),xn=r(ir,"."),ir.forEach(s),wn=c(be),$t=n(be,"LI",{});var rr=o($t);ke=n(rr,"A",{href:!0,rel:!0});var Dr=o(ke);Pn=r(Dr,"Original Code"),Dr.forEach(s),yn=r(rr,"."),rr.forEach(s),$n=c(be),jt=n(be,"LI",{});var lr=o(jt);De=n(lr,"A",{href:!0,rel:!0});var Sr=o(De);jn=r(Sr,"Demo"),Sr.forEach(s),kn=r(lr,"."),lr.forEach(s),be.forEach(s),sa=c(e),F=n(e,"H2",{class:!0});var Ua=o(F);se=n(Ua,"A",{id:!0,class:!0,href:!0});var Er=o(se);Jt=n(Er,"SPAN",{});var qr=o(Jt);h(Se.$$.fragment,qr),qr.forEach(s),Er.forEach(s),Dn=c(Ua),Qt=n(Ua,"SPAN",{});var Tr=o(Qt);Sn=r(Tr,"Tips"),Tr.forEach(s),Ua.forEach(s),aa=c(e),k=n(e,"UL",{});var Z=o(k);es=n(Z,"LI",{});var Ir=o(es);En=r(Ir,"The pipeline can be conditioned on real input images. Check out the code examples below to know more."),Ir.forEach(s),qn=c(Z),E=n(Z,"LI",{});var M=o(E);Tn=r(M,"The pipeline exposes two arguments namely "),ts=n(M,"CODE",{});var Cr=o(ts);In=r(Cr,"source_embeds"),Cr.forEach(s),Cn=r(M," and "),ss=n(M,"CODE",{});var Zr=o(ss);Zn=r(Zr,"target_embeds"),Zr.forEach(s),zn=r(M,`
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
`),as=n(M,"CODE",{});var zr=o(as);Nn=r(zr,"source_embeds"),zr.forEach(s),Ln=r(M," and \u201Cdog\u201D to "),ns=n(M,"CODE",{});var Nr=o(ns);An=r(Nr,"target_embeds"),Nr.forEach(s),Mn=r(M,". Refer to the code example below for more details."),M.forEach(s),Gn=c(Z),B=n(Z,"LI",{});var Gt=o(B);On=r(Gt,"When you\u2019re using this pipeline from a prompt, specify the "),os=n(Gt,"EM",{});var Lr=o(os);Fn=r(Lr,"source"),Lr.forEach(s),Bn=r(Gt,` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),is=n(Gt,"STRONG",{});var Ar=o(is);Un=r(Ar,"cat"),Ar.forEach(s),Hn=r(Gt," in the style of van gough\u201D."),Gt.forEach(s),Rn=c(Z),kt=n(Z,"LI",{});var pr=o(kt);Wn=r(pr,"If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),Ee=n(pr,"UL",{});var Ha=o(Ee);U=n(Ha,"LI",{});var Ot=o(U);Vn=r(Ot,"Swap the "),rs=n(Ot,"CODE",{});var Mr=o(rs);Kn=r(Mr,"source_embeds"),Mr.forEach(s),Xn=r(Ot," and "),ls=n(Ot,"CODE",{});var Gr=o(ls);Yn=r(Gr,"target_embeds"),Gr.forEach(s),Jn=r(Ot,"."),Ot.forEach(s),Qn=c(Ha),ps=n(Ha,"LI",{});var Or=o(ps);eo=r(Or,"Change the input prompt to include \u201Cdog\u201D."),Or.forEach(s),Ha.forEach(s),pr.forEach(s),to=c(Z),qe=n(Z,"LI",{});var Ra=o(qe);so=r(Ra,"To learn more about how the source and target embeddings are generated, refer to the "),Te=n(Ra,"A",{href:!0,rel:!0});var Fr=o(Te);ao=r(Fr,`original
paper`),Fr.forEach(s),no=r(Ra,". Below, we also provide some directions on how to generate the embeddings."),Ra.forEach(s),oo=c(Z),z=n(Z,"LI",{});var ve=o(z);io=r(ve,"Note that the quality of the outputs generated with this pipeline is dependent on how good the "),cs=n(ve,"CODE",{});var Br=o(cs);ro=r(Br,"source_embeds"),Br.forEach(s),lo=r(ve," and "),ds=n(ve,"CODE",{});var Ur=o(ds);po=r(Ur,"target_embeds"),Ur.forEach(s),co=r(ve," are. Please, refer to "),Dt=n(ve,"A",{href:!0});var Hr=o(Dt);uo=r(Hr,"this discussion"),Hr.forEach(s),fo=r(ve," for some suggestions on the topic."),ve.forEach(s),Z.forEach(s),na=c(e),H=n(e,"H2",{class:!0});var Wa=o(H);ae=n(Wa,"A",{id:!0,class:!0,href:!0});var Rr=o(ae);us=n(Rr,"SPAN",{});var Wr=o(us);h(Ie.$$.fragment,Wr),Wr.forEach(s),Rr.forEach(s),mo=c(Wa),fs=n(Wa,"SPAN",{});var Vr=o(fs);ho=r(Vr,"Available Pipelines:"),Vr.forEach(s),Wa.forEach(s),oa=c(e),ne=n(e,"TABLE",{});var Va=o(ne);ms=n(Va,"THEAD",{});var Kr=o(ms);R=n(Kr,"TR",{});var Ft=o(R);hs=n(Ft,"TH",{});var Xr=o(hs);go=r(Xr,"Pipeline"),Xr.forEach(s),_o=c(Ft),gs=n(Ft,"TH",{});var Yr=o(gs);bo=r(Yr,"Tasks"),Yr.forEach(s),vo=c(Ft),St=n(Ft,"TH",{align:!0});var Jr=o(St);xo=r(Jr,"Demo"),Jr.forEach(s),Ft.forEach(s),Kr.forEach(s),wo=c(Va),_s=n(Va,"TBODY",{});var Qr=o(_s);W=n(Qr,"TR",{});var Bt=o(W);bs=n(Bt,"TD",{});var el=o(bs);Ce=n(el,"A",{href:!0,rel:!0});var tl=o(Ce);Po=r(tl,"StableDiffusionPix2PixZeroPipeline"),tl.forEach(s),el.forEach(s),yo=c(Bt),vs=n(Bt,"TD",{});var sl=o(vs);xs=n(sl,"EM",{});var al=o(xs);$o=r(al,"Text-Based Image Editing"),al.forEach(s),sl.forEach(s),jo=c(Bt),Et=n(Bt,"TD",{align:!0});var nl=o(Et);Ze=n(nl,"A",{href:!0,rel:!0});var ol=o(Ze);ko=r(ol,"\u{1F917} Space"),ol.forEach(s),nl.forEach(s),Bt.forEach(s),Qr.forEach(s),Va.forEach(s),ia=c(e),V=n(e,"H2",{class:!0});var Ka=o(V);oe=n(Ka,"A",{id:!0,class:!0,href:!0});var il=o(oe);ws=n(il,"SPAN",{});var rl=o(ws);h(ze.$$.fragment,rl),rl.forEach(s),il.forEach(s),Do=c(Ka),Ps=n(Ka,"SPAN",{});var ll=o(Ps);So=r(ll,"Usage example"),ll.forEach(s),Ka.forEach(s),ra=c(e),K=n(e,"H3",{class:!0});var Xa=o(K);ie=n(Xa,"A",{id:!0,class:!0,href:!0});var pl=o(ie);ys=n(pl,"SPAN",{});var cl=o(ys);h(Ne.$$.fragment,cl),cl.forEach(s),pl.forEach(s),Eo=c(Xa),$s=n(Xa,"SPAN",{});var dl=o($s);qo=r(dl,"Based on an image generated with the input prompt"),dl.forEach(s),Xa.forEach(s),la=c(e),h(Le.$$.fragment,e),pa=c(e),X=n(e,"H3",{class:!0});var Ya=o(X);re=n(Ya,"A",{id:!0,class:!0,href:!0});var ul=o(re);js=n(ul,"SPAN",{});var fl=o(js);h(Ae.$$.fragment,fl),fl.forEach(s),ul.forEach(s),To=c(Ya),ks=n(Ya,"SPAN",{});var ml=o(ks);Io=r(ml,"Based on an input image"),ml.forEach(s),Ya.forEach(s),ca=c(e),le=n(e,"P",{});var Ja=o(le);Co=r(Ja,`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),Ds=n(Ja,"CODE",{});var hl=o(Ds);Zo=r(hl,"DDIMInverseScheduler"),hl.forEach(s),zo=r(Ja,` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),Ja.forEach(s),da=c(e),qt=n(e,"P",{});var gl=o(qt);No=r(gl,"First, let\u2019s load our pipeline:"),gl.forEach(s),ua=c(e),h(Me.$$.fragment,e),fa=c(e),Tt=n(e,"P",{});var _l=o(Tt);Lo=r(_l,"Then, we load an input image for conditioning and obtain a suitable caption for it:"),_l.forEach(s),ma=c(e),h(Ge.$$.fragment,e),ha=c(e),It=n(e,"P",{});var bl=o(It);Ao=r(bl,"Then we employ the generated caption and the input image to get the inverted noise:"),bl.forEach(s),ga=c(e),h(Oe.$$.fragment,e),_a=c(e),Ct=n(e,"P",{});var vl=o(Ct);Mo=r(vl,"Now, generate the image with edit directions:"),vl.forEach(s),ba=c(e),h(Fe.$$.fragment,e),va=c(e),Y=n(e,"H2",{class:!0});var Qa=o(Y);pe=n(Qa,"A",{id:!0,class:!0,href:!0});var xl=o(pe);Ss=n(xl,"SPAN",{});var wl=o(Ss);h(Be.$$.fragment,wl),wl.forEach(s),xl.forEach(s),Go=c(Qa),Es=n(Qa,"SPAN",{});var Pl=o(Es);Oo=r(Pl,"Generating source and target embeddings"),Pl.forEach(s),Qa.forEach(s),xa=c(e),C=n(e,"P",{});var xe=o(C);Fo=r(xe,"The authors originally used the "),Ue=n(xe,"A",{href:!0,rel:!0});var yl=o(Ue);Bo=r(yl,"GPT-3 API"),yl.forEach(s),Uo=r(xe,` 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 `),He=n(xe,"A",{href:!0,rel:!0});var $l=o(He);Ho=r($l,"Flan-T5"),$l.forEach(s),Ro=r(xe,` model
for generating captions and `),Re=n(xe,"A",{href:!0,rel:!0});var jl=o(Re);Wo=r(jl,"CLIP"),jl.forEach(s),Vo=r(xe,` for
computing embeddings on the generated captions.`),xe.forEach(s),wa=c(e),We=n(e,"P",{});var cr=o(We);qs=n(cr,"STRONG",{});var kl=o(qs);Ko=r(kl,"1. Load the generation model"),kl.forEach(s),Xo=r(cr,":"),cr.forEach(s),Pa=c(e),h(Ve.$$.fragment,e),ya=c(e),Ke=n(e,"P",{});var dr=o(Ke);Ts=n(dr,"STRONG",{});var Dl=o(Ts);Yo=r(Dl,"2. Construct a starting prompt"),Dl.forEach(s),Jo=r(dr,":"),dr.forEach(s),$a=c(e),h(Xe.$$.fragment,e),ja=c(e),Zt=n(e,"P",{});var Sl=o(Zt);Qo=r(Sl,"Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),Sl.forEach(s),ka=c(e),Ye=n(e,"P",{});var ur=o(Ye);Is=n(ur,"STRONG",{});var El=o(Is);ei=r(El,"3. Generate captions"),El.forEach(s),ti=r(ur,":"),ur.forEach(s),Da=c(e),zt=n(e,"P",{});var ql=o(zt);si=r(ql,"We can use a utility like so for this purpose."),ql.forEach(s),Sa=c(e),h(Je.$$.fragment,e),Ea=c(e),Nt=n(e,"P",{});var Tl=o(Nt);ai=r(Tl,"And then we just call it to generate our captions:"),Tl.forEach(s),qa=c(e),h(Qe.$$.fragment,e),Ta=c(e),N=n(e,"P",{});var Ut=o(N);ni=r(Ut,`We encourage you to play around with the different parameters supported by the
`),Cs=n(Ut,"CODE",{});var Il=o(Cs);oi=r(Il,"generate()"),Il.forEach(s),ii=r(Ut," method ("),et=n(Ut,"A",{href:!0,rel:!0});var Cl=o(et);ri=r(Cl,"documentation"),Cl.forEach(s),li=r(Ut,") for the generation quality you are looking for."),Ut.forEach(s),Ia=c(e),tt=n(e,"P",{});var fr=o(tt);Zs=n(fr,"STRONG",{});var Zl=o(Zs);pi=r(Zl,"4. Load the embedding model"),Zl.forEach(s),ci=r(fr,":"),fr.forEach(s),Ca=c(e),Lt=n(e,"P",{});var zl=o(Lt);di=r(zl,"Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),zl.forEach(s),Za=c(e),h(st.$$.fragment,e),za=c(e),at=n(e,"P",{});var mr=o(at);zs=n(mr,"STRONG",{});var Nl=o(zs);ui=r(Nl,"5. Compute embeddings"),Nl.forEach(s),fi=r(mr,":"),mr.forEach(s),Na=c(e),h(nt.$$.fragment,e),La=c(e),ce=n(e,"P",{});var en=o(ce);mi=r(en,"And you\u2019re done! "),ot=n(en,"A",{href:!0,rel:!0});var Ll=o(ot);hi=r(Ll,"Here"),Ll.forEach(s),gi=r(en," is a Colab Notebook that you can use to interact with the entire process."),en.forEach(s),Aa=c(e),At=n(e,"P",{});var Al=o(At);_i=r(Al,"Now, you can use these embeddings directly while calling the pipeline:"),Al.forEach(s),Ma=c(e),h(it.$$.fragment,e),Ga=c(e),J=n(e,"H2",{class:!0});var tn=o(J);de=n(tn,"A",{id:!0,class:!0,href:!0});var Ml=o(de);Ns=n(Ml,"SPAN",{});var Gl=o(Ns);h(rt.$$.fragment,Gl),Gl.forEach(s),Ml.forEach(s),bi=c(tn),Ls=n(tn,"SPAN",{});var Ol=o(Ls);vi=r(Ol,"StableDiffusionPix2PixZeroPipeline"),Ol.forEach(s),tn.forEach(s),Oa=c(e),P=n(e,"DIV",{class:!0});var $=o(P);h(lt.$$.fragment,$),xi=c($),As=n($,"P",{});var Fl=o(As);wi=r(Fl,"Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),Fl.forEach(s),Pi=c($),pt=n($,"P",{});var sn=o(pt);yi=r(sn,"This model inherits from "),Mt=n(sn,"A",{href:!0});var Bl=o(Mt);$i=r(Bl,"DiffusionPipeline"),Bl.forEach(s),ji=r(sn,`. 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.)`),sn.forEach(s),ki=c($),L=n($,"DIV",{class:!0});var Ht=o(L);h(ct.$$.fragment,Ht),Di=c(Ht),Ms=n(Ht,"P",{});var Ul=o(Ms);Si=r(Ul,"Function invoked when calling the pipeline for generation."),Ul.forEach(s),Ei=c(Ht),h(ue.$$.fragment,Ht),Ht.forEach(s),qi=c($),fe=n($,"DIV",{class:!0});var an=o(fe);h(dt.$$.fragment,an),Ti=c(an),Gs=n(an,"P",{});var Hl=o(Gs);Ii=r(Hl,"Constructs the edit direction to steer the image generation process semantically."),Hl.forEach(s),an.forEach(s),Ci=c($),me=n($,"DIV",{class:!0});var nn=o(me);h(ut.$$.fragment,nn),Zi=c(nn),q=n(nn,"P",{});var G=o(q);zi=r(G,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Os=n(G,"CODE",{});var Rl=o(Os);Ni=r(Rl,"enable_sequential_cpu_offload"),Rl.forEach(s),Li=r(G,", this method moves one whole model at a time to the GPU when its "),Fs=n(G,"CODE",{});var Wl=o(Fs);Ai=r(Wl,"forward"),Wl.forEach(s),Mi=r(G,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),Bs=n(G,"CODE",{});var Vl=o(Bs);Gi=r(Vl,"enable_sequential_cpu_offload"),Vl.forEach(s),Oi=r(G,", but performance is much better due to the iterative execution of the "),Us=n(G,"CODE",{});var Kl=o(Us);Fi=r(Kl,"unet"),Kl.forEach(s),Bi=r(G,"."),G.forEach(s),nn.forEach(s),Ui=c($),he=n($,"DIV",{class:!0});var on=o(he);h(ft.$$.fragment,on),Hi=c(on),Q=n(on,"P",{});var Rt=o(Q);Ri=r(Rt,`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
`),Hs=n(Rt,"CODE",{});var Xl=o(Hs);Wi=r(Xl,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),Xl.forEach(s),Vi=r(Rt,"forward"),Rs=n(Rt,"CODE",{});var Yl=o(Rs);Ki=r(Yl,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),Yl.forEach(s),Xi=r(Rt,"enable_model_cpu_offload`, but performance is lower."),Rt.forEach(s),on.forEach(s),Yi=c($),ge=n($,"DIV",{class:!0});var rn=o(ge);h(mt.$$.fragment,rn),Ji=c(rn),Ws=n(rn,"P",{});var Jl=o(Ws);Qi=r(Jl,"Generates caption for a given image."),Jl.forEach(s),rn.forEach(s),er=c($),A=n($,"DIV",{class:!0});var Wt=o(A);h(ht.$$.fragment,Wt),tr=c(Wt),Vs=n(Wt,"P",{});var Ql=o(Vs);sr=r(Ql,"Function used to generate inverted latents given a prompt and image."),Ql.forEach(s),ar=c(Wt),h(_e.$$.fragment,Wt),Wt.forEach(s),$.forEach(s),this.h()},h(){u(w,"name","hf:doc:metadata"),u(w,"content",JSON.stringify(cp)),u(x,"id","zeroshot-imagetoimage-translation"),u(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"),u(x,"href","#zeroshot-imagetoimage-translation"),u(y,"class","relative group"),u(te,"id","overview"),u(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"),u(te,"href","#overview"),u(O,"class","relative group"),u(ye,"href","https://arxiv.org/abs/2302.03027"),u(ye,"rel","nofollow"),u($e,"href","https://pix2pixzero.github.io/"),u($e,"rel","nofollow"),u(je,"href","https://arxiv.org/abs/2302.03027"),u(je,"rel","nofollow"),u(ke,"href","https://github.com/pix2pixzero/pix2pix-zero"),u(ke,"rel","nofollow"),u(De,"href","https://huggingface.co/spaces/pix2pix-zero-library/pix2pix-zero-demo"),u(De,"rel","nofollow"),u(se,"id","tips"),u(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"),u(se,"href","#tips"),u(F,"class","relative group"),u(Te,"href","https://arxiv.org/abs/2302.03027"),u(Te,"rel","nofollow"),u(Dt,"href","#generating-source-and-target-embeddings"),u(ae,"id","available-pipelines"),u(ae,"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"),u(ae,"href","#available-pipelines"),u(H,"class","relative group"),u(St,"align","center"),u(Ce,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py"),u(Ce,"rel","nofollow"),u(Ze,"href","https://huggingface.co/spaces/pix2pix-zero-library/pix2pix-zero-demo"),u(Ze,"rel","nofollow"),u(Et,"align","center"),u(oe,"id","usage-example"),u(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"),u(oe,"href","#usage-example"),u(V,"class","relative group"),u(ie,"id","based-on-an-image-generated-with-the-input-prompt"),u(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"),u(ie,"href","#based-on-an-image-generated-with-the-input-prompt"),u(K,"class","relative group"),u(re,"id","based-on-an-input-image"),u(re,"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"),u(re,"href","#based-on-an-input-image"),u(X,"class","relative group"),u(pe,"id","generating-source-and-target-embeddings"),u(pe,"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"),u(pe,"href","#generating-source-and-target-embeddings"),u(Y,"class","relative group"),u(Ue,"href","https://openai.com/api/"),u(Ue,"rel","nofollow"),u(He,"href","https://huggingface.co/docs/transformers/model_doc/flan-t5"),u(He,"rel","nofollow"),u(Re,"href","https://huggingface.co/docs/transformers/model_doc/clip"),u(Re,"rel","nofollow"),u(et,"href","https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.generation_tf_utils.TFGenerationMixin.generate"),u(et,"rel","nofollow"),u(ot,"href","https://colab.research.google.com/drive/1tz2C1EdfZYAPlzXXbTnf-5PRBiR8_R1F?usp=sharing"),u(ot,"rel","nofollow"),u(de,"id","diffusers.StableDiffusionPix2PixZeroPipeline"),u(de,"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"),u(de,"href","#diffusers.StableDiffusionPix2PixZeroPipeline"),u(J,"class","relative group"),u(Mt,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(L,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(fe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(me,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(he,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(ge,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(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,D),g(f,D,null),t(y,j),t(y,Vt),t(Vt,ln),d(e,Xs,l),d(e,O,l),t(O,te),t(te,Kt),g(we,Kt,null),t(O,pn),t(O,Xt),t(Xt,cn),d(e,Ys,l),d(e,Pe,l),t(Pe,ye),t(ye,dn),t(Pe,un),d(e,Js,l),d(e,vt,l),t(vt,fn),d(e,Qs,l),d(e,xt,l),t(xt,Yt),t(Yt,mn),d(e,ea,l),d(e,wt,l),t(wt,hn),d(e,ta,l),d(e,I,l),t(I,Pt),t(Pt,$e),t($e,gn),t(Pt,_n),t(I,bn),t(I,yt),t(yt,je),t(je,vn),t(yt,xn),t(I,wn),t(I,$t),t($t,ke),t(ke,Pn),t($t,yn),t(I,$n),t(I,jt),t(jt,De),t(De,jn),t(jt,kn),d(e,sa,l),d(e,F,l),t(F,se),t(se,Jt),g(Se,Jt,null),t(F,Dn),t(F,Qt),t(Qt,Sn),d(e,aa,l),d(e,k,l),t(k,es),t(es,En),t(k,qn),t(k,E),t(E,Tn),t(E,ts),t(ts,In),t(E,Cn),t(E,ss),t(ss,Zn),t(E,zn),t(E,as),t(as,Nn),t(E,Ln),t(E,ns),t(ns,An),t(E,Mn),t(k,Gn),t(k,B),t(B,On),t(B,os),t(os,Fn),t(B,Bn),t(B,is),t(is,Un),t(B,Hn),t(k,Rn),t(k,kt),t(kt,Wn),t(kt,Ee),t(Ee,U),t(U,Vn),t(U,rs),t(rs,Kn),t(U,Xn),t(U,ls),t(ls,Yn),t(U,Jn),t(Ee,Qn),t(Ee,ps),t(ps,eo),t(k,to),t(k,qe),t(qe,so),t(qe,Te),t(Te,ao),t(qe,no),t(k,oo),t(k,z),t(z,io),t(z,cs),t(cs,ro),t(z,lo),t(z,ds),t(ds,po),t(z,co),t(z,Dt),t(Dt,uo),t(z,fo),d(e,na,l),d(e,H,l),t(H,ae),t(ae,us),g(Ie,us,null),t(H,mo),t(H,fs),t(fs,ho),d(e,oa,l),d(e,ne,l),t(ne,ms),t(ms,R),t(R,hs),t(hs,go),t(R,_o),t(R,gs),t(gs,bo),t(R,vo),t(R,St),t(St,xo),t(ne,wo),t(ne,_s),t(_s,W),t(W,bs),t(bs,Ce),t(Ce,Po),t(W,yo),t(W,vs),t(vs,xs),t(xs,$o),t(W,jo),t(W,Et),t(Et,Ze),t(Ze,ko),d(e,ia,l),d(e,V,l),t(V,oe),t(oe,ws),g(ze,ws,null),t(V,Do),t(V,Ps),t(Ps,So),d(e,ra,l),d(e,K,l),t(K,ie),t(ie,ys),g(Ne,ys,null),t(K,Eo),t(K,$s),t($s,qo),d(e,la,l),g(Le,e,l),d(e,pa,l),d(e,X,l),t(X,re),t(re,js),g(Ae,js,null),t(X,To),t(X,ks),t(ks,Io),d(e,ca,l),d(e,le,l),t(le,Co),t(le,Ds),t(Ds,Zo),t(le,zo),d(e,da,l),d(e,qt,l),t(qt,No),d(e,ua,l),g(Me,e,l),d(e,fa,l),d(e,Tt,l),t(Tt,Lo),d(e,ma,l),g(Ge,e,l),d(e,ha,l),d(e,It,l),t(It,Ao),d(e,ga,l),g(Oe,e,l),d(e,_a,l),d(e,Ct,l),t(Ct,Mo),d(e,ba,l),g(Fe,e,l),d(e,va,l),d(e,Y,l),t(Y,pe),t(pe,Ss),g(Be,Ss,null),t(Y,Go),t(Y,Es),t(Es,Oo),d(e,xa,l),d(e,C,l),t(C,Fo),t(C,Ue),t(Ue,Bo),t(C,Uo),t(C,He),t(He,Ho),t(C,Ro),t(C,Re),t(Re,Wo),t(C,Vo),d(e,wa,l),d(e,We,l),t(We,qs),t(qs,Ko),t(We,Xo),d(e,Pa,l),g(Ve,e,l),d(e,ya,l),d(e,Ke,l),t(Ke,Ts),t(Ts,Yo),t(Ke,Jo),d(e,$a,l),g(Xe,e,l),d(e,ja,l),d(e,Zt,l),t(Zt,Qo),d(e,ka,l),d(e,Ye,l),t(Ye,Is),t(Is,ei),t(Ye,ti),d(e,Da,l),d(e,zt,l),t(zt,si),d(e,Sa,l),g(Je,e,l),d(e,Ea,l),d(e,Nt,l),t(Nt,ai),d(e,qa,l),g(Qe,e,l),d(e,Ta,l),d(e,N,l),t(N,ni),t(N,Cs),t(Cs,oi),t(N,ii),t(N,et),t(et,ri),t(N,li),d(e,Ia,l),d(e,tt,l),t(tt,Zs),t(Zs,pi),t(tt,ci),d(e,Ca,l),d(e,Lt,l),t(Lt,di),d(e,Za,l),g(st,e,l),d(e,za,l),d(e,at,l),t(at,zs),t(zs,ui),t(at,fi),d(e,Na,l),g(nt,e,l),d(e,La,l),d(e,ce,l),t(ce,mi),t(ce,ot),t(ot,hi),t(ce,gi),d(e,Aa,l),d(e,At,l),t(At,_i),d(e,Ma,l),g(it,e,l),d(e,Ga,l),d(e,J,l),t(J,de),t(de,Ns),g(rt,Ns,null),t(J,bi),t(J,Ls),t(Ls,vi),d(e,Oa,l),d(e,P,l),g(lt,P,null),t(P,xi),t(P,As),t(As,wi),t(P,Pi),t(P,pt),t(pt,yi),t(pt,Mt),t(Mt,$i),t(pt,ji),t(P,ki),t(P,L),g(ct,L,null),t(L,Di),t(L,Ms),t(Ms,Si),t(L,Ei),g(ue,L,null),t(P,qi),t(P,fe),g(dt,fe,null),t(fe,Ti),t(fe,Gs),t(Gs,Ii),t(P,Ci),t(P,me),g(ut,me,null),t(me,Zi),t(me,q),t(q,zi),t(q,Os),t(Os,Ni),t(q,Li),t(q,Fs),t(Fs,Ai),t(q,Mi),t(q,Bs),t(Bs,Gi),t(q,Oi),t(q,Us),t(Us,Fi),t(q,Bi),t(P,Ui),t(P,he),g(ft,he,null),t(he,Hi),t(he,Q),t(Q,Ri),t(Q,Hs),t(Hs,Wi),t(Q,Vi),t(Q,Rs),t(Rs,Ki),t(Q,Xi),t(P,Yi),t(P,ge),g(mt,ge,null),t(ge,Ji),t(ge,Ws),t(Ws,Qi),t(P,er),t(P,A),g(ht,A,null),t(A,tr),t(A,Vs),t(Vs,sr),t(A,ar),g(_e,A,null),Fa=!0},p(e,[l]){const gt={};l&2&&(gt.$$scope={dirty:l,ctx:e}),ue.$set(gt);const Ks={};l&2&&(Ks.$$scope={dirty:l,ctx:e}),_e.$set(Ks)},i(e){Fa||(_(f.$$.fragment,e),_(we.$$.fragment,e),_(Se.$$.fragment,e),_(Ie.$$.fragment,e),_(ze.$$.fragment,e),_(Ne.$$.fragment,e),_(Le.$$.fragment,e),_(Ae.$$.fragment,e),_(Me.$$.fragment,e),_(Ge.$$.fragment,e),_(Oe.$$.fragment,e),_(Fe.$$.fragment,e),_(Be.$$.fragment,e),_(Ve.$$.fragment,e),_(Xe.$$.fragment,e),_(Je.$$.fragment,e),_(Qe.$$.fragment,e),_(st.$$.fragment,e),_(nt.$$.fragment,e),_(it.$$.fragment,e),_(rt.$$.fragment,e),_(lt.$$.fragment,e),_(ct.$$.fragment,e),_(ue.$$.fragment,e),_(dt.$$.fragment,e),_(ut.$$.fragment,e),_(ft.$$.fragment,e),_(mt.$$.fragment,e),_(ht.$$.fragment,e),_(_e.$$.fragment,e),Fa=!0)},o(e){b(f.$$.fragment,e),b(we.$$.fragment,e),b(Se.$$.fragment,e),b(Ie.$$.fragment,e),b(ze.$$.fragment,e),b(Ne.$$.fragment,e),b(Le.$$.fragment,e),b(Ae.$$.fragment,e),b(Me.$$.fragment,e),b(Ge.$$.fragment,e),b(Oe.$$.fragment,e),b(Fe.$$.fragment,e),b(Be.$$.fragment,e),b(Ve.$$.fragment,e),b(Xe.$$.fragment,e),b(Je.$$.fragment,e),b(Qe.$$.fragment,e),b(st.$$.fragment,e),b(nt.$$.fragment,e),b(it.$$.fragment,e),b(rt.$$.fragment,e),b(lt.$$.fragment,e),b(ct.$$.fragment,e),b(ue.$$.fragment,e),b(dt.$$.fragment,e),b(ut.$$.fragment,e),b(ft.$$.fragment,e),b(mt.$$.fragment,e),b(ht.$$.fragment,e),b(_e.$$.fragment,e),Fa=!1},d(e){s(w),e&&s(T),e&&s(y),v(f),e&&s(Xs),e&&s(O),v(we),e&&s(Ys),e&&s(Pe),e&&s(Js),e&&s(vt),e&&s(Qs),e&&s(xt),e&&s(ea),e&&s(wt),e&&s(ta),e&&s(I),e&&s(sa),e&&s(F),v(Se),e&&s(aa),e&&s(k),e&&s(na),e&&s(H),v(Ie),e&&s(oa),e&&s(ne),e&&s(ia),e&&s(V),v(ze),e&&s(ra),e&&s(K),v(Ne),e&&s(la),v(Le,e),e&&s(pa),e&&s(X),v(Ae),e&&s(ca),e&&s(le),e&&s(da),e&&s(qt),e&&s(ua),v(Me,e),e&&s(fa),e&&s(Tt),e&&s(ma),v(Ge,e),e&&s(ha),e&&s(It),e&&s(ga),v(Oe,e),e&&s(_a),e&&s(Ct),e&&s(ba),v(Fe,e),e&&s(va),e&&s(Y),v(Be),e&&s(xa),e&&s(C),e&&s(wa),e&&s(We),e&&s(Pa),v(Ve,e),e&&s(ya),e&&s(Ke),e&&s($a),v(Xe,e),e&&s(ja),e&&s(Zt),e&&s(ka),e&&s(Ye),e&&s(Da),e&&s(zt),e&&s(Sa),v(Je,e),e&&s(Ea),e&&s(Nt),e&&s(qa),v(Qe,e),e&&s(Ta),e&&s(N),e&&s(Ia),e&&s(tt),e&&s(Ca),e&&s(Lt),e&&s(Za),v(st,e),e&&s(za),e&&s(at),e&&s(Na),v(nt,e),e&&s(La),e&&s(ce),e&&s(Aa),e&&s(At),e&&s(Ma),v(it,e),e&&s(Ga),e&&s(J),v(rt),e&&s(Oa),e&&s(P),v(lt),v(ct),v(ue),v(dt),v(ut),v(ft),v(mt),v(ht),v(_e)}}}const cp={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 dp(bt){return ip(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class _p extends sp{constructor(w){super();ap(this,w,dp,pp,np,{})}}export{_p as default,cp as metadata};
