import{S as au,i as iu,s as ou,e as i,k as f,w as h,t as n,M as lu,c as o,d as t,m as c,a as l,x as _,h as p,b as m,N as re,G as s,g as r,y as g,q as w,o as v,B as y,v as ru}from"../../chunks/vendor-hf-doc-builder.js";import{T as Bl}from"../../chunks/Tip-hf-doc-builder.js";import{I as as}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as k}from"../../chunks/CodeBlock-hf-doc-builder.js";function nu(z){let u,j,d,b,E;return{c(){u=i("p"),j=n(`It is useful to look at some inference samples while a model is training to measure the
training progress. In our `),d=i("a"),b=n("training scripts"),E=n(`, we support this utility with additional support for
logging to TensorBoard and Weights & Biases.`),this.h()},l($){u=o($,"P",{});var x=l(u);j=p(x,`It is useful to look at some inference samples while a model is training to measure the
training progress. In our `),d=o(x,"A",{href:!0,rel:!0});var I=l(d);b=p(I,"training scripts"),I.forEach(t),E=p(x,`, we support this utility with additional support for
logging to TensorBoard and Weights & Biases.`),x.forEach(t),this.h()},h(){m(d,"href","https://github.com/huggingface/diffusers/tree/main/examples/"),m(d,"rel","nofollow")},m($,x){r($,u,x),s(u,j),s(u,d),s(d,b),s(u,E)},d($){$&&t(u)}}}function pu(z){let u,j,d,b,E;return{c(){u=i("p"),j=n(`By construction, there are some limitations in this score. The captions in the training dataset
were crawled from the web and extracted from `),d=i("code"),b=n("alt"),E=n(` and similar tags associated an image on the internet.
They are not necessarily representative of what a human being would use to describe an image. Hence we
had to \u201Cengineer\u201D some prompts here.`)},l($){u=o($,"P",{});var x=l(u);j=p(x,`By construction, there are some limitations in this score. The captions in the training dataset
were crawled from the web and extracted from `),d=o(x,"CODE",{});var I=l(d);b=p(I,"alt"),I.forEach(t),E=p(x,` and similar tags associated an image on the internet.
They are not necessarily representative of what a human being would use to describe an image. Hence we
had to \u201Cengineer\u201D some prompts here.`),x.forEach(t)},m($,x){r($,u,x),s(u,j),s(u,d),s(d,b),s(u,E)},d($){$&&t(u)}}}function fu(z){let u,j;return{c(){u=i("p"),j=n("Both CLIP score and CLIP direction similarity rely on the CLIP model, which can make the evaluations biased.")},l(d){u=o(d,"P",{});var b=l(u);j=p(b,"Both CLIP score and CLIP direction similarity rely on the CLIP model, which can make the evaluations biased."),b.forEach(t)},m(d,b){r(d,u,b),s(u,j)},d(d){d&&t(u)}}}function cu(z){let u,j,d,b,E,$,x,I,Re,ne,D,B,Ke,O,T,pe,L,Qe;return{c(){u=i("p"),j=n("FID results tend to be fragile as they depend on a lot of factors:"),d=f(),b=i("ul"),E=i("li"),$=n("The specific Inception model used during computation."),x=f(),I=i("li"),Re=n("The implementation accuracy of the computation."),ne=f(),D=i("li"),B=n("The image format (not the same if we start from PNGs vs JPGs)."),Ke=f(),O=i("p"),T=n(`Keeping that in mind, FID is often most useful when comparing similar runs, but it is
hard to reproduce paper results unless the authors carefully disclose the FID
measurement code.`),pe=f(),L=i("p"),Qe=n("These points apply to other related metrics too, such as KID and IS.")},l(P){u=o(P,"P",{});var q=l(u);j=p(q,"FID results tend to be fragile as they depend on a lot of factors:"),q.forEach(t),d=c(P),b=o(P,"UL",{});var S=l(b);E=o(S,"LI",{});var is=l(E);$=p(is,"The specific Inception model used during computation."),is.forEach(t),x=c(S),I=o(S,"LI",{});var Ve=l(I);Re=p(Ve,"The implementation accuracy of the computation."),Ve.forEach(t),ne=c(S),D=o(S,"LI",{});var M=l(D);B=p(M,"The image format (not the same if we start from PNGs vs JPGs)."),M.forEach(t),S.forEach(t),Ke=c(P),O=o(P,"P",{});var os=l(O);T=p(os,`Keeping that in mind, FID is often most useful when comparing similar runs, but it is
hard to reproduce paper results unless the authors carefully disclose the FID
measurement code.`),os.forEach(t),pe=c(P),L=o(P,"P",{});var fe=l(L);Qe=p(fe,"These points apply to other related metrics too, such as KID and IS."),fe.forEach(t)},m(P,q){r(P,u,q),s(u,j),r(P,d,q),r(P,b,q),s(b,E),s(E,$),s(b,x),s(b,I),s(I,Re),s(b,ne),s(b,D),s(D,B),r(P,Ke,q),r(P,O,q),s(O,T),r(P,pe,q),r(P,L,q),s(L,Qe)},d(P){P&&t(u),P&&t(d),P&&t(b),P&&t(Ke),P&&t(O),P&&t(pe),P&&t(L)}}}function mu(z){let u,j,d,b,E,$,x,I,Re,ne,D,B,Ke,O,T,pe,L,Qe,P,q,S,is,Ve,M,os,fe,Wl,Gl,_i,ce,Hl,Ue,Rl,Kl,gi,Y,me,ra,Ze,Ql,na,Vl,wi,ls,Ul,vi,W,Xe,Zl,Je,pa,Xl,Jl,Yl,ee,er,Ye,fa,tr,sr,et,ca,ar,ir,or,tt,lr,st,ma,rr,nr,yi,te,ue,ua,at,pr,da,fr,bi,G,cr,it,mr,ur,ot,dr,hr,Pi,de,_r,lt,gr,wr,$i,rs,ha,vr,ki,ns,ps,Ef,xi,fs,yr,ji,H,_a,br,Pr,ga,$r,kr,wa,xr,Ei,he,jr,va,Er,Ir,Ii,_e,qr,rt,Dr,Lr,qi,nt,Di,ge,Cr,pt,Sr,Tr,Li,ft,Ci,cs,ms,If,Si,R,Ar,ya,Fr,Nr,ct,Or,Mr,Ti,us,ds,qf,Ai,hs,zr,Fi,we,Ni,se,ve,ba,mt,Br,Pa,Wr,Oi,_s,Gr,Mi,K,$a,Hr,Rr,ka,Kr,Qr,xa,Vr,zi,ae,ye,ja,ut,Ur,Ea,Zr,Bi,dt,ht,Xr,Jr,Wi,be,Yr,gs,en,tn,Gi,_t,Hi,ws,sn,Ri,gt,Ki,vs,an,Qi,wt,Vi,ys,on,Ui,Q,ln,bs,rn,nn,vt,pn,fn,Zi,yt,Xi,Pe,cn,bt,mn,un,Ji,Pt,Yi,Ps,dn,eo,$t,to,$e,hn,kt,_n,gn,so,ke,ao,ie,xe,Ia,xt,wn,qa,vn,io,je,yn,$s,bn,Pn,oo,ks,$n,lo,xs,js,Df,ro,A,kn,jt,xn,jn,Et,En,In,Da,qn,Dn,no,Ee,La,Ln,Cn,Ca,Sn,po,Es,Tn,fo,Is,qs,Lf,co,Ds,An,mo,It,uo,qt,ho,Ls,Fn,_o,V,Ie,Sa,Nn,On,Ta,Mn,zn,Bn,Cs,Aa,Wn,Gn,Hn,qe,Fa,Rn,Kn,Na,Qn,Vn,go,Ss,Un,wo,Dt,vo,Lt,yo,Ts,Zn,bo,Ct,Po,As,Fs,Cf,$o,Ns,Xn,ko,De,Jn,Os,Yn,ep,xo,St,jo,Ms,tp,Eo,Tt,Io,zs,sp,qo,At,Do,U,ap,Oa,ip,op,Ft,lp,rp,Lo,Le,np,Ma,pp,fp,Co,Nt,So,Ce,cp,za,mp,up,To,Ot,Ao,Bs,dp,Fo,F,hp,Ba,_p,gp,Wa,wp,vp,Ga,yp,bp,No,Se,Pp,Ha,$p,kp,Oo,Te,xp,Mt,Ra,jp,Ep,Mo,Ae,zo,oe,Ka,Qa,Ip,qp,zt,Dp,Lp,Bo,Ws,Va,Bt,Cp,Wt,Sp,Tp,Wo,le,Fe,Ua,Gt,Ap,Za,Fp,Go,C,Np,Ht,Op,Mp,Rt,zp,Bp,Kt,Xa,Wp,Gp,Qt,Hp,Rp,Ho,Ne,Kp,Vt,Qp,Vp,Ro,Gs,Ja,Up,Ko,Hs,Zp,Qo,Rs,Xp,Vo,Ut,Uo,Zt,Zo,Ks,Jp,Xo,Z,Qs,Sf,Yp,ef,Ya,tf,Jo,Vs,sf,Yo,Xt,el,Oe,af,Jt,ei,of,lf,tl,Yt,sl,Me,rf,es,ti,nf,pf,al,ts,il,Us,ff,ol,N,si,cf,mf,ai,uf,df,ii,hf,_f,oi,gf,ll,Zs,wf,rl,ze,nl,Be,vf,li,yf,bf,pl,X,Xs,Tf,Pf,$f,ri,kf,fl;return $=new as({}),Ze=new as({}),at=new as({}),nt=new k({props:{code:`from datasets import load_dataset

# prompts = load_dataset("nateraw/parti-prompts", split="train")
# prompts = prompts.shuffle()
# sample_prompts = [prompts[i]["Prompt"] for i in range(5)]

# Fixing these sample prompts in the interest of reproducibility.
sample_prompts = [
    "a corgi",
    "a hot air balloon with a yin-yang symbol, with the moon visible in the daytime sky",
    "a car with no windows",
    "a cube made of porcupine",
    'The saying "BE EXCELLENT TO EACH OTHER" written on a red brick wall with a graffiti image of a green alien wearing a tuxedo. A yellow fire hydrant is on a sidewalk in the foreground.',
]`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-comment"># prompts = load_dataset(&quot;nateraw/parti-prompts&quot;, split=&quot;train&quot;)</span>
<span class="hljs-comment"># prompts = prompts.shuffle()</span>
<span class="hljs-comment"># sample_prompts = [prompts[i][&quot;Prompt&quot;] for i in range(5)]</span>

<span class="hljs-comment"># Fixing these sample prompts in the interest of reproducibility.</span>
sample_prompts = [
    <span class="hljs-string">&quot;a corgi&quot;</span>,
    <span class="hljs-string">&quot;a hot air balloon with a yin-yang symbol, with the moon visible in the daytime sky&quot;</span>,
    <span class="hljs-string">&quot;a car with no windows&quot;</span>,
    <span class="hljs-string">&quot;a cube made of porcupine&quot;</span>,
    <span class="hljs-string">&#x27;The saying &quot;BE EXCELLENT TO EACH OTHER&quot; written on a red brick wall with a graffiti image of a green alien wearing a tuxedo. A yellow fire hydrant is on a sidewalk in the foreground.&#x27;</span>,
]`}}),ft=new k({props:{code:`import torch

seed = 0
generator = torch.manual_seed(seed)

images = sd_pipeline(sample_prompts, num_images_per_prompt=1, generator=generator, output_type="numpy").images`,highlighted:`<span class="hljs-keyword">import</span> torch

seed = <span class="hljs-number">0</span>
generator = torch.manual_seed(seed)

images = sd_pipeline(sample_prompts, num_images_per_prompt=<span class="hljs-number">1</span>, generator=generator, output_type=<span class="hljs-string">&quot;numpy&quot;</span>).images`}}),we=new Bl({props:{$$slots:{default:[nu]},$$scope:{ctx:z}}}),mt=new as({}),ut=new as({}),_t=new k({props:{code:`from diffusers import StableDiffusionPipeline
import torch

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

model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
sd_pipeline = StableDiffusionPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)`}}),gt=new k({props:{code:`prompts = [
    "a photo of an astronaut riding a horse on mars",
    "A high tech solarpunk utopia in the Amazon rainforest",
    "A pikachu fine dining with a view to the Eiffel Tower",
    "A mecha robot in a favela in expressionist style",
    "an insect robot preparing a delicious meal",
    "A small cabin on top of a snowy mountain in the style of Disney, artstation",
]

images = sd_pipeline(prompts, num_images_per_prompt=1, output_type="numpy").images

print(images.shape)
# (6, 512, 512, 3)`,highlighted:`prompts = [
    <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>,
    <span class="hljs-string">&quot;A high tech solarpunk utopia in the Amazon rainforest&quot;</span>,
    <span class="hljs-string">&quot;A pikachu fine dining with a view to the Eiffel Tower&quot;</span>,
    <span class="hljs-string">&quot;A mecha robot in a favela in expressionist style&quot;</span>,
    <span class="hljs-string">&quot;an insect robot preparing a delicious meal&quot;</span>,
    <span class="hljs-string">&quot;A small cabin on top of a snowy mountain in the style of Disney, artstation&quot;</span>,
]

images = sd_pipeline(prompts, num_images_per_prompt=<span class="hljs-number">1</span>, output_type=<span class="hljs-string">&quot;numpy&quot;</span>).images

<span class="hljs-built_in">print</span>(images.shape)
<span class="hljs-comment"># (6, 512, 512, 3)</span>`}}),wt=new k({props:{code:`from torchmetrics.functional.multimodal import clip_score
from functools import partial

clip_score_fn = partial(clip_score, model_name_or_path="openai/clip-vit-base-patch16")


def calculate_clip_score(images, prompts):
    images_int = (images * 255).astype("uint8")
    clip_score = clip_score_fn(torch.from_numpy(images_int).permute(0, 3, 1, 2), prompts).detach()
    return round(float(clip_score), 4)


sd_clip_score = calculate_clip_score(images, prompts)
print(f"CLIP score: {sd_clip_score}")
# CLIP score: 35.7038`,highlighted:`<span class="hljs-keyword">from</span> torchmetrics.functional.multimodal <span class="hljs-keyword">import</span> clip_score
<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial

clip_score_fn = partial(clip_score, model_name_or_path=<span class="hljs-string">&quot;openai/clip-vit-base-patch16&quot;</span>)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">calculate_clip_score</span>(<span class="hljs-params">images, prompts</span>):
    images_int = (images * <span class="hljs-number">255</span>).astype(<span class="hljs-string">&quot;uint8&quot;</span>)
    clip_score = clip_score_fn(torch.from_numpy(images_int).permute(<span class="hljs-number">0</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>), prompts).detach()
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">round</span>(<span class="hljs-built_in">float</span>(clip_score), <span class="hljs-number">4</span>)


sd_clip_score = calculate_clip_score(images, prompts)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;CLIP score: <span class="hljs-subst">{sd_clip_score}</span>&quot;</span>)
<span class="hljs-comment"># CLIP score: 35.7038</span>`}}),yt=new k({props:{code:`seed = 0
generator = torch.manual_seed(seed)

images = sd_pipeline(prompts, num_images_per_prompt=1, generator=generator, output_type="numpy").images`,highlighted:`seed = <span class="hljs-number">0</span>
generator = torch.manual_seed(seed)

images = sd_pipeline(prompts, num_images_per_prompt=<span class="hljs-number">1</span>, generator=generator, output_type=<span class="hljs-string">&quot;numpy&quot;</span>).images`}}),Pt=new k({props:{code:`model_ckpt_1_5 = "runwayml/stable-diffusion-v1-5"
sd_pipeline_1_5 = StableDiffusionPipeline.from_pretrained(model_ckpt_1_5, torch_dtype=weight_dtype).to(device)

images_1_5 = sd_pipeline_1_5(prompts, num_images_per_prompt=1, generator=generator, output_type="numpy").images`,highlighted:`model_ckpt_1_5 = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
sd_pipeline_1_5 = StableDiffusionPipeline.from_pretrained(model_ckpt_1_5, torch_dtype=weight_dtype).to(device)

images_1_5 = sd_pipeline_1_5(prompts, num_images_per_prompt=<span class="hljs-number">1</span>, generator=generator, output_type=<span class="hljs-string">&quot;numpy&quot;</span>).images`}}),$t=new k({props:{code:`sd_clip_score_1_4 = calculate_clip_score(images, prompts)
print(f"CLIP Score with v-1-4: {sd_clip_score_1_4}")
# CLIP Score with v-1-4: 34.9102

sd_clip_score_1_5 = calculate_clip_score(images_1_5, prompts)
print(f"CLIP Score with v-1-5: {sd_clip_score_1_5}")
# CLIP Score with v-1-5: 36.2137`,highlighted:`sd_clip_score_1_4 = calculate_clip_score(images, prompts)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;CLIP Score with v-1-4: <span class="hljs-subst">{sd_clip_score_1_4}</span>&quot;</span>)
<span class="hljs-comment"># CLIP Score with v-1-4: 34.9102</span>

sd_clip_score_1_5 = calculate_clip_score(images_1_5, prompts)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;CLIP Score with v-1-5: <span class="hljs-subst">{sd_clip_score_1_5}</span>&quot;</span>)
<span class="hljs-comment"># CLIP Score with v-1-5: 36.2137</span>`}}),ke=new Bl({props:{warning:!0,$$slots:{default:[pu]},$$scope:{ctx:z}}}),xt=new as({}),It=new k({props:{code:`from datasets import load_dataset

dataset = load_dataset("sayakpaul/instructpix2pix-demo", split="train")
dataset.features`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

dataset = load_dataset(<span class="hljs-string">&quot;sayakpaul/instructpix2pix-demo&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
dataset.features`}}),qt=new k({props:{code:`{'input': Value(dtype='string', id=None),
 'edit': Value(dtype='string', id=None),
 'output': Value(dtype='string', id=None),
 'image': Image(decode=True, id=None)}`,highlighted:`{<span class="hljs-string">&#x27;input&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;string&#x27;</span>, <span class="hljs-built_in">id</span>=None),
 <span class="hljs-string">&#x27;edit&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;string&#x27;</span>, <span class="hljs-built_in">id</span>=None),
 <span class="hljs-string">&#x27;output&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;string&#x27;</span>, <span class="hljs-built_in">id</span>=None),
 <span class="hljs-string">&#x27;image&#x27;</span>: Image(decode=True, <span class="hljs-built_in">id</span>=None)}`}}),Dt=new k({props:{code:`idx = 0
print(f"Original caption: {dataset[idx]['input']}")
print(f"Edit instruction: {dataset[idx]['edit']}")
print(f"Modified caption: {dataset[idx]['output']}")`,highlighted:`idx = <span class="hljs-number">0</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Original caption: <span class="hljs-subst">{dataset[idx][<span class="hljs-string">&#x27;input&#x27;</span>]}</span>&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Edit instruction: <span class="hljs-subst">{dataset[idx][<span class="hljs-string">&#x27;edit&#x27;</span>]}</span>&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Modified caption: <span class="hljs-subst">{dataset[idx][<span class="hljs-string">&#x27;output&#x27;</span>]}</span>&quot;</span>)`}}),Lt=new k({props:{code:`Original caption: 2. FAROE ISLANDS: An archipelago of 18 mountainous isles in the North Atlantic Ocean between Norway and Iceland, the Faroe Islands has 'everything you could hope for', according to Big 7 Travel. It boasts 'crystal clear waterfalls, rocky cliffs that seem to jut out of nowhere and velvety green hills'
Edit instruction: make the isles all white marble
Modified caption: 2. WHITE MARBLE ISLANDS: An archipelago of 18 mountainous white marble isles in the North Atlantic Ocean between Norway and Iceland, the White Marble Islands has 'everything you could hope for', according to Big 7 Travel. It boasts 'crystal clear waterfalls, rocky cliffs that seem to jut out of nowhere and velvety green hills'`,highlighted:`Original caption: 2. FAROE ISLANDS: An archipelago of 18 mountainous isles <span class="hljs-keyword">in</span> the North Atlantic Ocean between Norway and Iceland, the Faroe Islands has <span class="hljs-string">&#x27;everything you could hope for&#x27;</span>, according to Big 7 Travel. It boasts <span class="hljs-string">&#x27;crystal clear waterfalls, rocky cliffs that seem to jut out of nowhere and velvety green hills&#x27;</span>
Edit instruction: make the isles all white marble
Modified caption: 2. WHITE MARBLE ISLANDS: An archipelago of 18 mountainous white marble isles <span class="hljs-keyword">in</span> the North Atlantic Ocean between Norway and Iceland, the White Marble Islands has <span class="hljs-string">&#x27;everything you could hope for&#x27;</span>, according to Big 7 Travel. It boasts <span class="hljs-string">&#x27;crystal clear waterfalls, rocky cliffs that seem to jut out of nowhere and velvety green hills&#x27;</span>`}}),Ct=new k({props:{code:'dataset[idx]["image"]',highlighted:'dataset[idx][<span class="hljs-string">&quot;image&quot;</span>]'}}),St=new k({props:{code:`from diffusers import StableDiffusionInstructPix2PixPipeline

instruct_pix2pix_pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained(
    "timbrooks/instruct-pix2pix", torch_dtype=torch.float16
).to(device)`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionInstructPix2PixPipeline

instruct_pix2pix_pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained(
    <span class="hljs-string">&quot;timbrooks/instruct-pix2pix&quot;</span>, torch_dtype=torch.float16
).to(device)`}}),Tt=new k({props:{code:`import numpy as np


def edit_image(input_image, instruction):
    image = instruct_pix2pix_pipeline(
        instruction,
        image=input_image,
        output_type="numpy",
        generator=generator,
    ).images[0]
    return image


input_images = []
original_captions = []
modified_captions = []
edited_images = []

for idx in range(len(dataset)):
    input_image = dataset[idx]["image"]
    edit_instruction = dataset[idx]["edit"]
    edited_image = edit_image(input_image, edit_instruction)

    input_images.append(np.array(input_image))
    original_captions.append(dataset[idx]["input"])
    modified_captions.append(dataset[idx]["output"])
    edited_images.append(edited_image)`,highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">edit_image</span>(<span class="hljs-params">input_image, instruction</span>):
    image = instruct_pix2pix_pipeline(
        instruction,
        image=input_image,
        output_type=<span class="hljs-string">&quot;numpy&quot;</span>,
        generator=generator,
    ).images[<span class="hljs-number">0</span>]
    <span class="hljs-keyword">return</span> image


input_images = []
original_captions = []
modified_captions = []
edited_images = []

<span class="hljs-keyword">for</span> idx <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(dataset)):
    input_image = dataset[idx][<span class="hljs-string">&quot;image&quot;</span>]
    edit_instruction = dataset[idx][<span class="hljs-string">&quot;edit&quot;</span>]
    edited_image = edit_image(input_image, edit_instruction)

    input_images.append(np.array(input_image))
    original_captions.append(dataset[idx][<span class="hljs-string">&quot;input&quot;</span>])
    modified_captions.append(dataset[idx][<span class="hljs-string">&quot;output&quot;</span>])
    edited_images.append(edited_image)`}}),At=new k({props:{code:`from transformers import (
    CLIPTokenizer,
    CLIPTextModelWithProjection,
    CLIPVisionModelWithProjection,
    CLIPImageProcessor,
)

clip_id = "openai/clip-vit-large-patch14"
tokenizer = CLIPTokenizer.from_pretrained(clip_id)
text_encoder = CLIPTextModelWithProjection.from_pretrained(clip_id).to(device)
image_processor = CLIPImageProcessor.from_pretrained(clip_id)
image_encoder = CLIPVisionModelWithProjection.from_pretrained(clip_id).to(device)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> (
    CLIPTokenizer,
    CLIPTextModelWithProjection,
    CLIPVisionModelWithProjection,
    CLIPImageProcessor,
)

clip_id = <span class="hljs-string">&quot;openai/clip-vit-large-patch14&quot;</span>
tokenizer = CLIPTokenizer.from_pretrained(clip_id)
text_encoder = CLIPTextModelWithProjection.from_pretrained(clip_id).to(device)
image_processor = CLIPImageProcessor.from_pretrained(clip_id)
image_encoder = CLIPVisionModelWithProjection.from_pretrained(clip_id).to(device)`}}),Nt=new k({props:{code:`import torch.nn as nn
import torch.nn.functional as F


class DirectionalSimilarity(nn.Module):
    def __init__(self, tokenizer, text_encoder, image_processor, image_encoder):
        super().__init__()
        self.tokenizer = tokenizer
        self.text_encoder = text_encoder
        self.image_processor = image_processor
        self.image_encoder = image_encoder

    def preprocess_image(self, image):
        image = self.image_processor(image, return_tensors="pt")["pixel_values"]
        return {"pixel_values": image.to(device)}

    def tokenize_text(self, text):
        inputs = self.tokenizer(
            text,
            max_length=self.tokenizer.model_max_length,
            padding="max_length",
            truncation=True,
            return_tensors="pt",
        )
        return {"input_ids": inputs.input_ids.to(device)}

    def encode_image(self, image):
        preprocessed_image = self.preprocess_image(image)
        image_features = self.image_encoder(**preprocessed_image).image_embeds
        image_features = image_features / image_features.norm(dim=1, keepdim=True)
        return image_features

    def encode_text(self, text):
        tokenized_text = self.tokenize_text(text)
        text_features = self.text_encoder(**tokenized_text).text_embeds
        text_features = text_features / text_features.norm(dim=1, keepdim=True)
        return text_features

    def compute_directional_similarity(self, img_feat_one, img_feat_two, text_feat_one, text_feat_two):
        sim_direction = F.cosine_similarity(img_feat_two - img_feat_one, text_feat_two - text_feat_one)
        return sim_direction

    def forward(self, image_one, image_two, caption_one, caption_two):
        img_feat_one = self.encode_image(image_one)
        img_feat_two = self.encode_image(image_two)
        text_feat_one = self.encode_text(caption_one)
        text_feat_two = self.encode_text(caption_two)
        directional_similarity = self.compute_directional_similarity(
            img_feat_one, img_feat_two, text_feat_one, text_feat_two
        )
        return directional_similarity`,highlighted:`<span class="hljs-keyword">import</span> torch.nn <span class="hljs-keyword">as</span> nn
<span class="hljs-keyword">import</span> torch.nn.functional <span class="hljs-keyword">as</span> F


<span class="hljs-keyword">class</span> <span class="hljs-title class_">DirectionalSimilarity</span>(nn.Module):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, tokenizer, text_encoder, image_processor, image_encoder</span>):
        <span class="hljs-built_in">super</span>().__init__()
        self.tokenizer = tokenizer
        self.text_encoder = text_encoder
        self.image_processor = image_processor
        self.image_encoder = image_encoder

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_image</span>(<span class="hljs-params">self, image</span>):
        image = self.image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)[<span class="hljs-string">&quot;pixel_values&quot;</span>]
        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;pixel_values&quot;</span>: image.to(device)}

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_text</span>(<span class="hljs-params">self, text</span>):
        inputs = self.tokenizer(
            text,
            max_length=self.tokenizer.model_max_length,
            padding=<span class="hljs-string">&quot;max_length&quot;</span>,
            truncation=<span class="hljs-literal">True</span>,
            return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
        )
        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;input_ids&quot;</span>: inputs.input_ids.to(device)}

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">encode_image</span>(<span class="hljs-params">self, image</span>):
        preprocessed_image = self.preprocess_image(image)
        image_features = self.image_encoder(**preprocessed_image).image_embeds
        image_features = image_features / image_features.norm(dim=<span class="hljs-number">1</span>, keepdim=<span class="hljs-literal">True</span>)
        <span class="hljs-keyword">return</span> image_features

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">encode_text</span>(<span class="hljs-params">self, text</span>):
        tokenized_text = self.tokenize_text(text)
        text_features = self.text_encoder(**tokenized_text).text_embeds
        text_features = text_features / text_features.norm(dim=<span class="hljs-number">1</span>, keepdim=<span class="hljs-literal">True</span>)
        <span class="hljs-keyword">return</span> text_features

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_directional_similarity</span>(<span class="hljs-params">self, img_feat_one, img_feat_two, text_feat_one, text_feat_two</span>):
        sim_direction = F.cosine_similarity(img_feat_two - img_feat_one, text_feat_two - text_feat_one)
        <span class="hljs-keyword">return</span> sim_direction

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, image_one, image_two, caption_one, caption_two</span>):
        img_feat_one = self.encode_image(image_one)
        img_feat_two = self.encode_image(image_two)
        text_feat_one = self.encode_text(caption_one)
        text_feat_two = self.encode_text(caption_two)
        directional_similarity = self.compute_directional_similarity(
            img_feat_one, img_feat_two, text_feat_one, text_feat_two
        )
        <span class="hljs-keyword">return</span> directional_similarity`}}),Ot=new k({props:{code:`dir_similarity = DirectionalSimilarity(tokenizer, text_encoder, image_processor, image_encoder)
scores = []

for i in range(len(input_images)):
    original_image = input_images[i]
    original_caption = original_captions[i]
    edited_image = edited_images[i]
    modified_caption = modified_captions[i]

    similarity_score = dir_similarity(original_image, edited_image, original_caption, modified_caption)
    scores.append(float(similarity_score.detach().cpu()))

print(f"CLIP directional similarity: {np.mean(scores)}")
# CLIP directional similarity: 0.0797976553440094`,highlighted:`dir_similarity = DirectionalSimilarity(tokenizer, text_encoder, image_processor, image_encoder)
scores = []

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(input_images)):
    original_image = input_images[i]
    original_caption = original_captions[i]
    edited_image = edited_images[i]
    modified_caption = modified_captions[i]

    similarity_score = dir_similarity(original_image, edited_image, original_caption, modified_caption)
    scores.append(<span class="hljs-built_in">float</span>(similarity_score.detach().cpu()))

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;CLIP directional similarity: <span class="hljs-subst">{np.mean(scores)}</span>&quot;</span>)
<span class="hljs-comment"># CLIP directional similarity: 0.0797976553440094</span>`}}),Ae=new Bl({props:{$$slots:{default:[fu]},$$scope:{ctx:z}}}),Gt=new as({}),Ut=new k({props:{code:`from zipfile import ZipFile
import requests


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


dummy_dataset_url = "https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/sample-imagenet-images.zip"
local_filepath = download(dummy_dataset_url, dummy_dataset_url.split("/")[-1])

with ZipFile(local_filepath, "r") as zipper:
    zipper.extractall(".")`,highlighted:`<span class="hljs-keyword">from</span> zipfile <span class="hljs-keyword">import</span> ZipFile
<span class="hljs-keyword">import</span> requests


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


dummy_dataset_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/sample-imagenet-images.zip&quot;</span>
local_filepath = download(dummy_dataset_url, dummy_dataset_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

<span class="hljs-keyword">with</span> ZipFile(local_filepath, <span class="hljs-string">&quot;r&quot;</span>) <span class="hljs-keyword">as</span> zipper:
    zipper.extractall(<span class="hljs-string">&quot;.&quot;</span>)`}}),Zt=new k({props:{code:`from PIL import Image
import os

dataset_path = "sample-imagenet-images"
image_paths = sorted([os.path.join(dataset_path, x) for x in os.listdir(dataset_path)])

real_images = [np.array(Image.open(path).convert("RGB")) for path in image_paths]`,highlighted:`<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">import</span> os

dataset_path = <span class="hljs-string">&quot;sample-imagenet-images&quot;</span>
image_paths = <span class="hljs-built_in">sorted</span>([os.path.join(dataset_path, x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> os.listdir(dataset_path)])

real_images = [np.array(Image.<span class="hljs-built_in">open</span>(path).convert(<span class="hljs-string">&quot;RGB&quot;</span>)) <span class="hljs-keyword">for</span> path <span class="hljs-keyword">in</span> image_paths]`}}),Xt=new k({props:{code:`from torchvision.transforms import functional as F


def preprocess_image(image):
    image = torch.tensor(image).unsqueeze(0)
    image = image.permute(0, 3, 1, 2) / 255.0
    return F.center_crop(image, (256, 256))


real_images = torch.cat([preprocess_image(image) for image in real_images])
print(real_images.shape)
# torch.Size([10, 3, 256, 256])`,highlighted:`<span class="hljs-keyword">from</span> torchvision.transforms <span class="hljs-keyword">import</span> functional <span class="hljs-keyword">as</span> F


<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_image</span>(<span class="hljs-params">image</span>):
    image = torch.tensor(image).unsqueeze(<span class="hljs-number">0</span>)
    image = image.permute(<span class="hljs-number">0</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>) / <span class="hljs-number">255.0</span>
    <span class="hljs-keyword">return</span> F.center_crop(image, (<span class="hljs-number">256</span>, <span class="hljs-number">256</span>))


real_images = torch.cat([preprocess_image(image) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> real_images])
<span class="hljs-built_in">print</span>(real_images.shape)
<span class="hljs-comment"># torch.Size([10, 3, 256, 256])</span>`}}),Yt=new k({props:{code:`from diffusers import DiTPipeline, DPMSolverMultistepScheduler

dit_pipeline = DiTPipeline.from_pretrained("facebook/DiT-XL-2-256", torch_dtype=torch.float16)
dit_pipeline.scheduler = DPMSolverMultistepScheduler.from_config(dit_pipeline.scheduler.config)
dit_pipeline = dit_pipeline.to("cuda")

words = [
    "cassette player",
    "chainsaw",
    "chainsaw",
    "church",
    "gas pump",
    "gas pump",
    "gas pump",
    "parachute",
    "parachute",
    "tench",
]

class_ids = dit_pipeline.get_label_ids(words)
output = dit_pipeline(class_labels=class_ids, generator=generator, output_type="numpy")

fake_images = output.images
fake_images = torch.tensor(fake_images)
fake_images = fake_images.permute(0, 3, 1, 2)
print(fake_images.shape)
# torch.Size([10, 3, 256, 256])`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiTPipeline, DPMSolverMultistepScheduler

dit_pipeline = DiTPipeline.from_pretrained(<span class="hljs-string">&quot;facebook/DiT-XL-2-256&quot;</span>, torch_dtype=torch.float16)
dit_pipeline.scheduler = DPMSolverMultistepScheduler.from_config(dit_pipeline.scheduler.config)
dit_pipeline = dit_pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

words = [
    <span class="hljs-string">&quot;cassette player&quot;</span>,
    <span class="hljs-string">&quot;chainsaw&quot;</span>,
    <span class="hljs-string">&quot;chainsaw&quot;</span>,
    <span class="hljs-string">&quot;church&quot;</span>,
    <span class="hljs-string">&quot;gas pump&quot;</span>,
    <span class="hljs-string">&quot;gas pump&quot;</span>,
    <span class="hljs-string">&quot;gas pump&quot;</span>,
    <span class="hljs-string">&quot;parachute&quot;</span>,
    <span class="hljs-string">&quot;parachute&quot;</span>,
    <span class="hljs-string">&quot;tench&quot;</span>,
]

class_ids = dit_pipeline.get_label_ids(words)
output = dit_pipeline(class_labels=class_ids, generator=generator, output_type=<span class="hljs-string">&quot;numpy&quot;</span>)

fake_images = output.images
fake_images = torch.tensor(fake_images)
fake_images = fake_images.permute(<span class="hljs-number">0</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>)
<span class="hljs-built_in">print</span>(fake_images.shape)
<span class="hljs-comment"># torch.Size([10, 3, 256, 256])</span>`}}),ts=new k({props:{code:`from torchmetrics.image.fid import FrechetInceptionDistance

fid = FrechetInceptionDistance(normalize=True)
fid.update(real_images, real=True)
fid.update(fake_images, real=False)

print(f"FID: {float(fid.compute())}")
# FID: 177.7147216796875`,highlighted:`<span class="hljs-keyword">from</span> torchmetrics.image.fid <span class="hljs-keyword">import</span> FrechetInceptionDistance

fid = FrechetInceptionDistance(normalize=<span class="hljs-literal">True</span>)
fid.update(real_images, real=<span class="hljs-literal">True</span>)
fid.update(fake_images, real=<span class="hljs-literal">False</span>)

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;FID: <span class="hljs-subst">{<span class="hljs-built_in">float</span>(fid.compute())}</span>&quot;</span>)
<span class="hljs-comment"># FID: 177.7147216796875</span>`}}),ze=new Bl({props:{warning:!0,$$slots:{default:[cu]},$$scope:{ctx:z}}}),{c(){u=i("meta"),j=f(),d=i("h1"),b=i("a"),E=i("span"),h($.$$.fragment),x=f(),I=i("span"),Re=n("Evaluating Diffusion Models"),ne=f(),D=i("a"),B=i("img"),O=f(),T=i("p"),pe=n("Evaluation of generative models like "),L=i("a"),Qe=n("Stable Diffusion"),P=n(" is subjective in nature. But as practitioners and researchers, we often have to make careful choices amongst many different possibilities. So, when working with different generative models (like GANs, Diffusion, etc.), how do we choose one over the other?"),q=f(),S=i("p"),is=n(`Qualitative evaluation of such models can be error-prone and might incorrectly influence a decision.
However, quantitative metrics don\u2019t necessarily correspond to image quality. So, usually, a combination
of both qualitative and quantitative evaluations provides a stronger signal when choosing one model
over the other.`),Ve=f(),M=i("p"),os=n("In this document, we provide a non-exhaustive overview of qualitative and quantitative methods to evaluate Diffusion models. For quantitative methods, we specifically focus on how to implement them alongside "),fe=i("code"),Wl=n("diffusers"),Gl=n("."),_i=f(),ce=i("p"),Hl=n("The methods shown in this document can also be used to evaluate different "),Ue=i("a"),Rl=n("noise schedulers"),Kl=n(" keeping the underlying generation model fixed."),gi=f(),Y=i("h2"),me=i("a"),ra=i("span"),h(Ze.$$.fragment),Ql=f(),na=i("span"),Vl=n("Scenarios"),wi=f(),ls=i("p"),Ul=n("We cover Diffusion models with the following pipelines:"),vi=f(),W=i("ul"),Xe=i("li"),Zl=n("Text-guided image generation (such as the "),Je=i("a"),pa=i("code"),Xl=n("StableDiffusionPipeline"),Jl=n(")."),Yl=f(),ee=i("li"),er=n("Text-guided image generation, additionally conditioned on an input image (such as the "),Ye=i("a"),fa=i("code"),tr=n("StableDiffusionImg2ImgPipeline"),sr=n(", and "),et=i("a"),ca=i("code"),ar=n("StableDiffusionInstructPix2PixPipeline"),ir=n(")."),or=f(),tt=i("li"),lr=n("Class-conditioned image generation models (such as the "),st=i("a"),ma=i("code"),rr=n("DiTPipeline"),nr=n(")."),yi=f(),te=i("h2"),ue=i("a"),ua=i("span"),h(at.$$.fragment),pr=f(),da=i("span"),fr=n("Qualitative Evaluation"),bi=f(),G=i("p"),cr=n("Qualitative evaluation typically involves human assessment of generated images. Quality is measured across aspects such as compositionality, image-text alignment, and spatial relations. Common prompts provide a degree of uniformity for subjective metrics. DrawBench and PartiPrompts are prompt datasets used for qualitative benchmarking. DrawBench and PartiPrompts were introduced by "),it=i("a"),mr=n("Imagen"),ur=n(" and "),ot=i("a"),dr=n("Parti"),hr=n(" respectively."),Pi=f(),de=i("p"),_r=n("From the "),lt=i("a"),gr=n("official Parti website"),wr=n(":"),$i=f(),rs=i("blockquote"),ha=i("p"),vr=n("PartiPrompts (P2) is a rich set of over 1600 prompts in English that we release as part of this work. P2 can be used to measure model capabilities across various categories and challenge aspects."),ki=f(),ns=i("p"),ps=i("img"),xi=f(),fs=i("p"),yr=n("PartiPrompts has the following columns:"),ji=f(),H=i("ul"),_a=i("li"),br=n("Prompt"),Pr=f(),ga=i("li"),$r=n("Category of the prompt (such as \u201CAbstract\u201D, \u201CWorld Knowledge\u201D, etc.)"),kr=f(),wa=i("li"),xr=n("Challenge reflecting the difficulty (such as \u201CBasic\u201D, \u201CComplex\u201D, \u201CWriting & Symbols\u201D, etc.)"),Ei=f(),he=i("p"),jr=n("These benchmarks allow for side-by-side human evaluation of different image generation models. Let\u2019s see how we can use "),va=i("code"),Er=n("diffusers"),Ir=n(" on a couple of PartiPrompts."),Ii=f(),_e=i("p"),qr=n("Below we show some prompts sampled across different challenges: Basic, Complex, Linguistic Structures, Imagination, and Writing & Symbols. Here we are using PartiPrompts as a "),rt=i("a"),Dr=n("dataset"),Lr=n("."),qi=f(),h(nt.$$.fragment),Di=f(),ge=i("p"),Cr=n("Now we can use these prompts to generate some images using Stable Diffusion ("),pt=i("a"),Sr=n("v1-4 checkpoint"),Tr=n("):"),Li=f(),h(ft.$$.fragment),Ci=f(),cs=i("p"),ms=i("img"),Si=f(),R=i("p"),Ar=n("We can also set "),ya=i("code"),Fr=n("num_images_per_prompt"),Nr=n(" accordingly to compare different images for the same prompt. Running the same pipeline but with a different checkpoint ("),ct=i("a"),Or=n("v1-5"),Mr=n("), yields:"),Ti=f(),us=i("p"),ds=i("img"),Ai=f(),hs=i("p"),zr=n(`Once several images are generated from all the prompts using multiple models (under evaluation), these results are presented to human evaluators for scoring. For
more details on the DrawBench and PartiPrompts benchmarks, refer to their respective papers.`),Fi=f(),h(we.$$.fragment),Ni=f(),se=i("h2"),ve=i("a"),ba=i("span"),h(mt.$$.fragment),Br=f(),Pa=i("span"),Wr=n("Quantitative Evaluation"),Oi=f(),_s=i("p"),Gr=n("In this section, we will walk you through how to evaluate three different diffusion pipelines using:"),Mi=f(),K=i("ul"),$a=i("li"),Hr=n("CLIP score"),Rr=f(),ka=i("li"),Kr=n("CLIP directional similarity"),Qr=f(),xa=i("li"),Vr=n("FID"),zi=f(),ae=i("h3"),ye=i("a"),ja=i("span"),h(ut.$$.fragment),Ur=f(),Ea=i("span"),Zr=n("Text-guided image generation"),Bi=f(),dt=i("p"),ht=i("a"),Xr=n("CLIP score"),Jr=n(" measures the compatibility of image-caption pairs. Higher CLIP scores imply higher compatibility \u{1F53C}. The CLIP score is a quantitative measurement of the qualitative concept \u201Ccompatibility\u201D. Image-caption pair compatibility can also be thought of as the semantic similarity between the image and the caption. CLIP score was found to have high correlation with human judgement."),Wi=f(),be=i("p"),Yr=n("Let\u2019s first load a "),gs=i("a"),en=n("StableDiffusionPipeline"),tn=n(":"),Gi=f(),h(_t.$$.fragment),Hi=f(),ws=i("p"),sn=n("Generate some images with multiple prompts:"),Ri=f(),h(gt.$$.fragment),Ki=f(),vs=i("p"),an=n("And then, we calculate the CLIP score."),Qi=f(),h(wt.$$.fragment),Vi=f(),ys=i("p"),on=n("In the above example, we generated one image per prompt. If we generated multiple images per prompt, we would have to take the average score from the generated images per prompt."),Ui=f(),Q=i("p"),ln=n("Now, if we wanted to compare two checkpoints compatible with the "),bs=i("a"),rn=n("StableDiffusionPipeline"),nn=n(` we should pass a generator while calling the pipeline. First, we generate images with a
fixed seed with the `),vt=i("a"),pn=n("v1-4 Stable Diffusion checkpoint"),fn=n(":"),Zi=f(),h(yt.$$.fragment),Xi=f(),Pe=i("p"),cn=n("Then we load the "),bt=i("a"),mn=n("v1-5 checkpoint"),un=n(" to generate images:"),Ji=f(),h(Pt.$$.fragment),Yi=f(),Ps=i("p"),dn=n("And finally, we compare their CLIP scores:"),eo=f(),h($t.$$.fragment),to=f(),$e=i("p"),hn=n("It seems like the "),kt=i("a"),_n=n("v1-5"),gn=n(" checkpoint performs better than its predecessor. Note, however, that the number of prompts we used to compute the CLIP scores is quite low. For a more practical evaluation, this number should be way higher, and the prompts should be diverse."),so=f(),h(ke.$$.fragment),ao=f(),ie=i("h3"),xe=i("a"),Ia=i("span"),h(xt.$$.fragment),wn=f(),qa=i("span"),vn=n("Image-conditioned text-to-image generation"),io=f(),je=i("p"),yn=n("In this case, we condition the generation pipeline with an input image as well as a text prompt. Let\u2019s take the "),$s=i("a"),bn=n("StableDiffusionInstructPix2PixPipeline"),Pn=n(", as an example. It takes an edit instruction as an input prompt and an input image to be edited."),oo=f(),ks=i("p"),$n=n("Here is one example:"),lo=f(),xs=i("p"),js=i("img"),ro=f(),A=i("p"),kn=n("One strategy to evaluate such a model is to measure the consistency of the change between the two images (in "),jt=i("a"),xn=n("CLIP"),jn=n(" space) with the change between the two image captions (as shown in "),Et=i("a"),En=n("CLIP-Guided Domain Adaptation of Image Generators"),In=n("). This is referred to as the \u201D"),Da=i("strong"),qn=n("CLIP directional similarity"),Dn=n("\u201C."),no=f(),Ee=i("ul"),La=i("li"),Ln=n("Caption 1 corresponds to the input image (image 1) that is to be edited."),Cn=f(),Ca=i("li"),Sn=n("Caption 2 corresponds to the edited image (image 2). It should reflect the edit instruction."),po=f(),Es=i("p"),Tn=n("Following is a pictorial overview:"),fo=f(),Is=i("p"),qs=i("img"),co=f(),Ds=i("p"),An=n("We have prepared a mini dataset to implement this metric. Let\u2019s first load the dataset."),mo=f(),h(It.$$.fragment),uo=f(),h(qt.$$.fragment),ho=f(),Ls=i("p"),Fn=n("Here we have:"),_o=f(),V=i("ul"),Ie=i("li"),Sa=i("code"),Nn=n("input"),On=n(" is a caption corresponding to the "),Ta=i("code"),Mn=n("image"),zn=n("."),Bn=f(),Cs=i("li"),Aa=i("code"),Wn=n("edit"),Gn=n(" denotes the edit instruction."),Hn=f(),qe=i("li"),Fa=i("code"),Rn=n("output"),Kn=n(" denotes the modified caption reflecting the "),Na=i("code"),Qn=n("edit"),Vn=n(" instruction."),go=f(),Ss=i("p"),Un=n("Let\u2019s take a look at a sample."),wo=f(),h(Dt.$$.fragment),vo=f(),h(Lt.$$.fragment),yo=f(),Ts=i("p"),Zn=n("And here is the image:"),bo=f(),h(Ct.$$.fragment),Po=f(),As=i("p"),Fs=i("img"),$o=f(),Ns=i("p"),Xn=n("We will first edit the images of our dataset with the edit instruction and compute the directional similarity."),ko=f(),De=i("p"),Jn=n("Let\u2019s first load the "),Os=i("a"),Yn=n("StableDiffusionInstructPix2PixPipeline"),ep=n(":"),xo=f(),h(St.$$.fragment),jo=f(),Ms=i("p"),tp=n("Now, we perform the edits:"),Eo=f(),h(Tt.$$.fragment),Io=f(),zs=i("p"),sp=n("To measure the directional similarity, we first load CLIP\u2019s image and text encoders:"),qo=f(),h(At.$$.fragment),Do=f(),U=i("p"),ap=n("Notice that we are using a particular CLIP checkpoint, i.e.,\xA0"),Oa=i("code"),ip=n("openai/clip-vit-large-patch14"),op=n(". This is because the Stable Diffusion pre-training was performed with this CLIP variant. For more details, refer to the\xA0"),Ft=i("a"),lp=n("documentation"),rp=n("."),Lo=f(),Le=i("p"),np=n("Next, we prepare a PyTorch\xA0"),Ma=i("code"),pp=n("nn.Module"),fp=n("\xA0to compute directional similarity:"),Co=f(),h(Nt.$$.fragment),So=f(),Ce=i("p"),cp=n("Let\u2019s put\xA0"),za=i("code"),mp=n("DirectionalSimilarity"),up=n("\xA0to use now."),To=f(),h(Ot.$$.fragment),Ao=f(),Bs=i("p"),dp=n("Like the CLIP Score, the higher the CLIP directional similarity, the better it is."),Fo=f(),F=i("p"),hp=n("It should be noted that the\xA0"),Ba=i("code"),_p=n("StableDiffusionInstructPix2PixPipeline"),gp=n("\xA0exposes two arguments, namely,\xA0"),Wa=i("code"),wp=n("image_guidance_scale"),vp=n("\xA0and\xA0"),Ga=i("code"),yp=n("guidance_scale"),bp=n("\xA0that let you control the quality of the final edited image. We encourage you to experiment with these two arguments and see the impact of that on the directional similarity."),No=f(),Se=i("p"),Pp=n("We can extend the idea of this metric to measure how similar the original image and edited version are. To do that, we can just do\xA0"),Ha=i("code"),$p=n("F.cosine_similarity(img_feat_two, img_feat_one)"),kp=n(". For these kinds of edits, we would still want the primary semantics of the images to be preserved as much as possible, i.e., a high similarity score."),Oo=f(),Te=i("p"),xp=n("We can use these metrics for similar pipelines such as the "),Mt=i("a"),Ra=i("code"),jp=n("StableDiffusionPix2PixZeroPipeline"),Ep=n("."),Mo=f(),h(Ae.$$.fragment),zo=f(),oe=i("p"),Ka=i("strong"),Qa=i("em"),Ip=n("Extending metrics like IS, FID (discussed later), or KID can be difficult"),qp=n(" when the model under evaluation was pre-trained on a large image-captioning dataset (such as the "),zt=i("a"),Dp=n("LAION-5B dataset"),Lp=n("). This is because underlying these metrics is an InceptionNet (pre-trained on the ImageNet-1k dataset) used for extracting intermediate image features. The pre-training dataset of Stable Diffusion may have limited overlap with the pre-training dataset of InceptionNet, so it is not a good candidate here for feature extraction."),Bo=f(),Ws=i("p"),Va=i("strong"),Bt=i("em"),Cp=n("Using the above metrics helps evaluate models that are class-conditioned. For example, "),Wt=i("a"),Sp=n("DiT"),Tp=n(". It was pre-trained being conditioned on the ImageNet-1k classes."),Wo=f(),le=i("h3"),Fe=i("a"),Ua=i("span"),h(Gt.$$.fragment),Ap=f(),Za=i("span"),Fp=n("Class-conditioned image generation"),Go=f(),C=i("p"),Np=n("Class-conditioned generative models are usually pre-trained on a class-labeled dataset such as "),Ht=i("a"),Op=n("ImageNet-1k"),Mp=n(". Popular metrics for evaluating these models include Fr\xE9chet Inception Distance (FID), Kernel Inception Distance (KID), and Inception Score (IS). In this document, we focus on FID ("),Rt=i("a"),zp=n("Heusel et al."),Bp=n("). We show how to compute it with the "),Kt=i("a"),Xa=i("code"),Wp=n("DiTPipeline"),Gp=n(", which uses the "),Qt=i("a"),Hp=n("DiT model"),Rp=n(" under the hood."),Ho=f(),Ne=i("p"),Kp=n("FID aims to measure how similar are two datasets of images. As per "),Vt=i("a"),Qp=n("this resource"),Vp=n(":"),Ro=f(),Gs=i("blockquote"),Ja=i("p"),Up=n("Fr\xE9chet Inception Distance is a measure of similarity between two datasets of images. It was shown to correlate well with the human judgment of visual quality and is most often used to evaluate the quality of samples of Generative Adversarial Networks. FID is calculated by computing the Fr\xE9chet distance between two Gaussians fitted to feature representations of the Inception network."),Ko=f(),Hs=i("p"),Zp=n("These two datasets are essentially the dataset of real images and the dataset of fake images (generated images in our case). FID is usually calculated with two large datasets. However, for this document, we will work with two mini datasets."),Qo=f(),Rs=i("p"),Xp=n("Let\u2019s first download a few images from the ImageNet-1k training set:"),Vo=f(),h(Ut.$$.fragment),Uo=f(),h(Zt.$$.fragment),Zo=f(),Ks=i("p"),Jp=n("These are 10 images from the following Imagenet-1k classes: \u201Ccassette_player\u201D, \u201Cchain_saw\u201D (x2), \u201Cchurch\u201D, \u201Cgas_pump\u201D (x3), \u201Cparachute\u201D (x2), and \u201Ctench\u201D."),Xo=f(),Z=i("p"),Qs=i("img"),Yp=i("br"),ef=f(),Ya=i("em"),tf=n("Real images."),Jo=f(),Vs=i("p"),sf=n("Now that the images are loaded, let\u2019s apply some lightweight pre-processing on them to use them for FID calculation."),Yo=f(),h(Xt.$$.fragment),el=f(),Oe=i("p"),af=n("We now load the\xA0"),Jt=i("a"),ei=i("code"),of=n("DiTPipeline"),lf=n(" to generate images conditioned on the above-mentioned classes."),tl=f(),h(Yt.$$.fragment),sl=f(),Me=i("p"),rf=n("Now, we can compute the FID using\xA0"),es=i("a"),ti=i("code"),nf=n("torchmetrics"),pf=n("."),al=f(),h(ts.$$.fragment),il=f(),Us=i("p"),ff=n("The lower the FID, the better it is. Several things can influence FID here:"),ol=f(),N=i("ul"),si=i("li"),cf=n("Number of images (both real and fake)"),mf=f(),ai=i("li"),uf=n("Randomness induced in the diffusion process"),df=f(),ii=i("li"),hf=n("Number of inference steps in the diffusion process"),_f=f(),oi=i("li"),gf=n("The scheduler being used in the diffusion process"),ll=f(),Zs=i("p"),wf=n("For the last two points, it is, therefore, a good practice to run the evaluation across different seeds and inference steps, and then report an average result."),rl=f(),h(ze.$$.fragment),nl=f(),Be=i("p"),vf=n("As a final step, let\u2019s visually inspect the\xA0"),li=i("code"),yf=n("fake_images"),bf=n("."),pl=f(),X=i("p"),Xs=i("img"),Pf=i("br"),$f=f(),ri=i("em"),kf=n("Fake images."),this.h()},l(e){const a=lu('[data-svelte="svelte-1phssyn"]',document.head);u=o(a,"META",{name:!0,content:!0}),a.forEach(t),j=c(e),d=o(e,"H1",{class:!0});var ss=l(d);b=o(ss,"A",{id:!0,class:!0,href:!0});var ni=l(b);E=o(ni,"SPAN",{});var pi=l(E);_($.$$.fragment,pi),pi.forEach(t),ni.forEach(t),x=c(ss),I=o(ss,"SPAN",{});var fi=l(I);Re=p(fi,"Evaluating Diffusion Models"),fi.forEach(t),ss.forEach(t),ne=c(e),D=o(e,"A",{target:!0,href:!0});var Af=l(D);B=o(Af,"IMG",{src:!0,alt:!0}),Af.forEach(t),O=c(e),T=o(e,"P",{});var cl=l(T);pe=p(cl,"Evaluation of generative models like "),L=o(cl,"A",{href:!0,rel:!0});var Ff=l(L);Qe=p(Ff,"Stable Diffusion"),Ff.forEach(t),P=p(cl," is subjective in nature. But as practitioners and researchers, we often have to make careful choices amongst many different possibilities. So, when working with different generative models (like GANs, Diffusion, etc.), how do we choose one over the other?"),cl.forEach(t),q=c(e),S=o(e,"P",{});var Nf=l(S);is=p(Nf,`Qualitative evaluation of such models can be error-prone and might incorrectly influence a decision.
However, quantitative metrics don\u2019t necessarily correspond to image quality. So, usually, a combination
of both qualitative and quantitative evaluations provides a stronger signal when choosing one model
over the other.`),Nf.forEach(t),Ve=c(e),M=o(e,"P",{});var ml=l(M);os=p(ml,"In this document, we provide a non-exhaustive overview of qualitative and quantitative methods to evaluate Diffusion models. For quantitative methods, we specifically focus on how to implement them alongside "),fe=o(ml,"CODE",{});var Of=l(fe);Wl=p(Of,"diffusers"),Of.forEach(t),Gl=p(ml,"."),ml.forEach(t),_i=c(e),ce=o(e,"P",{});var ul=l(ce);Hl=p(ul,"The methods shown in this document can also be used to evaluate different "),Ue=o(ul,"A",{href:!0,rel:!0});var Mf=l(Ue);Rl=p(Mf,"noise schedulers"),Mf.forEach(t),Kl=p(ul," keeping the underlying generation model fixed."),ul.forEach(t),gi=c(e),Y=o(e,"H2",{class:!0});var dl=l(Y);me=o(dl,"A",{id:!0,class:!0,href:!0});var zf=l(me);ra=o(zf,"SPAN",{});var Bf=l(ra);_(Ze.$$.fragment,Bf),Bf.forEach(t),zf.forEach(t),Ql=c(dl),na=o(dl,"SPAN",{});var Wf=l(na);Vl=p(Wf,"Scenarios"),Wf.forEach(t),dl.forEach(t),wi=c(e),ls=o(e,"P",{});var Gf=l(ls);Ul=p(Gf,"We cover Diffusion models with the following pipelines:"),Gf.forEach(t),vi=c(e),W=o(e,"UL",{});var Js=l(W);Xe=o(Js,"LI",{});var hl=l(Xe);Zl=p(hl,"Text-guided image generation (such as the "),Je=o(hl,"A",{href:!0,rel:!0});var Hf=l(Je);pa=o(Hf,"CODE",{});var Rf=l(pa);Xl=p(Rf,"StableDiffusionPipeline"),Rf.forEach(t),Hf.forEach(t),Jl=p(hl,")."),hl.forEach(t),Yl=c(Js),ee=o(Js,"LI",{});var Ys=l(ee);er=p(Ys,"Text-guided image generation, additionally conditioned on an input image (such as the "),Ye=o(Ys,"A",{href:!0,rel:!0});var Kf=l(Ye);fa=o(Kf,"CODE",{});var Qf=l(fa);tr=p(Qf,"StableDiffusionImg2ImgPipeline"),Qf.forEach(t),Kf.forEach(t),sr=p(Ys,", and "),et=o(Ys,"A",{href:!0,rel:!0});var Vf=l(et);ca=o(Vf,"CODE",{});var Uf=l(ca);ar=p(Uf,"StableDiffusionInstructPix2PixPipeline"),Uf.forEach(t),Vf.forEach(t),ir=p(Ys,")."),Ys.forEach(t),or=c(Js),tt=o(Js,"LI",{});var _l=l(tt);lr=p(_l,"Class-conditioned image generation models (such as the "),st=o(_l,"A",{href:!0,rel:!0});var Zf=l(st);ma=o(Zf,"CODE",{});var Xf=l(ma);rr=p(Xf,"DiTPipeline"),Xf.forEach(t),Zf.forEach(t),nr=p(_l,")."),_l.forEach(t),Js.forEach(t),yi=c(e),te=o(e,"H2",{class:!0});var gl=l(te);ue=o(gl,"A",{id:!0,class:!0,href:!0});var Jf=l(ue);ua=o(Jf,"SPAN",{});var Yf=l(ua);_(at.$$.fragment,Yf),Yf.forEach(t),Jf.forEach(t),pr=c(gl),da=o(gl,"SPAN",{});var ec=l(da);fr=p(ec,"Qualitative Evaluation"),ec.forEach(t),gl.forEach(t),bi=c(e),G=o(e,"P",{});var ea=l(G);cr=p(ea,"Qualitative evaluation typically involves human assessment of generated images. Quality is measured across aspects such as compositionality, image-text alignment, and spatial relations. Common prompts provide a degree of uniformity for subjective metrics. DrawBench and PartiPrompts are prompt datasets used for qualitative benchmarking. DrawBench and PartiPrompts were introduced by "),it=o(ea,"A",{href:!0,rel:!0});var tc=l(it);mr=p(tc,"Imagen"),tc.forEach(t),ur=p(ea," and "),ot=o(ea,"A",{href:!0,rel:!0});var sc=l(ot);dr=p(sc,"Parti"),sc.forEach(t),hr=p(ea," respectively."),ea.forEach(t),Pi=c(e),de=o(e,"P",{});var wl=l(de);_r=p(wl,"From the "),lt=o(wl,"A",{href:!0,rel:!0});var ac=l(lt);gr=p(ac,"official Parti website"),ac.forEach(t),wr=p(wl,":"),wl.forEach(t),$i=c(e),rs=o(e,"BLOCKQUOTE",{});var ic=l(rs);ha=o(ic,"P",{});var oc=l(ha);vr=p(oc,"PartiPrompts (P2) is a rich set of over 1600 prompts in English that we release as part of this work. P2 can be used to measure model capabilities across various categories and challenge aspects."),oc.forEach(t),ic.forEach(t),ki=c(e),ns=o(e,"P",{});var lc=l(ns);ps=o(lc,"IMG",{src:!0,alt:!0}),lc.forEach(t),xi=c(e),fs=o(e,"P",{});var rc=l(fs);yr=p(rc,"PartiPrompts has the following columns:"),rc.forEach(t),ji=c(e),H=o(e,"UL",{});var ta=l(H);_a=o(ta,"LI",{});var nc=l(_a);br=p(nc,"Prompt"),nc.forEach(t),Pr=c(ta),ga=o(ta,"LI",{});var pc=l(ga);$r=p(pc,"Category of the prompt (such as \u201CAbstract\u201D, \u201CWorld Knowledge\u201D, etc.)"),pc.forEach(t),kr=c(ta),wa=o(ta,"LI",{});var fc=l(wa);xr=p(fc,"Challenge reflecting the difficulty (such as \u201CBasic\u201D, \u201CComplex\u201D, \u201CWriting & Symbols\u201D, etc.)"),fc.forEach(t),ta.forEach(t),Ei=c(e),he=o(e,"P",{});var vl=l(he);jr=p(vl,"These benchmarks allow for side-by-side human evaluation of different image generation models. Let\u2019s see how we can use "),va=o(vl,"CODE",{});var cc=l(va);Er=p(cc,"diffusers"),cc.forEach(t),Ir=p(vl," on a couple of PartiPrompts."),vl.forEach(t),Ii=c(e),_e=o(e,"P",{});var yl=l(_e);qr=p(yl,"Below we show some prompts sampled across different challenges: Basic, Complex, Linguistic Structures, Imagination, and Writing & Symbols. Here we are using PartiPrompts as a "),rt=o(yl,"A",{href:!0,rel:!0});var mc=l(rt);Dr=p(mc,"dataset"),mc.forEach(t),Lr=p(yl,"."),yl.forEach(t),qi=c(e),_(nt.$$.fragment,e),Di=c(e),ge=o(e,"P",{});var bl=l(ge);Cr=p(bl,"Now we can use these prompts to generate some images using Stable Diffusion ("),pt=o(bl,"A",{href:!0,rel:!0});var uc=l(pt);Sr=p(uc,"v1-4 checkpoint"),uc.forEach(t),Tr=p(bl,"):"),bl.forEach(t),Li=c(e),_(ft.$$.fragment,e),Ci=c(e),cs=o(e,"P",{});var dc=l(cs);ms=o(dc,"IMG",{src:!0,alt:!0}),dc.forEach(t),Si=c(e),R=o(e,"P",{});var sa=l(R);Ar=p(sa,"We can also set "),ya=o(sa,"CODE",{});var hc=l(ya);Fr=p(hc,"num_images_per_prompt"),hc.forEach(t),Nr=p(sa," accordingly to compare different images for the same prompt. Running the same pipeline but with a different checkpoint ("),ct=o(sa,"A",{href:!0,rel:!0});var _c=l(ct);Or=p(_c,"v1-5"),_c.forEach(t),Mr=p(sa,"), yields:"),sa.forEach(t),Ti=c(e),us=o(e,"P",{});var gc=l(us);ds=o(gc,"IMG",{src:!0,alt:!0}),gc.forEach(t),Ai=c(e),hs=o(e,"P",{});var wc=l(hs);zr=p(wc,`Once several images are generated from all the prompts using multiple models (under evaluation), these results are presented to human evaluators for scoring. For
more details on the DrawBench and PartiPrompts benchmarks, refer to their respective papers.`),wc.forEach(t),Fi=c(e),_(we.$$.fragment,e),Ni=c(e),se=o(e,"H2",{class:!0});var Pl=l(se);ve=o(Pl,"A",{id:!0,class:!0,href:!0});var vc=l(ve);ba=o(vc,"SPAN",{});var yc=l(ba);_(mt.$$.fragment,yc),yc.forEach(t),vc.forEach(t),Br=c(Pl),Pa=o(Pl,"SPAN",{});var bc=l(Pa);Wr=p(bc,"Quantitative Evaluation"),bc.forEach(t),Pl.forEach(t),Oi=c(e),_s=o(e,"P",{});var Pc=l(_s);Gr=p(Pc,"In this section, we will walk you through how to evaluate three different diffusion pipelines using:"),Pc.forEach(t),Mi=c(e),K=o(e,"UL",{});var aa=l(K);$a=o(aa,"LI",{});var $c=l($a);Hr=p($c,"CLIP score"),$c.forEach(t),Rr=c(aa),ka=o(aa,"LI",{});var kc=l(ka);Kr=p(kc,"CLIP directional similarity"),kc.forEach(t),Qr=c(aa),xa=o(aa,"LI",{});var xc=l(xa);Vr=p(xc,"FID"),xc.forEach(t),aa.forEach(t),zi=c(e),ae=o(e,"H3",{class:!0});var $l=l(ae);ye=o($l,"A",{id:!0,class:!0,href:!0});var jc=l(ye);ja=o(jc,"SPAN",{});var Ec=l(ja);_(ut.$$.fragment,Ec),Ec.forEach(t),jc.forEach(t),Ur=c($l),Ea=o($l,"SPAN",{});var Ic=l(Ea);Zr=p(Ic,"Text-guided image generation"),Ic.forEach(t),$l.forEach(t),Bi=c(e),dt=o(e,"P",{});var xf=l(dt);ht=o(xf,"A",{href:!0,rel:!0});var qc=l(ht);Xr=p(qc,"CLIP score"),qc.forEach(t),Jr=p(xf," measures the compatibility of image-caption pairs. Higher CLIP scores imply higher compatibility \u{1F53C}. The CLIP score is a quantitative measurement of the qualitative concept \u201Ccompatibility\u201D. Image-caption pair compatibility can also be thought of as the semantic similarity between the image and the caption. CLIP score was found to have high correlation with human judgement."),xf.forEach(t),Wi=c(e),be=o(e,"P",{});var kl=l(be);Yr=p(kl,"Let\u2019s first load a "),gs=o(kl,"A",{href:!0});var Dc=l(gs);en=p(Dc,"StableDiffusionPipeline"),Dc.forEach(t),tn=p(kl,":"),kl.forEach(t),Gi=c(e),_(_t.$$.fragment,e),Hi=c(e),ws=o(e,"P",{});var Lc=l(ws);sn=p(Lc,"Generate some images with multiple prompts:"),Lc.forEach(t),Ri=c(e),_(gt.$$.fragment,e),Ki=c(e),vs=o(e,"P",{});var Cc=l(vs);an=p(Cc,"And then, we calculate the CLIP score."),Cc.forEach(t),Qi=c(e),_(wt.$$.fragment,e),Vi=c(e),ys=o(e,"P",{});var Sc=l(ys);on=p(Sc,"In the above example, we generated one image per prompt. If we generated multiple images per prompt, we would have to take the average score from the generated images per prompt."),Sc.forEach(t),Ui=c(e),Q=o(e,"P",{});var ia=l(Q);ln=p(ia,"Now, if we wanted to compare two checkpoints compatible with the "),bs=o(ia,"A",{href:!0});var Tc=l(bs);rn=p(Tc,"StableDiffusionPipeline"),Tc.forEach(t),nn=p(ia,` we should pass a generator while calling the pipeline. First, we generate images with a
fixed seed with the `),vt=o(ia,"A",{href:!0,rel:!0});var Ac=l(vt);pn=p(Ac,"v1-4 Stable Diffusion checkpoint"),Ac.forEach(t),fn=p(ia,":"),ia.forEach(t),Zi=c(e),_(yt.$$.fragment,e),Xi=c(e),Pe=o(e,"P",{});var xl=l(Pe);cn=p(xl,"Then we load the "),bt=o(xl,"A",{href:!0,rel:!0});var Fc=l(bt);mn=p(Fc,"v1-5 checkpoint"),Fc.forEach(t),un=p(xl," to generate images:"),xl.forEach(t),Ji=c(e),_(Pt.$$.fragment,e),Yi=c(e),Ps=o(e,"P",{});var Nc=l(Ps);dn=p(Nc,"And finally, we compare their CLIP scores:"),Nc.forEach(t),eo=c(e),_($t.$$.fragment,e),to=c(e),$e=o(e,"P",{});var jl=l($e);hn=p(jl,"It seems like the "),kt=o(jl,"A",{href:!0,rel:!0});var Oc=l(kt);_n=p(Oc,"v1-5"),Oc.forEach(t),gn=p(jl," checkpoint performs better than its predecessor. Note, however, that the number of prompts we used to compute the CLIP scores is quite low. For a more practical evaluation, this number should be way higher, and the prompts should be diverse."),jl.forEach(t),so=c(e),_(ke.$$.fragment,e),ao=c(e),ie=o(e,"H3",{class:!0});var El=l(ie);xe=o(El,"A",{id:!0,class:!0,href:!0});var Mc=l(xe);Ia=o(Mc,"SPAN",{});var zc=l(Ia);_(xt.$$.fragment,zc),zc.forEach(t),Mc.forEach(t),wn=c(El),qa=o(El,"SPAN",{});var Bc=l(qa);vn=p(Bc,"Image-conditioned text-to-image generation"),Bc.forEach(t),El.forEach(t),io=c(e),je=o(e,"P",{});var Il=l(je);yn=p(Il,"In this case, we condition the generation pipeline with an input image as well as a text prompt. Let\u2019s take the "),$s=o(Il,"A",{href:!0});var Wc=l($s);bn=p(Wc,"StableDiffusionInstructPix2PixPipeline"),Wc.forEach(t),Pn=p(Il,", as an example. It takes an edit instruction as an input prompt and an input image to be edited."),Il.forEach(t),oo=c(e),ks=o(e,"P",{});var Gc=l(ks);$n=p(Gc,"Here is one example:"),Gc.forEach(t),lo=c(e),xs=o(e,"P",{});var Hc=l(xs);js=o(Hc,"IMG",{src:!0,alt:!0}),Hc.forEach(t),ro=c(e),A=o(e,"P",{});var We=l(A);kn=p(We,"One strategy to evaluate such a model is to measure the consistency of the change between the two images (in "),jt=o(We,"A",{href:!0,rel:!0});var Rc=l(jt);xn=p(Rc,"CLIP"),Rc.forEach(t),jn=p(We," space) with the change between the two image captions (as shown in "),Et=o(We,"A",{href:!0,rel:!0});var Kc=l(Et);En=p(Kc,"CLIP-Guided Domain Adaptation of Image Generators"),Kc.forEach(t),In=p(We,"). This is referred to as the \u201D"),Da=o(We,"STRONG",{});var Qc=l(Da);qn=p(Qc,"CLIP directional similarity"),Qc.forEach(t),Dn=p(We,"\u201C."),We.forEach(t),no=c(e),Ee=o(e,"UL",{});var ql=l(Ee);La=o(ql,"LI",{});var Vc=l(La);Ln=p(Vc,"Caption 1 corresponds to the input image (image 1) that is to be edited."),Vc.forEach(t),Cn=c(ql),Ca=o(ql,"LI",{});var Uc=l(Ca);Sn=p(Uc,"Caption 2 corresponds to the edited image (image 2). It should reflect the edit instruction."),Uc.forEach(t),ql.forEach(t),po=c(e),Es=o(e,"P",{});var Zc=l(Es);Tn=p(Zc,"Following is a pictorial overview:"),Zc.forEach(t),fo=c(e),Is=o(e,"P",{});var Xc=l(Is);qs=o(Xc,"IMG",{src:!0,alt:!0}),Xc.forEach(t),co=c(e),Ds=o(e,"P",{});var Jc=l(Ds);An=p(Jc,"We have prepared a mini dataset to implement this metric. Let\u2019s first load the dataset."),Jc.forEach(t),mo=c(e),_(It.$$.fragment,e),uo=c(e),_(qt.$$.fragment,e),ho=c(e),Ls=o(e,"P",{});var Yc=l(Ls);Fn=p(Yc,"Here we have:"),Yc.forEach(t),_o=c(e),V=o(e,"UL",{});var oa=l(V);Ie=o(oa,"LI",{});var ci=l(Ie);Sa=o(ci,"CODE",{});var em=l(Sa);Nn=p(em,"input"),em.forEach(t),On=p(ci," is a caption corresponding to the "),Ta=o(ci,"CODE",{});var tm=l(Ta);Mn=p(tm,"image"),tm.forEach(t),zn=p(ci,"."),ci.forEach(t),Bn=c(oa),Cs=o(oa,"LI",{});var jf=l(Cs);Aa=o(jf,"CODE",{});var sm=l(Aa);Wn=p(sm,"edit"),sm.forEach(t),Gn=p(jf," denotes the edit instruction."),jf.forEach(t),Hn=c(oa),qe=o(oa,"LI",{});var mi=l(qe);Fa=o(mi,"CODE",{});var am=l(Fa);Rn=p(am,"output"),am.forEach(t),Kn=p(mi," denotes the modified caption reflecting the "),Na=o(mi,"CODE",{});var im=l(Na);Qn=p(im,"edit"),im.forEach(t),Vn=p(mi," instruction."),mi.forEach(t),oa.forEach(t),go=c(e),Ss=o(e,"P",{});var om=l(Ss);Un=p(om,"Let\u2019s take a look at a sample."),om.forEach(t),wo=c(e),_(Dt.$$.fragment,e),vo=c(e),_(Lt.$$.fragment,e),yo=c(e),Ts=o(e,"P",{});var lm=l(Ts);Zn=p(lm,"And here is the image:"),lm.forEach(t),bo=c(e),_(Ct.$$.fragment,e),Po=c(e),As=o(e,"P",{});var rm=l(As);Fs=o(rm,"IMG",{src:!0,alt:!0}),rm.forEach(t),$o=c(e),Ns=o(e,"P",{});var nm=l(Ns);Xn=p(nm,"We will first edit the images of our dataset with the edit instruction and compute the directional similarity."),nm.forEach(t),ko=c(e),De=o(e,"P",{});var Dl=l(De);Jn=p(Dl,"Let\u2019s first load the "),Os=o(Dl,"A",{href:!0});var pm=l(Os);Yn=p(pm,"StableDiffusionInstructPix2PixPipeline"),pm.forEach(t),ep=p(Dl,":"),Dl.forEach(t),xo=c(e),_(St.$$.fragment,e),jo=c(e),Ms=o(e,"P",{});var fm=l(Ms);tp=p(fm,"Now, we perform the edits:"),fm.forEach(t),Eo=c(e),_(Tt.$$.fragment,e),Io=c(e),zs=o(e,"P",{});var cm=l(zs);sp=p(cm,"To measure the directional similarity, we first load CLIP\u2019s image and text encoders:"),cm.forEach(t),qo=c(e),_(At.$$.fragment,e),Do=c(e),U=o(e,"P",{});var la=l(U);ap=p(la,"Notice that we are using a particular CLIP checkpoint, i.e.,\xA0"),Oa=o(la,"CODE",{});var mm=l(Oa);ip=p(mm,"openai/clip-vit-large-patch14"),mm.forEach(t),op=p(la,". This is because the Stable Diffusion pre-training was performed with this CLIP variant. For more details, refer to the\xA0"),Ft=o(la,"A",{href:!0,rel:!0});var um=l(Ft);lp=p(um,"documentation"),um.forEach(t),rp=p(la,"."),la.forEach(t),Lo=c(e),Le=o(e,"P",{});var Ll=l(Le);np=p(Ll,"Next, we prepare a PyTorch\xA0"),Ma=o(Ll,"CODE",{});var dm=l(Ma);pp=p(dm,"nn.Module"),dm.forEach(t),fp=p(Ll,"\xA0to compute directional similarity:"),Ll.forEach(t),Co=c(e),_(Nt.$$.fragment,e),So=c(e),Ce=o(e,"P",{});var Cl=l(Ce);cp=p(Cl,"Let\u2019s put\xA0"),za=o(Cl,"CODE",{});var hm=l(za);mp=p(hm,"DirectionalSimilarity"),hm.forEach(t),up=p(Cl,"\xA0to use now."),Cl.forEach(t),To=c(e),_(Ot.$$.fragment,e),Ao=c(e),Bs=o(e,"P",{});var _m=l(Bs);dp=p(_m,"Like the CLIP Score, the higher the CLIP directional similarity, the better it is."),_m.forEach(t),Fo=c(e),F=o(e,"P",{});var Ge=l(F);hp=p(Ge,"It should be noted that the\xA0"),Ba=o(Ge,"CODE",{});var gm=l(Ba);_p=p(gm,"StableDiffusionInstructPix2PixPipeline"),gm.forEach(t),gp=p(Ge,"\xA0exposes two arguments, namely,\xA0"),Wa=o(Ge,"CODE",{});var wm=l(Wa);wp=p(wm,"image_guidance_scale"),wm.forEach(t),vp=p(Ge,"\xA0and\xA0"),Ga=o(Ge,"CODE",{});var vm=l(Ga);yp=p(vm,"guidance_scale"),vm.forEach(t),bp=p(Ge,"\xA0that let you control the quality of the final edited image. We encourage you to experiment with these two arguments and see the impact of that on the directional similarity."),Ge.forEach(t),No=c(e),Se=o(e,"P",{});var Sl=l(Se);Pp=p(Sl,"We can extend the idea of this metric to measure how similar the original image and edited version are. To do that, we can just do\xA0"),Ha=o(Sl,"CODE",{});var ym=l(Ha);$p=p(ym,"F.cosine_similarity(img_feat_two, img_feat_one)"),ym.forEach(t),kp=p(Sl,". For these kinds of edits, we would still want the primary semantics of the images to be preserved as much as possible, i.e., a high similarity score."),Sl.forEach(t),Oo=c(e),Te=o(e,"P",{});var Tl=l(Te);xp=p(Tl,"We can use these metrics for similar pipelines such as the "),Mt=o(Tl,"A",{href:!0,rel:!0});var bm=l(Mt);Ra=o(bm,"CODE",{});var Pm=l(Ra);jp=p(Pm,"StableDiffusionPix2PixZeroPipeline"),Pm.forEach(t),bm.forEach(t),Ep=p(Tl,"."),Tl.forEach(t),Mo=c(e),_(Ae.$$.fragment,e),zo=c(e),oe=o(e,"P",{});var ui=l(oe);Ka=o(ui,"STRONG",{});var $m=l(Ka);Qa=o($m,"EM",{});var km=l(Qa);Ip=p(km,"Extending metrics like IS, FID (discussed later), or KID can be difficult"),km.forEach(t),$m.forEach(t),qp=p(ui," when the model under evaluation was pre-trained on a large image-captioning dataset (such as the "),zt=o(ui,"A",{href:!0,rel:!0});var xm=l(zt);Dp=p(xm,"LAION-5B dataset"),xm.forEach(t),Lp=p(ui,"). This is because underlying these metrics is an InceptionNet (pre-trained on the ImageNet-1k dataset) used for extracting intermediate image features. The pre-training dataset of Stable Diffusion may have limited overlap with the pre-training dataset of InceptionNet, so it is not a good candidate here for feature extraction."),ui.forEach(t),Bo=c(e),Ws=o(e,"P",{});var jm=l(Ws);Va=o(jm,"STRONG",{});var Em=l(Va);Bt=o(Em,"EM",{});var Al=l(Bt);Cp=p(Al,"Using the above metrics helps evaluate models that are class-conditioned. For example, "),Wt=o(Al,"A",{href:!0,rel:!0});var Im=l(Wt);Sp=p(Im,"DiT"),Im.forEach(t),Tp=p(Al,". It was pre-trained being conditioned on the ImageNet-1k classes."),Al.forEach(t),Em.forEach(t),jm.forEach(t),Wo=c(e),le=o(e,"H3",{class:!0});var Fl=l(le);Fe=o(Fl,"A",{id:!0,class:!0,href:!0});var qm=l(Fe);Ua=o(qm,"SPAN",{});var Dm=l(Ua);_(Gt.$$.fragment,Dm),Dm.forEach(t),qm.forEach(t),Ap=c(Fl),Za=o(Fl,"SPAN",{});var Lm=l(Za);Fp=p(Lm,"Class-conditioned image generation"),Lm.forEach(t),Fl.forEach(t),Go=c(e),C=o(e,"P",{});var J=l(C);Np=p(J,"Class-conditioned generative models are usually pre-trained on a class-labeled dataset such as "),Ht=o(J,"A",{href:!0,rel:!0});var Cm=l(Ht);Op=p(Cm,"ImageNet-1k"),Cm.forEach(t),Mp=p(J,". Popular metrics for evaluating these models include Fr\xE9chet Inception Distance (FID), Kernel Inception Distance (KID), and Inception Score (IS). In this document, we focus on FID ("),Rt=o(J,"A",{href:!0,rel:!0});var Sm=l(Rt);zp=p(Sm,"Heusel et al."),Sm.forEach(t),Bp=p(J,"). We show how to compute it with the "),Kt=o(J,"A",{href:!0,rel:!0});var Tm=l(Kt);Xa=o(Tm,"CODE",{});var Am=l(Xa);Wp=p(Am,"DiTPipeline"),Am.forEach(t),Tm.forEach(t),Gp=p(J,", which uses the "),Qt=o(J,"A",{href:!0,rel:!0});var Fm=l(Qt);Hp=p(Fm,"DiT model"),Fm.forEach(t),Rp=p(J," under the hood."),J.forEach(t),Ho=c(e),Ne=o(e,"P",{});var Nl=l(Ne);Kp=p(Nl,"FID aims to measure how similar are two datasets of images. As per "),Vt=o(Nl,"A",{href:!0,rel:!0});var Nm=l(Vt);Qp=p(Nm,"this resource"),Nm.forEach(t),Vp=p(Nl,":"),Nl.forEach(t),Ro=c(e),Gs=o(e,"BLOCKQUOTE",{});var Om=l(Gs);Ja=o(Om,"P",{});var Mm=l(Ja);Up=p(Mm,"Fr\xE9chet Inception Distance is a measure of similarity between two datasets of images. It was shown to correlate well with the human judgment of visual quality and is most often used to evaluate the quality of samples of Generative Adversarial Networks. FID is calculated by computing the Fr\xE9chet distance between two Gaussians fitted to feature representations of the Inception network."),Mm.forEach(t),Om.forEach(t),Ko=c(e),Hs=o(e,"P",{});var zm=l(Hs);Zp=p(zm,"These two datasets are essentially the dataset of real images and the dataset of fake images (generated images in our case). FID is usually calculated with two large datasets. However, for this document, we will work with two mini datasets."),zm.forEach(t),Qo=c(e),Rs=o(e,"P",{});var Bm=l(Rs);Xp=p(Bm,"Let\u2019s first download a few images from the ImageNet-1k training set:"),Bm.forEach(t),Vo=c(e),_(Ut.$$.fragment,e),Uo=c(e),_(Zt.$$.fragment,e),Zo=c(e),Ks=o(e,"P",{});var Wm=l(Ks);Jp=p(Wm,"These are 10 images from the following Imagenet-1k classes: \u201Ccassette_player\u201D, \u201Cchain_saw\u201D (x2), \u201Cchurch\u201D, \u201Cgas_pump\u201D (x3), \u201Cparachute\u201D (x2), and \u201Ctench\u201D."),Wm.forEach(t),Xo=c(e),Z=o(e,"P",{align:!0});var di=l(Z);Qs=o(di,"IMG",{src:!0,alt:!0}),Yp=o(di,"BR",{}),ef=c(di),Ya=o(di,"EM",{});var Gm=l(Ya);tf=p(Gm,"Real images."),Gm.forEach(t),di.forEach(t),Jo=c(e),Vs=o(e,"P",{});var Hm=l(Vs);sf=p(Hm,"Now that the images are loaded, let\u2019s apply some lightweight pre-processing on them to use them for FID calculation."),Hm.forEach(t),Yo=c(e),_(Xt.$$.fragment,e),el=c(e),Oe=o(e,"P",{});var Ol=l(Oe);af=p(Ol,"We now load the\xA0"),Jt=o(Ol,"A",{href:!0,rel:!0});var Rm=l(Jt);ei=o(Rm,"CODE",{});var Km=l(ei);of=p(Km,"DiTPipeline"),Km.forEach(t),Rm.forEach(t),lf=p(Ol," to generate images conditioned on the above-mentioned classes."),Ol.forEach(t),tl=c(e),_(Yt.$$.fragment,e),sl=c(e),Me=o(e,"P",{});var Ml=l(Me);rf=p(Ml,"Now, we can compute the FID using\xA0"),es=o(Ml,"A",{href:!0,rel:!0});var Qm=l(es);ti=o(Qm,"CODE",{});var Vm=l(ti);nf=p(Vm,"torchmetrics"),Vm.forEach(t),Qm.forEach(t),pf=p(Ml,"."),Ml.forEach(t),al=c(e),_(ts.$$.fragment,e),il=c(e),Us=o(e,"P",{});var Um=l(Us);ff=p(Um,"The lower the FID, the better it is. Several things can influence FID here:"),Um.forEach(t),ol=c(e),N=o(e,"UL",{});var He=l(N);si=o(He,"LI",{});var Zm=l(si);cf=p(Zm,"Number of images (both real and fake)"),Zm.forEach(t),mf=c(He),ai=o(He,"LI",{});var Xm=l(ai);uf=p(Xm,"Randomness induced in the diffusion process"),Xm.forEach(t),df=c(He),ii=o(He,"LI",{});var Jm=l(ii);hf=p(Jm,"Number of inference steps in the diffusion process"),Jm.forEach(t),_f=c(He),oi=o(He,"LI",{});var Ym=l(oi);gf=p(Ym,"The scheduler being used in the diffusion process"),Ym.forEach(t),He.forEach(t),ll=c(e),Zs=o(e,"P",{});var eu=l(Zs);wf=p(eu,"For the last two points, it is, therefore, a good practice to run the evaluation across different seeds and inference steps, and then report an average result."),eu.forEach(t),rl=c(e),_(ze.$$.fragment,e),nl=c(e),Be=o(e,"P",{});var zl=l(Be);vf=p(zl,"As a final step, let\u2019s visually inspect the\xA0"),li=o(zl,"CODE",{});var tu=l(li);yf=p(tu,"fake_images"),tu.forEach(t),bf=p(zl,"."),zl.forEach(t),pl=c(e),X=o(e,"P",{align:!0});var hi=l(X);Xs=o(hi,"IMG",{src:!0,alt:!0}),Pf=o(hi,"BR",{}),$f=c(hi),ri=o(hi,"EM",{});var su=l(ri);kf=p(su,"Fake images."),su.forEach(t),hi.forEach(t),this.h()},h(){m(u,"name","hf:doc:metadata"),m(u,"content",JSON.stringify(uu)),m(b,"id","evaluating-diffusion-models"),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","#evaluating-diffusion-models"),m(d,"class","relative group"),re(B.src,Ke="https://colab.research.google.com/assets/colab-badge.svg")||m(B,"src",Ke),m(B,"alt","Open In Colab"),m(D,"target","_blank"),m(D,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/evaluation.ipynb"),m(L,"href","https://huggingface.co/docs/diffusers/stable_diffusion"),m(L,"rel","nofollow"),m(Ue,"href","https://huggingface.co/docs/diffusers/main/en/api/schedulers/overview"),m(Ue,"rel","nofollow"),m(me,"id","scenarios"),m(me,"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(me,"href","#scenarios"),m(Y,"class","relative group"),m(Je,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img"),m(Je,"rel","nofollow"),m(Ye,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/img2img"),m(Ye,"rel","nofollow"),m(et,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix"),m(et,"rel","nofollow"),m(st,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/dit"),m(st,"rel","nofollow"),m(ue,"id","qualitative-evaluation"),m(ue,"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(ue,"href","#qualitative-evaluation"),m(te,"class","relative group"),m(it,"href","https://imagen.research.google/"),m(it,"rel","nofollow"),m(ot,"href","https://parti.research.google/"),m(ot,"rel","nofollow"),m(lt,"href","https://parti.research.google/"),m(lt,"rel","nofollow"),re(ps.src,Ef="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/parti-prompts.png")||m(ps,"src",Ef),m(ps,"alt","parti-prompts"),m(rt,"href","https://huggingface.co/datasets/nateraw/parti-prompts"),m(rt,"rel","nofollow"),m(pt,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),m(pt,"rel","nofollow"),re(ms.src,If="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/parti-prompts-14.png")||m(ms,"src",If),m(ms,"alt","parti-prompts-14"),m(ct,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),m(ct,"rel","nofollow"),re(ds.src,qf="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/parti-prompts-15.png")||m(ds,"src",qf),m(ds,"alt","parti-prompts-15"),m(ve,"id","quantitative-evaluation"),m(ve,"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(ve,"href","#quantitative-evaluation"),m(se,"class","relative group"),m(ye,"id","textguided-image-generation"),m(ye,"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(ye,"href","#textguided-image-generation"),m(ae,"class","relative group"),m(ht,"href","https://arxiv.org/abs/2104.08718"),m(ht,"rel","nofollow"),m(gs,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),m(bs,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),m(vt,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),m(vt,"rel","nofollow"),m(bt,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),m(bt,"rel","nofollow"),m(kt,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),m(kt,"rel","nofollow"),m(xe,"id","imageconditioned-texttoimage-generation"),m(xe,"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(xe,"href","#imageconditioned-texttoimage-generation"),m(ie,"class","relative group"),m($s,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/pix2pix#diffusers.StableDiffusionInstructPix2PixPipeline"),re(js.src,Df="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/edit-instruction.png")||m(js,"src",Df),m(js,"alt","edit-instruction"),m(jt,"href","https://huggingface.co/docs/transformers/model_doc/clip"),m(jt,"rel","nofollow"),m(Et,"href","https://arxiv.org/abs/2108.00946"),m(Et,"rel","nofollow"),re(qs.src,Lf="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/edit-consistency.png")||m(qs,"src",Lf),m(qs,"alt","edit-consistency"),re(Fs.src,Cf="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/edit-dataset.png")||m(Fs,"src",Cf),m(Fs,"alt","edit-dataset"),m(Os,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/pix2pix#diffusers.StableDiffusionInstructPix2PixPipeline"),m(Ft,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix#diffusers.StableDiffusionInstructPix2PixPipeline.text_encoder"),m(Ft,"rel","nofollow"),m(Mt,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/pix2pix_zero#diffusers.StableDiffusionPix2PixZeroPipeline"),m(Mt,"rel","nofollow"),m(zt,"href","https://laion.ai/blog/laion-5b/"),m(zt,"rel","nofollow"),m(Wt,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview"),m(Wt,"rel","nofollow"),m(Fe,"id","classconditioned-image-generation"),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","#classconditioned-image-generation"),m(le,"class","relative group"),m(Ht,"href","https://huggingface.co/datasets/imagenet-1k"),m(Ht,"rel","nofollow"),m(Rt,"href","https://arxiv.org/abs/1706.08500"),m(Rt,"rel","nofollow"),m(Kt,"href","https://huggingface.co/docs/diffusers/api/pipelines/dit"),m(Kt,"rel","nofollow"),m(Qt,"href","https://arxiv.org/abs/2212.09748"),m(Qt,"rel","nofollow"),m(Vt,"href","https://mmgeneration.readthedocs.io/en/latest/quick_run.html#fid"),m(Vt,"rel","nofollow"),re(Qs.src,Sf="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/real-images.png")||m(Qs,"src",Sf),m(Qs,"alt","real-images"),m(Z,"align","center"),m(Jt,"href","https://huggingface.co/docs/diffusers/api/pipelines/dit"),m(Jt,"rel","nofollow"),m(es,"href","https://torchmetrics.readthedocs.io/"),m(es,"rel","nofollow"),re(Xs.src,Tf="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/fake-images.png")||m(Xs,"src",Tf),m(Xs,"alt","fake-images"),m(X,"align","center")},m(e,a){s(document.head,u),r(e,j,a),r(e,d,a),s(d,b),s(b,E),g($,E,null),s(d,x),s(d,I),s(I,Re),r(e,ne,a),r(e,D,a),s(D,B),r(e,O,a),r(e,T,a),s(T,pe),s(T,L),s(L,Qe),s(T,P),r(e,q,a),r(e,S,a),s(S,is),r(e,Ve,a),r(e,M,a),s(M,os),s(M,fe),s(fe,Wl),s(M,Gl),r(e,_i,a),r(e,ce,a),s(ce,Hl),s(ce,Ue),s(Ue,Rl),s(ce,Kl),r(e,gi,a),r(e,Y,a),s(Y,me),s(me,ra),g(Ze,ra,null),s(Y,Ql),s(Y,na),s(na,Vl),r(e,wi,a),r(e,ls,a),s(ls,Ul),r(e,vi,a),r(e,W,a),s(W,Xe),s(Xe,Zl),s(Xe,Je),s(Je,pa),s(pa,Xl),s(Xe,Jl),s(W,Yl),s(W,ee),s(ee,er),s(ee,Ye),s(Ye,fa),s(fa,tr),s(ee,sr),s(ee,et),s(et,ca),s(ca,ar),s(ee,ir),s(W,or),s(W,tt),s(tt,lr),s(tt,st),s(st,ma),s(ma,rr),s(tt,nr),r(e,yi,a),r(e,te,a),s(te,ue),s(ue,ua),g(at,ua,null),s(te,pr),s(te,da),s(da,fr),r(e,bi,a),r(e,G,a),s(G,cr),s(G,it),s(it,mr),s(G,ur),s(G,ot),s(ot,dr),s(G,hr),r(e,Pi,a),r(e,de,a),s(de,_r),s(de,lt),s(lt,gr),s(de,wr),r(e,$i,a),r(e,rs,a),s(rs,ha),s(ha,vr),r(e,ki,a),r(e,ns,a),s(ns,ps),r(e,xi,a),r(e,fs,a),s(fs,yr),r(e,ji,a),r(e,H,a),s(H,_a),s(_a,br),s(H,Pr),s(H,ga),s(ga,$r),s(H,kr),s(H,wa),s(wa,xr),r(e,Ei,a),r(e,he,a),s(he,jr),s(he,va),s(va,Er),s(he,Ir),r(e,Ii,a),r(e,_e,a),s(_e,qr),s(_e,rt),s(rt,Dr),s(_e,Lr),r(e,qi,a),g(nt,e,a),r(e,Di,a),r(e,ge,a),s(ge,Cr),s(ge,pt),s(pt,Sr),s(ge,Tr),r(e,Li,a),g(ft,e,a),r(e,Ci,a),r(e,cs,a),s(cs,ms),r(e,Si,a),r(e,R,a),s(R,Ar),s(R,ya),s(ya,Fr),s(R,Nr),s(R,ct),s(ct,Or),s(R,Mr),r(e,Ti,a),r(e,us,a),s(us,ds),r(e,Ai,a),r(e,hs,a),s(hs,zr),r(e,Fi,a),g(we,e,a),r(e,Ni,a),r(e,se,a),s(se,ve),s(ve,ba),g(mt,ba,null),s(se,Br),s(se,Pa),s(Pa,Wr),r(e,Oi,a),r(e,_s,a),s(_s,Gr),r(e,Mi,a),r(e,K,a),s(K,$a),s($a,Hr),s(K,Rr),s(K,ka),s(ka,Kr),s(K,Qr),s(K,xa),s(xa,Vr),r(e,zi,a),r(e,ae,a),s(ae,ye),s(ye,ja),g(ut,ja,null),s(ae,Ur),s(ae,Ea),s(Ea,Zr),r(e,Bi,a),r(e,dt,a),s(dt,ht),s(ht,Xr),s(dt,Jr),r(e,Wi,a),r(e,be,a),s(be,Yr),s(be,gs),s(gs,en),s(be,tn),r(e,Gi,a),g(_t,e,a),r(e,Hi,a),r(e,ws,a),s(ws,sn),r(e,Ri,a),g(gt,e,a),r(e,Ki,a),r(e,vs,a),s(vs,an),r(e,Qi,a),g(wt,e,a),r(e,Vi,a),r(e,ys,a),s(ys,on),r(e,Ui,a),r(e,Q,a),s(Q,ln),s(Q,bs),s(bs,rn),s(Q,nn),s(Q,vt),s(vt,pn),s(Q,fn),r(e,Zi,a),g(yt,e,a),r(e,Xi,a),r(e,Pe,a),s(Pe,cn),s(Pe,bt),s(bt,mn),s(Pe,un),r(e,Ji,a),g(Pt,e,a),r(e,Yi,a),r(e,Ps,a),s(Ps,dn),r(e,eo,a),g($t,e,a),r(e,to,a),r(e,$e,a),s($e,hn),s($e,kt),s(kt,_n),s($e,gn),r(e,so,a),g(ke,e,a),r(e,ao,a),r(e,ie,a),s(ie,xe),s(xe,Ia),g(xt,Ia,null),s(ie,wn),s(ie,qa),s(qa,vn),r(e,io,a),r(e,je,a),s(je,yn),s(je,$s),s($s,bn),s(je,Pn),r(e,oo,a),r(e,ks,a),s(ks,$n),r(e,lo,a),r(e,xs,a),s(xs,js),r(e,ro,a),r(e,A,a),s(A,kn),s(A,jt),s(jt,xn),s(A,jn),s(A,Et),s(Et,En),s(A,In),s(A,Da),s(Da,qn),s(A,Dn),r(e,no,a),r(e,Ee,a),s(Ee,La),s(La,Ln),s(Ee,Cn),s(Ee,Ca),s(Ca,Sn),r(e,po,a),r(e,Es,a),s(Es,Tn),r(e,fo,a),r(e,Is,a),s(Is,qs),r(e,co,a),r(e,Ds,a),s(Ds,An),r(e,mo,a),g(It,e,a),r(e,uo,a),g(qt,e,a),r(e,ho,a),r(e,Ls,a),s(Ls,Fn),r(e,_o,a),r(e,V,a),s(V,Ie),s(Ie,Sa),s(Sa,Nn),s(Ie,On),s(Ie,Ta),s(Ta,Mn),s(Ie,zn),s(V,Bn),s(V,Cs),s(Cs,Aa),s(Aa,Wn),s(Cs,Gn),s(V,Hn),s(V,qe),s(qe,Fa),s(Fa,Rn),s(qe,Kn),s(qe,Na),s(Na,Qn),s(qe,Vn),r(e,go,a),r(e,Ss,a),s(Ss,Un),r(e,wo,a),g(Dt,e,a),r(e,vo,a),g(Lt,e,a),r(e,yo,a),r(e,Ts,a),s(Ts,Zn),r(e,bo,a),g(Ct,e,a),r(e,Po,a),r(e,As,a),s(As,Fs),r(e,$o,a),r(e,Ns,a),s(Ns,Xn),r(e,ko,a),r(e,De,a),s(De,Jn),s(De,Os),s(Os,Yn),s(De,ep),r(e,xo,a),g(St,e,a),r(e,jo,a),r(e,Ms,a),s(Ms,tp),r(e,Eo,a),g(Tt,e,a),r(e,Io,a),r(e,zs,a),s(zs,sp),r(e,qo,a),g(At,e,a),r(e,Do,a),r(e,U,a),s(U,ap),s(U,Oa),s(Oa,ip),s(U,op),s(U,Ft),s(Ft,lp),s(U,rp),r(e,Lo,a),r(e,Le,a),s(Le,np),s(Le,Ma),s(Ma,pp),s(Le,fp),r(e,Co,a),g(Nt,e,a),r(e,So,a),r(e,Ce,a),s(Ce,cp),s(Ce,za),s(za,mp),s(Ce,up),r(e,To,a),g(Ot,e,a),r(e,Ao,a),r(e,Bs,a),s(Bs,dp),r(e,Fo,a),r(e,F,a),s(F,hp),s(F,Ba),s(Ba,_p),s(F,gp),s(F,Wa),s(Wa,wp),s(F,vp),s(F,Ga),s(Ga,yp),s(F,bp),r(e,No,a),r(e,Se,a),s(Se,Pp),s(Se,Ha),s(Ha,$p),s(Se,kp),r(e,Oo,a),r(e,Te,a),s(Te,xp),s(Te,Mt),s(Mt,Ra),s(Ra,jp),s(Te,Ep),r(e,Mo,a),g(Ae,e,a),r(e,zo,a),r(e,oe,a),s(oe,Ka),s(Ka,Qa),s(Qa,Ip),s(oe,qp),s(oe,zt),s(zt,Dp),s(oe,Lp),r(e,Bo,a),r(e,Ws,a),s(Ws,Va),s(Va,Bt),s(Bt,Cp),s(Bt,Wt),s(Wt,Sp),s(Bt,Tp),r(e,Wo,a),r(e,le,a),s(le,Fe),s(Fe,Ua),g(Gt,Ua,null),s(le,Ap),s(le,Za),s(Za,Fp),r(e,Go,a),r(e,C,a),s(C,Np),s(C,Ht),s(Ht,Op),s(C,Mp),s(C,Rt),s(Rt,zp),s(C,Bp),s(C,Kt),s(Kt,Xa),s(Xa,Wp),s(C,Gp),s(C,Qt),s(Qt,Hp),s(C,Rp),r(e,Ho,a),r(e,Ne,a),s(Ne,Kp),s(Ne,Vt),s(Vt,Qp),s(Ne,Vp),r(e,Ro,a),r(e,Gs,a),s(Gs,Ja),s(Ja,Up),r(e,Ko,a),r(e,Hs,a),s(Hs,Zp),r(e,Qo,a),r(e,Rs,a),s(Rs,Xp),r(e,Vo,a),g(Ut,e,a),r(e,Uo,a),g(Zt,e,a),r(e,Zo,a),r(e,Ks,a),s(Ks,Jp),r(e,Xo,a),r(e,Z,a),s(Z,Qs),s(Z,Yp),s(Z,ef),s(Z,Ya),s(Ya,tf),r(e,Jo,a),r(e,Vs,a),s(Vs,sf),r(e,Yo,a),g(Xt,e,a),r(e,el,a),r(e,Oe,a),s(Oe,af),s(Oe,Jt),s(Jt,ei),s(ei,of),s(Oe,lf),r(e,tl,a),g(Yt,e,a),r(e,sl,a),r(e,Me,a),s(Me,rf),s(Me,es),s(es,ti),s(ti,nf),s(Me,pf),r(e,al,a),g(ts,e,a),r(e,il,a),r(e,Us,a),s(Us,ff),r(e,ol,a),r(e,N,a),s(N,si),s(si,cf),s(N,mf),s(N,ai),s(ai,uf),s(N,df),s(N,ii),s(ii,hf),s(N,_f),s(N,oi),s(oi,gf),r(e,ll,a),r(e,Zs,a),s(Zs,wf),r(e,rl,a),g(ze,e,a),r(e,nl,a),r(e,Be,a),s(Be,vf),s(Be,li),s(li,yf),s(Be,bf),r(e,pl,a),r(e,X,a),s(X,Xs),s(X,Pf),s(X,$f),s(X,ri),s(ri,kf),fl=!0},p(e,[a]){const ss={};a&2&&(ss.$$scope={dirty:a,ctx:e}),we.$set(ss);const ni={};a&2&&(ni.$$scope={dirty:a,ctx:e}),ke.$set(ni);const pi={};a&2&&(pi.$$scope={dirty:a,ctx:e}),Ae.$set(pi);const fi={};a&2&&(fi.$$scope={dirty:a,ctx:e}),ze.$set(fi)},i(e){fl||(w($.$$.fragment,e),w(Ze.$$.fragment,e),w(at.$$.fragment,e),w(nt.$$.fragment,e),w(ft.$$.fragment,e),w(we.$$.fragment,e),w(mt.$$.fragment,e),w(ut.$$.fragment,e),w(_t.$$.fragment,e),w(gt.$$.fragment,e),w(wt.$$.fragment,e),w(yt.$$.fragment,e),w(Pt.$$.fragment,e),w($t.$$.fragment,e),w(ke.$$.fragment,e),w(xt.$$.fragment,e),w(It.$$.fragment,e),w(qt.$$.fragment,e),w(Dt.$$.fragment,e),w(Lt.$$.fragment,e),w(Ct.$$.fragment,e),w(St.$$.fragment,e),w(Tt.$$.fragment,e),w(At.$$.fragment,e),w(Nt.$$.fragment,e),w(Ot.$$.fragment,e),w(Ae.$$.fragment,e),w(Gt.$$.fragment,e),w(Ut.$$.fragment,e),w(Zt.$$.fragment,e),w(Xt.$$.fragment,e),w(Yt.$$.fragment,e),w(ts.$$.fragment,e),w(ze.$$.fragment,e),fl=!0)},o(e){v($.$$.fragment,e),v(Ze.$$.fragment,e),v(at.$$.fragment,e),v(nt.$$.fragment,e),v(ft.$$.fragment,e),v(we.$$.fragment,e),v(mt.$$.fragment,e),v(ut.$$.fragment,e),v(_t.$$.fragment,e),v(gt.$$.fragment,e),v(wt.$$.fragment,e),v(yt.$$.fragment,e),v(Pt.$$.fragment,e),v($t.$$.fragment,e),v(ke.$$.fragment,e),v(xt.$$.fragment,e),v(It.$$.fragment,e),v(qt.$$.fragment,e),v(Dt.$$.fragment,e),v(Lt.$$.fragment,e),v(Ct.$$.fragment,e),v(St.$$.fragment,e),v(Tt.$$.fragment,e),v(At.$$.fragment,e),v(Nt.$$.fragment,e),v(Ot.$$.fragment,e),v(Ae.$$.fragment,e),v(Gt.$$.fragment,e),v(Ut.$$.fragment,e),v(Zt.$$.fragment,e),v(Xt.$$.fragment,e),v(Yt.$$.fragment,e),v(ts.$$.fragment,e),v(ze.$$.fragment,e),fl=!1},d(e){t(u),e&&t(j),e&&t(d),y($),e&&t(ne),e&&t(D),e&&t(O),e&&t(T),e&&t(q),e&&t(S),e&&t(Ve),e&&t(M),e&&t(_i),e&&t(ce),e&&t(gi),e&&t(Y),y(Ze),e&&t(wi),e&&t(ls),e&&t(vi),e&&t(W),e&&t(yi),e&&t(te),y(at),e&&t(bi),e&&t(G),e&&t(Pi),e&&t(de),e&&t($i),e&&t(rs),e&&t(ki),e&&t(ns),e&&t(xi),e&&t(fs),e&&t(ji),e&&t(H),e&&t(Ei),e&&t(he),e&&t(Ii),e&&t(_e),e&&t(qi),y(nt,e),e&&t(Di),e&&t(ge),e&&t(Li),y(ft,e),e&&t(Ci),e&&t(cs),e&&t(Si),e&&t(R),e&&t(Ti),e&&t(us),e&&t(Ai),e&&t(hs),e&&t(Fi),y(we,e),e&&t(Ni),e&&t(se),y(mt),e&&t(Oi),e&&t(_s),e&&t(Mi),e&&t(K),e&&t(zi),e&&t(ae),y(ut),e&&t(Bi),e&&t(dt),e&&t(Wi),e&&t(be),e&&t(Gi),y(_t,e),e&&t(Hi),e&&t(ws),e&&t(Ri),y(gt,e),e&&t(Ki),e&&t(vs),e&&t(Qi),y(wt,e),e&&t(Vi),e&&t(ys),e&&t(Ui),e&&t(Q),e&&t(Zi),y(yt,e),e&&t(Xi),e&&t(Pe),e&&t(Ji),y(Pt,e),e&&t(Yi),e&&t(Ps),e&&t(eo),y($t,e),e&&t(to),e&&t($e),e&&t(so),y(ke,e),e&&t(ao),e&&t(ie),y(xt),e&&t(io),e&&t(je),e&&t(oo),e&&t(ks),e&&t(lo),e&&t(xs),e&&t(ro),e&&t(A),e&&t(no),e&&t(Ee),e&&t(po),e&&t(Es),e&&t(fo),e&&t(Is),e&&t(co),e&&t(Ds),e&&t(mo),y(It,e),e&&t(uo),y(qt,e),e&&t(ho),e&&t(Ls),e&&t(_o),e&&t(V),e&&t(go),e&&t(Ss),e&&t(wo),y(Dt,e),e&&t(vo),y(Lt,e),e&&t(yo),e&&t(Ts),e&&t(bo),y(Ct,e),e&&t(Po),e&&t(As),e&&t($o),e&&t(Ns),e&&t(ko),e&&t(De),e&&t(xo),y(St,e),e&&t(jo),e&&t(Ms),e&&t(Eo),y(Tt,e),e&&t(Io),e&&t(zs),e&&t(qo),y(At,e),e&&t(Do),e&&t(U),e&&t(Lo),e&&t(Le),e&&t(Co),y(Nt,e),e&&t(So),e&&t(Ce),e&&t(To),y(Ot,e),e&&t(Ao),e&&t(Bs),e&&t(Fo),e&&t(F),e&&t(No),e&&t(Se),e&&t(Oo),e&&t(Te),e&&t(Mo),y(Ae,e),e&&t(zo),e&&t(oe),e&&t(Bo),e&&t(Ws),e&&t(Wo),e&&t(le),y(Gt),e&&t(Go),e&&t(C),e&&t(Ho),e&&t(Ne),e&&t(Ro),e&&t(Gs),e&&t(Ko),e&&t(Hs),e&&t(Qo),e&&t(Rs),e&&t(Vo),y(Ut,e),e&&t(Uo),y(Zt,e),e&&t(Zo),e&&t(Ks),e&&t(Xo),e&&t(Z),e&&t(Jo),e&&t(Vs),e&&t(Yo),y(Xt,e),e&&t(el),e&&t(Oe),e&&t(tl),y(Yt,e),e&&t(sl),e&&t(Me),e&&t(al),y(ts,e),e&&t(il),e&&t(Us),e&&t(ol),e&&t(N),e&&t(ll),e&&t(Zs),e&&t(rl),y(ze,e),e&&t(nl),e&&t(Be),e&&t(pl),e&&t(X)}}}const uu={local:"evaluating-diffusion-models",sections:[{local:"scenarios",title:"Scenarios"},{local:"qualitative-evaluation",title:"Qualitative Evaluation"},{local:"quantitative-evaluation",sections:[{local:"textguided-image-generation",title:"Text-guided image generation"},{local:"imageconditioned-texttoimage-generation",title:"Image-conditioned text-to-image generation"},{local:"classconditioned-image-generation",title:"Class-conditioned image generation"}],title:"Quantitative Evaluation"}],title:"Evaluating Diffusion Models"};function du(z){return ru(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class vu extends au{constructor(u){super();iu(this,u,du,mu,ou,{})}}export{vu as default,uu as metadata};
