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