import{s as fe,n as _e,o as he}from"../chunks/scheduler.8c3d61f6.js";import{S as ge,i as be,g as i,s,r as U,A as De,h as d,f as o,c as a,j as P,u as k,x,k as H,y as l,a as n,v as T,d as M,t as $,w as q}from"../chunks/index.da70eac4.js";import{D as se}from"../chunks/Docstring.6b390b9a.js";import{H as ae,E as ye}from"../chunks/EditOnGithub.1e64e623.js";function ve(re){let c,z,I,E,f,S,_,ie='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.',F,h,de="The abstract from the paper is:",R,g,le='<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>',W,b,j,r,D,Z,C,ce="A 2D UNet model that takes a noisy sample and a timestep and returns a sample shaped output.",ee,B,me=`This model inherits from <a href="/docs/diffusers/pr_10126/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).`,te,p,y,oe,O,pe='The <a href="/docs/diffusers/pr_10126/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a> forward method.',V,v,G,m,w,ne,A,ue='The output of <a href="/docs/diffusers/pr_10126/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>.',J,N,K,L,Q;return f=new ae({props:{title:"UNet2DModel",local:"unet2dmodel",headingTag:"h1"}}),b=new ae({props:{title:"UNet2DModel",local:"diffusers.UNet2DModel",headingTag:"h2"}}),D=new se({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/vr_10126/src/diffusers/models/unets/unet_2d.py#L40"}}),y=new se({props:{name:"forward",anchor:"diffusers.UNet2DModel.forward",parameters:[{name:"sample",val:": Tensor"},{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.Tensor</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.Tensor</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.Tensor</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/pr_10126/en/api/models/unet2d#diffusers.models.unets.unet_2d.UNet2DOutput">UNet2DOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/diffusers/blob/vr_10126/src/diffusers/models/unets/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/pr_10126/en/api/models/unet2d#diffusers.models.unets.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/pr_10126/en/api/models/unet2d#diffusers.models.unets.unet_2d.UNet2DOutput"
>UNet2DOutput</a> or <code>tuple</code></p>
`}}),v=new ae({props:{title:"UNet2DOutput",local:"diffusers.models.unets.unet_2d.UNet2DOutput",headingTag:"h2"}}),w=new se({props:{name:"class diffusers.models.unets.unet_2d.UNet2DOutput",anchor:"diffusers.models.unets.unet_2d.UNet2DOutput",parameters:[{name:"sample",val:": Tensor"}],parametersDescription:[{anchor:"diffusers.models.unets.unet_2d.UNet2DOutput.sample",description:`<strong>sample</strong> (<code>torch.Tensor</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/vr_10126/src/diffusers/models/unets/unet_2d.py#L27"}}),N=new ye({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/unet2d.md"}}),{c(){c=i("meta"),z=s(),I=i("p"),E=s(),U(f.$$.fragment),S=s(),_=i("p"),_.innerHTML=ie,F=s(),h=i("p"),h.textContent=de,R=s(),g=i("p"),g.innerHTML=le,W=s(),U(b.$$.fragment),j=s(),r=i("div"),U(D.$$.fragment),Z=s(),C=i("p"),C.textContent=ce,ee=s(),B=i("p"),B.innerHTML=me,te=s(),p=i("div"),U(y.$$.fragment),oe=s(),O=i("p"),O.innerHTML=pe,V=s(),U(v.$$.fragment),G=s(),m=i("div"),U(w.$$.fragment),ne=s(),A=i("p"),A.innerHTML=ue,J=s(),U(N.$$.fragment),K=s(),L=i("p"),this.h()},l(e){const t=De("svelte-u9bgzb",document.head);c=d(t,"META",{name:!0,content:!0}),t.forEach(o),z=a(e),I=d(e,"P",{}),P(I).forEach(o),E=a(e),k(f.$$.fragment,e),S=a(e),_=d(e,"P",{"data-svelte-h":!0}),x(_)!=="svelte-19ccbr7"&&(_.innerHTML=ie),F=a(e),h=d(e,"P",{"data-svelte-h":!0}),x(h)!=="svelte-1cwsb16"&&(h.textContent=de),R=a(e),g=d(e,"P",{"data-svelte-h":!0}),x(g)!=="svelte-12epiox"&&(g.innerHTML=le),W=a(e),k(b.$$.fragment,e),j=a(e),r=d(e,"DIV",{class:!0});var u=P(r);k(D.$$.fragment,u),Z=a(u),C=d(u,"P",{"data-svelte-h":!0}),x(C)!=="svelte-1cto8u0"&&(C.textContent=ce),ee=a(u),B=d(u,"P",{"data-svelte-h":!0}),x(B)!=="svelte-1nohfiu"&&(B.innerHTML=me),te=a(u),p=d(u,"DIV",{class:!0});var X=P(p);k(y.$$.fragment,X),oe=a(X),O=d(X,"P",{"data-svelte-h":!0}),x(O)!=="svelte-3idk71"&&(O.innerHTML=pe),X.forEach(o),u.forEach(o),V=a(e),k(v.$$.fragment,e),G=a(e),m=d(e,"DIV",{class:!0});var Y=P(m);k(w.$$.fragment,Y),ne=a(Y),A=d(Y,"P",{"data-svelte-h":!0}),x(A)!=="svelte-mah6j1"&&(A.innerHTML=ue),Y.forEach(o),J=a(e),k(N.$$.fragment,e),K=a(e),L=d(e,"P",{}),P(L).forEach(o),this.h()},h(){H(c,"name","hf:doc:metadata"),H(c,"content",we),H(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(r,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(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,t){l(document.head,c),n(e,z,t),n(e,I,t),n(e,E,t),T(f,e,t),n(e,S,t),n(e,_,t),n(e,F,t),n(e,h,t),n(e,R,t),n(e,g,t),n(e,W,t),T(b,e,t),n(e,j,t),n(e,r,t),T(D,r,null),l(r,Z),l(r,C),l(r,ee),l(r,B),l(r,te),l(r,p),T(y,p,null),l(p,oe),l(p,O),n(e,V,t),T(v,e,t),n(e,G,t),n(e,m,t),T(w,m,null),l(m,ne),l(m,A),n(e,J,t),T(N,e,t),n(e,K,t),n(e,L,t),Q=!0},p:_e,i(e){Q||(M(f.$$.fragment,e),M(b.$$.fragment,e),M(D.$$.fragment,e),M(y.$$.fragment,e),M(v.$$.fragment,e),M(w.$$.fragment,e),M(N.$$.fragment,e),Q=!0)},o(e){$(f.$$.fragment,e),$(b.$$.fragment,e),$(D.$$.fragment,e),$(y.$$.fragment,e),$(v.$$.fragment,e),$(w.$$.fragment,e),$(N.$$.fragment,e),Q=!1},d(e){e&&(o(z),o(I),o(E),o(S),o(_),o(F),o(h),o(R),o(g),o(W),o(j),o(r),o(V),o(G),o(m),o(J),o(K),o(L)),o(c),q(f,e),q(b,e),q(D),q(y),q(v,e),q(w),q(N,e)}}}const we='{"title":"UNet2DModel","local":"unet2dmodel","sections":[{"title":"UNet2DModel","local":"diffusers.UNet2DModel","sections":[],"depth":2},{"title":"UNet2DOutput","local":"diffusers.models.unets.unet_2d.UNet2DOutput","sections":[],"depth":2}],"depth":1}';function Ne(re){return he(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Me extends ge{constructor(c){super(),be(this,c,Ne,ve,fe,{})}}export{Me as component};
