import{s as pe,n as ue,o as fe}from"../chunks/scheduler.182ea377.js";import{S as he,i as _e,g as r,s,r as M,A as ge,h as d,f as t,c as a,j as L,u as $,x as N,k as P,y as l,a as n,v as q,d as C,t as B,w as O}from"../chunks/index.abf12888.js";import{D as oe}from"../chunks/Docstring.93f6f462.js";import{H as ne}from"../chunks/Heading.16916d63.js";function be(se){let c,H,A,F,f,z,h,ae='The <a href="https://huggingface.co/papers/1505.04597" rel="nofollow">UNet</a> model was originally introduced by Ronneberger et al. for biomedical image segmentation, but it is also commonly used in 🤗 Diffusers because it outputs images that are the same size as the input. It is one of the most important components of a diffusion system because it facilitates the actual diffusion process. There are several variants of the UNet model in 🤗 Diffusers, depending on it’s number of dimensions and whether it is a conditional model or not. This is a 2D UNet model.',E,_,ie="The abstract from the paper is:",S,g,re='<em>There is large consent that successful training of deep networks requires many thousand annotated training samples. In this paper, we present a network and training strategy that relies on the strong use of data augmentation to use the available annotated samples more efficiently. The architecture consists of a contracting path to capture context and a symmetric expanding path that enables precise localization. We show that such a network can be trained end-to-end from very few images and outperforms the prior best method (a sliding-window convolutional network) on the ISBI challenge for segmentation of neuronal structures in electron microscopic stacks. Using the same network trained on transmitted light microscopy images (phase contrast and DIC) we won the ISBI cell tracking challenge 2015 in these categories by a large margin. Moreover, the network is fast. Segmentation of a 512x512 image takes less than a second on a recent GPU. The full implementation (based on Caffe) and the trained networks are available at <a href="http://lmb.informatik.uni-freiburg.de/people/ronneber/u-net" rel="nofollow">http://lmb.informatik.uni-freiburg.de/people/ronneber/u-net</a>.</em>',R,b,W,i,D,X,U,de="A 2D UNet model that takes a noisy sample and a timestep and returns a sample shaped output.",Y,x,le=`This model inherits from <a href="/docs/diffusers/main/en/api/models/overview#diffusers.ModelMixin">ModelMixin</a>. Check the superclass documentation for it’s generic methods implemented
for all models (such as downloading or saving).`,Z,p,y,ee,T,ce='The <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a> forward method.',j,w,V,m,v,te,k,me='The output of <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>.',G,I,J;return f=new ne({props:{title:"UNet2DModel",local:"unet2dmodel",headingTag:"h1"}}),b=new ne({props:{title:"UNet2DModel",local:"diffusers.UNet2DModel",headingTag:"h2"}}),D=new oe({props:{name:"class diffusers.UNet2DModel",anchor:"diffusers.UNet2DModel",parameters:[{name:"sample_size",val:": typing.Union[int, typing.Tuple[int, int], NoneType] = None"},{name:"in_channels",val:": int = 3"},{name:"out_channels",val:": int = 3"},{name:"center_input_sample",val:": bool = False"},{name:"time_embedding_type",val:": str = 'positional'"},{name:"freq_shift",val:": int = 0"},{name:"flip_sin_to_cos",val:": bool = True"},{name:"down_block_types",val:": typing.Tuple[str] = ('DownBlock2D', 'AttnDownBlock2D', 'AttnDownBlock2D', 'AttnDownBlock2D')"},{name:"up_block_types",val:": typing.Tuple[str] = ('AttnUpBlock2D', 'AttnUpBlock2D', 'AttnUpBlock2D', 'UpBlock2D')"},{name:"block_out_channels",val:": typing.Tuple[int] = (224, 448, 672, 896)"},{name:"layers_per_block",val:": int = 2"},{name:"mid_block_scale_factor",val:": float = 1"},{name:"downsample_padding",val:": int = 1"},{name:"downsample_type",val:": str = 'conv'"},{name:"upsample_type",val:": str = 'conv'"},{name:"dropout",val:": float = 0.0"},{name:"act_fn",val:": str = 'silu'"},{name:"attention_head_dim",val:": typing.Optional[int] = 8"},{name:"norm_num_groups",val:": int = 32"},{name:"attn_norm_num_groups",val:": typing.Optional[int] = None"},{name:"norm_eps",val:": float = 1e-05"},{name:"resnet_time_scale_shift",val:": str = 'default'"},{name:"add_attention",val:": bool = True"},{name:"class_embed_type",val:": typing.Optional[str] = None"},{name:"num_class_embeds",val:": typing.Optional[int] = None"},{name:"num_train_timesteps",val:": typing.Optional[int] = None"}],parametersDescription:[{anchor:"diffusers.UNet2DModel.sample_size",description:`<strong>sample_size</strong> (<code>int</code> or <code>Tuple[int, int]</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Height and width of input/output sample. Dimensions must be a multiple of <code>2 ** (len(block_out_channels) - 1)</code>.`,name:"sample_size"},{anchor:"diffusers.UNet2DModel.in_channels",description:"<strong>in_channels</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014; Number of channels in the input sample.",name:"in_channels"},{anchor:"diffusers.UNet2DModel.out_channels",description:"<strong>out_channels</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014; Number of channels in the output.",name:"out_channels"},{anchor:"diffusers.UNet2DModel.center_input_sample",description:"<strong>center_input_sample</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014; Whether to center the input sample.",name:"center_input_sample"},{anchor:"diffusers.UNet2DModel.time_embedding_type",description:"<strong>time_embedding_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;positional&quot;</code>) &#x2014; Type of time embedding to use.",name:"time_embedding_type"},{anchor:"diffusers.UNet2DModel.freq_shift",description:"<strong>freq_shift</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014; Frequency shift for Fourier time embedding.",name:"freq_shift"},{anchor:"diffusers.UNet2DModel.flip_sin_to_cos",description:`<strong>flip_sin_to_cos</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to flip sin to cos for Fourier time embedding.`,name:"flip_sin_to_cos"},{anchor:"diffusers.UNet2DModel.down_block_types",description:`<strong>down_block_types</strong> (<code>Tuple[str]</code>, <em>optional</em>, defaults to <code>(&quot;DownBlock2D&quot;, &quot;AttnDownBlock2D&quot;, &quot;AttnDownBlock2D&quot;, &quot;AttnDownBlock2D&quot;)</code>) &#x2014;
Tuple of downsample block types.`,name:"down_block_types"},{anchor:"diffusers.UNet2DModel.mid_block_type",description:`<strong>mid_block_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;UNetMidBlock2D&quot;</code>) &#x2014;
Block type for middle of UNet, it can be either <code>UNetMidBlock2D</code> or <code>UnCLIPUNetMidBlock2D</code>.`,name:"mid_block_type"},{anchor:"diffusers.UNet2DModel.up_block_types",description:`<strong>up_block_types</strong> (<code>Tuple[str]</code>, <em>optional</em>, defaults to <code>(&quot;AttnUpBlock2D&quot;, &quot;AttnUpBlock2D&quot;, &quot;AttnUpBlock2D&quot;, &quot;UpBlock2D&quot;)</code>) &#x2014;
Tuple of upsample block types.`,name:"up_block_types"},{anchor:"diffusers.UNet2DModel.block_out_channels",description:`<strong>block_out_channels</strong> (<code>Tuple[int]</code>, <em>optional</em>, defaults to <code>(224, 448, 672, 896)</code>) &#x2014;
Tuple of block output channels.`,name:"block_out_channels"},{anchor:"diffusers.UNet2DModel.layers_per_block",description:"<strong>layers_per_block</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2</code>) &#x2014; The number of layers per block.",name:"layers_per_block"},{anchor:"diffusers.UNet2DModel.mid_block_scale_factor",description:"<strong>mid_block_scale_factor</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1</code>) &#x2014; The scale factor for the mid block.",name:"mid_block_scale_factor"},{anchor:"diffusers.UNet2DModel.downsample_padding",description:"<strong>downsample_padding</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) &#x2014; The padding for the downsample convolution.",name:"downsample_padding"},{anchor:"diffusers.UNet2DModel.downsample_type",description:`<strong>downsample_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>conv</code>) &#x2014;
The downsample type for downsampling layers. Choose between &#x201C;conv&#x201D; and &#x201C;resnet&#x201D;`,name:"downsample_type"},{anchor:"diffusers.UNet2DModel.upsample_type",description:`<strong>upsample_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>conv</code>) &#x2014;
The upsample type for upsampling layers. Choose between &#x201C;conv&#x201D; and &#x201C;resnet&#x201D;`,name:"upsample_type"},{anchor:"diffusers.UNet2DModel.dropout",description:"<strong>dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014; The dropout probability to use.",name:"dropout"},{anchor:"diffusers.UNet2DModel.act_fn",description:"<strong>act_fn</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;silu&quot;</code>) &#x2014; The activation function to use.",name:"act_fn"},{anchor:"diffusers.UNet2DModel.attention_head_dim",description:"<strong>attention_head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>8</code>) &#x2014; The attention head dimension.",name:"attention_head_dim"},{anchor:"diffusers.UNet2DModel.norm_num_groups",description:"<strong>norm_num_groups</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) &#x2014; The number of groups for normalization.",name:"norm_num_groups"},{anchor:"diffusers.UNet2DModel.attn_norm_num_groups",description:`<strong>attn_norm_num_groups</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
If set to an integer, a group norm layer will be created in the mid block&#x2019;s <code>Attention</code> layer with the
given number of groups. If left as <code>None</code>, the group norm layer will only be created if
<code>resnet_time_scale_shift</code> is set to <code>default</code>, and if created will have <code>norm_num_groups</code> groups.`,name:"attn_norm_num_groups"},{anchor:"diffusers.UNet2DModel.norm_eps",description:"<strong>norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-5</code>) &#x2014; The epsilon for normalization.",name:"norm_eps"},{anchor:"diffusers.UNet2DModel.resnet_time_scale_shift",description:`<strong>resnet_time_scale_shift</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;default&quot;</code>) &#x2014; Time scale shift config
for ResNet blocks (see <code>ResnetBlock2D</code>). Choose from <code>default</code> or <code>scale_shift</code>.`,name:"resnet_time_scale_shift"},{anchor:"diffusers.UNet2DModel.class_embed_type",description:`<strong>class_embed_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
The type of class embedding to use which is ultimately summed with the time embeddings. Choose from <code>None</code>,
<code>&quot;timestep&quot;</code>, or <code>&quot;identity&quot;</code>.`,name:"class_embed_type"},{anchor:"diffusers.UNet2DModel.num_class_embeds",description:`<strong>num_class_embeds</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Input dimension of the learnable embedding matrix to be projected to <code>time_embed_dim</code> when performing class
conditioning with <code>class_embed_type</code> equal to <code>None</code>.`,name:"num_class_embeds"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/unet_2d.py#L40"}}),y=new oe({props:{name:"forward",anchor:"diffusers.UNet2DModel.forward",parameters:[{name:"sample",val:": FloatTensor"},{name:"timestep",val:": typing.Union[torch.Tensor, float, int]"},{name:"class_labels",val:": typing.Optional[torch.Tensor] = None"},{name:"return_dict",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.UNet2DModel.forward.sample",description:`<strong>sample</strong> (<code>torch.FloatTensor</code>) &#x2014;
The noisy input tensor with the following shape <code>(batch, channel, height, width)</code>.`,name:"sample"},{anchor:"diffusers.UNet2DModel.forward.timestep",description:"<strong>timestep</strong> (<code>torch.FloatTensor</code> or <code>float</code> or <code>int</code>) &#x2014; The number of timesteps to denoise an input.",name:"timestep"},{anchor:"diffusers.UNet2DModel.forward.class_labels",description:`<strong>class_labels</strong> (<code>torch.FloatTensor</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Optional class labels for conditioning. Their embeddings will be summed with the timestep embeddings.`,name:"class_labels"},{anchor:"diffusers.UNet2DModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.models.unet_2d.UNet2DOutput">UNet2DOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/unet_2d.py#L243",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>If <code>return_dict</code> is True, an <a
  href="/docs/diffusers/main/en/api/models/unet2d#diffusers.models.unet_2d.UNet2DOutput"
>UNet2DOutput</a> is returned, otherwise a <code>tuple</code> is
returned where the first element is the sample tensor.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/diffusers/main/en/api/models/unet2d#diffusers.models.unet_2d.UNet2DOutput"
>UNet2DOutput</a> or <code>tuple</code></p>
`}}),w=new ne({props:{title:"UNet2DOutput",local:"diffusers.models.unet_2d.UNet2DOutput",headingTag:"h2"}}),v=new oe({props:{name:"class diffusers.models.unet_2d.UNet2DOutput",anchor:"diffusers.models.unet_2d.UNet2DOutput",parameters:[{name:"sample",val:": FloatTensor"}],parametersDescription:[{anchor:"diffusers.models.unet_2d.UNet2DOutput.sample",description:`<strong>sample</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
The hidden states output from the last layer of the model.`,name:"sample"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/unet_2d.py#L28"}}),{c(){c=r("meta"),H=s(),A=r("p"),F=s(),M(f.$$.fragment),z=s(),h=r("p"),h.innerHTML=ae,E=s(),_=r("p"),_.textContent=ie,S=s(),g=r("p"),g.innerHTML=re,R=s(),M(b.$$.fragment),W=s(),i=r("div"),M(D.$$.fragment),X=s(),U=r("p"),U.textContent=de,Y=s(),x=r("p"),x.innerHTML=le,Z=s(),p=r("div"),M(y.$$.fragment),ee=s(),T=r("p"),T.innerHTML=ce,j=s(),M(w.$$.fragment),V=s(),m=r("div"),M(v.$$.fragment),te=s(),k=r("p"),k.innerHTML=me,G=s(),I=r("p"),this.h()},l(e){const o=ge("svelte-u9bgzb",document.head);c=d(o,"META",{name:!0,content:!0}),o.forEach(t),H=a(e),A=d(e,"P",{}),L(A).forEach(t),F=a(e),$(f.$$.fragment,e),z=a(e),h=d(e,"P",{"data-svelte-h":!0}),N(h)!=="svelte-19ccbr7"&&(h.innerHTML=ae),E=a(e),_=d(e,"P",{"data-svelte-h":!0}),N(_)!=="svelte-1cwsb16"&&(_.textContent=ie),S=a(e),g=d(e,"P",{"data-svelte-h":!0}),N(g)!=="svelte-12epiox"&&(g.innerHTML=re),R=a(e),$(b.$$.fragment,e),W=a(e),i=d(e,"DIV",{class:!0});var u=L(i);$(D.$$.fragment,u),X=a(u),U=d(u,"P",{"data-svelte-h":!0}),N(U)!=="svelte-1cto8u0"&&(U.textContent=de),Y=a(u),x=d(u,"P",{"data-svelte-h":!0}),N(x)!=="svelte-1hyu2ru"&&(x.innerHTML=le),Z=a(u),p=d(u,"DIV",{class:!0});var K=L(p);$(y.$$.fragment,K),ee=a(K),T=d(K,"P",{"data-svelte-h":!0}),N(T)!=="svelte-q0c6m1"&&(T.innerHTML=ce),K.forEach(t),u.forEach(t),j=a(e),$(w.$$.fragment,e),V=a(e),m=d(e,"DIV",{class:!0});var Q=L(m);$(v.$$.fragment,Q),te=a(Q),k=d(Q,"P",{"data-svelte-h":!0}),N(k)!=="svelte-14w6j91"&&(k.innerHTML=me),Q.forEach(t),G=a(e),I=d(e,"P",{}),L(I).forEach(t),this.h()},h(){P(c,"name","hf:doc:metadata"),P(c,"content",De),P(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),P(i,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),P(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,o){l(document.head,c),n(e,H,o),n(e,A,o),n(e,F,o),q(f,e,o),n(e,z,o),n(e,h,o),n(e,E,o),n(e,_,o),n(e,S,o),n(e,g,o),n(e,R,o),q(b,e,o),n(e,W,o),n(e,i,o),q(D,i,null),l(i,X),l(i,U),l(i,Y),l(i,x),l(i,Z),l(i,p),q(y,p,null),l(p,ee),l(p,T),n(e,j,o),q(w,e,o),n(e,V,o),n(e,m,o),q(v,m,null),l(m,te),l(m,k),n(e,G,o),n(e,I,o),J=!0},p:ue,i(e){J||(C(f.$$.fragment,e),C(b.$$.fragment,e),C(D.$$.fragment,e),C(y.$$.fragment,e),C(w.$$.fragment,e),C(v.$$.fragment,e),J=!0)},o(e){B(f.$$.fragment,e),B(b.$$.fragment,e),B(D.$$.fragment,e),B(y.$$.fragment,e),B(w.$$.fragment,e),B(v.$$.fragment,e),J=!1},d(e){e&&(t(H),t(A),t(F),t(z),t(h),t(E),t(_),t(S),t(g),t(R),t(W),t(i),t(j),t(V),t(m),t(G),t(I)),t(c),O(f,e),O(b,e),O(D),O(y),O(w,e),O(v)}}}const De='{"title":"UNet2DModel","local":"unet2dmodel","sections":[{"title":"UNet2DModel","local":"diffusers.UNet2DModel","sections":[],"depth":2},{"title":"UNet2DOutput","local":"diffusers.models.unet_2d.UNet2DOutput","sections":[],"depth":2}],"depth":1}';function ye(se){return fe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xe extends he{constructor(c){super(),_e(this,c,ye,be,pe,{})}}export{xe as component};
