import{S as wr,i as yr,s as Mr,e as a,k as p,w as h,t as o,M as Jr,c as n,d as s,m as c,a as l,x as f,h as i,b as m,G as t,g as d,y as g,q as b,o as w,B as y,v as _r,L as br}from"../../../chunks/vendor-hf-doc-builder.js";import{D as mt}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as I}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as be}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as gr}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Tr(ut){let J,E,T,M,U;return M=new I({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBERElNU2NoZWR1bGVyJTJDJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZSUwQSUwQSUwQWRlZiUyMGRvd25sb2FkKGVtYmVkZGluZ191cmwlMkMlMjBsb2NhbF9maWxlcGF0aCklM0ElMEElMjAlMjAlMjAlMjByJTIwJTNEJTIwcmVxdWVzdHMuZ2V0KGVtYmVkZGluZ191cmwpJTBBJTIwJTIwJTIwJTIwd2l0aCUyMG9wZW4obG9jYWxfZmlsZXBhdGglMkMlMjAlMjJ3YiUyMiklMjBhcyUyMGYlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmLndyaXRlKHIuY29udGVudCklMEElMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb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jAlMjB0YXJnZXRfZW1iZWRzJTNEdGFyZ2V0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9ndWlkYW5jZV9hbW91bnQlM0QwLjE1JTJDJTBBKS5pbWFnZXMlMEElMEFpbWFnZXMlNUIwJTVELnNhdmUoJTIyZWRpdGVkX2ltYWdlX2RvZy5wbmclMjIp",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"),E=o("Examples:"),T=p(),h(M.$$.fragment)},l(u){J=n(u,"P",{});var j=l(J);E=i(j,"Examples:"),j.forEach(s),T=c(u),f(M.$$.fragment,u)},m(u,j){d(u,J,j),t(J,E),d(u,T,j),g(M,u,j),U=!0},p:br,i(u){U||(b(M.$$.fragment,u),U=!0)},o(u){w(M.$$.fragment,u),U=!1},d(u){u&&s(J),u&&s(T),y(M,u)}}}function Zr(ut){let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TIwJTYwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCU2MCUyMHRvJTIwMC4wMSUyMG9yJTIwbGVzcyUyMHRvJTIwYXZvaWQlMjBpbnB1dCUyMGxhdGVudCUyMGdyYWRpZW50JTIwZXhwbG9zaW9uJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBjYXB0aW9uJTJDJTBBJTIwJTIwJTIwJTIwc291cmNlX2VtYmVkcyUzRHNvdXJjZV9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjB0YXJnZXRfZW1iZWRzJTNEdGFyZ2V0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9ndWlkYW5jZV9hbW91bnQlM0QwLjE1JTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBJTIwJTIwJTIwJTIwbGF0ZW50cyUzRGludl9sYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0JTNEY2FwdGlvbiUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyZWRpdGVkX2ltYWdlLnBuZyUyMik=",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"),E=o("Examples:"),T=p(),h(M.$$.fragment)},l(u){J=n(u,"P",{});var j=l(J);E=i(j,"Examples:"),j.forEach(s),T=c(u),f(M.$$.fragment,u)},m(u,j){d(u,J,j),t(J,E),d(u,T,j),g(M,u,j),U=!0},p:br,i(u){U||(b(M.$$.fragment,u),U=!0)},o(u){w(M.$$.fragment,u),U=!1},d(u){u&&s(J),u&&s(T),y(M,u)}}}function jr(ut){let J,E,T,M,U,u,j,Rt,Fa,Xs,we,ye,Da,za,Rs,ht,Qa,Vs,ft,Vt,Ha,Ns,B,Aa,Me,qa,La,Je,Ka,Oa,_e,en,tn,Cs,S,K,Nt,Te,sn,Ct,an,Ss,v,St,nn,ln,x,on,Yt,rn,pn,$t,cn,dn,Ft,mn,un,Dt,hn,fn,gn,Y,bn,zt,wn,yn,Qt,Mn,Jn,_n,gt,Tn,Ze,$,Zn,Ht,jn,vn,At,Un,In,xn,qt,Gn,En,je,Bn,ve,Wn,kn,Pn,P,Xn,Lt,Rn,Vn,Kt,Nn,Cn,bt,Sn,Yn,Ys,F,O,Ot,Ue,$n,es,Fn,$s,ee,ts,D,ss,Dn,zn,as,Qn,Hn,wt,An,qn,ns,z,ls,Ie,Ln,Kn,os,is,On,el,yt,xe,tl,Fs,Q,te,rs,Ge,sl,ps,al,Ds,H,se,cs,Ee,nl,ds,ll,zs,Be,Qs,A,ae,ms,We,ol,us,il,Hs,ne,rl,hs,pl,cl,As,Mt,dl,qs,ke,Ls,Jt,ml,Ks,Pe,Os,_t,ul,ea,Xe,ta,Tt,hl,sa,Re,aa,q,le,fs,Ve,fl,gs,gl,na,W,bl,Ne,wl,yl,Ce,Ml,Jl,Se,_l,Tl,la,Ye,bs,Zl,jl,oa,$e,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b2FkKHNyY19lbWJzX3VybC5zcGxpdCglMjIlMkYlMjIpJTVCLTElNUQpJTBBdGFyZ2V0X2VtYmVkcyUyMCUzRCUyMHRvcmNoLmxvYWQodGFyZ2V0X2VtYnNfdXJsLnNwbGl0KCUyMiUyRiUyMiklNUItMSU1RCklMEElMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfZW1iZWRzJTNEc3JjX2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9lbWJlZHMlM0R0YXJnZXRfZW1iZWRzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCUzRDAuMTUlMkMlMEEpLmltYWdlcyUwQWltYWdlcyU1QjAlNUQuc2F2ZSglMjJlZGl0ZWRfaW1hZ2VfZG9nLnBuZyUyMik=",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>)`}}),We=new be({}),ke=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()`}}),Pe=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 be({}),$e=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)`}}),De=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>`}}),Qe=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>)`}}),He=new I({props:{code:"c291cmNlX2NhcHRpb25zJTIwJTNEJTIwZ2VuZXJhdGVfY2FwdGlvbnMoc291cmNlX3RleHQpJTBBdGFyZ2V0X2NhcHRpb25zJTIwJTNEJTIwZ2VuZXJhdGVfY2FwdGlvbnModGFyZ2V0X2NvbmNlcHQp",highlighted:`source_captions = generate_captions(source_text)
target_captions = generate_captions(target_concept)`}}),Le=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`}}),Oe=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMjAlMEElMEFkZWYlMjBlbWJlZF9jYXB0aW9ucyhzZW50ZW5jZXMlMkMlMjB0b2tlbml6ZXIlMkMlMjB0ZXh0X2VuY29kZXIlMkMlMjBkZXZpY2UlM0QlMjJjdWRhJTIyKSUzQSUwQSUyMCUyMCUyMCUyMHd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ih0ZXh0X2lucHV0X2lkcy50byhkZXZpY2UpJTJDJTIwYXR0ZW50aW9uX21hc2slM0ROb25lKSU1QjAlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbWJlZGRpbmdzLmFwcGVuZChwcm9tcHRfZW1iZWRzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHRvcmNoLmNvbmNhdGVuYXRlKGVtYmVkZGluZ3MlMkMlMjBkaW0lM0QwKS5tZWFuKGRpbSUzRDApLnVuc3F1ZWV6ZSgwKSUwQSUwQXNvdXJjZV9lbWJlZGRpbmdzJTIwJTNEJTIwZW1iZWRfY2FwdGlvbnMoc291cmNlX2NhcHRpb25zJTJDJTIwdG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyKSUwQXRhcmdldF9lbWJlZGRpbmdzJTIwJTNEJTIwZW1iZWRfY2FwdGlvbnModGFyZ2V0X2NhcHRpb25zJTJDJTIwdG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch 

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

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