import{S as Xc,i as $c,s as xc,e as a,k as d,w as f,t as s,M as Vc,c as o,d as n,m as p,a as i,x as u,h as l,b as m,G as t,g as c,y as h,q as g,o as b,B as y,v as Sc,L as Nc}from"../../../chunks/vendor-hf-doc-builder.js";import{D as ee}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as J}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as te}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Fc}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Pc(xa){let T,N;return T=new J({props:{code:"aW1wb3J0JTIwUElMJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBpbyUyMGltcG9ydCUyMEJ5dGVzSU8lMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uRGlmZkVkaXRQaXBlbGluZSUwQSUwQSUwQWRlZiUyMGRvd25sb2FkX2ltYWdlKHVybCklM0ElMEElMjAlMjAlMjAlMjByZXNwb25zZSUyMCUzRCUyMHJlcXVlc3RzLmdldCh1cmwpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwUElMLkltYWdlLm9wZW4oQnl0ZXNJTyhyZXNwb25zZS5jb250ZW50KSkuY29udmVydCglMjJSR0IlMjIpJTBBJTBBJTBBaW1nX3VybCUyMCUzRCUyMCUyMmh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRlhpYW5nLWNkJTJGRGlmZkVkaXQtc3RhYmxlLWRpZmZ1c2lvbiUyRnJhdyUyRm1haW4lMkZhc3NldHMlMkZvcmlnaW4ucG5nJTIyJTBBJTBBaW5pdF9pbWFnZSUyMCUzRCUyMGRvd25sb2FkX2ltYWdlKGltZ191cmwpLnJlc2l6ZSgoNzY4JTJDJTIwNzY4KSklMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uRGlmZkVkaXRQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLTItMSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSklMEFwaXBlJTIwJTNEJTIwcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQXBpcGVsaW5lLnNjaGVkdWxlciUyMCUzRCUyMERESU1TY2hlZHVsZXIuZnJvbV9jb25maWcocGlwZWxpbmUuc2NoZWR1bGVyLmNvbmZpZyklMEFwaXBlbGluZS5pbnZlcnNlX3NjaGVkdWxlciUyMCUzRCUyMERESU1JbnZlcnNlU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGVsaW5lLnNjaGVkdWxlci5jb25maWcpJTBBcGlwZWxpbmUuZW5hYmxlX21vZGVsX2NwdV9vZmZsb2FkKCklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJBJTIwYm93bCUyMG9mJTIwZnJ1aXRzJTIyJTBBJTBBaW52ZXJ0ZWRfbGF0ZW50cyUyMCUzRCUyMHBpcGUuaW52ZXJ0KGltYWdlJTNEaW5pdF9pbWFnZSUyQyUyMHByb21wdCUzRHByb21wdCkubGF0ZW50cw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> PIL
<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> io <span class="hljs-keyword">import</span> BytesIO

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


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">download_image</span>(<span class="hljs-params">url</span>):
<span class="hljs-meta">... </span>    response = requests.get(url)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> PIL.Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span>img_url = <span class="hljs-string">&quot;https://github.com/Xiang-cd/DiffEdit-stable-diffusion/raw/main/assets/origin.png&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>init_image = download_image(img_url).resize((<span class="hljs-number">768</span>, <span class="hljs-number">768</span>))

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionDiffEditPipeline.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;stabilityai/stable-diffusion-2-1&quot;</span>, torch_dtype=torch.float16
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</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>prompt = <span class="hljs-string">&quot;A bowl of fruits&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>inverted_latents = pipe.invert(image=init_image, prompt=prompt).latents`}}),{c(){f(T.$$.fragment)},l(v){u(T.$$.fragment,v)},m(v,B){h(T,v,B),N=!0},p:Nc,i(v){N||(g(T.$$.fragment,v),N=!0)},o(v){b(T.$$.fragment,v),N=!1},d(v){y(T,v)}}}function Hc(xa){let T,N,v,B,hn,Me,wi,gn,vi,Va,F,ne,bn,Je,Mi,yn,Ji,Sa,Te,Ee,Ti,Ei,Na,jt,Ui,Fa,Gt,_n,Ii,Pa,Wt,Zi,Ha,C,Bt,Ue,ki,ji,Gi,Ct,Ie,Wi,Bi,Ci,Rt,Ze,Ri,Di,Ya,P,ae,wn,ke,Xi,vn,$i,Aa,M,Mn,xi,Vi,j,Si,Jn,Ni,Fi,Tn,Pi,Hi,En,Yi,Ai,zi,E,Qi,Un,Li,qi,In,Oi,Ki,Zn,es,ts,kn,ns,as,jn,os,is,ss,G,ls,Gn,rs,ds,Wn,ps,cs,Dt,ms,fs,us,I,hs,Bn,gs,bs,Cn,ys,_s,Rn,ws,vs,Dn,Ms,Js,Ts,Xt,Es,H,W,Us,Xn,Is,Zs,$n,ks,js,xn,Gs,Ws,Bs,je,Cs,Vn,Rs,Ds,Xs,Y,$s,Sn,xs,Vs,Nn,Ss,Ns,Fs,Ge,Ps,$t,Hs,Ys,za,A,oe,Fn,We,As,Pn,zs,Qa,ie,Hn,Be,Yn,Qs,Ls,An,qs,Os,zn,Ce,Qn,Re,Ks,el,Ln,qn,tl,La,z,se,On,De,nl,Kn,al,qa,Q,le,ea,Xe,ol,ta,il,Oa,re,sl,na,ll,rl,Ka,xt,dl,eo,$e,to,Vt,pl,no,xe,ao,St,cl,oo,Ve,io,Nt,ml,so,Se,lo,Ft,fl,ro,Ne,po,L,de,aa,Fe,ul,oa,hl,co,pe,gl,Pe,bl,yl,mo,Pt,_l,fo,He,uo,Ht,wl,ho,Ye,go,Yt,vl,bo,Ae,yo,At,Ml,_o,ze,wo,zt,Jl,vo,Qe,Mo,q,ce,ia,Le,Tl,sa,El,Jo,me,Ul,qe,Il,Zl,To,Oe,la,kl,jl,Eo,Ke,Uo,et,ra,Gl,Wl,Io,tt,Zo,Qt,Bl,ko,nt,da,Cl,Rl,jo,Lt,Dl,Go,at,Wo,qt,Xl,Bo,ot,Co,R,$l,pa,xl,Vl,it,Sl,Nl,Ro,st,ca,Fl,Pl,Do,Ot,Hl,Xo,lt,$o,rt,ma,Yl,Al,xo,dt,Vo,Kt,zl,So,pt,No,O,fe,fa,ct,Ql,ua,Ll,Fo,_,mt,ql,ft,Ol,ha,Kl,er,tr,ut,nr,en,ar,or,ir,ga,sr,lr,ht,gt,ba,rr,dr,tn,pr,cr,bt,ya,mr,fr,nn,ur,hr,_a,gr,br,wa,yt,va,yr,_r,an,wr,vr,D,_t,Mr,Ma,Jr,Tr,Ja,Er,Ur,X,wt,Ir,Ta,Zr,kr,ue,jr,he,vt,Gr,Mt,Wr,Ea,Br,Cr,Rr,ge,Jt,Dr,Tt,Xr,Ua,$r,xr,Vr,be,Et,Sr,Z,Nr,Ia,Fr,Pr,Za,Hr,Yr,ka,Ar,zr,ja,Qr,Lr,qr,ye,Ut,Or,K,Kr,Ga,ed,td,Wa,nd,ad,od,$,It,id,Ba,sd,ld,Ca,rd,dd,x,Zt,pd,Ra,cd,md,Da,fd,Po,on,Xa,$a,ud,Ho;return Me=new te({}),Je=new te({}),ke=new te({}),We=new te({}),De=new te({}),Xe=new te({}),$e=new J({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVNjaGVkdWxlciUyQyUyMERESU1JbnZlcnNlU2NoZWR1bGVyJTJDJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZSUwQSUwQXNkX21vZGVsX2NrcHQlMjAlM0QlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24tMi0xJTIyJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25EaWZmRWRpdFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBzZF9tb2RlbF9ja3B0JTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwc2FmZXR5X2NoZWNrZXIlM0ROb25lJTJDJTBBKSUwQXBpcGVsaW5lLnNjaGVkdWxlciUyMCUzRCUyMERESU1TY2hlZHVsZXIuZnJvbV9jb25maWcocGlwZWxpbmUuc2NoZWR1bGVyLmNvbmZpZyklMEFwaXBlbGluZS5pbnZlcnNlX3NjaGVkdWxlciUyMCUzRCUyMERESU1JbnZlcnNlU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGVsaW5lLnNjaGVkdWxlci5jb25maWcpJTBBcGlwZWxpbmUuZW5hYmxlX21vZGVsX2NwdV9vZmZsb2FkKCklMEFwaXBlbGluZS5lbmFibGVfdmFlX3NsaWNpbmcoKSUwQWdlbmVyYXRvciUyMCUzRCUyMHRvcmNoLm1hbnVhbF9zZWVkKDAp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

sd_model_ckpt = <span class="hljs-string">&quot;stabilityai/stable-diffusion-2-1&quot;</span>
pipeline = StableDiffusionDiffEditPipeline.from_pretrained(
    sd_model_ckpt,
    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()
pipeline.enable_vae_slicing()
generator = torch.manual_seed(<span class="hljs-number">0</span>)`}}),xe=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGxvYWRfaW1hZ2UlMEElMEFpbWdfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGWGlhbmctY2QlMkZEaWZmRWRpdC1zdGFibGUtZGlmZnVzaW9uJTJGcmF3JTJGbWFpbiUyRmFzc2V0cyUyRm9yaWdpbi5wbmclMjIlMEFyYXdfaW1hZ2UlMjAlM0QlMjBsb2FkX2ltYWdlKGltZ191cmwpLmNvbnZlcnQoJTIyUkdCJTIyKS5yZXNpemUoKDc2OCUyQyUyMDc2OCkp",highlighted:`<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

img_url = <span class="hljs-string">&quot;https://github.com/Xiang-cd/DiffEdit-stable-diffusion/raw/main/assets/origin.png&quot;</span>
raw_image = load_image(img_url).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">768</span>, <span class="hljs-number">768</span>))`}}),Ve=new J({props:{code:"JTIzJTIwU2VlJTIwdGhlJTIwJTIyR2VuZXJhdGluZyUyMHNvdXJjZSUyMGFuZCUyMHRhcmdldCUyMGVtYmVkZGluZ3MlMjIlMjBzZWN0aW9uJTIwYmVsb3clMjB0byUwQSUyMyUyMGF1dG9tYXRlJTIwdGhlJTIwZ2VuZXJhdGlvbiUyMG9mJTIwdGhlc2UlMjBjYXB0aW9ucyUyMHdpdGglMjBhJTIwcHJlLXRyYWluZWQlMjBtb2RlbCUyMGxpa2UlMjBGbGFuLVQ1JTIwYXMlMjBleHBsYWluZWQlMjBiZWxvdy4lMEElMEFzb3VyY2VfcHJvbXB0JTIwJTNEJTIwJTIyYSUyMGJvd2wlMjBvZiUyMGZydWl0cyUyMiUwQXRhcmdldF9wcm9tcHQlMjAlM0QlMjAlMjJhJTIwYmFza2V0JTIwb2YlMjBmcnVpdHMlMjIlMEFtYXNrX2ltYWdlJTIwJTNEJTIwcGlwZWxpbmUuZ2VuZXJhdGVfbWFzayglMEElMjAlMjAlMjAlMjBpbWFnZSUzRHJhd19pbWFnZSUyQyUwQSUyMCUyMCUyMCUyMHNvdXJjZV9wcm9tcHQlM0Rzb3VyY2VfcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X3Byb21wdCUzRHRhcmdldF9wcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMEEp",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_prompt = <span class="hljs-string">&quot;a bowl of fruits&quot;</span>
target_prompt = <span class="hljs-string">&quot;a basket of fruits&quot;</span>
mask_image = pipeline.generate_mask(
    image=raw_image,
    source_prompt=source_prompt,
    target_prompt=target_prompt,
    generator=generator,
)`}}),Se=new J({props:{code:"aW52X2xhdGVudHMlMjAlM0QlMjBwaXBlbGluZS5pbnZlcnQocHJvbXB0JTNEc291cmNlX3Byb21wdCUyQyUyMGltYWdlJTNEcmF3X2ltYWdlJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5sYXRlbnRz",highlighted:"inv_latents = pipeline.invert(prompt=source_prompt, image=raw_image, generator=generator).latents"}}),Ne=new J({props:{code:"aW1hZ2UlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0R0YXJnZXRfcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwbWFza19pbWFnZSUzRG1hc2tfaW1hZ2UlMkMlMEElMjAlMjAlMjAlMjBpbWFnZV9sYXRlbnRzJTNEaW52X2xhdGVudHMlMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMEElMjAlMjAlMjAlMjBuZWdhdGl2ZV9wcm9tcHQlM0Rzb3VyY2VfcHJvbXB0JTJDJTBBKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJlZGl0ZWRfaW1hZ2UucG5nJTIyKQ==",highlighted:`image = pipeline(
    prompt=target_prompt,
    mask_image=mask_image,
    image_latents=inv_latents,
    generator=generator,
    negative_prompt=source_prompt,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),Fe=new te({}),He=new J({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQmxpcEZvckNvbmRpdGlvbmFsR2VuZXJhdGlvbiUyQyUyMEJsaXBQcm9jZXNzb3IlMEElMEFjYXB0aW9uZXJfaWQlMjAlM0QlMjAlMjJTYWxlc2ZvcmNlJTJGYmxpcC1pbWFnZS1jYXB0aW9uaW5nLWJhc2UlMjIlMEFwcm9jZXNzb3IlMjAlM0QlMjBCbGlwUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZChjYXB0aW9uZXJfaWQpJTBBbW9kZWwlMjAlM0QlMjBCbGlwRm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uLmZyb21fcHJldHJhaW5lZChjYXB0aW9uZXJfaWQlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMjBsb3dfY3B1X21lbV91c2FnZSUzRFRydWUp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor

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>)`}}),Ye=new J({props:{code:"JTQwdG9yY2gubm9fZ3JhZCgpJTBBZGVmJTIwZ2VuZXJhdGVfY2FwdGlvbihpbWFnZXMlMkMlMjBjYXB0aW9uX2dlbmVyYXRvciUyQyUyMGNhcHRpb25fcHJvY2Vzc29yKSUzQSUwQSUyMCUyMCUyMCUyMHRleHQlMjAlM0QlMjAlMjJhJTIwcGhvdG9ncmFwaCUyMG9mJTIyJTBBJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwY2FwdGlvbl9wcm9jZXNzb3IoaW1hZ2VzJTJDJTIwdGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnRvKGRldmljZSUzRCUyMmN1ZGElMjIlMkMlMjBkdHlwZSUzRGNhcHRpb25fZ2VuZXJhdG9yLmR0eXBlKSUwQSUyMCUyMCUyMCUyMGNhcHRpb25fZ2VuZXJhdG9yLnRvKCUyMmN1ZGElMjIpJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMGNhcHRpb25fZ2VuZXJhdG9yLmdlbmVyYXRlKCoqaW5wdXRzJTJDJTIwbWF4X25ld190b2tlbnMlM0QxMjgpJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwb2ZmbG9hZCUyMGNhcHRpb24lMjBnZW5lcmF0b3IlMEElMjAlMjAlMjAlMjBjYXB0aW9uX2dlbmVyYXRvci50byglMjJjcHUlMjIpJTBBJTBBJTIwJTIwJTIwJTIwY2FwdGlvbiUyMCUzRCUyMGNhcHRpb25fcHJvY2Vzc29yLmJhdGNoX2RlY29kZShvdXRwdXRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTVCMCU1RCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGNhcHRpb24=",highlighted:`<span class="hljs-meta">@torch.no_grad()</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_caption</span>(<span class="hljs-params">images, caption_generator, caption_processor</span>):
    text = <span class="hljs-string">&quot;a photograph of&quot;</span>

    inputs = caption_processor(images, text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device=<span class="hljs-string">&quot;cuda&quot;</span>, dtype=caption_generator.dtype)
    caption_generator.to(<span class="hljs-string">&quot;cuda&quot;</span>)
    outputs = caption_generator.generate(**inputs, max_new_tokens=<span class="hljs-number">128</span>)

    <span class="hljs-comment"># offload caption generator</span>
    caption_generator.to(<span class="hljs-string">&quot;cpu&quot;</span>)

    caption = caption_processor.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
    <span class="hljs-keyword">return</span> caption`}}),Ae=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGxvYWRfaW1hZ2UlMEElMEFpbWdfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGWGlhbmctY2QlMkZEaWZmRWRpdC1zdGFibGUtZGlmZnVzaW9uJTJGcmF3JTJGbWFpbiUyRmFzc2V0cyUyRm9yaWdpbi5wbmclMjIlMEFyYXdfaW1hZ2UlMjAlM0QlMjBsb2FkX2ltYWdlKGltZ191cmwpLmNvbnZlcnQoJTIyUkdCJTIyKS5yZXNpemUoKDc2OCUyQyUyMDc2OCkpJTBBY2FwdGlvbiUyMCUzRCUyMGdlbmVyYXRlX2NhcHRpb24ocmF3X2ltYWdlJTJDJTIwbW9kZWwlMkMlMjBwcm9jZXNzb3Ip",highlighted:`<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

img_url = <span class="hljs-string">&quot;https://github.com/Xiang-cd/DiffEdit-stable-diffusion/raw/main/assets/origin.png&quot;</span>
raw_image = load_image(img_url).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">768</span>, <span class="hljs-number">768</span>))
caption = generate_caption(raw_image, model, processor)`}}),ze=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1JbnZlcnNlU2NoZWR1bGVyJTJDJTIwRERJTVNjaGVkdWxlciUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uRGlmZkVkaXRQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLTItMSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSklMEFwaXBlbGluZSUyMCUzRCUyMHBpcGVsaW5lLnRvKCUyMmN1ZGElMjIpJTBBcGlwZWxpbmUuZW5hYmxlX21vZGVsX2NwdV9vZmZsb2FkKCklMEFwaXBlbGluZS5lbmFibGVfdmFlX3NsaWNpbmcoKSUwQSUwQXBpcGVsaW5lLnNjaGVkdWxlciUyMCUzRCUyMERESU1TY2hlZHVsZXIuZnJvbV9jb25maWcocGlwZWxpbmUuc2NoZWR1bGVyLmNvbmZpZyklMEFwaXBlbGluZS5pbnZlcnNlX3NjaGVkdWxlciUyMCUzRCUyMERESU1JbnZlcnNlU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGVsaW5lLnNjaGVkdWxlci5jb25maWcpJTBBJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEFpbnZfbGF0ZW50cyUyMCUzRCUyMHBpcGVsaW5lLmludmVydChwcm9tcHQlM0RjYXB0aW9uJTJDJTIwaW1hZ2UlM0RyYXdfaW1hZ2UlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmxhdGVudHM=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMInverseScheduler, DDIMScheduler

pipeline = StableDiffusionDiffEditPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-2-1&quot;</span>, torch_dtype=torch.float16
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.enable_model_cpu_offload()
pipeline.enable_vae_slicing()

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

generator = torch.manual_seed(<span class="hljs-number">0</span>)
inv_latents = pipeline.invert(prompt=caption, image=raw_image, generator=generator).latents`}}),Qe=new J({props:{code:"c291cmNlX3Byb21wdCUyMCUzRCUyMCUyMmElMjBib3dsJTIwb2YlMjBmcnVpdHMlMjIlMEF0YXJnZXRfcHJvbXB0JTIwJTNEJTIwJTIyYSUyMGJhc2tldCUyMG9mJTIwZnJ1aXRzJTIyJTBBJTBBbWFza19pbWFnZSUyMCUzRCUyMHBpcGVsaW5lLmdlbmVyYXRlX21hc2soJTBBJTIwJTIwJTIwJTIwaW1hZ2UlM0RyYXdfaW1hZ2UlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfcHJvbXB0JTNEc291cmNlX3Byb21wdCUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9wcm9tcHQlM0R0YXJnZXRfcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTNEdGFyZ2V0X3Byb21wdCUyQyUwQSUyMCUyMCUyMCUyMG1hc2tfaW1hZ2UlM0RtYXNrX2ltYWdlJTJDJTBBJTIwJTIwJTIwJTIwaW1hZ2VfbGF0ZW50cyUzRGludl9sYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0JTNEc291cmNlX3Byb21wdCUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyZWRpdGVkX2ltYWdlLnBuZyUyMik=",highlighted:`source_prompt = <span class="hljs-string">&quot;a bowl of fruits&quot;</span>
target_prompt = <span class="hljs-string">&quot;a basket of fruits&quot;</span>

mask_image = pipeline.generate_mask(
    image=raw_image,
    source_prompt=source_prompt,
    target_prompt=target_prompt,
    generator=generator,
)

image = pipeline(
    prompt=target_prompt,
    mask_image=mask_image,
    image_latents=inv_latents,
    generator=generator,
    negative_prompt=source_prompt,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),Le=new te({}),Ke=new J({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)`}}),tt=new J({props:{code:"c291cmNlX2NvbmNlcHQlMjAlM0QlMjAlMjJib3dsJTIyJTBBdGFyZ2V0X2NvbmNlcHQlMjAlM0QlMjAlMjJiYXNrZXQlMjIlMEElMEFzb3VyY2VfdGV4dCUyMCUzRCUyMGYlMjJQcm92aWRlJTIwYSUyMGNhcHRpb24lMjBmb3IlMjBpbWFnZXMlMjBjb250YWluaW5nJTIwYSUyMCU3QnNvdXJjZV9jb25jZXB0JTdELiUyMCUyMiUwQSUyMlRoZSUyMGNhcHRpb25zJTIwc2hvdWxkJTIwYmUlMjBpbiUyMEVuZ2xpc2glMjBhbmQlMjBzaG91bGQlMjBiZSUyMG5vJTIwbG9uZ2VyJTIwdGhhbiUyMDE1MCUyMGNoYXJhY3RlcnMuJTIyJTBBJTBBdGFyZ2V0X3RleHQlMjAlM0QlMjBmJTIyUHJvdmlkZSUyMGElMjBjYXB0aW9uJTIwZm9yJTIwaW1hZ2VzJTIwY29udGFpbmluZyUyMGElMjAlN0J0YXJnZXRfY29uY2VwdCU3RC4lMjAlMjIlMEElMjJUaGUlMjBjYXB0aW9ucyUyMHNob3VsZCUyMGJlJTIwaW4lMjBFbmdsaXNoJTIwYW5kJTIwc2hvdWxkJTIwYmUlMjBubyUyMGxvbmdlciUyMHRoYW4lMjAxNTAlMjBjaGFyYWN0ZXJzLiUyMg==",highlighted:`source_concept = <span class="hljs-string">&quot;bowl&quot;</span>
target_concept = <span class="hljs-string">&quot;basket&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>`}}),at=new J({props:{code:"JTQwdG9yY2gubm9fZ3JhZCUwQWRlZiUyMGdlbmVyYXRlX3Byb21wdHMoaW5wdXRfcHJvbXB0KSUzQSUwQSUyMCUyMCUyMCUyMGlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplcihpbnB1dF9wcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMudG8oJTIyY3VkYSUyMiklMEElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfaWRzJTJDJTIwdGVtcGVyYXR1cmUlM0QwLjglMkMlMjBudW1fcmV0dXJuX3NlcXVlbmNlcyUzRDE2JTJDJTIwZG9fc2FtcGxlJTNEVHJ1ZSUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMTI4JTJDJTIwdG9wX2slM0QxMCUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKG91dHB1dHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-meta">@torch.no_grad</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_prompts</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>)`}}),ot=new J({props:{code:"c291cmNlX3Byb21wdHMlMjAlM0QlMjBnZW5lcmF0ZV9wcm9tcHRzKHNvdXJjZV90ZXh0KSUwQXRhcmdldF9wcm9tcHRzJTIwJTNEJTIwZ2VuZXJhdGVfcHJvbXB0cyh0YXJnZXRfdGV4dCk=",highlighted:`source_prompts = generate_prompts(source_text)
target_prompts = generate_prompts(target_text)`}}),lt=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvbkRpZmZFZGl0UGlwZWxpbmUlMjAlMEElMEFwaXBlbGluZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvbkRpZmZFZGl0UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi0yLTElMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpJTBBcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmVuYWJsZV9tb2RlbF9jcHVfb2ZmbG9hZCgpJTBBcGlwZWxpbmUuZW5hYmxlX3ZhZV9zbGljaW5nKCklMEElMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5tYW51YWxfc2VlZCgwKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionDiffEditPipeline 

pipeline = StableDiffusionDiffEditPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-2-1&quot;</span>, torch_dtype=torch.float16
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.enable_model_cpu_offload()
pipeline.enable_vae_slicing()

generator = torch.manual_seed(<span class="hljs-number">0</span>)`}}),dt=new J({props:{code:"aW1wb3J0JTIwdG9yY2glMjAlMEElMEElNDB0b3JjaC5ub19ncmFkKCklMEFkZWYlMjBlbWJlZF9wcm9tcHRzKHNlbnRlbmNlcyUyQyUyMHRva2VuaXplciUyQyUyMHRleHRfZW5jb2RlciUyQyUyMGRldmljZSUzRCUyMmN1ZGElMjIpJTNBJTBBJTIwJTIwJTIwJTIwZW1iZWRkaW5ncyUyMCUzRCUyMCU1QiU1RCUwQSUyMCUyMCUyMCUyMGZvciUyMHNlbnQlMjBpbiUyMHNlbnRlbmNlcyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRleHRfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbnQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwYWRkaW5nJTNEJTIybWF4X2xlbmd0aCUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1heF9sZW5ndGglM0R0b2tlbml6ZXIubW9kZWxfbWF4X2xlbmd0aCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRydW5jYXRpb24lM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0ZXh0X2lucHV0X2lkcyUyMCUzRCUyMHRleHRfaW5wdXRzLmlucHV0X2lkcyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByb21wdF9lbWJlZHMlMjAlM0QlMjB0ZXh0X2VuY29kZXIodGV4dF9pbnB1dF9pZHMudG8oZGV2aWNlKSUyQyUyMGF0dGVudGlvbl9tYXNrJTNETm9uZSklNUIwJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZW1iZWRkaW5ncy5hcHBlbmQocHJvbXB0X2VtYmVkcyklMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b3JjaC5jb25jYXRlbmF0ZShlbWJlZGRpbmdzJTJDJTIwZGltJTNEMCkubWVhbihkaW0lM0QwKS51bnNxdWVlemUoMCklMEElMEFzb3VyY2VfZW1iZWRkaW5ncyUyMCUzRCUyMGVtYmVkX3Byb21wdHMoc291cmNlX3Byb21wdHMlMkMlMjBwaXBlbGluZS50b2tlbml6ZXIlMkMlMjBwaXBlbGluZS50ZXh0X2VuY29kZXIpJTBBdGFyZ2V0X2VtYmVkZGluZ3MlMjAlM0QlMjBlbWJlZF9wcm9tcHRzKHRhcmdldF9jYXB0aW9ucyUyQyUyMHBpcGVsaW5lLnRva2VuaXplciUyQyUyMHBpcGVsaW5lLnRleHRfZW5jb2Rlcik=",highlighted:`<span class="hljs-keyword">import</span> torch 

<span class="hljs-meta">@torch.no_grad()</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">embed_prompts</span>(<span class="hljs-params">sentences, tokenizer, text_encoder, device=<span class="hljs-string">&quot;cuda&quot;</span></span>):
    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_prompts(source_prompts, pipeline.tokenizer, pipeline.text_encoder)
target_embeddings = embed_prompts(target_captions, pipeline.tokenizer, pipeline.text_encoder)`}}),pt=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1JbnZlcnNlU2NoZWR1bGVyJTJDJTIwRERJTVNjaGVkdWxlciUwQWZyb20lMjBkaWZmdXNlcnMudXRpbHMlMjBpbXBvcnQlMjBsb2FkX2ltYWdlJTBBJTBBcGlwZWxpbmUuc2NoZWR1bGVyJTIwJTNEJTIwRERJTVNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlbGluZS5zY2hlZHVsZXIuY29uZmlnKSUwQXBpcGVsaW5lLmludmVyc2Vfc2NoZWR1bGVyJTIwJTNEJTIwRERJTUludmVyc2VTY2hlZHVsZXIuZnJvbV9jb25maWcocGlwZWxpbmUuc2NoZWR1bGVyLmNvbmZpZyklMEElMEFpbWdfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGWGlhbmctY2QlMkZEaWZmRWRpdC1zdGFibGUtZGlmZnVzaW9uJTJGcmF3JTJGbWFpbiUyRmFzc2V0cyUyRm9yaWdpbi5wbmclMjIlMEFyYXdfaW1hZ2UlMjAlM0QlMjBsb2FkX2ltYWdlKGltZ191cmwpLmNvbnZlcnQoJTIyUkdCJTIyKS5yZXNpemUoKDc2OCUyQyUyMDc2OCkpJTBBJTBBJTBBbWFza19pbWFnZSUyMCUzRCUyMHBpcGVsaW5lLmdlbmVyYXRlX21hc2soJTBBJTIwJTIwJTIwJTIwaW1hZ2UlM0RyYXdfaW1hZ2UlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfcHJvbXB0X2VtYmVkcyUzRHNvdXJjZV9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjB0YXJnZXRfcHJvbXB0X2VtYmVkcyUzRHRhcmdldF9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMEEpJTBBJTBBaW52X2xhdGVudHMlMjAlM0QlMjBwaXBlbGluZS5pbnZlcnQoJTBBJTIwJTIwJTIwJTIwcHJvbXB0X2VtYmVkcyUzRHNvdXJjZV9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjBpbWFnZSUzRHJhd19pbWFnZSUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciUyQyUwQSkubGF0ZW50cyUwQSUwQWltYWdlcyUyMCUzRCUyMHBpcGVsaW5lKCUwQSUyMCUyMCUyMCUyMG1hc2tfaW1hZ2UlM0RtYXNrX2ltYWdlJTJDJTBBJTIwJTIwJTIwJTIwaW1hZ2VfbGF0ZW50cyUzRGludl9sYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwcHJvbXB0X2VtYmVkcyUzRHRhcmdldF9lbWJlZGRpbmdzJTJDJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0X2VtYmVkcyUzRHNvdXJjZV9lbWJlZGRpbmdzJTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBKS5pbWFnZXMlMEFpbWFnZXMlNUIwJTVELnNhdmUoJTIyZWRpdGVkX2ltYWdlLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMInverseScheduler, DDIMScheduler
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

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

img_url = <span class="hljs-string">&quot;https://github.com/Xiang-cd/DiffEdit-stable-diffusion/raw/main/assets/origin.png&quot;</span>
raw_image = load_image(img_url).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">768</span>, <span class="hljs-number">768</span>))


mask_image = pipeline.generate_mask(
    image=raw_image,
    source_prompt_embeds=source_embeds,
    target_prompt_embeds=target_embeds,
    generator=generator,
)

inv_latents = pipeline.invert(
    prompt_embeds=source_embeds,
    image=raw_image,
    generator=generator,
).latents

images = pipeline(
    mask_image=mask_image,
    image_latents=inv_latents,
    prompt_embeds=target_embeddings,
    negative_prompt_embeds=source_embeddings,
    generator=generator,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),ct=new te({}),mt=new ee({props:{name:"class diffusers.StableDiffusionDiffEditPipeline",anchor:"diffusers.StableDiffusionDiffEditPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPImageProcessor"},{name:"inverse_scheduler",val:": DDIMInverseScheduler"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionDiffEditPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.18.0/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.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.18.0/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.18.0/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.inverse_scheduler",description:`<strong>inverse_scheduler</strong> (<code>[DDIMInverseScheduler]</code>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to fill in the unmasked part of the input latents`,name:"inverse_scheduler"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.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"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L240"}}),_t=new ee({props:{name:"generate_mask",anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask",parameters:[{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"target_prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"target_negative_prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"target_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"target_negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"source_prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"source_negative_prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"source_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"source_negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"num_maps_per_mask",val:": typing.Optional[int] = 10"},{name:"mask_encode_strength",val:": typing.Optional[float] = 0.5"},{name:"mask_thresholding_ratio",val:": typing.Optional[float] = 3.0"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"output_type",val:": typing.Optional[str] = 'np'"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.image",description:`<strong>image</strong> (<code>PIL.Image.Image</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be used for computing the mask.`,name:"image"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.target_prompt",description:`<strong>target_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the semantic mask generation. If not defined, one has to pass
<code>prompt_embeds</code>. instead.`,name:"target_prompt"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.target_negative_prompt",description:`<strong>target_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:"target_negative_prompt"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.target_prompt_embeds",description:`<strong>target_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:"target_prompt_embeds"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.target_negative_prompt_embeds",description:`<strong>target_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:"target_negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.source_prompt",description:`<strong>source_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the semantic mask generation using the method in <a href="https://arxiv.org/pdf/2210.11427.pdf" rel="nofollow">DiffEdit:
Diffusion-Based Semantic Image Editing with Mask Guidance</a>. If
not defined, one has to pass <code>source_prompt_embeds</code> or <code>source_image</code> instead.`,name:"source_prompt"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.source_negative_prompt",description:`<strong>source_negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the semantic mask generation away from using the method in <a href="https://arxiv.org/pdf/2210.11427.pdf" rel="nofollow">DiffEdit:
Diffusion-Based Semantic Image Editing with Mask Guidance</a>. If
not defined, one has to pass <code>source_negative_prompt_embeds</code> or <code>source_image</code> instead.`,name:"source_negative_prompt"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.source_prompt_embeds",description:`<strong>source_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings to guide the semantic mask generation. Can be used to easily tweak text
inputs, <em>e.g.</em> prompt weighting. If not provided, text embeddings will be generated from
<code>source_prompt</code> input argument.`,name:"source_prompt_embeds"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.source_negative_prompt_embeds",description:`<strong>source_negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings to negatively guide the semantic mask generation. Can be used to easily
tweak text inputs, <em>e.g.</em> prompt weighting. If not provided, text embeddings will be generated from
<code>source_negative_prompt</code> input argument.`,name:"source_negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.num_maps_per_mask",description:`<strong>num_maps_per_mask</strong> (<code>int</code>, <em>optional</em>, defaults to 10) &#x2014;
The number of noise maps sampled to generate the semantic mask using the method in <a href="https://arxiv.org/pdf/2210.11427.pdf" rel="nofollow">DiffEdit:
Diffusion-Based Semantic Image Editing with Mask Guidance</a>.`,name:"num_maps_per_mask"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.mask_encode_strength",description:`<strong>mask_encode_strength</strong> (<code>float</code>, <em>optional</em>, defaults to 0.5) &#x2014;
Conceptually, the strength of the noise maps sampled to generate the semantic mask using the method in
<a href="https://arxiv.org/pdf/2210.11427.pdf" rel="nofollow">DiffEdit: Diffusion-Based Semantic Image Editing with Mask Guidance</a>. Must be between 0 and 1.`,name:"mask_encode_strength"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.mask_thresholding_ratio",description:`<strong>mask_thresholding_ratio</strong> (<code>float</code>, <em>optional</em>, defaults to 3.0) &#x2014;
The maximum multiple of the mean absolute difference used to clamp the semantic guidance map before
mask binarization.`,name:"mask_thresholding_ratio"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.generate_mask.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.StableDiffusionDiffEditPipeline.generate_mask.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.StableDiffusionDiffEditPipeline.generate_mask.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.StableDiffusionDiffEditPipeline.generate_mask.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.StableDiffusionDiffEditPipeline.generate_mask.cross_attention_kwargs",description:`<strong>cross_attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined under
<code>self.processor</code> in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py" rel="nofollow">diffusers.cross_attention</a>.`,name:"cross_attention_kwargs"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L873",returnDescription:`
<p><code>List[PIL.Image.Image]</code> if <code>output_type</code> is <code>"pil"</code>, otherwise a
<code>np.array</code>. When returning a <code>List[PIL.Image.Image]</code>, the list will consist of a batch of single-channel
binary image with dimensions <code>(height // self.vae_scale_factor, width // self.vae_scale_factor)</code>, otherwise
the <code>np.array</code> will have shape <code>(batch_size, height // self.vae_scale_factor, width // self.vae_scale_factor)</code>.</p>
`,returnType:`
<p><code>List[PIL.Image.Image]</code> or <code>np.array</code></p>
`}}),wt=new ee({props:{name:"invert",anchor:"diffusers.StableDiffusionDiffEditPipeline.invert",parameters:[{name:"prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"inpaint_strength",val:": float = 0.8"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[typing.List[str], str, NoneType] = None"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"decode_latents",val:": bool = False"},{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 = 0"},{name:"num_auto_corr_rolls",val:": int = 5"}],parametersDescription:[{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.invert.image",description:`<strong>image</strong> (<code>PIL.Image.Image</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch to produce the inverted latents, guided by <code>prompt</code>.`,name:"image"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.invert.inpaint_strength",description:`<strong>inpaint_strength</strong> (<code>float</code>, <em>optional</em>, defaults to 0.8) &#x2014;
Conceptually, indicates how far into the noising process to run latent inversion. Must be between 0 and<ol>
<li>When <code>strength</code> is 1, the inversion process will be run for the full number of iterations specified
in <code>num_inference_steps</code>. <code>image</code> will be used as a reference for the inversion process, adding more
noise the larger the <code>strength</code>. If <code>strength</code> is 0, no inpainting will occur.</li>
</ol>`,name:"inpaint_strength"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.invert.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.invert.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.StableDiffusionDiffEditPipeline.invert.generator",description:`<strong>generator</strong> (<code>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.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.invert.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.StableDiffusionDiffEditPipeline.invert.decode_latents",description:`<strong>decode_latents</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to decode the inverted latents into a generated image. Setting this argument to <code>True</code>
will decode all inverted latents for each timestep into a list of generated images.`,name:"decode_latents"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.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 <code>~pipelines.stable_diffusion.DiffEditInversionPipelineOutput</code> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.invert.cross_attention_kwargs",description:`<strong>cross_attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined under
<code>self.processor</code> in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py" rel="nofollow">diffusers.cross_attention</a>.`,name:"cross_attention_kwargs"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.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.StableDiffusionDiffEditPipeline.invert.num_reg_steps",description:`<strong>num_reg_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
Number of regularization loss steps`,name:"num_reg_steps"},{anchor:"diffusers.StableDiffusionDiffEditPipeline.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.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L1095",returnDescription:`
<p><code>DiffEditInversionPipelineOutput</code> or
<code>tuple</code>: <code>DiffEditInversionPipelineOutput</code>
if <code>return_dict</code> is <code>True</code>, otherwise a <code>tuple</code>. When returning a tuple, the first element is the inverted
latents tensors ordered by increasing noise, and then second is the corresponding decoded images if
<code>decode_latents</code> is <code>True</code>, otherwise <code>None</code>.</p>
`}}),ue=new Fc({props:{anchor:"diffusers.StableDiffusionDiffEditPipeline.invert.example",$$slots:{default:[Pc]},$$scope:{ctx:xa}}}),vt=new ee({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionDiffEditPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L381"}}),Jt=new ee({props:{name:"disable_vae_tiling",anchor:"diffusers.StableDiffusionDiffEditPipeline.disable_vae_tiling",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L399"}}),Et=new ee({props:{name:"enable_model_cpu_offload",anchor:"diffusers.StableDiffusionDiffEditPipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L433"}}),Ut=new ee({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionDiffEditPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L407"}}),It=new ee({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionDiffEditPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L371"}}),Zt=new ee({props:{name:"enable_vae_tiling",anchor:"diffusers.StableDiffusionDiffEditPipeline.enable_vae_tiling",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.18.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py#L389"}}),{c(){T=a("meta"),N=d(),v=a("h1"),B=a("a"),hn=a("span"),f(Me.$$.fragment),wi=d(),gn=a("span"),vi=s("Zero-shot Diffusion-based Semantic Image Editing with Mask Guidance"),Va=d(),F=a("h2"),ne=a("a"),bn=a("span"),f(Je.$$.fragment),Mi=d(),yn=a("span"),Ji=s("Overview"),Sa=d(),Te=a("p"),Ee=a("a"),Ti=s("DiffEdit: Diffusion-based semantic image editing with mask guidance"),Ei=s(" by Guillaume Couairon, Jakob Verbeek, Holger Schwenk, and Matthieu Cord."),Na=d(),jt=a("p"),Ui=s("The abstract of the paper is the following:"),Fa=d(),Gt=a("p"),_n=a("em"),Ii=s("Image generation has recently seen tremendous advances, with diffusion models allowing to synthesize convincing images for a large variety of text prompts. In this article, we propose DiffEdit, a method to take advantage of text-conditioned diffusion models for the task of semantic image editing, where the goal is to edit an image based on a text query. Semantic image editing is an extension of image generation, with the additional constraint that the generated image should be as similar as possible to a given input image. Current editing methods based on diffusion models usually require to provide a mask, making the task much easier by treating it as a conditional inpainting task. In contrast, our main contribution is able to automatically generate a mask highlighting regions of the input image that need to be edited, by contrasting predictions of a diffusion model conditioned on different text prompts. Moreover, we rely on latent inference to preserve content in those regions of interest and show excellent synergies with mask-based diffusion. DiffEdit achieves state-of-the-art editing performance on ImageNet. In addition, we evaluate semantic image editing in more challenging settings, using images from the COCO dataset as well as text-based generated images."),Pa=d(),Wt=a("p"),Zi=s("Resources:"),Ha=d(),C=a("ul"),Bt=a("li"),Ue=a("a"),ki=s("Paper"),ji=s("."),Gi=d(),Ct=a("li"),Ie=a("a"),Wi=s("Blog Post with Demo"),Bi=s("."),Ci=d(),Rt=a("li"),Ze=a("a"),Ri=s("Implementation on Github"),Di=s("."),Ya=d(),P=a("h2"),ae=a("a"),wn=a("span"),f(ke.$$.fragment),Xi=d(),vn=a("span"),$i=s("Tips"),Aa=d(),M=a("ul"),Mn=a("li"),xi=s("The pipeline can generate masks that can be fed into other inpainting pipelines. Check out the code examples below to know more."),Vi=d(),j=a("li"),Si=s("In order to generate an image using this pipeline, both an image mask (manually specified or generated using "),Jn=a("code"),Ni=s("generate_mask"),Fi=s(`)
and a set of partially inverted latents (generated using `),Tn=a("code"),Pi=s("invert"),Hi=s(") "),En=a("em"),Yi=s("must"),Ai=s(` be provided as arguments when calling the pipeline to generate the final edited image.
Refer to the code examples below for more details.`),zi=d(),E=a("li"),Qi=s("The function "),Un=a("code"),Li=s("generate_mask"),qi=s(" exposes two prompt arguments, "),In=a("code"),Oi=s("source_prompt"),Ki=s(" and "),Zn=a("code"),es=s("target_prompt"),ts=s(`,
that let you control the locations 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 generated mask, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),kn=a("code"),ns=s("source_prompt_embeds"),as=s(" and \u201Cdog\u201D to "),jn=a("code"),os=s("target_prompt_embeds"),is=s(". Refer to the code example below for more details."),ss=d(),G=a("li"),ls=s("When generating partially inverted latents using "),Gn=a("code"),rs=s("invert"),ds=s(`, assign a caption or text embedding describing the
overall image to the `),Wn=a("code"),ps=s("prompt"),cs=s(` argument to help guide the inverse latent sampling process. In most cases, the
source concept is sufficently descriptive to yield good results, but feel free to explore alternatives.
Please refer to `),Dt=a("a"),ms=s("this code example"),fs=s(" for more details."),us=d(),I=a("li"),hs=s("When calling the pipeline to generate the final edited image, assign the source concept to "),Bn=a("code"),gs=s("negative_prompt"),bs=s(`
and the target concept to `),Cn=a("code"),ys=s("prompt"),_s=s(`. Taking the above example, you simply have to set the embeddings related to
the phrases including \u201Ccat\u201D to `),Rn=a("code"),ws=s("negative_prompt_embeds"),vs=s(" and \u201Cdog\u201D to "),Dn=a("code"),Ms=s("prompt_embeds"),Js=s(`. Refer to the code example
below for more details.`),Ts=d(),Xt=a("li"),Es=s("If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),H=a("ul"),W=a("li"),Us=s("Swap the "),Xn=a("code"),Is=s("source_prompt"),Zs=s(" and "),$n=a("code"),ks=s("target_prompt"),js=s(" in the arguments to "),xn=a("code"),Gs=s("generate_mask"),Ws=s("."),Bs=d(),je=a("li"),Cs=s("Change the input prompt for "),Vn=a("code"),Rs=s("invert"),Ds=s(" to include \u201Cdog\u201D."),Xs=d(),Y=a("li"),$s=s("Swap the "),Sn=a("code"),xs=s("prompt"),Vs=s(" and "),Nn=a("code"),Ss=s("negative_prompt"),Ns=s(" in the arguments to call the pipeline to generate the final edited image."),Fs=d(),Ge=a("li"),Ps=s("Note that the source and target prompts, or their corresponding embeddings, can also be automatically generated. Please, refer to "),$t=a("a"),Hs=s("this discussion"),Ys=s(" for more details."),za=d(),A=a("h2"),oe=a("a"),Fn=a("span"),f(We.$$.fragment),As=d(),Pn=a("span"),zs=s("Available Pipelines:"),Qa=d(),ie=a("table"),Hn=a("thead"),Be=a("tr"),Yn=a("th"),Qs=s("Pipeline"),Ls=d(),An=a("th"),qs=s("Tasks"),Os=d(),zn=a("tbody"),Ce=a("tr"),Qn=a("td"),Re=a("a"),Ks=s("StableDiffusionDiffEditPipeline"),el=d(),Ln=a("td"),qn=a("em"),tl=s("Text-Based Image Editing"),La=d(),z=a("h2"),se=a("a"),On=a("span"),f(De.$$.fragment),nl=d(),Kn=a("span"),al=s("Usage example"),qa=d(),Q=a("h3"),le=a("a"),ea=a("span"),f(Xe.$$.fragment),ol=d(),ta=a("span"),il=s("Based on an input image with a caption"),Oa=d(),re=a("p"),sl=s(`When the pipeline is conditioned on an input image, we first obtain partially inverted latents from the input image using a
`),na=a("code"),ll=s("DDIMInverseScheduler"),rl=s(` with the help of a caption. Then we generate an editing mask to identify relevant regions in the image using the source and target prompts. Finally,
the inverted noise and generated mask is used to start the generation process.`),Ka=d(),xt=a("p"),dl=s("First, let\u2019s load our pipeline:"),eo=d(),f($e.$$.fragment),to=d(),Vt=a("p"),pl=s("Then, we load an input image to edit using our method:"),no=d(),f(xe.$$.fragment),ao=d(),St=a("p"),cl=s("Then, we employ the source and target prompts to generate the editing mask:"),oo=d(),f(Ve.$$.fragment),io=d(),Nt=a("p"),ml=s("Then, we employ the caption and the input image to get the inverted latents:"),so=d(),f(Se.$$.fragment),lo=d(),Ft=a("p"),fl=s("Now, generate the image with the inverted latents and semantically generated mask:"),ro=d(),f(Ne.$$.fragment),po=d(),L=a("h2"),de=a("a"),aa=a("span"),f(Fe.$$.fragment),ul=d(),oa=a("span"),hl=s("Generating image captions for inversion"),co=d(),pe=a("p"),gl=s(`The authors originally used the source concept prompt as the caption for generating the partially inverted latents. However, we can also leverage open source and public image captioning models for the same purpose.
Below, we provide an end-to-end example with the `),Pe=a("a"),bl=s("BLIP"),yl=s(` model
for generating captions.`),mo=d(),Pt=a("p"),_l=s("First, let\u2019s load our automatic image captioning model:"),fo=d(),f(He.$$.fragment),uo=d(),Ht=a("p"),wl=s("Then, we define a utility to generate captions from an input image using the model:"),ho=d(),f(Ye.$$.fragment),go=d(),Yt=a("p"),vl=s("Then, we load an input image for conditioning and obtain a suitable caption for it:"),bo=d(),f(Ae.$$.fragment),yo=d(),At=a("p"),Ml=s("Then, we employ the generated caption and the input image to get the inverted latents:"),_o=d(),f(ze.$$.fragment),wo=d(),zt=a("p"),Jl=s("Now, generate the image with the inverted latents and semantically generated mask from our source and target prompts:"),vo=d(),f(Qe.$$.fragment),Mo=d(),q=a("h2"),ce=a("a"),ia=a("span"),f(Le.$$.fragment),Tl=d(),sa=a("span"),El=s("Generating source and target embeddings"),Jo=d(),me=a("p"),Ul=s(`The authors originally required the user to manually provide the source and target prompts 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 `),qe=a("a"),Il=s("Flan-T5"),Zl=s(` model
for generating source an target embeddings.`),To=d(),Oe=a("p"),la=a("strong"),kl=s("1. Load the generation model"),jl=s(":"),Eo=d(),f(Ke.$$.fragment),Uo=d(),et=a("p"),ra=a("strong"),Gl=s("2. Construct a starting prompt"),Wl=s(":"),Io=d(),f(tt.$$.fragment),Zo=d(),Qt=a("p"),Bl=s("Here, we\u2019re interested in the \u201Cbowl -> basket\u201D direction."),ko=d(),nt=a("p"),da=a("strong"),Cl=s("3. Generate prompts"),Rl=s(":"),jo=d(),Lt=a("p"),Dl=s("We can use a utility like so for this purpose."),Go=d(),f(at.$$.fragment),Wo=d(),qt=a("p"),Xl=s("And then we just call it to generate our prompts:"),Bo=d(),f(ot.$$.fragment),Co=d(),R=a("p"),$l=s(`We encourage you to play around with the different parameters supported by the
`),pa=a("code"),xl=s("generate()"),Vl=s(" method ("),it=a("a"),Sl=s("documentation"),Nl=s(") for the generation quality you are looking for."),Ro=d(),st=a("p"),ca=a("strong"),Fl=s("4. Load the embedding model"),Pl=s(":"),Do=d(),Ot=a("p"),Hl=s("Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),Xo=d(),f(lt.$$.fragment),$o=d(),rt=a("p"),ma=a("strong"),Yl=s("5. Compute embeddings"),Al=s(":"),xo=d(),f(dt.$$.fragment),Vo=d(),Kt=a("p"),zl=s("And you\u2019re done! Now, you can use these embeddings directly while calling the pipeline:"),So=d(),f(pt.$$.fragment),No=d(),O=a("h2"),fe=a("a"),fa=a("span"),f(ct.$$.fragment),Ql=d(),ua=a("span"),Ll=s("StableDiffusionDiffEditPipeline"),Fo=d(),_=a("div"),f(mt.$$.fragment),ql=d(),ft=a("p"),Ol=s("Pipeline for text-guided image inpainting using Stable Diffusion using DiffEdit. "),ha=a("em"),Kl=s("This is an experimental feature"),er=s("."),tr=d(),ut=a("p"),nr=s("This model inherits from "),en=a("a"),ar=s("DiffusionPipeline"),or=s(`. 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.)`),ir=d(),ga=a("p"),sr=s("In addition the pipeline inherits the following loading methods:"),lr=d(),ht=a("ul"),gt=a("li"),ba=a("em"),rr=s("Textual-Inversion"),dr=s(": "),tn=a("a"),pr=s("loaders.TextualInversionLoaderMixin.load_textual_inversion()"),cr=d(),bt=a("li"),ya=a("em"),mr=s("LoRA"),fr=s(": "),nn=a("a"),ur=s("loaders.LoraLoaderMixin.load_lora_weights()"),hr=d(),_a=a("p"),gr=s("as well as the following saving methods:"),br=d(),wa=a("ul"),yt=a("li"),va=a("em"),yr=s("LoRA"),_r=s(": "),an=a("a"),wr=s("loaders.LoraLoaderMixin.save_lora_weights()"),vr=d(),D=a("div"),f(_t.$$.fragment),Mr=d(),Ma=a("p"),Jr=s("Function used to generate a latent mask given a mask prompt, a target prompt, and an image."),Tr=d(),Ja=a("p"),Er=s("Examples:"),Ur=d(),X=a("div"),f(wt.$$.fragment),Ir=d(),Ta=a("p"),Zr=s("Function used to generate inverted latents given a prompt and image."),kr=d(),f(ue.$$.fragment),jr=d(),he=a("div"),f(vt.$$.fragment),Gr=d(),Mt=a("p"),Wr=s("Disable sliced VAE decoding. If "),Ea=a("code"),Br=s("enable_vae_slicing"),Cr=s(` was previously invoked, this method will go back to
computing decoding in one step.`),Rr=d(),ge=a("div"),f(Jt.$$.fragment),Dr=d(),Tt=a("p"),Xr=s("Disable tiled VAE decoding. If "),Ua=a("code"),$r=s("enable_vae_tiling"),xr=s(` was previously invoked, this method will go back to
computing decoding in one step.`),Vr=d(),be=a("div"),f(Et.$$.fragment),Sr=d(),Z=a("p"),Nr=s(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Ia=a("code"),Fr=s("enable_sequential_cpu_offload"),Pr=s(", this method moves one whole model at a time to the GPU when its "),Za=a("code"),Hr=s("forward"),Yr=s(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),ka=a("code"),Ar=s("enable_sequential_cpu_offload"),zr=s(", but performance is much better due to the iterative execution of the "),ja=a("code"),Qr=s("unet"),Lr=s("."),qr=d(),ye=a("div"),f(Ut.$$.fragment),Or=d(),K=a("p"),Kr=s(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Ga=a("code"),ed=s("torch.device('meta') and loaded to GPU only when their specific submodule has its "),td=s("forward"),Wa=a("code"),nd=s("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),ad=s("enable_model_cpu_offload`, but performance is lower."),od=d(),$=a("div"),f(It.$$.fragment),id=d(),Ba=a("p"),sd=s("Enable sliced VAE decoding."),ld=d(),Ca=a("p"),rd=s(`When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
steps. This is useful to save some memory and allow larger batch sizes.`),dd=d(),x=a("div"),f(Zt.$$.fragment),pd=d(),Ra=a("p"),cd=s("Enable tiled VAE decoding."),md=d(),Da=a("p"),fd=s(`When this option is enabled, the VAE will split the input tensor into tiles to compute decoding and encoding in
several steps. This is useful to save a large amount of memory and to allow the processing of larger images.`),Po=d(),on=a("ul"),Xa=a("li"),$a=a("strong"),ud=s("call"),this.h()},l(e){const r=Vc('[data-svelte="svelte-1phssyn"]',document.head);T=o(r,"META",{name:!0,content:!0}),r.forEach(n),N=p(e),v=o(e,"H1",{class:!0});var kt=i(v);B=o(kt,"A",{id:!0,class:!0,href:!0});var Ed=i(B);hn=o(Ed,"SPAN",{});var Ud=i(hn);u(Me.$$.fragment,Ud),Ud.forEach(n),Ed.forEach(n),wi=p(kt),gn=o(kt,"SPAN",{});var Id=i(gn);vi=l(Id,"Zero-shot Diffusion-based Semantic Image Editing with Mask Guidance"),Id.forEach(n),kt.forEach(n),Va=p(e),F=o(e,"H2",{class:!0});var Yo=i(F);ne=o(Yo,"A",{id:!0,class:!0,href:!0});var Zd=i(ne);bn=o(Zd,"SPAN",{});var kd=i(bn);u(Je.$$.fragment,kd),kd.forEach(n),Zd.forEach(n),Mi=p(Yo),yn=o(Yo,"SPAN",{});var jd=i(yn);Ji=l(jd,"Overview"),jd.forEach(n),Yo.forEach(n),Sa=p(e),Te=o(e,"P",{});var hd=i(Te);Ee=o(hd,"A",{href:!0,rel:!0});var Gd=i(Ee);Ti=l(Gd,"DiffEdit: Diffusion-based semantic image editing with mask guidance"),Gd.forEach(n),Ei=l(hd," by Guillaume Couairon, Jakob Verbeek, Holger Schwenk, and Matthieu Cord."),hd.forEach(n),Na=p(e),jt=o(e,"P",{});var Wd=i(jt);Ui=l(Wd,"The abstract of the paper is the following:"),Wd.forEach(n),Fa=p(e),Gt=o(e,"P",{});var Bd=i(Gt);_n=o(Bd,"EM",{});var Cd=i(_n);Ii=l(Cd,"Image generation has recently seen tremendous advances, with diffusion models allowing to synthesize convincing images for a large variety of text prompts. In this article, we propose DiffEdit, a method to take advantage of text-conditioned diffusion models for the task of semantic image editing, where the goal is to edit an image based on a text query. Semantic image editing is an extension of image generation, with the additional constraint that the generated image should be as similar as possible to a given input image. Current editing methods based on diffusion models usually require to provide a mask, making the task much easier by treating it as a conditional inpainting task. In contrast, our main contribution is able to automatically generate a mask highlighting regions of the input image that need to be edited, by contrasting predictions of a diffusion model conditioned on different text prompts. Moreover, we rely on latent inference to preserve content in those regions of interest and show excellent synergies with mask-based diffusion. DiffEdit achieves state-of-the-art editing performance on ImageNet. In addition, we evaluate semantic image editing in more challenging settings, using images from the COCO dataset as well as text-based generated images."),Cd.forEach(n),Bd.forEach(n),Pa=p(e),Wt=o(e,"P",{});var Rd=i(Wt);Zi=l(Rd,"Resources:"),Rd.forEach(n),Ha=p(e),C=o(e,"UL",{});var sn=i(C);Bt=o(sn,"LI",{});var gd=i(Bt);Ue=o(gd,"A",{href:!0,rel:!0});var Dd=i(Ue);ki=l(Dd,"Paper"),Dd.forEach(n),ji=l(gd,"."),gd.forEach(n),Gi=p(sn),Ct=o(sn,"LI",{});var bd=i(Ct);Ie=o(bd,"A",{href:!0,rel:!0});var Xd=i(Ie);Wi=l(Xd,"Blog Post with Demo"),Xd.forEach(n),Bi=l(bd,"."),bd.forEach(n),Ci=p(sn),Rt=o(sn,"LI",{});var yd=i(Rt);Ze=o(yd,"A",{href:!0,rel:!0});var $d=i(Ze);Ri=l($d,"Implementation on Github"),$d.forEach(n),Di=l(yd,"."),yd.forEach(n),sn.forEach(n),Ya=p(e),P=o(e,"H2",{class:!0});var Ao=i(P);ae=o(Ao,"A",{id:!0,class:!0,href:!0});var xd=i(ae);wn=o(xd,"SPAN",{});var Vd=i(wn);u(ke.$$.fragment,Vd),Vd.forEach(n),xd.forEach(n),Xi=p(Ao),vn=o(Ao,"SPAN",{});var Sd=i(vn);$i=l(Sd,"Tips"),Sd.forEach(n),Ao.forEach(n),Aa=p(e),M=o(e,"UL",{});var U=i(M);Mn=o(U,"LI",{});var Nd=i(Mn);xi=l(Nd,"The pipeline can generate masks that can be fed into other inpainting pipelines. Check out the code examples below to know more."),Nd.forEach(n),Vi=p(U),j=o(U,"LI",{});var _e=i(j);Si=l(_e,"In order to generate an image using this pipeline, both an image mask (manually specified or generated using "),Jn=o(_e,"CODE",{});var Fd=i(Jn);Ni=l(Fd,"generate_mask"),Fd.forEach(n),Fi=l(_e,`)
and a set of partially inverted latents (generated using `),Tn=o(_e,"CODE",{});var Pd=i(Tn);Pi=l(Pd,"invert"),Pd.forEach(n),Hi=l(_e,") "),En=o(_e,"EM",{});var Hd=i(En);Yi=l(Hd,"must"),Hd.forEach(n),Ai=l(_e,` be provided as arguments when calling the pipeline to generate the final edited image.
Refer to the code examples below for more details.`),_e.forEach(n),zi=p(U),E=o(U,"LI",{});var k=i(E);Qi=l(k,"The function "),Un=o(k,"CODE",{});var Yd=i(Un);Li=l(Yd,"generate_mask"),Yd.forEach(n),qi=l(k," exposes two prompt arguments, "),In=o(k,"CODE",{});var Ad=i(In);Oi=l(Ad,"source_prompt"),Ad.forEach(n),Ki=l(k," and "),Zn=o(k,"CODE",{});var zd=i(Zn);es=l(zd,"target_prompt"),zd.forEach(n),ts=l(k,`,
that let you control the locations 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 generated mask, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),kn=o(k,"CODE",{});var Qd=i(kn);ns=l(Qd,"source_prompt_embeds"),Qd.forEach(n),as=l(k," and \u201Cdog\u201D to "),jn=o(k,"CODE",{});var Ld=i(jn);os=l(Ld,"target_prompt_embeds"),Ld.forEach(n),is=l(k,". Refer to the code example below for more details."),k.forEach(n),ss=p(U),G=o(U,"LI",{});var we=i(G);ls=l(we,"When generating partially inverted latents using "),Gn=o(we,"CODE",{});var qd=i(Gn);rs=l(qd,"invert"),qd.forEach(n),ds=l(we,`, assign a caption or text embedding describing the
overall image to the `),Wn=o(we,"CODE",{});var Od=i(Wn);ps=l(Od,"prompt"),Od.forEach(n),cs=l(we,` argument to help guide the inverse latent sampling process. In most cases, the
source concept is sufficently descriptive to yield good results, but feel free to explore alternatives.
Please refer to `),Dt=o(we,"A",{href:!0});var Kd=i(Dt);ms=l(Kd,"this code example"),Kd.forEach(n),fs=l(we," for more details."),we.forEach(n),us=p(U),I=o(U,"LI",{});var V=i(I);hs=l(V,"When calling the pipeline to generate the final edited image, assign the source concept to "),Bn=o(V,"CODE",{});var ep=i(Bn);gs=l(ep,"negative_prompt"),ep.forEach(n),bs=l(V,`
and the target concept to `),Cn=o(V,"CODE",{});var tp=i(Cn);ys=l(tp,"prompt"),tp.forEach(n),_s=l(V,`. Taking the above example, you simply have to set the embeddings related to
the phrases including \u201Ccat\u201D to `),Rn=o(V,"CODE",{});var np=i(Rn);ws=l(np,"negative_prompt_embeds"),np.forEach(n),vs=l(V," and \u201Cdog\u201D to "),Dn=o(V,"CODE",{});var ap=i(Dn);Ms=l(ap,"prompt_embeds"),ap.forEach(n),Js=l(V,`. Refer to the code example
below for more details.`),V.forEach(n),Ts=p(U),Xt=o(U,"LI",{});var _d=i(Xt);Es=l(_d,"If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),H=o(_d,"UL",{});var ln=i(H);W=o(ln,"LI",{});var ve=i(W);Us=l(ve,"Swap the "),Xn=o(ve,"CODE",{});var op=i(Xn);Is=l(op,"source_prompt"),op.forEach(n),Zs=l(ve," and "),$n=o(ve,"CODE",{});var ip=i($n);ks=l(ip,"target_prompt"),ip.forEach(n),js=l(ve," in the arguments to "),xn=o(ve,"CODE",{});var sp=i(xn);Gs=l(sp,"generate_mask"),sp.forEach(n),Ws=l(ve,"."),ve.forEach(n),Bs=p(ln),je=o(ln,"LI",{});var zo=i(je);Cs=l(zo,"Change the input prompt for "),Vn=o(zo,"CODE",{});var lp=i(Vn);Rs=l(lp,"invert"),lp.forEach(n),Ds=l(zo," to include \u201Cdog\u201D."),zo.forEach(n),Xs=p(ln),Y=o(ln,"LI",{});var rn=i(Y);$s=l(rn,"Swap the "),Sn=o(rn,"CODE",{});var rp=i(Sn);xs=l(rp,"prompt"),rp.forEach(n),Vs=l(rn," and "),Nn=o(rn,"CODE",{});var dp=i(Nn);Ss=l(dp,"negative_prompt"),dp.forEach(n),Ns=l(rn," in the arguments to call the pipeline to generate the final edited image."),rn.forEach(n),ln.forEach(n),_d.forEach(n),Fs=p(U),Ge=o(U,"LI",{});var Qo=i(Ge);Ps=l(Qo,"Note that the source and target prompts, or their corresponding embeddings, can also be automatically generated. Please, refer to "),$t=o(Qo,"A",{href:!0});var pp=i($t);Hs=l(pp,"this discussion"),pp.forEach(n),Ys=l(Qo," for more details."),Qo.forEach(n),U.forEach(n),za=p(e),A=o(e,"H2",{class:!0});var Lo=i(A);oe=o(Lo,"A",{id:!0,class:!0,href:!0});var cp=i(oe);Fn=o(cp,"SPAN",{});var mp=i(Fn);u(We.$$.fragment,mp),mp.forEach(n),cp.forEach(n),As=p(Lo),Pn=o(Lo,"SPAN",{});var fp=i(Pn);zs=l(fp,"Available Pipelines:"),fp.forEach(n),Lo.forEach(n),Qa=p(e),ie=o(e,"TABLE",{});var qo=i(ie);Hn=o(qo,"THEAD",{});var up=i(Hn);Be=o(up,"TR",{});var Oo=i(Be);Yn=o(Oo,"TH",{});var hp=i(Yn);Qs=l(hp,"Pipeline"),hp.forEach(n),Ls=p(Oo),An=o(Oo,"TH",{});var gp=i(An);qs=l(gp,"Tasks"),gp.forEach(n),Oo.forEach(n),up.forEach(n),Os=p(qo),zn=o(qo,"TBODY",{});var bp=i(zn);Ce=o(bp,"TR",{});var Ko=i(Ce);Qn=o(Ko,"TD",{});var yp=i(Qn);Re=o(yp,"A",{href:!0,rel:!0});var _p=i(Re);Ks=l(_p,"StableDiffusionDiffEditPipeline"),_p.forEach(n),yp.forEach(n),el=p(Ko),Ln=o(Ko,"TD",{});var wp=i(Ln);qn=o(wp,"EM",{});var vp=i(qn);tl=l(vp,"Text-Based Image Editing"),vp.forEach(n),wp.forEach(n),Ko.forEach(n),bp.forEach(n),qo.forEach(n),La=p(e),z=o(e,"H2",{class:!0});var ei=i(z);se=o(ei,"A",{id:!0,class:!0,href:!0});var Mp=i(se);On=o(Mp,"SPAN",{});var Jp=i(On);u(De.$$.fragment,Jp),Jp.forEach(n),Mp.forEach(n),nl=p(ei),Kn=o(ei,"SPAN",{});var Tp=i(Kn);al=l(Tp,"Usage example"),Tp.forEach(n),ei.forEach(n),qa=p(e),Q=o(e,"H3",{class:!0});var ti=i(Q);le=o(ti,"A",{id:!0,class:!0,href:!0});var Ep=i(le);ea=o(Ep,"SPAN",{});var Up=i(ea);u(Xe.$$.fragment,Up),Up.forEach(n),Ep.forEach(n),ol=p(ti),ta=o(ti,"SPAN",{});var Ip=i(ta);il=l(Ip,"Based on an input image with a caption"),Ip.forEach(n),ti.forEach(n),Oa=p(e),re=o(e,"P",{});var ni=i(re);sl=l(ni,`When the pipeline is conditioned on an input image, we first obtain partially inverted latents from the input image using a
`),na=o(ni,"CODE",{});var Zp=i(na);ll=l(Zp,"DDIMInverseScheduler"),Zp.forEach(n),rl=l(ni,` with the help of a caption. Then we generate an editing mask to identify relevant regions in the image using the source and target prompts. Finally,
the inverted noise and generated mask is used to start the generation process.`),ni.forEach(n),Ka=p(e),xt=o(e,"P",{});var kp=i(xt);dl=l(kp,"First, let\u2019s load our pipeline:"),kp.forEach(n),eo=p(e),u($e.$$.fragment,e),to=p(e),Vt=o(e,"P",{});var jp=i(Vt);pl=l(jp,"Then, we load an input image to edit using our method:"),jp.forEach(n),no=p(e),u(xe.$$.fragment,e),ao=p(e),St=o(e,"P",{});var Gp=i(St);cl=l(Gp,"Then, we employ the source and target prompts to generate the editing mask:"),Gp.forEach(n),oo=p(e),u(Ve.$$.fragment,e),io=p(e),Nt=o(e,"P",{});var Wp=i(Nt);ml=l(Wp,"Then, we employ the caption and the input image to get the inverted latents:"),Wp.forEach(n),so=p(e),u(Se.$$.fragment,e),lo=p(e),Ft=o(e,"P",{});var Bp=i(Ft);fl=l(Bp,"Now, generate the image with the inverted latents and semantically generated mask:"),Bp.forEach(n),ro=p(e),u(Ne.$$.fragment,e),po=p(e),L=o(e,"H2",{class:!0});var ai=i(L);de=o(ai,"A",{id:!0,class:!0,href:!0});var Cp=i(de);aa=o(Cp,"SPAN",{});var Rp=i(aa);u(Fe.$$.fragment,Rp),Rp.forEach(n),Cp.forEach(n),ul=p(ai),oa=o(ai,"SPAN",{});var Dp=i(oa);hl=l(Dp,"Generating image captions for inversion"),Dp.forEach(n),ai.forEach(n),co=p(e),pe=o(e,"P",{});var oi=i(pe);gl=l(oi,`The authors originally used the source concept prompt as the caption for generating the partially inverted latents. However, we can also leverage open source and public image captioning models for the same purpose.
Below, we provide an end-to-end example with the `),Pe=o(oi,"A",{href:!0,rel:!0});var Xp=i(Pe);bl=l(Xp,"BLIP"),Xp.forEach(n),yl=l(oi,` model
for generating captions.`),oi.forEach(n),mo=p(e),Pt=o(e,"P",{});var $p=i(Pt);_l=l($p,"First, let\u2019s load our automatic image captioning model:"),$p.forEach(n),fo=p(e),u(He.$$.fragment,e),uo=p(e),Ht=o(e,"P",{});var xp=i(Ht);wl=l(xp,"Then, we define a utility to generate captions from an input image using the model:"),xp.forEach(n),ho=p(e),u(Ye.$$.fragment,e),go=p(e),Yt=o(e,"P",{});var Vp=i(Yt);vl=l(Vp,"Then, we load an input image for conditioning and obtain a suitable caption for it:"),Vp.forEach(n),bo=p(e),u(Ae.$$.fragment,e),yo=p(e),At=o(e,"P",{});var Sp=i(At);Ml=l(Sp,"Then, we employ the generated caption and the input image to get the inverted latents:"),Sp.forEach(n),_o=p(e),u(ze.$$.fragment,e),wo=p(e),zt=o(e,"P",{});var Np=i(zt);Jl=l(Np,"Now, generate the image with the inverted latents and semantically generated mask from our source and target prompts:"),Np.forEach(n),vo=p(e),u(Qe.$$.fragment,e),Mo=p(e),q=o(e,"H2",{class:!0});var ii=i(q);ce=o(ii,"A",{id:!0,class:!0,href:!0});var Fp=i(ce);ia=o(Fp,"SPAN",{});var Pp=i(ia);u(Le.$$.fragment,Pp),Pp.forEach(n),Fp.forEach(n),Tl=p(ii),sa=o(ii,"SPAN",{});var Hp=i(sa);El=l(Hp,"Generating source and target embeddings"),Hp.forEach(n),ii.forEach(n),Jo=p(e),me=o(e,"P",{});var si=i(me);Ul=l(si,`The authors originally required the user to manually provide the source and target prompts 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 `),qe=o(si,"A",{href:!0,rel:!0});var Yp=i(qe);Il=l(Yp,"Flan-T5"),Yp.forEach(n),Zl=l(si,` model
for generating source an target embeddings.`),si.forEach(n),To=p(e),Oe=o(e,"P",{});var wd=i(Oe);la=o(wd,"STRONG",{});var Ap=i(la);kl=l(Ap,"1. Load the generation model"),Ap.forEach(n),jl=l(wd,":"),wd.forEach(n),Eo=p(e),u(Ke.$$.fragment,e),Uo=p(e),et=o(e,"P",{});var vd=i(et);ra=o(vd,"STRONG",{});var zp=i(ra);Gl=l(zp,"2. Construct a starting prompt"),zp.forEach(n),Wl=l(vd,":"),vd.forEach(n),Io=p(e),u(tt.$$.fragment,e),Zo=p(e),Qt=o(e,"P",{});var Qp=i(Qt);Bl=l(Qp,"Here, we\u2019re interested in the \u201Cbowl -> basket\u201D direction."),Qp.forEach(n),ko=p(e),nt=o(e,"P",{});var Md=i(nt);da=o(Md,"STRONG",{});var Lp=i(da);Cl=l(Lp,"3. Generate prompts"),Lp.forEach(n),Rl=l(Md,":"),Md.forEach(n),jo=p(e),Lt=o(e,"P",{});var qp=i(Lt);Dl=l(qp,"We can use a utility like so for this purpose."),qp.forEach(n),Go=p(e),u(at.$$.fragment,e),Wo=p(e),qt=o(e,"P",{});var Op=i(qt);Xl=l(Op,"And then we just call it to generate our prompts:"),Op.forEach(n),Bo=p(e),u(ot.$$.fragment,e),Co=p(e),R=o(e,"P",{});var dn=i(R);$l=l(dn,`We encourage you to play around with the different parameters supported by the
`),pa=o(dn,"CODE",{});var Kp=i(pa);xl=l(Kp,"generate()"),Kp.forEach(n),Vl=l(dn," method ("),it=o(dn,"A",{href:!0,rel:!0});var ec=i(it);Sl=l(ec,"documentation"),ec.forEach(n),Nl=l(dn,") for the generation quality you are looking for."),dn.forEach(n),Ro=p(e),st=o(e,"P",{});var Jd=i(st);ca=o(Jd,"STRONG",{});var tc=i(ca);Fl=l(tc,"4. Load the embedding model"),tc.forEach(n),Pl=l(Jd,":"),Jd.forEach(n),Do=p(e),Ot=o(e,"P",{});var nc=i(Ot);Hl=l(nc,"Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),nc.forEach(n),Xo=p(e),u(lt.$$.fragment,e),$o=p(e),rt=o(e,"P",{});var Td=i(rt);ma=o(Td,"STRONG",{});var ac=i(ma);Yl=l(ac,"5. Compute embeddings"),ac.forEach(n),Al=l(Td,":"),Td.forEach(n),xo=p(e),u(dt.$$.fragment,e),Vo=p(e),Kt=o(e,"P",{});var oc=i(Kt);zl=l(oc,"And you\u2019re done! Now, you can use these embeddings directly while calling the pipeline:"),oc.forEach(n),So=p(e),u(pt.$$.fragment,e),No=p(e),O=o(e,"H2",{class:!0});var li=i(O);fe=o(li,"A",{id:!0,class:!0,href:!0});var ic=i(fe);fa=o(ic,"SPAN",{});var sc=i(fa);u(ct.$$.fragment,sc),sc.forEach(n),ic.forEach(n),Ql=p(li),ua=o(li,"SPAN",{});var lc=i(ua);Ll=l(lc,"StableDiffusionDiffEditPipeline"),lc.forEach(n),li.forEach(n),Fo=p(e),_=o(e,"DIV",{class:!0});var w=i(_);u(mt.$$.fragment,w),ql=p(w),ft=o(w,"P",{});var ri=i(ft);Ol=l(ri,"Pipeline for text-guided image inpainting using Stable Diffusion using DiffEdit. "),ha=o(ri,"EM",{});var rc=i(ha);Kl=l(rc,"This is an experimental feature"),rc.forEach(n),er=l(ri,"."),ri.forEach(n),tr=p(w),ut=o(w,"P",{});var di=i(ut);nr=l(di,"This model inherits from "),en=o(di,"A",{href:!0});var dc=i(en);ar=l(dc,"DiffusionPipeline"),dc.forEach(n),or=l(di,`. 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.)`),di.forEach(n),ir=p(w),ga=o(w,"P",{});var pc=i(ga);sr=l(pc,"In addition the pipeline inherits the following loading methods:"),pc.forEach(n),lr=p(w),ht=o(w,"UL",{});var pi=i(ht);gt=o(pi,"LI",{});var ci=i(gt);ba=o(ci,"EM",{});var cc=i(ba);rr=l(cc,"Textual-Inversion"),cc.forEach(n),dr=l(ci,": "),tn=o(ci,"A",{href:!0});var mc=i(tn);pr=l(mc,"loaders.TextualInversionLoaderMixin.load_textual_inversion()"),mc.forEach(n),ci.forEach(n),cr=p(pi),bt=o(pi,"LI",{});var mi=i(bt);ya=o(mi,"EM",{});var fc=i(ya);mr=l(fc,"LoRA"),fc.forEach(n),fr=l(mi,": "),nn=o(mi,"A",{href:!0});var uc=i(nn);ur=l(uc,"loaders.LoraLoaderMixin.load_lora_weights()"),uc.forEach(n),mi.forEach(n),pi.forEach(n),hr=p(w),_a=o(w,"P",{});var hc=i(_a);gr=l(hc,"as well as the following saving methods:"),hc.forEach(n),br=p(w),wa=o(w,"UL",{});var gc=i(wa);yt=o(gc,"LI",{});var fi=i(yt);va=o(fi,"EM",{});var bc=i(va);yr=l(bc,"LoRA"),bc.forEach(n),_r=l(fi,": "),an=o(fi,"A",{href:!0});var yc=i(an);wr=l(yc,"loaders.LoraLoaderMixin.save_lora_weights()"),yc.forEach(n),fi.forEach(n),gc.forEach(n),vr=p(w),D=o(w,"DIV",{class:!0});var pn=i(D);u(_t.$$.fragment,pn),Mr=p(pn),Ma=o(pn,"P",{});var _c=i(Ma);Jr=l(_c,"Function used to generate a latent mask given a mask prompt, a target prompt, and an image."),_c.forEach(n),Tr=p(pn),Ja=o(pn,"P",{});var wc=i(Ja);Er=l(wc,"Examples:"),wc.forEach(n),pn.forEach(n),Ur=p(w),X=o(w,"DIV",{class:!0});var cn=i(X);u(wt.$$.fragment,cn),Ir=p(cn),Ta=o(cn,"P",{});var vc=i(Ta);Zr=l(vc,"Function used to generate inverted latents given a prompt and image."),vc.forEach(n),kr=p(cn),u(ue.$$.fragment,cn),cn.forEach(n),jr=p(w),he=o(w,"DIV",{class:!0});var ui=i(he);u(vt.$$.fragment,ui),Gr=p(ui),Mt=o(ui,"P",{});var hi=i(Mt);Wr=l(hi,"Disable sliced VAE decoding. If "),Ea=o(hi,"CODE",{});var Mc=i(Ea);Br=l(Mc,"enable_vae_slicing"),Mc.forEach(n),Cr=l(hi,` was previously invoked, this method will go back to
computing decoding in one step.`),hi.forEach(n),ui.forEach(n),Rr=p(w),ge=o(w,"DIV",{class:!0});var gi=i(ge);u(Jt.$$.fragment,gi),Dr=p(gi),Tt=o(gi,"P",{});var bi=i(Tt);Xr=l(bi,"Disable tiled VAE decoding. If "),Ua=o(bi,"CODE",{});var Jc=i(Ua);$r=l(Jc,"enable_vae_tiling"),Jc.forEach(n),xr=l(bi,` was previously invoked, this method will go back to
computing decoding in one step.`),bi.forEach(n),gi.forEach(n),Vr=p(w),be=o(w,"DIV",{class:!0});var yi=i(be);u(Et.$$.fragment,yi),Sr=p(yi),Z=o(yi,"P",{});var S=i(Z);Nr=l(S,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),Ia=o(S,"CODE",{});var Tc=i(Ia);Fr=l(Tc,"enable_sequential_cpu_offload"),Tc.forEach(n),Pr=l(S,", this method moves one whole model at a time to the GPU when its "),Za=o(S,"CODE",{});var Ec=i(Za);Hr=l(Ec,"forward"),Ec.forEach(n),Yr=l(S,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),ka=o(S,"CODE",{});var Uc=i(ka);Ar=l(Uc,"enable_sequential_cpu_offload"),Uc.forEach(n),zr=l(S,", but performance is much better due to the iterative execution of the "),ja=o(S,"CODE",{});var Ic=i(ja);Qr=l(Ic,"unet"),Ic.forEach(n),Lr=l(S,"."),S.forEach(n),yi.forEach(n),qr=p(w),ye=o(w,"DIV",{class:!0});var _i=i(ye);u(Ut.$$.fragment,_i),Or=p(_i),K=o(_i,"P",{});var mn=i(K);Kr=l(mn,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),Ga=o(mn,"CODE",{});var Zc=i(Ga);ed=l(Zc,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),Zc.forEach(n),td=l(mn,"forward"),Wa=o(mn,"CODE",{});var kc=i(Wa);nd=l(kc,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),kc.forEach(n),ad=l(mn,"enable_model_cpu_offload`, but performance is lower."),mn.forEach(n),_i.forEach(n),od=p(w),$=o(w,"DIV",{class:!0});var fn=i($);u(It.$$.fragment,fn),id=p(fn),Ba=o(fn,"P",{});var jc=i(Ba);sd=l(jc,"Enable sliced VAE decoding."),jc.forEach(n),ld=p(fn),Ca=o(fn,"P",{});var Gc=i(Ca);rd=l(Gc,`When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
steps. This is useful to save some memory and allow larger batch sizes.`),Gc.forEach(n),fn.forEach(n),dd=p(w),x=o(w,"DIV",{class:!0});var un=i(x);u(Zt.$$.fragment,un),pd=p(un),Ra=o(un,"P",{});var Wc=i(Ra);cd=l(Wc,"Enable tiled VAE decoding."),Wc.forEach(n),md=p(un),Da=o(un,"P",{});var Bc=i(Da);fd=l(Bc,`When this option is enabled, the VAE will split the input tensor into tiles to compute decoding and encoding in
several steps. This is useful to save a large amount of memory and to allow the processing of larger images.`),Bc.forEach(n),un.forEach(n),w.forEach(n),Po=p(e),on=o(e,"UL",{});var Cc=i(on);Xa=o(Cc,"LI",{});var Rc=i(Xa);$a=o(Rc,"STRONG",{});var Dc=i($a);ud=l(Dc,"call"),Dc.forEach(n),Rc.forEach(n),Cc.forEach(n),this.h()},h(){m(T,"name","hf:doc:metadata"),m(T,"content",JSON.stringify(Yc)),m(B,"id","zeroshot-diffusionbased-semantic-image-editing-with-mask-guidance"),m(B,"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(B,"href","#zeroshot-diffusionbased-semantic-image-editing-with-mask-guidance"),m(v,"class","relative group"),m(ne,"id","overview"),m(ne,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ne,"href","#overview"),m(F,"class","relative group"),m(Ee,"href","https://arxiv.org/abs/2210.11427"),m(Ee,"rel","nofollow"),m(Ue,"href","https://arxiv.org/abs/2210.11427"),m(Ue,"rel","nofollow"),m(Ie,"href","https://blog.problemsolversguild.com/technical/research/2022/11/02/DiffEdit-Implementation.html"),m(Ie,"rel","nofollow"),m(Ze,"href","https://github.com/Xiang-cd/DiffEdit-stable-diffusion/"),m(Ze,"rel","nofollow"),m(ae,"id","tips"),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","#tips"),m(P,"class","relative group"),m(Dt,"href","#generating-image-captions-for-inversion"),m($t,"href","#generating-source-and-target-embeddings"),m(oe,"id","available-pipelines"),m(oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(oe,"href","#available-pipelines"),m(A,"class","relative group"),m(Re,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py"),m(Re,"rel","nofollow"),m(se,"id","usage-example"),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","#usage-example"),m(z,"class","relative group"),m(le,"id","based-on-an-input-image-with-a-caption"),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","#based-on-an-input-image-with-a-caption"),m(Q,"class","relative group"),m(de,"id","generating-image-captions-for-inversion"),m(de,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(de,"href","#generating-image-captions-for-inversion"),m(L,"class","relative group"),m(Pe,"href","https://huggingface.co/docs/transformers/model_doc/blip"),m(Pe,"rel","nofollow"),m(ce,"id","generating-source-and-target-embeddings"),m(ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(ce,"href","#generating-source-and-target-embeddings"),m(q,"class","relative group"),m(qe,"href","https://huggingface.co/docs/transformers/model_doc/flan-t5"),m(qe,"rel","nofollow"),m(it,"href","https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.generation_tf_utils.TFGenerationMixin.generate"),m(it,"rel","nofollow"),m(fe,"id","diffusers.StableDiffusionDiffEditPipeline"),m(fe,"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(fe,"href","#diffusers.StableDiffusionDiffEditPipeline"),m(O,"class","relative group"),m(en,"href","/docs/diffusers/v0.18.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),m(tn,"href","/docs/diffusers/v0.18.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline.load_textual_inversion"),m(nn,"href","/docs/diffusers/v0.18.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline.load_lora_weights"),m(an,"href","/docs/diffusers/v0.18.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline.save_lora_weights"),m(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(X,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(he,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(ge,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(be,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(ye,"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(x,"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,T),c(e,N,r),c(e,v,r),t(v,B),t(B,hn),h(Me,hn,null),t(v,wi),t(v,gn),t(gn,vi),c(e,Va,r),c(e,F,r),t(F,ne),t(ne,bn),h(Je,bn,null),t(F,Mi),t(F,yn),t(yn,Ji),c(e,Sa,r),c(e,Te,r),t(Te,Ee),t(Ee,Ti),t(Te,Ei),c(e,Na,r),c(e,jt,r),t(jt,Ui),c(e,Fa,r),c(e,Gt,r),t(Gt,_n),t(_n,Ii),c(e,Pa,r),c(e,Wt,r),t(Wt,Zi),c(e,Ha,r),c(e,C,r),t(C,Bt),t(Bt,Ue),t(Ue,ki),t(Bt,ji),t(C,Gi),t(C,Ct),t(Ct,Ie),t(Ie,Wi),t(Ct,Bi),t(C,Ci),t(C,Rt),t(Rt,Ze),t(Ze,Ri),t(Rt,Di),c(e,Ya,r),c(e,P,r),t(P,ae),t(ae,wn),h(ke,wn,null),t(P,Xi),t(P,vn),t(vn,$i),c(e,Aa,r),c(e,M,r),t(M,Mn),t(Mn,xi),t(M,Vi),t(M,j),t(j,Si),t(j,Jn),t(Jn,Ni),t(j,Fi),t(j,Tn),t(Tn,Pi),t(j,Hi),t(j,En),t(En,Yi),t(j,Ai),t(M,zi),t(M,E),t(E,Qi),t(E,Un),t(Un,Li),t(E,qi),t(E,In),t(In,Oi),t(E,Ki),t(E,Zn),t(Zn,es),t(E,ts),t(E,kn),t(kn,ns),t(E,as),t(E,jn),t(jn,os),t(E,is),t(M,ss),t(M,G),t(G,ls),t(G,Gn),t(Gn,rs),t(G,ds),t(G,Wn),t(Wn,ps),t(G,cs),t(G,Dt),t(Dt,ms),t(G,fs),t(M,us),t(M,I),t(I,hs),t(I,Bn),t(Bn,gs),t(I,bs),t(I,Cn),t(Cn,ys),t(I,_s),t(I,Rn),t(Rn,ws),t(I,vs),t(I,Dn),t(Dn,Ms),t(I,Js),t(M,Ts),t(M,Xt),t(Xt,Es),t(Xt,H),t(H,W),t(W,Us),t(W,Xn),t(Xn,Is),t(W,Zs),t(W,$n),t($n,ks),t(W,js),t(W,xn),t(xn,Gs),t(W,Ws),t(H,Bs),t(H,je),t(je,Cs),t(je,Vn),t(Vn,Rs),t(je,Ds),t(H,Xs),t(H,Y),t(Y,$s),t(Y,Sn),t(Sn,xs),t(Y,Vs),t(Y,Nn),t(Nn,Ss),t(Y,Ns),t(M,Fs),t(M,Ge),t(Ge,Ps),t(Ge,$t),t($t,Hs),t(Ge,Ys),c(e,za,r),c(e,A,r),t(A,oe),t(oe,Fn),h(We,Fn,null),t(A,As),t(A,Pn),t(Pn,zs),c(e,Qa,r),c(e,ie,r),t(ie,Hn),t(Hn,Be),t(Be,Yn),t(Yn,Qs),t(Be,Ls),t(Be,An),t(An,qs),t(ie,Os),t(ie,zn),t(zn,Ce),t(Ce,Qn),t(Qn,Re),t(Re,Ks),t(Ce,el),t(Ce,Ln),t(Ln,qn),t(qn,tl),c(e,La,r),c(e,z,r),t(z,se),t(se,On),h(De,On,null),t(z,nl),t(z,Kn),t(Kn,al),c(e,qa,r),c(e,Q,r),t(Q,le),t(le,ea),h(Xe,ea,null),t(Q,ol),t(Q,ta),t(ta,il),c(e,Oa,r),c(e,re,r),t(re,sl),t(re,na),t(na,ll),t(re,rl),c(e,Ka,r),c(e,xt,r),t(xt,dl),c(e,eo,r),h($e,e,r),c(e,to,r),c(e,Vt,r),t(Vt,pl),c(e,no,r),h(xe,e,r),c(e,ao,r),c(e,St,r),t(St,cl),c(e,oo,r),h(Ve,e,r),c(e,io,r),c(e,Nt,r),t(Nt,ml),c(e,so,r),h(Se,e,r),c(e,lo,r),c(e,Ft,r),t(Ft,fl),c(e,ro,r),h(Ne,e,r),c(e,po,r),c(e,L,r),t(L,de),t(de,aa),h(Fe,aa,null),t(L,ul),t(L,oa),t(oa,hl),c(e,co,r),c(e,pe,r),t(pe,gl),t(pe,Pe),t(Pe,bl),t(pe,yl),c(e,mo,r),c(e,Pt,r),t(Pt,_l),c(e,fo,r),h(He,e,r),c(e,uo,r),c(e,Ht,r),t(Ht,wl),c(e,ho,r),h(Ye,e,r),c(e,go,r),c(e,Yt,r),t(Yt,vl),c(e,bo,r),h(Ae,e,r),c(e,yo,r),c(e,At,r),t(At,Ml),c(e,_o,r),h(ze,e,r),c(e,wo,r),c(e,zt,r),t(zt,Jl),c(e,vo,r),h(Qe,e,r),c(e,Mo,r),c(e,q,r),t(q,ce),t(ce,ia),h(Le,ia,null),t(q,Tl),t(q,sa),t(sa,El),c(e,Jo,r),c(e,me,r),t(me,Ul),t(me,qe),t(qe,Il),t(me,Zl),c(e,To,r),c(e,Oe,r),t(Oe,la),t(la,kl),t(Oe,jl),c(e,Eo,r),h(Ke,e,r),c(e,Uo,r),c(e,et,r),t(et,ra),t(ra,Gl),t(et,Wl),c(e,Io,r),h(tt,e,r),c(e,Zo,r),c(e,Qt,r),t(Qt,Bl),c(e,ko,r),c(e,nt,r),t(nt,da),t(da,Cl),t(nt,Rl),c(e,jo,r),c(e,Lt,r),t(Lt,Dl),c(e,Go,r),h(at,e,r),c(e,Wo,r),c(e,qt,r),t(qt,Xl),c(e,Bo,r),h(ot,e,r),c(e,Co,r),c(e,R,r),t(R,$l),t(R,pa),t(pa,xl),t(R,Vl),t(R,it),t(it,Sl),t(R,Nl),c(e,Ro,r),c(e,st,r),t(st,ca),t(ca,Fl),t(st,Pl),c(e,Do,r),c(e,Ot,r),t(Ot,Hl),c(e,Xo,r),h(lt,e,r),c(e,$o,r),c(e,rt,r),t(rt,ma),t(ma,Yl),t(rt,Al),c(e,xo,r),h(dt,e,r),c(e,Vo,r),c(e,Kt,r),t(Kt,zl),c(e,So,r),h(pt,e,r),c(e,No,r),c(e,O,r),t(O,fe),t(fe,fa),h(ct,fa,null),t(O,Ql),t(O,ua),t(ua,Ll),c(e,Fo,r),c(e,_,r),h(mt,_,null),t(_,ql),t(_,ft),t(ft,Ol),t(ft,ha),t(ha,Kl),t(ft,er),t(_,tr),t(_,ut),t(ut,nr),t(ut,en),t(en,ar),t(ut,or),t(_,ir),t(_,ga),t(ga,sr),t(_,lr),t(_,ht),t(ht,gt),t(gt,ba),t(ba,rr),t(gt,dr),t(gt,tn),t(tn,pr),t(ht,cr),t(ht,bt),t(bt,ya),t(ya,mr),t(bt,fr),t(bt,nn),t(nn,ur),t(_,hr),t(_,_a),t(_a,gr),t(_,br),t(_,wa),t(wa,yt),t(yt,va),t(va,yr),t(yt,_r),t(yt,an),t(an,wr),t(_,vr),t(_,D),h(_t,D,null),t(D,Mr),t(D,Ma),t(Ma,Jr),t(D,Tr),t(D,Ja),t(Ja,Er),t(_,Ur),t(_,X),h(wt,X,null),t(X,Ir),t(X,Ta),t(Ta,Zr),t(X,kr),h(ue,X,null),t(_,jr),t(_,he),h(vt,he,null),t(he,Gr),t(he,Mt),t(Mt,Wr),t(Mt,Ea),t(Ea,Br),t(Mt,Cr),t(_,Rr),t(_,ge),h(Jt,ge,null),t(ge,Dr),t(ge,Tt),t(Tt,Xr),t(Tt,Ua),t(Ua,$r),t(Tt,xr),t(_,Vr),t(_,be),h(Et,be,null),t(be,Sr),t(be,Z),t(Z,Nr),t(Z,Ia),t(Ia,Fr),t(Z,Pr),t(Z,Za),t(Za,Hr),t(Z,Yr),t(Z,ka),t(ka,Ar),t(Z,zr),t(Z,ja),t(ja,Qr),t(Z,Lr),t(_,qr),t(_,ye),h(Ut,ye,null),t(ye,Or),t(ye,K),t(K,Kr),t(K,Ga),t(Ga,ed),t(K,td),t(K,Wa),t(Wa,nd),t(K,ad),t(_,od),t(_,$),h(It,$,null),t($,id),t($,Ba),t(Ba,sd),t($,ld),t($,Ca),t(Ca,rd),t(_,dd),t(_,x),h(Zt,x,null),t(x,pd),t(x,Ra),t(Ra,cd),t(x,md),t(x,Da),t(Da,fd),c(e,Po,r),c(e,on,r),t(on,Xa),t(Xa,$a),t($a,ud),Ho=!0},p(e,[r]){const kt={};r&2&&(kt.$$scope={dirty:r,ctx:e}),ue.$set(kt)},i(e){Ho||(g(Me.$$.fragment,e),g(Je.$$.fragment,e),g(ke.$$.fragment,e),g(We.$$.fragment,e),g(De.$$.fragment,e),g(Xe.$$.fragment,e),g($e.$$.fragment,e),g(xe.$$.fragment,e),g(Ve.$$.fragment,e),g(Se.$$.fragment,e),g(Ne.$$.fragment,e),g(Fe.$$.fragment,e),g(He.$$.fragment,e),g(Ye.$$.fragment,e),g(Ae.$$.fragment,e),g(ze.$$.fragment,e),g(Qe.$$.fragment,e),g(Le.$$.fragment,e),g(Ke.$$.fragment,e),g(tt.$$.fragment,e),g(at.$$.fragment,e),g(ot.$$.fragment,e),g(lt.$$.fragment,e),g(dt.$$.fragment,e),g(pt.$$.fragment,e),g(ct.$$.fragment,e),g(mt.$$.fragment,e),g(_t.$$.fragment,e),g(wt.$$.fragment,e),g(ue.$$.fragment,e),g(vt.$$.fragment,e),g(Jt.$$.fragment,e),g(Et.$$.fragment,e),g(Ut.$$.fragment,e),g(It.$$.fragment,e),g(Zt.$$.fragment,e),Ho=!0)},o(e){b(Me.$$.fragment,e),b(Je.$$.fragment,e),b(ke.$$.fragment,e),b(We.$$.fragment,e),b(De.$$.fragment,e),b(Xe.$$.fragment,e),b($e.$$.fragment,e),b(xe.$$.fragment,e),b(Ve.$$.fragment,e),b(Se.$$.fragment,e),b(Ne.$$.fragment,e),b(Fe.$$.fragment,e),b(He.$$.fragment,e),b(Ye.$$.fragment,e),b(Ae.$$.fragment,e),b(ze.$$.fragment,e),b(Qe.$$.fragment,e),b(Le.$$.fragment,e),b(Ke.$$.fragment,e),b(tt.$$.fragment,e),b(at.$$.fragment,e),b(ot.$$.fragment,e),b(lt.$$.fragment,e),b(dt.$$.fragment,e),b(pt.$$.fragment,e),b(ct.$$.fragment,e),b(mt.$$.fragment,e),b(_t.$$.fragment,e),b(wt.$$.fragment,e),b(ue.$$.fragment,e),b(vt.$$.fragment,e),b(Jt.$$.fragment,e),b(Et.$$.fragment,e),b(Ut.$$.fragment,e),b(It.$$.fragment,e),b(Zt.$$.fragment,e),Ho=!1},d(e){n(T),e&&n(N),e&&n(v),y(Me),e&&n(Va),e&&n(F),y(Je),e&&n(Sa),e&&n(Te),e&&n(Na),e&&n(jt),e&&n(Fa),e&&n(Gt),e&&n(Pa),e&&n(Wt),e&&n(Ha),e&&n(C),e&&n(Ya),e&&n(P),y(ke),e&&n(Aa),e&&n(M),e&&n(za),e&&n(A),y(We),e&&n(Qa),e&&n(ie),e&&n(La),e&&n(z),y(De),e&&n(qa),e&&n(Q),y(Xe),e&&n(Oa),e&&n(re),e&&n(Ka),e&&n(xt),e&&n(eo),y($e,e),e&&n(to),e&&n(Vt),e&&n(no),y(xe,e),e&&n(ao),e&&n(St),e&&n(oo),y(Ve,e),e&&n(io),e&&n(Nt),e&&n(so),y(Se,e),e&&n(lo),e&&n(Ft),e&&n(ro),y(Ne,e),e&&n(po),e&&n(L),y(Fe),e&&n(co),e&&n(pe),e&&n(mo),e&&n(Pt),e&&n(fo),y(He,e),e&&n(uo),e&&n(Ht),e&&n(ho),y(Ye,e),e&&n(go),e&&n(Yt),e&&n(bo),y(Ae,e),e&&n(yo),e&&n(At),e&&n(_o),y(ze,e),e&&n(wo),e&&n(zt),e&&n(vo),y(Qe,e),e&&n(Mo),e&&n(q),y(Le),e&&n(Jo),e&&n(me),e&&n(To),e&&n(Oe),e&&n(Eo),y(Ke,e),e&&n(Uo),e&&n(et),e&&n(Io),y(tt,e),e&&n(Zo),e&&n(Qt),e&&n(ko),e&&n(nt),e&&n(jo),e&&n(Lt),e&&n(Go),y(at,e),e&&n(Wo),e&&n(qt),e&&n(Bo),y(ot,e),e&&n(Co),e&&n(R),e&&n(Ro),e&&n(st),e&&n(Do),e&&n(Ot),e&&n(Xo),y(lt,e),e&&n($o),e&&n(rt),e&&n(xo),y(dt,e),e&&n(Vo),e&&n(Kt),e&&n(So),y(pt,e),e&&n(No),e&&n(O),y(ct),e&&n(Fo),e&&n(_),y(mt),y(_t),y(wt),y(ue),y(vt),y(Jt),y(Et),y(Ut),y(It),y(Zt),e&&n(Po),e&&n(on)}}}const Yc={local:"zeroshot-diffusionbased-semantic-image-editing-with-mask-guidance",sections:[{local:"overview",title:"Overview"},{local:"tips",title:"Tips "},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",sections:[{local:"based-on-an-input-image-with-a-caption",title:"Based on an input image with a caption"}],title:"Usage example"},{local:"generating-image-captions-for-inversion",title:"Generating image captions for inversion"},{local:"generating-source-and-target-embeddings",title:"Generating source and target embeddings "},{local:"diffusers.StableDiffusionDiffEditPipeline",title:"StableDiffusionDiffEditPipeline"}],title:"Zero-shot Diffusion-based Semantic Image Editing with Mask Guidance"};function Ac(xa){return Sc(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Kc extends Xc{constructor(T){super();$c(this,T,Ac,Hc,xc,{})}}export{Kc as default,Yc as metadata};
