import{S as wo,i as yo,s as Vo,e as n,k as p,w as V,t as i,M as $o,c as a,d as o,m as u,a as r,x as $,h as l,b as d,G as t,g as h,y as T,q as M,o as D,B as k,v as To,L as bo}from"../../chunks/vendor-hf-doc-builder.js";import{T as Mo}from"../../chunks/Tip-hf-doc-builder.js";import{D as Ft}from"../../chunks/Docstring-hf-doc-builder.js";import{C as vo}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as He}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as _o}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Do(A){let m,v,g,f,b;return f=new vo({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFZpdERldENvbmZpZyUyQyUyMFZpdERldE1vZGVsJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMFZpdERldCUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwVml0RGV0Q29uZmlnKCklMEElMEElMjMlMjBJbml0aWFsaXppbmclMjBhJTIwbW9kZWwlMjAod2l0aCUyMHJhbmRvbSUyMHdlaWdodHMpJTIwZnJvbSUyMHRoZSUyMGNvbmZpZ3VyYXRpb24lMEFtb2RlbCUyMCUzRCUyMFZpdERldE1vZGVsKGNvbmZpZ3VyYXRpb24pJTBBJTBBJTIzJTIwQWNjZXNzaW5nJTIwdGhlJTIwbW9kZWwlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMG1vZGVsLmNvbmZpZw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> VitDetConfig, VitDetModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a VitDet configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = VitDetConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VitDetModel(configuration)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`}}),{c(){m=n("p"),v=i("Example:"),g=p(),V(f.$$.fragment)},l(s){m=a(s,"P",{});var _=r(m);v=l(_,"Example:"),_.forEach(o),g=u(s),$(f.$$.fragment,s)},m(s,_){h(s,m,_),t(m,v),h(s,g,_),T(f,s,_),b=!0},p:bo,i(s){b||(M(f.$$.fragment,s),b=!0)},o(s){D(f.$$.fragment,s),b=!1},d(s){s&&o(m),s&&o(g),k(f,s)}}}function ko(A){let m,v,g,f,b;return{c(){m=n("p"),v=i("Although the recipe for forward pass needs to be defined within this function, one should call the "),g=n("code"),f=i("Module"),b=i(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(s){m=a(s,"P",{});var _=r(m);v=l(_,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(_,"CODE",{});var J=r(g);f=l(J,"Module"),J.forEach(o),b=l(_,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),_.forEach(o)},m(s,_){h(s,m,_),t(m,v),t(m,g),t(g,f),t(m,b)},d(s){s&&o(m)}}}function Eo(A){let m,v,g,f,b;return f=new vo({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFZpdERldENvbmZpZyUyQyUyMFZpdERldE1vZGVsJTBBaW1wb3J0JTIwdG9yY2glMEElMEFjb25maWclMjAlM0QlMjBWaXREZXRDb25maWcoKSUwQW1vZGVsJTIwJTNEJTIwVml0RGV0TW9kZWwoY29uZmlnKSUwQSUwQXBpeGVsX3ZhbHVlcyUyMCUzRCUyMHRvcmNoLnJhbmRuKDElMkMlMjAzJTJDJTIwMjI0JTJDJTIwMjI0KSUwQSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwocGl4ZWxfdmFsdWVzKSUwQSUwQWxhc3RfaGlkZGVuX3N0YXRlcyUyMCUzRCUyMG91dHB1dHMubGFzdF9oaWRkZW5fc3RhdGUlMEFsaXN0KGxhc3RfaGlkZGVuX3N0YXRlcy5zaGFwZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> VitDetConfig, VitDetModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>config = VitDetConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VitDetModel(config)

<span class="hljs-meta">&gt;&gt;&gt; </span>pixel_values = torch.randn(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">224</span>, <span class="hljs-number">224</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(pixel_values)

<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">list</span>(last_hidden_states.shape)
[<span class="hljs-number">1</span>, <span class="hljs-number">768</span>, <span class="hljs-number">14</span>, <span class="hljs-number">14</span>]`}}),{c(){m=n("p"),v=i("Examples:"),g=p(),V(f.$$.fragment)},l(s){m=a(s,"P",{});var _=r(m);v=l(_,"Examples:"),_.forEach(o),g=u(s),$(f.$$.fragment,s)},m(s,_){h(s,m,_),t(m,v),h(s,g,_),T(f,s,_),b=!0},p:bo,i(s){b||(M(f.$$.fragment,s),b=!0)},o(s){D(f.$$.fragment,s),b=!1},d(s){s&&o(m),s&&o(g),k(f,s)}}}function Co(A){let m,v,g,f,b,s,_,J,Le,ze,j,U,ye,O,Xe,Ve,Ke,Pe,C,Ye,H,Qe,et,se,tt,ot,We,ie,nt,Ie,le,$e,at,Ze,de,rt,Ae,ce,Te,st,Je,x,it,L,lt,dt,X,ct,mt,Ue,z,R,Me,K,ht,De,ft,Re,w,Y,pt,P,ut,me,gt,_t,Q,bt,vt,wt,W,yt,he,Vt,$t,fe,Tt,Mt,Dt,N,Ne,I,F,ke,ee,kt,Ee,Et,Fe,E,te,Ct,oe,xt,ne,jt,zt,Pt,y,ae,Wt,Z,It,pe,Zt,At,Ce,Jt,Ut,Rt,G,Nt,S,Ge;return s=new He({}),O=new He({}),K=new He({}),Y=new Ft({props:{name:"class transformers.VitDetConfig",anchor:"transformers.VitDetConfig",parameters:[{name:"hidden_size",val:" = 768"},{name:"num_hidden_layers",val:" = 12"},{name:"num_attention_heads",val:" = 12"},{name:"mlp_ratio",val:" = 4"},{name:"hidden_act",val:" = 'gelu'"},{name:"dropout_prob",val:" = 0.0"},{name:"initializer_range",val:" = 0.02"},{name:"layer_norm_eps",val:" = 1e-06"},{name:"image_size",val:" = 224"},{name:"pretrain_image_size",val:" = 224"},{name:"patch_size",val:" = 16"},{name:"num_channels",val:" = 3"},{name:"qkv_bias",val:" = True"},{name:"drop_path_rate",val:" = 0.0"},{name:"window_block_indices",val:" = []"},{name:"residual_block_indices",val:" = []"},{name:"use_absolute_position_embeddings",val:" = True"},{name:"use_relative_position_embeddings",val:" = False"},{name:"window_size",val:" = 0"},{name:"out_features",val:" = None"},{name:"out_indices",val:" = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.VitDetConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 768) &#x2014;
Dimensionality of the encoder layers and the pooler layer.`,name:"hidden_size"},{anchor:"transformers.VitDetConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of hidden layers in the Transformer encoder.`,name:"num_hidden_layers"},{anchor:"transformers.VitDetConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"num_attention_heads"},{anchor:"transformers.VitDetConfig.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Ratio of mlp hidden dim to embedding dim.`,name:"mlp_ratio"},{anchor:"transformers.VitDetConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code> or <code>function</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the encoder and pooler. If string, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;selu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"hidden_act"},{anchor:"transformers.VitDetConfig.dropout_prob",description:`<strong>dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"dropout_prob"},{anchor:"transformers.VitDetConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.VitDetConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-6) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.VitDetConfig.image_size",description:`<strong>image_size</strong> (<code>int</code>, <em>optional</em>, defaults to 224) &#x2014;
The size (resolution) of each image.`,name:"image_size"},{anchor:"transformers.VitDetConfig.pretrain_image_size",description:`<strong>pretrain_image_size</strong> (<code>int</code>, <em>optional</em>, defaults to 224) &#x2014;
The size (resolution) of each image during pretraining.`,name:"pretrain_image_size"},{anchor:"transformers.VitDetConfig.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.VitDetConfig.num_channels",description:`<strong>num_channels</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014;
The number of input channels.`,name:"num_channels"},{anchor:"transformers.VitDetConfig.qkv_bias",description:`<strong>qkv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to add a bias to the queries, keys and values.`,name:"qkv_bias"},{anchor:"transformers.VitDetConfig.drop_path_rate",description:`<strong>drop_path_rate</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Stochastic depth rate.`,name:"drop_path_rate"},{anchor:"transformers.VitDetConfig.window_block_indices",description:`<strong>window_block_indices</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
List of indices of blocks that should have window attention instead of regular global self-attention.`,name:"window_block_indices"},{anchor:"transformers.VitDetConfig.residual_block_indices",description:`<strong>residual_block_indices</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
List of indices of blocks that should have an extra residual block after the MLP.`,name:"residual_block_indices"},{anchor:"transformers.VitDetConfig.use_absolute_position_embeddings",description:`<strong>use_absolute_position_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to add absolute position embeddings to the patch embeddings.`,name:"use_absolute_position_embeddings"},{anchor:"transformers.VitDetConfig.use_relative_position_embeddings",description:`<strong>use_relative_position_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to add relative position embeddings to the attention maps.`,name:"use_relative_position_embeddings"},{anchor:"transformers.VitDetConfig.window_size",description:`<strong>window_size</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
The size of the attention window.`,name:"window_size"},{anchor:"transformers.VitDetConfig.out_features",description:`<strong>out_features</strong> (<code>List[str]</code>, <em>optional</em>) &#x2014;
If used as backbone, list of features to output. Can be any of <code>&quot;stem&quot;</code>, <code>&quot;stage1&quot;</code>, <code>&quot;stage2&quot;</code>, etc.
(depending on how many stages the model has). If unset and <code>out_indices</code> is set, will default to the
corresponding stages. If unset and <code>out_indices</code> is unset, will default to the last stage.`,name:"out_features"},{anchor:"transformers.VitDetConfig.out_indices",description:`<strong>out_indices</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
If used as backbone, list of indices of features to output. Can be any of 0, 1, 2, etc. (depending on how
many stages the model has). If unset and <code>out_features</code> is set, will default to the corresponding stages.
If unset and <code>out_features</code> is unset, will default to the last stage.`,name:"out_indices"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vitdet/configuration_vitdet.py#L30"}}),N=new _o({props:{anchor:"transformers.VitDetConfig.example",$$slots:{default:[Do]},$$scope:{ctx:A}}}),ee=new He({}),te=new Ft({props:{name:"class transformers.VitDetModel",anchor:"transformers.VitDetModel",parameters:[{name:"config",val:": VitDetConfig"}],parametersDescription:[{anchor:"transformers.VitDetModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/vitdet#transformers.VitDetConfig">VitDetConfig</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vitdet/modeling_vitdet.py#L712"}}),ae=new Ft({props:{name:"forward",anchor:"transformers.VitDetModel.forward",parameters:[{name:"pixel_values",val:": typing.Optional[torch.Tensor] = None"},{name:"head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.VitDetModel.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
Pixel values. Pixel values can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoImageProcessor">AutoImageProcessor</a>. See <a href="/docs/transformers/main/en/model_doc/mobilevit#transformers.MobileViTFeatureExtractor.__call__">ViTImageProcessor.<strong>call</strong>()</a>
for details.`,name:"pixel_values"},{anchor:"transformers.VitDetModel.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.VitDetModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.VitDetModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.VitDetModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/main/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/vitdet/modeling_vitdet.py#L734",returnDescription:`
<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.BaseModelOutput"
>transformers.modeling_outputs.BaseModelOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/main/en/model_doc/vitdet#transformers.VitDetConfig"
>VitDetConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) \u2014 Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.BaseModelOutput"
>transformers.modeling_outputs.BaseModelOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),G=new Mo({props:{$$slots:{default:[ko]},$$scope:{ctx:A}}}),S=new _o({props:{anchor:"transformers.VitDetModel.forward.example",$$slots:{default:[Eo]},$$scope:{ctx:A}}}),{c(){m=n("meta"),v=p(),g=n("h1"),f=n("a"),b=n("span"),V(s.$$.fragment),_=p(),J=n("span"),Le=i("ViTDet"),ze=p(),j=n("h2"),U=n("a"),ye=n("span"),V(O.$$.fragment),Xe=p(),Ve=n("span"),Ke=i("Overview"),Pe=p(),C=n("p"),Ye=i("The ViTDet model was proposed in "),H=n("a"),Qe=i("Exploring Plain Vision Transformer Backbones for Object Detection"),et=i(` by Yanghao Li, Hanzi Mao, Ross Girshick, Kaiming He.
VitDet leverages the plain `),se=n("a"),tt=i("Vision Transformer"),ot=i(" for the task of object detection."),We=p(),ie=n("p"),nt=i("The abstract from the paper is the following:"),Ie=p(),le=n("p"),$e=n("em"),at=i("We explore the plain, non-hierarchical Vision Transformer (ViT) as a backbone network for object detection. This design enables the original ViT architecture to be fine-tuned for object detection without needing to redesign a hierarchical backbone for pre-training. With minimal adaptations for fine-tuning, our plain-backbone detector can achieve competitive results. Surprisingly, we observe: (i) it is sufficient to build a simple feature pyramid from a single-scale feature map (without the common FPN design) and (ii) it is sufficient to use window attention (without shifting) aided with very few cross-window propagation blocks. With plain ViT backbones pre-trained as Masked Autoencoders (MAE), our detector, named ViTDet, can compete with the previous leading methods that were all based on hierarchical backbones, reaching up to 61.3 AP_box on the COCO dataset using only ImageNet-1K pre-training. We hope our study will draw attention to research on plain-backbone detectors."),Ze=p(),de=n("p"),rt=i("Tips:"),Ae=p(),ce=n("ul"),Te=n("li"),st=i("For the moment, only the backbone is available."),Je=p(),x=n("p"),it=i("This model was contributed by "),L=n("a"),lt=i("nielsr"),dt=i(`.
The original code can be found `),X=n("a"),ct=i("here"),mt=i("."),Ue=p(),z=n("h2"),R=n("a"),Me=n("span"),V(K.$$.fragment),ht=p(),De=n("span"),ft=i("VitDetConfig"),Re=p(),w=n("div"),V(Y.$$.fragment),pt=p(),P=n("p"),ut=i("This is the configuration class to store the configuration of a "),me=n("a"),gt=i("VitDetModel"),_t=i(`. It is used to instantiate an
VitDet model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the VitDet
`),Q=n("a"),bt=i("google/vitdet-base-patch16-224"),vt=i(" architecture."),wt=p(),W=n("p"),yt=i("Configuration objects inherit from "),he=n("a"),Vt=i("PretrainedConfig"),$t=i(` and can be used to control the model outputs. Read the
documentation from `),fe=n("a"),Tt=i("PretrainedConfig"),Mt=i(" for more information."),Dt=p(),V(N.$$.fragment),Ne=p(),I=n("h2"),F=n("a"),ke=n("span"),V(ee.$$.fragment),kt=p(),Ee=n("span"),Et=i("VitDetModel"),Fe=p(),E=n("div"),V(te.$$.fragment),Ct=p(),oe=n("p"),xt=i(`The bare VitDet Transformer model outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ne=n("a"),jt=i("torch.nn.Module"),zt=i(` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),Pt=p(),y=n("div"),V(ae.$$.fragment),Wt=p(),Z=n("p"),It=i("The "),pe=n("a"),Zt=i("VitDetModel"),At=i(" forward method, overrides the "),Ce=n("code"),Jt=i("__call__"),Ut=i(" special method."),Rt=p(),V(G.$$.fragment),Nt=p(),V(S.$$.fragment),this.h()},l(e){const c=$o('[data-svelte="svelte-1phssyn"]',document.head);m=a(c,"META",{name:!0,content:!0}),c.forEach(o),v=u(e),g=a(e,"H1",{class:!0});var re=r(g);f=a(re,"A",{id:!0,class:!0,href:!0});var xe=r(f);b=a(xe,"SPAN",{});var je=r(b);$(s.$$.fragment,je),je.forEach(o),xe.forEach(o),_=u(re),J=a(re,"SPAN",{});var Gt=r(J);Le=l(Gt,"ViTDet"),Gt.forEach(o),re.forEach(o),ze=u(e),j=a(e,"H2",{class:!0});var Se=r(j);U=a(Se,"A",{id:!0,class:!0,href:!0});var St=r(U);ye=a(St,"SPAN",{});var qt=r(ye);$(O.$$.fragment,qt),qt.forEach(o),St.forEach(o),Xe=u(Se),Ve=a(Se,"SPAN",{});var Bt=r(Ve);Ke=l(Bt,"Overview"),Bt.forEach(o),Se.forEach(o),Pe=u(e),C=a(e,"P",{});var ue=r(C);Ye=l(ue,"The ViTDet model was proposed in "),H=a(ue,"A",{href:!0,rel:!0});var Ot=r(H);Qe=l(Ot,"Exploring Plain Vision Transformer Backbones for Object Detection"),Ot.forEach(o),et=l(ue,` by Yanghao Li, Hanzi Mao, Ross Girshick, Kaiming He.
VitDet leverages the plain `),se=a(ue,"A",{href:!0});var Ht=r(se);tt=l(Ht,"Vision Transformer"),Ht.forEach(o),ot=l(ue," for the task of object detection."),ue.forEach(o),We=u(e),ie=a(e,"P",{});var Lt=r(ie);nt=l(Lt,"The abstract from the paper is the following:"),Lt.forEach(o),Ie=u(e),le=a(e,"P",{});var Xt=r(le);$e=a(Xt,"EM",{});var Kt=r($e);at=l(Kt,"We explore the plain, non-hierarchical Vision Transformer (ViT) as a backbone network for object detection. This design enables the original ViT architecture to be fine-tuned for object detection without needing to redesign a hierarchical backbone for pre-training. With minimal adaptations for fine-tuning, our plain-backbone detector can achieve competitive results. Surprisingly, we observe: (i) it is sufficient to build a simple feature pyramid from a single-scale feature map (without the common FPN design) and (ii) it is sufficient to use window attention (without shifting) aided with very few cross-window propagation blocks. With plain ViT backbones pre-trained as Masked Autoencoders (MAE), our detector, named ViTDet, can compete with the previous leading methods that were all based on hierarchical backbones, reaching up to 61.3 AP_box on the COCO dataset using only ImageNet-1K pre-training. We hope our study will draw attention to research on plain-backbone detectors."),Kt.forEach(o),Xt.forEach(o),Ze=u(e),de=a(e,"P",{});var Yt=r(de);rt=l(Yt,"Tips:"),Yt.forEach(o),Ae=u(e),ce=a(e,"UL",{});var Qt=r(ce);Te=a(Qt,"LI",{});var eo=r(Te);st=l(eo,"For the moment, only the backbone is available."),eo.forEach(o),Qt.forEach(o),Je=u(e),x=a(e,"P",{});var ge=r(x);it=l(ge,"This model was contributed by "),L=a(ge,"A",{href:!0,rel:!0});var to=r(L);lt=l(to,"nielsr"),to.forEach(o),dt=l(ge,`.
The original code can be found `),X=a(ge,"A",{href:!0,rel:!0});var oo=r(X);ct=l(oo,"here"),oo.forEach(o),mt=l(ge,"."),ge.forEach(o),Ue=u(e),z=a(e,"H2",{class:!0});var qe=r(z);R=a(qe,"A",{id:!0,class:!0,href:!0});var no=r(R);Me=a(no,"SPAN",{});var ao=r(Me);$(K.$$.fragment,ao),ao.forEach(o),no.forEach(o),ht=u(qe),De=a(qe,"SPAN",{});var ro=r(De);ft=l(ro,"VitDetConfig"),ro.forEach(o),qe.forEach(o),Re=u(e),w=a(e,"DIV",{class:!0});var q=r(w);$(Y.$$.fragment,q),pt=u(q),P=a(q,"P",{});var _e=r(P);ut=l(_e,"This is the configuration class to store the configuration of a "),me=a(_e,"A",{href:!0});var so=r(me);gt=l(so,"VitDetModel"),so.forEach(o),_t=l(_e,`. It is used to instantiate an
VitDet model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the VitDet
`),Q=a(_e,"A",{href:!0,rel:!0});var io=r(Q);bt=l(io,"google/vitdet-base-patch16-224"),io.forEach(o),vt=l(_e," architecture."),_e.forEach(o),wt=u(q),W=a(q,"P",{});var be=r(W);yt=l(be,"Configuration objects inherit from "),he=a(be,"A",{href:!0});var lo=r(he);Vt=l(lo,"PretrainedConfig"),lo.forEach(o),$t=l(be,` and can be used to control the model outputs. Read the
documentation from `),fe=a(be,"A",{href:!0});var co=r(fe);Tt=l(co,"PretrainedConfig"),co.forEach(o),Mt=l(be," for more information."),be.forEach(o),Dt=u(q),$(N.$$.fragment,q),q.forEach(o),Ne=u(e),I=a(e,"H2",{class:!0});var Be=r(I);F=a(Be,"A",{id:!0,class:!0,href:!0});var mo=r(F);ke=a(mo,"SPAN",{});var ho=r(ke);$(ee.$$.fragment,ho),ho.forEach(o),mo.forEach(o),kt=u(Be),Ee=a(Be,"SPAN",{});var fo=r(Ee);Et=l(fo,"VitDetModel"),fo.forEach(o),Be.forEach(o),Fe=u(e),E=a(e,"DIV",{class:!0});var ve=r(E);$(te.$$.fragment,ve),Ct=u(ve),oe=a(ve,"P",{});var Oe=r(oe);xt=l(Oe,`The bare VitDet Transformer model outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ne=a(Oe,"A",{href:!0,rel:!0});var po=r(ne);jt=l(po,"torch.nn.Module"),po.forEach(o),zt=l(Oe,` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),Oe.forEach(o),Pt=u(ve),y=a(ve,"DIV",{class:!0});var B=r(y);$(ae.$$.fragment,B),Wt=u(B),Z=a(B,"P",{});var we=r(Z);It=l(we,"The "),pe=a(we,"A",{href:!0});var uo=r(pe);Zt=l(uo,"VitDetModel"),uo.forEach(o),At=l(we," forward method, overrides the "),Ce=a(we,"CODE",{});var go=r(Ce);Jt=l(go,"__call__"),go.forEach(o),Ut=l(we," special method."),we.forEach(o),Rt=u(B),$(G.$$.fragment,B),Nt=u(B),$(S.$$.fragment,B),B.forEach(o),ve.forEach(o),this.h()},h(){d(m,"name","hf:doc:metadata"),d(m,"content",JSON.stringify(xo)),d(f,"id","vitdet"),d(f,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(f,"href","#vitdet"),d(g,"class","relative group"),d(U,"id","overview"),d(U,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(U,"href","#overview"),d(j,"class","relative group"),d(H,"href","https://arxiv.org/abs/2203.16527"),d(H,"rel","nofollow"),d(se,"href","vit"),d(L,"href","https://huggingface.co/nielsr"),d(L,"rel","nofollow"),d(X,"href","https://github.com/facebookresearch/detectron2/tree/main/projects/ViTDet"),d(X,"rel","nofollow"),d(R,"id","transformers.VitDetConfig"),d(R,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(R,"href","#transformers.VitDetConfig"),d(z,"class","relative group"),d(me,"href","/docs/transformers/main/en/model_doc/vitdet#transformers.VitDetModel"),d(Q,"href","https://huggingface.co/google/vitdet-base-patch16-224"),d(Q,"rel","nofollow"),d(he,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),d(fe,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),d(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(F,"id","transformers.VitDetModel"),d(F,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(F,"href","#transformers.VitDetModel"),d(I,"class","relative group"),d(ne,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(ne,"rel","nofollow"),d(pe,"href","/docs/transformers/main/en/model_doc/vitdet#transformers.VitDetModel"),d(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(E,"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,c){t(document.head,m),h(e,v,c),h(e,g,c),t(g,f),t(f,b),T(s,b,null),t(g,_),t(g,J),t(J,Le),h(e,ze,c),h(e,j,c),t(j,U),t(U,ye),T(O,ye,null),t(j,Xe),t(j,Ve),t(Ve,Ke),h(e,Pe,c),h(e,C,c),t(C,Ye),t(C,H),t(H,Qe),t(C,et),t(C,se),t(se,tt),t(C,ot),h(e,We,c),h(e,ie,c),t(ie,nt),h(e,Ie,c),h(e,le,c),t(le,$e),t($e,at),h(e,Ze,c),h(e,de,c),t(de,rt),h(e,Ae,c),h(e,ce,c),t(ce,Te),t(Te,st),h(e,Je,c),h(e,x,c),t(x,it),t(x,L),t(L,lt),t(x,dt),t(x,X),t(X,ct),t(x,mt),h(e,Ue,c),h(e,z,c),t(z,R),t(R,Me),T(K,Me,null),t(z,ht),t(z,De),t(De,ft),h(e,Re,c),h(e,w,c),T(Y,w,null),t(w,pt),t(w,P),t(P,ut),t(P,me),t(me,gt),t(P,_t),t(P,Q),t(Q,bt),t(P,vt),t(w,wt),t(w,W),t(W,yt),t(W,he),t(he,Vt),t(W,$t),t(W,fe),t(fe,Tt),t(W,Mt),t(w,Dt),T(N,w,null),h(e,Ne,c),h(e,I,c),t(I,F),t(F,ke),T(ee,ke,null),t(I,kt),t(I,Ee),t(Ee,Et),h(e,Fe,c),h(e,E,c),T(te,E,null),t(E,Ct),t(E,oe),t(oe,xt),t(oe,ne),t(ne,jt),t(oe,zt),t(E,Pt),t(E,y),T(ae,y,null),t(y,Wt),t(y,Z),t(Z,It),t(Z,pe),t(pe,Zt),t(Z,At),t(Z,Ce),t(Ce,Jt),t(Z,Ut),t(y,Rt),T(G,y,null),t(y,Nt),T(S,y,null),Ge=!0},p(e,[c]){const re={};c&2&&(re.$$scope={dirty:c,ctx:e}),N.$set(re);const xe={};c&2&&(xe.$$scope={dirty:c,ctx:e}),G.$set(xe);const je={};c&2&&(je.$$scope={dirty:c,ctx:e}),S.$set(je)},i(e){Ge||(M(s.$$.fragment,e),M(O.$$.fragment,e),M(K.$$.fragment,e),M(Y.$$.fragment,e),M(N.$$.fragment,e),M(ee.$$.fragment,e),M(te.$$.fragment,e),M(ae.$$.fragment,e),M(G.$$.fragment,e),M(S.$$.fragment,e),Ge=!0)},o(e){D(s.$$.fragment,e),D(O.$$.fragment,e),D(K.$$.fragment,e),D(Y.$$.fragment,e),D(N.$$.fragment,e),D(ee.$$.fragment,e),D(te.$$.fragment,e),D(ae.$$.fragment,e),D(G.$$.fragment,e),D(S.$$.fragment,e),Ge=!1},d(e){o(m),e&&o(v),e&&o(g),k(s),e&&o(ze),e&&o(j),k(O),e&&o(Pe),e&&o(C),e&&o(We),e&&o(ie),e&&o(Ie),e&&o(le),e&&o(Ze),e&&o(de),e&&o(Ae),e&&o(ce),e&&o(Je),e&&o(x),e&&o(Ue),e&&o(z),k(K),e&&o(Re),e&&o(w),k(Y),k(N),e&&o(Ne),e&&o(I),k(ee),e&&o(Fe),e&&o(E),k(te),k(ae),k(G),k(S)}}}const xo={local:"vitdet",sections:[{local:"overview",title:"Overview"},{local:"transformers.VitDetConfig",title:"VitDetConfig"},{local:"transformers.VitDetModel",title:"VitDetModel"}],title:"ViTDet"};function jo(A){return To(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Jo extends wo{constructor(m){super();yo(this,m,jo,Co,Vo,{})}}export{Jo as default,xo as metadata};
