import{s as fe,n as he,o as _e}from"../chunks/scheduler.8c3d61f6.js";import{S as ge,i as be,g as d,s,r as y,A as De,h as i,f as o,c as a,j as P,u as x,x as k,k as H,y as l,a as n,v as T,d as M,t as $,w as q}from"../chunks/index.589a98e8.js";import{D as se}from"../chunks/Docstring.27406313.js";import{H as ae,E as we}from"../chunks/EditOnGithub.e5a8d9cb.js";function ve(re){let c,z,I,E,f,S,h,de='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,_,ie="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/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).`,te,u,w,oe,O,ue='The <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a> forward method.',V,v,G,m,N,ne,A,pe='The output of <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>.',J,U,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:": Union = 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:": Tuple = ('DownBlock2D', 'AttnDownBlock2D', 'AttnDownBlock2D', 'AttnDownBlock2D')"},{name:"up_block_types",val:": Tuple = ('AttnUpBlock2D', 'AttnUpBlock2D', 'AttnUpBlock2D', 'UpBlock2D')"},{name:"block_out_channels",val:": Tuple = (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:": Optional = 8"},{name:"norm_num_groups",val:": int = 32"},{name:"attn_norm_num_groups",val:": Optional = 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:": Optional = None"},{name:"num_class_embeds",val:": Optional = None"},{name:"num_train_timesteps",val:": Optional = 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/unets/unet_2d.py#L40"}}),w=new se({props:{name:"forward",anchor:"diffusers.UNet2DModel.forward",parameters:[{name:"sample",val:": Tensor"},{name:"timestep",val:": Union"},{name:"class_labels",val:": Optional = 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/main/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/main/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/main/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/main/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"}}),N=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/main/src/diffusers/models/unets/unet_2d.py#L27"}}),U=new we({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/unet2d.md"}}),{c(){c=d("meta"),z=s(),I=d("p"),E=s(),y(f.$$.fragment),S=s(),h=d("p"),h.innerHTML=de,F=s(),_=d("p"),_.textContent=ie,R=s(),g=d("p"),g.innerHTML=le,W=s(),y(b.$$.fragment),j=s(),r=d("div"),y(D.$$.fragment),Z=s(),C=d("p"),C.textContent=ce,ee=s(),B=d("p"),B.innerHTML=me,te=s(),u=d("div"),y(w.$$.fragment),oe=s(),O=d("p"),O.innerHTML=ue,V=s(),y(v.$$.fragment),G=s(),m=d("div"),y(N.$$.fragment),ne=s(),A=d("p"),A.innerHTML=pe,J=s(),y(U.$$.fragment),K=s(),L=d("p"),this.h()},l(e){const t=De("svelte-u9bgzb",document.head);c=i(t,"META",{name:!0,content:!0}),t.forEach(o),z=a(e),I=i(e,"P",{}),P(I).forEach(o),E=a(e),x(f.$$.fragment,e),S=a(e),h=i(e,"P",{"data-svelte-h":!0}),k(h)!=="svelte-19ccbr7"&&(h.innerHTML=de),F=a(e),_=i(e,"P",{"data-svelte-h":!0}),k(_)!=="svelte-1cwsb16"&&(_.textContent=ie),R=a(e),g=i(e,"P",{"data-svelte-h":!0}),k(g)!=="svelte-12epiox"&&(g.innerHTML=le),W=a(e),x(b.$$.fragment,e),j=a(e),r=i(e,"DIV",{class:!0});var p=P(r);x(D.$$.fragment,p),Z=a(p),C=i(p,"P",{"data-svelte-h":!0}),k(C)!=="svelte-1cto8u0"&&(C.textContent=ce),ee=a(p),B=i(p,"P",{"data-svelte-h":!0}),k(B)!=="svelte-1hyu2ru"&&(B.innerHTML=me),te=a(p),u=i(p,"DIV",{class:!0});var X=P(u);x(w.$$.fragment,X),oe=a(X),O=i(X,"P",{"data-svelte-h":!0}),k(O)!=="svelte-q0c6m1"&&(O.innerHTML=ue),X.forEach(o),p.forEach(o),V=a(e),x(v.$$.fragment,e),G=a(e),m=i(e,"DIV",{class:!0});var Y=P(m);x(N.$$.fragment,Y),ne=a(Y),A=i(Y,"P",{"data-svelte-h":!0}),k(A)!=="svelte-14w6j91"&&(A.innerHTML=pe),Y.forEach(o),J=a(e),x(U.$$.fragment,e),K=a(e),L=i(e,"P",{}),P(L).forEach(o),this.h()},h(){H(c,"name","hf:doc:metadata"),H(c,"content",Ne),H(u,"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,h,t),n(e,F,t),n(e,_,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,u),T(w,u,null),l(u,oe),l(u,O),n(e,V,t),T(v,e,t),n(e,G,t),n(e,m,t),T(N,m,null),l(m,ne),l(m,A),n(e,J,t),T(U,e,t),n(e,K,t),n(e,L,t),Q=!0},p:he,i(e){Q||(M(f.$$.fragment,e),M(b.$$.fragment,e),M(D.$$.fragment,e),M(w.$$.fragment,e),M(v.$$.fragment,e),M(N.$$.fragment,e),M(U.$$.fragment,e),Q=!0)},o(e){$(f.$$.fragment,e),$(b.$$.fragment,e),$(D.$$.fragment,e),$(w.$$.fragment,e),$(v.$$.fragment,e),$(N.$$.fragment,e),$(U.$$.fragment,e),Q=!1},d(e){e&&(o(z),o(I),o(E),o(S),o(h),o(F),o(_),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(w),q(v,e),q(N),q(U,e)}}}const Ne='{"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 Ue(re){return _e(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Me extends ge{constructor(c){super(),be(this,c,Ue,ve,fe,{})}}export{Me as component};
