import{s as he,n as ge,o as be}from"../chunks/scheduler.53228c21.js";import{S as De,i as ye,e as r,s,c as f,h as we,a as d,d as o,b as a,f as H,g as _,j as C,k as z,l,m as n,n as h,t as g,o as b,p as D}from"../chunks/index.100fac89.js";import{C as ve}from"../chunks/CopyLLMTxtMenu.2cdbb51f.js";import{D as ie}from"../chunks/Docstring.d46840f1.js";import{H as re,E as Ne}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.3fcbbc76.js";function Ue(de){let c,E,I,S,y,F,w,R,v,le='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.',W,N,ce="The abstract from the paper is:",j,U,me='<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>',V,x,G,i,T,te,B,pe="A 2D UNet model that takes a noisy sample and a timestep and returns a sample shaped output.",oe,O,ue=`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).`,ne,p,k,se,L,fe='The <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a> forward method.',J,$,K,m,M,ae,A,_e='The output of <a href="/docs/diffusers/main/en/api/models/unet2d#diffusers.UNet2DModel">UNet2DModel</a>.',Q,q,X,P,Y;return y=new ve({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),w=new re({props:{title:"UNet2DModel",local:"unet2dmodel",headingTag:"h1"}}),x=new re({props:{title:"UNet2DModel",local:"diffusers.UNet2DModel",headingTag:"h2"}}),T=new ie({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:"time_embedding_dim",val:": typing.Optional[int] = None"},{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:"mid_block_type",val:": typing.Optional[str] = 'UNetMidBlock2D'"},{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>None</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"}}),k=new ie({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/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#L250",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>
`}}),$=new re({props:{title:"UNet2DOutput",local:"diffusers.models.unets.unet_2d.UNet2DOutput",headingTag:"h2"}}),M=new ie({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#L28"}}),q=new Ne({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/models/unet2d.md"}}),{c(){c=r("meta"),E=s(),I=r("p"),S=s(),f(y.$$.fragment),F=s(),f(w.$$.fragment),R=s(),v=r("p"),v.innerHTML=le,W=s(),N=r("p"),N.textContent=ce,j=s(),U=r("p"),U.innerHTML=me,V=s(),f(x.$$.fragment),G=s(),i=r("div"),f(T.$$.fragment),te=s(),B=r("p"),B.textContent=pe,oe=s(),O=r("p"),O.innerHTML=ue,ne=s(),p=r("div"),f(k.$$.fragment),se=s(),L=r("p"),L.innerHTML=fe,J=s(),f($.$$.fragment),K=s(),m=r("div"),f(M.$$.fragment),ae=s(),A=r("p"),A.innerHTML=_e,Q=s(),f(q.$$.fragment),X=s(),P=r("p"),this.h()},l(e){const t=we("svelte-u9bgzb",document.head);c=d(t,"META",{name:!0,content:!0}),t.forEach(o),E=a(e),I=d(e,"P",{}),H(I).forEach(o),S=a(e),_(y.$$.fragment,e),F=a(e),_(w.$$.fragment,e),R=a(e),v=d(e,"P",{"data-svelte-h":!0}),C(v)!=="svelte-19ccbr7"&&(v.innerHTML=le),W=a(e),N=d(e,"P",{"data-svelte-h":!0}),C(N)!=="svelte-1cwsb16"&&(N.textContent=ce),j=a(e),U=d(e,"P",{"data-svelte-h":!0}),C(U)!=="svelte-12epiox"&&(U.innerHTML=me),V=a(e),_(x.$$.fragment,e),G=a(e),i=d(e,"DIV",{class:!0});var u=H(i);_(T.$$.fragment,u),te=a(u),B=d(u,"P",{"data-svelte-h":!0}),C(B)!=="svelte-1cto8u0"&&(B.textContent=pe),oe=a(u),O=d(u,"P",{"data-svelte-h":!0}),C(O)!=="svelte-1hyu2ru"&&(O.innerHTML=ue),ne=a(u),p=d(u,"DIV",{class:!0});var Z=H(p);_(k.$$.fragment,Z),se=a(Z),L=d(Z,"P",{"data-svelte-h":!0}),C(L)!=="svelte-q0c6m1"&&(L.innerHTML=fe),Z.forEach(o),u.forEach(o),J=a(e),_($.$$.fragment,e),K=a(e),m=d(e,"DIV",{class:!0});var ee=H(m);_(M.$$.fragment,ee),ae=a(ee),A=d(ee,"P",{"data-svelte-h":!0}),C(A)!=="svelte-14w6j91"&&(A.innerHTML=_e),ee.forEach(o),Q=a(e),_(q.$$.fragment,e),X=a(e),P=d(e,"P",{}),H(P).forEach(o),this.h()},h(){z(c,"name","hf:doc:metadata"),z(c,"content",xe),z(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),z(i,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),z(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,E,t),n(e,I,t),n(e,S,t),h(y,e,t),n(e,F,t),h(w,e,t),n(e,R,t),n(e,v,t),n(e,W,t),n(e,N,t),n(e,j,t),n(e,U,t),n(e,V,t),h(x,e,t),n(e,G,t),n(e,i,t),h(T,i,null),l(i,te),l(i,B),l(i,oe),l(i,O),l(i,ne),l(i,p),h(k,p,null),l(p,se),l(p,L),n(e,J,t),h($,e,t),n(e,K,t),n(e,m,t),h(M,m,null),l(m,ae),l(m,A),n(e,Q,t),h(q,e,t),n(e,X,t),n(e,P,t),Y=!0},p:ge,i(e){Y||(g(y.$$.fragment,e),g(w.$$.fragment,e),g(x.$$.fragment,e),g(T.$$.fragment,e),g(k.$$.fragment,e),g($.$$.fragment,e),g(M.$$.fragment,e),g(q.$$.fragment,e),Y=!0)},o(e){b(y.$$.fragment,e),b(w.$$.fragment,e),b(x.$$.fragment,e),b(T.$$.fragment,e),b(k.$$.fragment,e),b($.$$.fragment,e),b(M.$$.fragment,e),b(q.$$.fragment,e),Y=!1},d(e){e&&(o(E),o(I),o(S),o(F),o(R),o(v),o(W),o(N),o(j),o(U),o(V),o(G),o(i),o(J),o(K),o(m),o(Q),o(X),o(P)),o(c),D(y,e),D(w,e),D(x,e),D(T),D(k),D($,e),D(M),D(q,e)}}}const xe='{"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 Te(de){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Be extends De{constructor(c){super(),ye(this,c,Te,Ue,he,{})}}export{Be as component};
