Buckets:

rtrm's picture
download
raw
15.4 kB
import{s as ye,o as $e,n as Ie}from"../chunks/scheduler.53228c21.js";import{S as we,i as ve,e as l,s as a,c as M,h as Pe,a as p,d as s,b as i,f as H,g as D,j as v,k as O,l as u,m as n,n as b,t as y,o as $,p as I}from"../chunks/index.100fac89.js";import{C as je}from"../chunks/CopyLLMTxtMenu.af6dc933.js";import{D as de}from"../chunks/Docstring.e3782034.js";import{C as xe}from"../chunks/CodeBlock.d30a6509.js";import{E as Te}from"../chunks/ExampleCodeBlock.849f3c4b.js";import{H as me,E as Ue}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.a6c27641.js";function Ce(z){let o,j="Example:",h,d,m;return d=new xe({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1QaXBlbGluZSUwQWltcG9ydCUyMFBJTC5JbWFnZSUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQSUyMyUyMGxvYWQlMjBtb2RlbCUyMGFuZCUyMHNjaGVkdWxlciUwQXBpcGUlMjAlM0QlMjBERElNUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMmZ1c2luZyUyRmRkaW0tbHN1bi1iZWRyb29tJTIyKSUwQSUwQSUyMyUyMHJ1biUyMHBpcGVsaW5lJTIwaW4lMjBpbmZlcmVuY2UlMjAoc2FtcGxlJTIwcmFuZG9tJTIwbm9pc2UlMjBhbmQlMjBkZW5vaXNlKSUwQWltYWdlJTIwJTNEJTIwcGlwZShldGElM0QwLjAlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTApJTBBJTBBJTIzJTIwcHJvY2VzcyUyMGltYWdlJTIwdG8lMjBQSUwlMEFpbWFnZV9wcm9jZXNzZWQlMjAlM0QlMjBpbWFnZS5jcHUoKS5wZXJtdXRlKDAlMkMlMjAyJTJDJTIwMyUyQyUyMDEpJTBBaW1hZ2VfcHJvY2Vzc2VkJTIwJTNEJTIwKGltYWdlX3Byb2Nlc3NlZCUyMCUyQiUyMDEuMCklMjAqJTIwMTI3LjUlMEFpbWFnZV9wcm9jZXNzZWQlMjAlM0QlMjBpbWFnZV9wcm9jZXNzZWQubnVtcHkoKS5hc3R5cGUobnAudWludDgpJTBBaW1hZ2VfcGlsJTIwJTNEJTIwUElMLkltYWdlLmZyb21hcnJheShpbWFnZV9wcm9jZXNzZWQlNUIwJTVEKSUwQSUwQSUyMyUyMHNhdmUlMjBpbWFnZSUwQWltYWdlX3BpbC5zYXZlKCUyMnRlc3QucG5nJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> PIL.Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># load model and scheduler</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = DDIMPipeline.from_pretrained(<span class="hljs-string">&quot;fusing/ddim-lsun-bedroom&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># run pipeline in inference (sample random noise and denoise)</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(eta=<span class="hljs-number">0.0</span>, num_inference_steps=<span class="hljs-number">50</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># process image to PIL</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processed = image.cpu().permute(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processed = (image_processed + <span class="hljs-number">1.0</span>) * <span class="hljs-number">127.5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_processed = image_processed.numpy().astype(np.uint8)
<span class="hljs-meta">&gt;&gt;&gt; </span>image_pil = PIL.Image.fromarray(image_processed[<span class="hljs-number">0</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># save image</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image_pil.save(<span class="hljs-string">&quot;test.png&quot;</span>)`,wrap:!1}}),{c(){o=l("p"),o.textContent=j,h=a(),M(d.$$.fragment)},l(r){o=p(r,"P",{"data-svelte-h":!0}),v(o)!=="svelte-11lpom8"&&(o.textContent=j),h=i(r),D(d.$$.fragment,r)},m(r,f){n(r,o,f),n(r,h,f),b(d,r,f),m=!0},p:Ie,i(r){m||(y(d.$$.fragment,r),m=!0)},o(r){$(d.$$.fragment,r),m=!1},d(r){r&&(s(o),s(h)),I(d,r)}}}function Je(z){let o,j,h,d,m,r,f,X,x,ue='<a href="https://huggingface.co/papers/2010.02502" rel="nofollow">Denoising Diffusion Implicit Models</a> (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon.',q,T,fe="The abstract from the paper is:",A,U,ge="<em>Denoising diffusion probabilistic models (DDPMs) have achieved high quality image generation without adversarial training, yet they require simulating a Markov chain for many steps to produce a sample. To accelerate sampling, we present denoising diffusion implicit models (DDIMs), a more efficient class of iterative implicit probabilistic models with the same training procedure as DDPMs. In DDPMs, the generative process is defined as the reverse of a Markovian diffusion process. We construct a class of non-Markovian diffusion processes that lead to the same training objective, but whose reverse process can be much faster to sample from. We empirically demonstrate that DDIMs can produce high quality samples 10× to 50× faster in terms of wall-clock time compared to DDPMs, allow us to trade off computation for sample quality, and can perform semantically meaningful image interpolation directly in the latent space.</em>",F,C,he='The original codebase can be found at <a href="https://github.com/ermongroup/ddim" rel="nofollow">ermongroup/ddim</a>.',R,J,Y,c,S,ie,G,_e="Pipeline for image generation.",re,L,Me=`This model inherits from <a href="/docs/diffusers/pr_12507/en/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`,oe,_,Z,le,k,De="The call function to the pipeline for generation.",pe,P,K,W,ee,w,B,ce,E,be="Output class for image pipelines.",te,N,se,V,ne;return m=new je({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),f=new me({props:{title:"DDIM",local:"ddim",headingTag:"h1"}}),J=new me({props:{title:"DDIMPipeline",local:"diffusers.DDIMPipeline",headingTag:"h2"}}),S=new de({props:{name:"class diffusers.DDIMPipeline",anchor:"diffusers.DDIMPipeline",parameters:[{name:"unet",val:": UNet2DModel"},{name:"scheduler",val:": DDIMScheduler"}],parametersDescription:[{anchor:"diffusers.DDIMPipeline.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/pr_12507/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>) &#x2014;
A <code>UNet2DModel</code> to denoise the encoded image latents.`,name:"unet"},{anchor:"diffusers.DDIMPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/pr_12507/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image. Can be one of
<a href="/docs/diffusers/pr_12507/en/api/schedulers/ddpm#diffusers.DDPMScheduler">DDPMScheduler</a>, or <a href="/docs/diffusers/pr_12507/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>.`,name:"scheduler"}],source:"https://github.com/huggingface/diffusers/blob/vr_12507/src/diffusers/pipelines/ddim/pipeline_ddim.py#L34"}}),Z=new de({props:{name:"__call__",anchor:"diffusers.DDIMPipeline.__call__",parameters:[{name:"batch_size",val:": int = 1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"eta",val:": float = 0.0"},{name:"num_inference_steps",val:": int = 50"},{name:"use_clipped_model_output",val:": typing.Optional[bool] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.DDIMPipeline.__call__.batch_size",description:`<strong>batch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate.`,name:"batch_size"},{anchor:"diffusers.DDIMPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code>, <em>optional</em>) &#x2014;
A <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow"><code>torch.Generator</code></a> to make
generation deterministic.`,name:"generator"},{anchor:"diffusers.DDIMPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) from the <a href="https://huggingface.co/papers/2010.02502" rel="nofollow">DDIM</a> paper. Only
applies to the <a href="/docs/diffusers/pr_12507/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, and is ignored in other schedulers. A value of <code>0</code>
corresponds to DDIM and <code>1</code> corresponds to DDPM.`,name:"eta"},{anchor:"diffusers.DDIMPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.DDIMPipeline.__call__.use_clipped_model_output",description:`<strong>use_clipped_model_output</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
If <code>True</code> or <code>False</code>, see documentation for <a href="/docs/diffusers/pr_12507/en/api/schedulers/ddim#diffusers.DDIMScheduler.step">DDIMScheduler.step()</a>. If <code>None</code>, nothing is passed
downstream to the scheduler (use <code>None</code> for schedulers which don&#x2019;t support this argument).`,name:"use_clipped_model_output"},{anchor:"diffusers.DDIMPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generated image. Choose between <code>PIL.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.DDIMPipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/pr_12507/en/api/pipelines/consistency_models#diffusers.ImagePipelineOutput">ImagePipelineOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/vr_12507/src/diffusers/pipelines/ddim/pipeline_ddim.py#L59",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>
<p>If <code>return_dict</code> is <code>True</code>, <a
href="/docs/diffusers/pr_12507/en/api/pipelines/consistency_models#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> is returned, otherwise a <code>tuple</code> is
returned where the first element is a list with the generated images</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>
<p><a
href="/docs/diffusers/pr_12507/en/api/pipelines/consistency_models#diffusers.ImagePipelineOutput"
>ImagePipelineOutput</a> or <code>tuple</code></p>
`}}),P=new Te({props:{anchor:"diffusers.DDIMPipeline.__call__.example",$$slots:{default:[Ce]},$$scope:{ctx:z}}}),W=new me({props:{title:"ImagePipelineOutput",local:"diffusers.ImagePipelineOutput",headingTag:"h2"}}),B=new de({props:{name:"class diffusers.ImagePipelineOutput",anchor:"diffusers.ImagePipelineOutput",parameters:[{name:"images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]"}],parametersDescription:[{anchor:"diffusers.ImagePipelineOutput.images",description:`<strong>images</strong> (<code>List[PIL.Image.Image]</code> or <code>np.ndarray</code>) &#x2014;
List of denoised PIL images of length <code>batch_size</code> or NumPy array of shape <code>(batch_size, height, width, num_channels)</code>.`,name:"images"}],source:"https://github.com/huggingface/diffusers/blob/vr_12507/src/diffusers/pipelines/pipeline_utils.py#L118"}}),N=new Ue({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/ddim.md"}}),{c(){o=l("meta"),j=a(),h=l("p"),d=a(),M(m.$$.fragment),r=a(),M(f.$$.fragment),X=a(),x=l("p"),x.innerHTML=ue,q=a(),T=l("p"),T.textContent=fe,A=a(),U=l("p"),U.innerHTML=ge,F=a(),C=l("p"),C.innerHTML=he,R=a(),M(J.$$.fragment),Y=a(),c=l("div"),M(S.$$.fragment),ie=a(),G=l("p"),G.textContent=_e,re=a(),L=l("p"),L.innerHTML=Me,oe=a(),_=l("div"),M(Z.$$.fragment),le=a(),k=l("p"),k.textContent=De,pe=a(),M(P.$$.fragment),K=a(),M(W.$$.fragment),ee=a(),w=l("div"),M(B.$$.fragment),ce=a(),E=l("p"),E.textContent=be,te=a(),M(N.$$.fragment),se=a(),V=l("p"),this.h()},l(e){const t=Pe("svelte-u9bgzb",document.head);o=p(t,"META",{name:!0,content:!0}),t.forEach(s),j=i(e),h=p(e,"P",{}),H(h).forEach(s),d=i(e),D(m.$$.fragment,e),r=i(e),D(f.$$.fragment,e),X=i(e),x=p(e,"P",{"data-svelte-h":!0}),v(x)!=="svelte-1qeb1a3"&&(x.innerHTML=ue),q=i(e),T=p(e,"P",{"data-svelte-h":!0}),v(T)!=="svelte-1cwsb16"&&(T.textContent=fe),A=i(e),U=p(e,"P",{"data-svelte-h":!0}),v(U)!=="svelte-ui1c4c"&&(U.innerHTML=ge),F=i(e),C=p(e,"P",{"data-svelte-h":!0}),v(C)!=="svelte-m1hmpt"&&(C.innerHTML=he),R=i(e),D(J.$$.fragment,e),Y=i(e),c=p(e,"DIV",{class:!0});var g=H(c);D(S.$$.fragment,g),ie=i(g),G=p(g,"P",{"data-svelte-h":!0}),v(G)!=="svelte-2egq7o"&&(G.textContent=_e),re=i(g),L=p(g,"P",{"data-svelte-h":!0}),v(L)!=="svelte-7x0y3h"&&(L.innerHTML=Me),oe=i(g),_=p(g,"DIV",{class:!0});var Q=H(_);D(Z.$$.fragment,Q),le=i(Q),k=p(Q,"P",{"data-svelte-h":!0}),v(k)!=="svelte-50j04k"&&(k.textContent=De),pe=i(Q),D(P.$$.fragment,Q),Q.forEach(s),g.forEach(s),K=i(e),D(W.$$.fragment,e),ee=i(e),w=p(e,"DIV",{class:!0});var ae=H(w);D(B.$$.fragment,ae),ce=i(ae),E=p(ae,"P",{"data-svelte-h":!0}),v(E)!=="svelte-19wetgi"&&(E.textContent=be),ae.forEach(s),te=i(e),D(N.$$.fragment,e),se=i(e),V=p(e,"P",{}),H(V).forEach(s),this.h()},h(){O(o,"name","hf:doc:metadata"),O(o,"content",Se),O(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){u(document.head,o),n(e,j,t),n(e,h,t),n(e,d,t),b(m,e,t),n(e,r,t),b(f,e,t),n(e,X,t),n(e,x,t),n(e,q,t),n(e,T,t),n(e,A,t),n(e,U,t),n(e,F,t),n(e,C,t),n(e,R,t),b(J,e,t),n(e,Y,t),n(e,c,t),b(S,c,null),u(c,ie),u(c,G),u(c,re),u(c,L),u(c,oe),u(c,_),b(Z,_,null),u(_,le),u(_,k),u(_,pe),b(P,_,null),n(e,K,t),b(W,e,t),n(e,ee,t),n(e,w,t),b(B,w,null),u(w,ce),u(w,E),n(e,te,t),b(N,e,t),n(e,se,t),n(e,V,t),ne=!0},p(e,[t]){const g={};t&2&&(g.$$scope={dirty:t,ctx:e}),P.$set(g)},i(e){ne||(y(m.$$.fragment,e),y(f.$$.fragment,e),y(J.$$.fragment,e),y(S.$$.fragment,e),y(Z.$$.fragment,e),y(P.$$.fragment,e),y(W.$$.fragment,e),y(B.$$.fragment,e),y(N.$$.fragment,e),ne=!0)},o(e){$(m.$$.fragment,e),$(f.$$.fragment,e),$(J.$$.fragment,e),$(S.$$.fragment,e),$(Z.$$.fragment,e),$(P.$$.fragment,e),$(W.$$.fragment,e),$(B.$$.fragment,e),$(N.$$.fragment,e),ne=!1},d(e){e&&(s(j),s(h),s(d),s(r),s(X),s(x),s(q),s(T),s(A),s(U),s(F),s(C),s(R),s(Y),s(c),s(K),s(ee),s(w),s(te),s(se),s(V)),s(o),I(m,e),I(f,e),I(J,e),I(S),I(Z),I(P),I(W,e),I(B),I(N,e)}}}const Se='{"title":"DDIM","local":"ddim","sections":[{"title":"DDIMPipeline","local":"diffusers.DDIMPipeline","sections":[],"depth":2},{"title":"ImagePipelineOutput","local":"diffusers.ImagePipelineOutput","sections":[],"depth":2}],"depth":1}';function Ze(z){return $e(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Qe extends we{constructor(o){super(),ve(this,o,Ze,Je,ye,{})}}export{Qe as component};

Xet Storage Details

Size:
15.4 kB
·
Xet hash:
e5767bfff6f30fed43b2050e0f9a382297c960a67b99ed86c26f2ca7fa0d2fa5

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.