import{S as mt,i as ct,s as gt,e as r,k as m,w as Y,t as n,M as ht,c as l,d as t,m as c,a as f,x as G,h as s,b as u,N as dt,G as i,g as o,y as B,q as L,o as z,B as F,v as bt}from"../../chunks/vendor-hf-doc-builder.js";import{T as _t}from"../../chunks/Tip-hf-doc-builder.js";import{I as wt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as ke}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as yt}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function $t(te){let p,v,g,d,$;return{c(){p=r("p"),v=n("\u{1F4A1} Want to train your own unconditional image generation model? Take a look at the training "),g=r("a"),d=n("guide"),$=n(" to learn how to generate your own images."),this.h()},l(h){p=l(h,"P",{});var b=f(p);v=s(b,"\u{1F4A1} Want to train your own unconditional image generation model? Take a look at the training "),g=l(b,"A",{href:!0});var k=f(g);d=s(k,"guide"),k.forEach(t),$=s(b," to learn how to generate your own images."),b.forEach(t),this.h()},h(){u(g,"href","training/unconditional_training")},m(h,b){o(h,p,b),i(p,v),i(p,g),i(g,d),i(p,$)},d(h){h&&t(p)}}}function vt(te){let p,v,g,d,$,h,b,k,Pe,ie,x,ae,H,Ee,oe,P,De,O,Te,je,ne,_,xe,R,Ae,qe,A,Ue,Ie,se,E,re,w,Se,W,Me,Ne,q,Ce,Ye,le,U,fe,D,Ge,J,Be,Le,ue,I,pe,T,ze,Z,Fe,He,me,S,ce,j,Oe,M,ee,Re,We,ge,K,Je,he,N,de,Q,Ke,be,y,Qe,_e;return h=new wt({}),x=new yt({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/unconditional_image_generation.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/unconditional_image_generation.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/unconditional_image_generation.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/unconditional_image_generation.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/unconditional_image_generation.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/unconditional_image_generation.ipynb"}]}}),E=new _t({props:{$$slots:{default:[$t]},$$scope:{ctx:te}}}),U=new ke({props:{code:`from diffusers import DiffusionPipeline

generator = DiffusionPipeline.from_pretrained("anton-l/ddpm-butterflies-128")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>generator = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;anton-l/ddpm-butterflies-128&quot;</span>)`}}),I=new ke({props:{code:'generator.to("cuda")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>generator.to(<span class="hljs-string">&quot;cuda&quot;</span>)'}}),S=new ke({props:{code:"image = generator().images[0]",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>image = generator().images[<span class="hljs-number">0</span>]'}}),N=new ke({props:{code:'image.save("generated_image.png")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;generated_image.png&quot;</span>)'}}),{c(){p=r("meta"),v=m(),g=r("h1"),d=r("a"),$=r("span"),Y(h.$$.fragment),b=m(),k=r("span"),Pe=n("Unconditional image generation"),ie=m(),Y(x.$$.fragment),ae=m(),H=r("p"),Ee=n("Unconditional image generation is a relatively straightforward task. The model only generates images - without any additional context like text or an image - resembling the training data it was trained on."),oe=m(),P=r("p"),De=n("The "),O=r("a"),Te=n("DiffusionPipeline"),je=n(" is the easiest way to use a pre-trained diffusion system for inference."),ne=m(),_=r("p"),xe=n("Start by creating an instance of "),R=r("a"),Ae=n("DiffusionPipeline"),qe=n(` and specify which pipeline checkpoint you would like to download.
You can use any of the \u{1F9E8} Diffusers `),A=r("a"),Ue=n("checkpoints"),Ie=n(" from the Hub (the checkpoint you\u2019ll use generates images of butterflies)."),se=m(),Y(E.$$.fragment),re=m(),w=r("p"),Se=n("In this guide, you\u2019ll use "),W=r("a"),Me=n("DiffusionPipeline"),Ne=n(" for unconditional image generation with "),q=r("a"),Ce=n("DDPM"),Ye=n(":"),le=m(),Y(U.$$.fragment),fe=m(),D=r("p"),Ge=n("The "),J=r("a"),Be=n("DiffusionPipeline"),Le=n(` downloads and caches all modeling, tokenization, and scheduling components.
Because the model consists of roughly 1.4 billion parameters, we strongly recommend running it on a GPU.
You can move the generator object to a GPU, just like you would in PyTorch:`),ue=m(),Y(I.$$.fragment),pe=m(),T=r("p"),ze=n("Now you can use the "),Z=r("code"),Fe=n("generator"),He=n(" to generate an image:"),me=m(),Y(S.$$.fragment),ce=m(),j=r("p"),Oe=n("The output is by default wrapped into a "),M=r("a"),ee=r("code"),Re=n("PIL.Image"),We=n(" object."),ge=m(),K=r("p"),Je=n("You can save the image by calling:"),he=m(),Y(N.$$.fragment),de=m(),Q=r("p"),Ke=n("Try out the Spaces below, and feel free to play around with the inference steps parameter to see how it affects the image quality!"),be=m(),y=r("iframe"),this.h()},l(e){const a=ht('[data-svelte="svelte-1phssyn"]',document.head);p=l(a,"META",{name:!0,content:!0}),a.forEach(t),v=c(e),g=l(e,"H1",{class:!0});var C=f(g);d=l(C,"A",{id:!0,class:!0,href:!0});var Ve=f(d);$=l(Ve,"SPAN",{});var Xe=f($);G(h.$$.fragment,Xe),Xe.forEach(t),Ve.forEach(t),b=c(C),k=l(C,"SPAN",{});var Ze=f(k);Pe=s(Ze,"Unconditional image generation"),Ze.forEach(t),C.forEach(t),ie=c(e),G(x.$$.fragment,e),ae=c(e),H=l(e,"P",{});var et=f(H);Ee=s(et,"Unconditional image generation is a relatively straightforward task. The model only generates images - without any additional context like text or an image - resembling the training data it was trained on."),et.forEach(t),oe=c(e),P=l(e,"P",{});var we=f(P);De=s(we,"The "),O=l(we,"A",{href:!0});var tt=f(O);Te=s(tt,"DiffusionPipeline"),tt.forEach(t),je=s(we," is the easiest way to use a pre-trained diffusion system for inference."),we.forEach(t),ne=c(e),_=l(e,"P",{});var V=f(_);xe=s(V,"Start by creating an instance of "),R=l(V,"A",{href:!0});var it=f(R);Ae=s(it,"DiffusionPipeline"),it.forEach(t),qe=s(V,` and specify which pipeline checkpoint you would like to download.
You can use any of the \u{1F9E8} Diffusers `),A=l(V,"A",{href:!0,rel:!0});var at=f(A);Ue=s(at,"checkpoints"),at.forEach(t),Ie=s(V," from the Hub (the checkpoint you\u2019ll use generates images of butterflies)."),V.forEach(t),se=c(e),G(E.$$.fragment,e),re=c(e),w=l(e,"P",{});var X=f(w);Se=s(X,"In this guide, you\u2019ll use "),W=l(X,"A",{href:!0});var ot=f(W);Me=s(ot,"DiffusionPipeline"),ot.forEach(t),Ne=s(X," for unconditional image generation with "),q=l(X,"A",{href:!0,rel:!0});var nt=f(q);Ce=s(nt,"DDPM"),nt.forEach(t),Ye=s(X,":"),X.forEach(t),le=c(e),G(U.$$.fragment,e),fe=c(e),D=l(e,"P",{});var ye=f(D);Ge=s(ye,"The "),J=l(ye,"A",{href:!0});var st=f(J);Be=s(st,"DiffusionPipeline"),st.forEach(t),Le=s(ye,` downloads and caches all modeling, tokenization, and scheduling components.
Because the model consists of roughly 1.4 billion parameters, we strongly recommend running it on a GPU.
You can move the generator object to a GPU, just like you would in PyTorch:`),ye.forEach(t),ue=c(e),G(I.$$.fragment,e),pe=c(e),T=l(e,"P",{});var $e=f(T);ze=s($e,"Now you can use the "),Z=l($e,"CODE",{});var rt=f(Z);Fe=s(rt,"generator"),rt.forEach(t),He=s($e," to generate an image:"),$e.forEach(t),me=c(e),G(S.$$.fragment,e),ce=c(e),j=l(e,"P",{});var ve=f(j);Oe=s(ve,"The output is by default wrapped into a "),M=l(ve,"A",{href:!0,rel:!0});var lt=f(M);ee=l(lt,"CODE",{});var ft=f(ee);Re=s(ft,"PIL.Image"),ft.forEach(t),lt.forEach(t),We=s(ve," object."),ve.forEach(t),ge=c(e),K=l(e,"P",{});var ut=f(K);Je=s(ut,"You can save the image by calling:"),ut.forEach(t),he=c(e),G(N.$$.fragment,e),de=c(e),Q=l(e,"P",{});var pt=f(Q);Ke=s(pt,"Try out the Spaces below, and feel free to play around with the inference steps parameter to see how it affects the image quality!"),pt.forEach(t),be=c(e),y=l(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),f(y).forEach(t),this.h()},h(){u(p,"name","hf:doc:metadata"),u(p,"content",JSON.stringify(kt)),u(d,"id","unconditional-image-generation"),u(d,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(d,"href","#unconditional-image-generation"),u(g,"class","relative group"),u(O,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(R,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(A,"href","https://huggingface.co/models?library=diffusers&sort=downloads"),u(A,"rel","nofollow"),u(W,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(q,"href","https://arxiv.org/abs/2006.11239"),u(q,"rel","nofollow"),u(J,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),u(M,"href","https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#the-image-class"),u(M,"rel","nofollow"),dt(y.src,Qe="https://stevhliu-ddpm-butterflies-128.hf.space")||u(y,"src",Qe),u(y,"frameborder","0"),u(y,"width","850"),u(y,"height","500")},m(e,a){i(document.head,p),o(e,v,a),o(e,g,a),i(g,d),i(d,$),B(h,$,null),i(g,b),i(g,k),i(k,Pe),o(e,ie,a),B(x,e,a),o(e,ae,a),o(e,H,a),i(H,Ee),o(e,oe,a),o(e,P,a),i(P,De),i(P,O),i(O,Te),i(P,je),o(e,ne,a),o(e,_,a),i(_,xe),i(_,R),i(R,Ae),i(_,qe),i(_,A),i(A,Ue),i(_,Ie),o(e,se,a),B(E,e,a),o(e,re,a),o(e,w,a),i(w,Se),i(w,W),i(W,Me),i(w,Ne),i(w,q),i(q,Ce),i(w,Ye),o(e,le,a),B(U,e,a),o(e,fe,a),o(e,D,a),i(D,Ge),i(D,J),i(J,Be),i(D,Le),o(e,ue,a),B(I,e,a),o(e,pe,a),o(e,T,a),i(T,ze),i(T,Z),i(Z,Fe),i(T,He),o(e,me,a),B(S,e,a),o(e,ce,a),o(e,j,a),i(j,Oe),i(j,M),i(M,ee),i(ee,Re),i(j,We),o(e,ge,a),o(e,K,a),i(K,Je),o(e,he,a),B(N,e,a),o(e,de,a),o(e,Q,a),i(Q,Ke),o(e,be,a),o(e,y,a),_e=!0},p(e,[a]){const C={};a&2&&(C.$$scope={dirty:a,ctx:e}),E.$set(C)},i(e){_e||(L(h.$$.fragment,e),L(x.$$.fragment,e),L(E.$$.fragment,e),L(U.$$.fragment,e),L(I.$$.fragment,e),L(S.$$.fragment,e),L(N.$$.fragment,e),_e=!0)},o(e){z(h.$$.fragment,e),z(x.$$.fragment,e),z(E.$$.fragment,e),z(U.$$.fragment,e),z(I.$$.fragment,e),z(S.$$.fragment,e),z(N.$$.fragment,e),_e=!1},d(e){t(p),e&&t(v),e&&t(g),F(h),e&&t(ie),F(x,e),e&&t(ae),e&&t(H),e&&t(oe),e&&t(P),e&&t(ne),e&&t(_),e&&t(se),F(E,e),e&&t(re),e&&t(w),e&&t(le),F(U,e),e&&t(fe),e&&t(D),e&&t(ue),F(I,e),e&&t(pe),e&&t(T),e&&t(me),F(S,e),e&&t(ce),e&&t(j),e&&t(ge),e&&t(K),e&&t(he),F(N,e),e&&t(de),e&&t(Q),e&&t(be),e&&t(y)}}}const kt={local:"unconditional-image-generation",title:"Unconditional image generation"};function Pt(te){return bt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class At extends mt{constructor(p){super();ct(this,p,Pt,vt,gt,{})}}export{At as default,kt as metadata};
