import{S as wo,i as yo,s as To,e as n,k as f,w as T,t as i,M as Vo,c as a,d as o,m as u,a as s,x as V,h as l,b as d,G as t,g as h,y as M,q as $,o as k,B as E,v as Mo,L as bo}from"../../chunks/vendor-hf-doc-builder.js";import{T as $o}from"../../chunks/Tip-hf-doc-builder.js";import{D as At}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 ko(W){let m,v,g,p,b;return p=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=f(),T(p.$$.fragment)},l(r){m=a(r,"P",{});var _=s(m);v=l(_,"Example:"),_.forEach(o),g=u(r),V(p.$$.fragment,r)},m(r,_){h(r,m,_),t(m,v),h(r,g,_),M(p,r,_),b=!0},p:bo,i(r){b||($(p.$$.fragment,r),b=!0)},o(r){k(p.$$.fragment,r),b=!1},d(r){r&&o(m),r&&o(g),E(p,r)}}}function Eo(W){let m,v,g,p,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"),p=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(r){m=a(r,"P",{});var _=s(m);v=l(_,"Although the recipe for forward pass needs to be defined within this function, one should call the "),g=a(_,"CODE",{});var P=s(g);p=l(P,"Module"),P.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(r,_){h(r,m,_),t(m,v),t(m,g),t(g,p),t(m,b)},d(r){r&&o(m)}}}function Do(W){let m,v,g,p,b;return p=new vo({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMFZpdERldE1vZGVsJTBBaW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGF0YXNldHMlMjBpbXBvcnQlMjBsb2FkX2RhdGFzZXQlMEElMEFkYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmh1Z2dpbmdmYWNlJTJGY2F0cy1pbWFnZSUyMiklMEFpbWFnZSUyMCUzRCUyMGRhdGFzZXQlNUIlMjJ0ZXN0JTIyJTVEJTVCJTIyaW1hZ2UlMjIlNUQlNUIwJTVEJTBBJTBBaW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRnZpdC1kZXQtYmFzZSUyMiklMEFtb2RlbCUyMCUzRCUyMFZpdERldE1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRnZpdC1kZXQtYmFzZSUyMiklMEElMEFpbnB1dHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IoaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQXdpdGglMjB0b3JjaC5ub19ncmFkKCklM0ElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpJTBBJTBBbGFzdF9oaWRkZW5fc3RhdGVzJTIwJTNEJTIwb3V0cHV0cy5sYXN0X2hpZGRlbl9zdGF0ZSUwQWxpc3QobGFzdF9oaWRkZW5fc3RhdGVzLnNoYXBlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, VitDetModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;huggingface/cats-image&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>image = dataset[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-string">&quot;image&quot;</span>][<span class="hljs-number">0</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;facebook/vit-det-base&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = VitDetModel.from_pretrained(<span class="hljs-string">&quot;facebook/vit-det-base&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(image, return_tensors=<span class="hljs-string">&quot;pt&quot;</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(**inputs)

<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">197</span>, <span class="hljs-number">768</span>]`}}),{c(){m=n("p"),v=i("Example:"),g=f(),T(p.$$.fragment)},l(r){m=a(r,"P",{});var _=s(m);v=l(_,"Example:"),_.forEach(o),g=u(r),V(p.$$.fragment,r)},m(r,_){h(r,m,_),t(m,v),h(r,g,_),M(p,r,_),b=!0},p:bo,i(r){b||($(p.$$.fragment,r),b=!0)},o(r){k(p.$$.fragment,r),b=!1},d(r){r&&o(m),r&&o(g),E(p,r)}}}function Co(W){let m,v,g,p,b,r,_,P,Xe,ze,x,U,ye,Y,Oe,Te,Le,Je,C,Qe,H,Ke,et,re,tt,ot,Ze,ie,nt,Ie,le,Ve,at,Fe,de,st,We,ce,Me,rt,Pe,j,it,X,lt,dt,O,ct,mt,Ue,z,N,$e,L,ht,ke,pt,Ne,w,Q,ft,J,ut,me,gt,_t,K,bt,vt,wt,Z,yt,he,Tt,Vt,pe,Mt,$t,kt,B,Be,I,A,Ee,ee,Et,De,Dt,Ae,D,te,Ct,oe,jt,ne,xt,zt,Jt,y,ae,Zt,F,It,fe,Ft,Wt,Ce,Pt,Ut,Nt,q,Bt,R,qe;return r=new He({}),Y=new He({}),L=new He({}),Q=new At({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"}}),B=new _o({props:{anchor:"transformers.VitDetConfig.example",$$slots:{default:[ko]},$$scope:{ctx:W}}}),ee=new He({}),te=new At({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#L717"}}),ae=new At({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/donut#transformers.DonutFeatureExtractor.__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#L739",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>
`}}),q=new $o({props:{$$slots:{default:[Eo]},$$scope:{ctx:W}}}),R=new _o({props:{anchor:"transformers.VitDetModel.forward.example",$$slots:{default:[Do]},$$scope:{ctx:W}}}),{c(){m=n("meta"),v=f(),g=n("h1"),p=n("a"),b=n("span"),T(r.$$.fragment),_=f(),P=n("span"),Xe=i("ViTDet"),ze=f(),x=n("h2"),U=n("a"),ye=n("span"),T(Y.$$.fragment),Oe=f(),Te=n("span"),Le=i("Overview"),Je=f(),C=n("p"),Qe=i("The ViTDet model was proposed in "),H=n("a"),Ke=i("Exploring Plain Vision Transformer Backbones for Object Detection"),et=i(` by Yanghao Li, Hanzi Mao, Ross Girshick, Kaiming He.
VitDet leverages the plain `),re=n("a"),tt=i("Vision Transformer"),ot=i(" for the task of object detection."),Ze=f(),ie=n("p"),nt=i("The abstract from the paper is the following:"),Ie=f(),le=n("p"),Ve=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."),Fe=f(),de=n("p"),st=i("Tips:"),We=f(),ce=n("ul"),Me=n("li"),rt=i("For the moment, only the backbone is available."),Pe=f(),j=n("p"),it=i("This model was contributed by "),X=n("a"),lt=i("nielsr"),dt=i(`.
The original code can be found `),O=n("a"),ct=i("here"),mt=i("."),Ue=f(),z=n("h2"),N=n("a"),$e=n("span"),T(L.$$.fragment),ht=f(),ke=n("span"),pt=i("VitDetConfig"),Ne=f(),w=n("div"),T(Q.$$.fragment),ft=f(),J=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
`),K=n("a"),bt=i("google/vitdet-base-patch16-224"),vt=i(" architecture."),wt=f(),Z=n("p"),yt=i("Configuration objects inherit from "),he=n("a"),Tt=i("PretrainedConfig"),Vt=i(` and can be used to control the model outputs. Read the
documentation from `),pe=n("a"),Mt=i("PretrainedConfig"),$t=i(" for more information."),kt=f(),T(B.$$.fragment),Be=f(),I=n("h2"),A=n("a"),Ee=n("span"),T(ee.$$.fragment),Et=f(),De=n("span"),Dt=i("VitDetModel"),Ae=f(),D=n("div"),T(te.$$.fragment),Ct=f(),oe=n("p"),jt=i(`The bare VitDet Transformer model outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ne=n("a"),xt=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.`),Jt=f(),y=n("div"),T(ae.$$.fragment),Zt=f(),F=n("p"),It=i("The "),fe=n("a"),Ft=i("VitDetModel"),Wt=i(" forward method, overrides the "),Ce=n("code"),Pt=i("__call__"),Ut=i(" special method."),Nt=f(),T(q.$$.fragment),Bt=f(),T(R.$$.fragment),this.h()},l(e){const c=Vo('[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 se=s(g);p=a(se,"A",{id:!0,class:!0,href:!0});var je=s(p);b=a(je,"SPAN",{});var xe=s(b);V(r.$$.fragment,xe),xe.forEach(o),je.forEach(o),_=u(se),P=a(se,"SPAN",{});var qt=s(P);Xe=l(qt,"ViTDet"),qt.forEach(o),se.forEach(o),ze=u(e),x=a(e,"H2",{class:!0});var Re=s(x);U=a(Re,"A",{id:!0,class:!0,href:!0});var Rt=s(U);ye=a(Rt,"SPAN",{});var Gt=s(ye);V(Y.$$.fragment,Gt),Gt.forEach(o),Rt.forEach(o),Oe=u(Re),Te=a(Re,"SPAN",{});var St=s(Te);Le=l(St,"Overview"),St.forEach(o),Re.forEach(o),Je=u(e),C=a(e,"P",{});var ue=s(C);Qe=l(ue,"The ViTDet model was proposed in "),H=a(ue,"A",{href:!0,rel:!0});var Yt=s(H);Ke=l(Yt,"Exploring Plain Vision Transformer Backbones for Object Detection"),Yt.forEach(o),et=l(ue,` by Yanghao Li, Hanzi Mao, Ross Girshick, Kaiming He.
VitDet leverages the plain `),re=a(ue,"A",{href:!0});var Ht=s(re);tt=l(Ht,"Vision Transformer"),Ht.forEach(o),ot=l(ue," for the task of object detection."),ue.forEach(o),Ze=u(e),ie=a(e,"P",{});var Xt=s(ie);nt=l(Xt,"The abstract from the paper is the following:"),Xt.forEach(o),Ie=u(e),le=a(e,"P",{});var Ot=s(le);Ve=a(Ot,"EM",{});var Lt=s(Ve);at=l(Lt,"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."),Lt.forEach(o),Ot.forEach(o),Fe=u(e),de=a(e,"P",{});var Qt=s(de);st=l(Qt,"Tips:"),Qt.forEach(o),We=u(e),ce=a(e,"UL",{});var Kt=s(ce);Me=a(Kt,"LI",{});var eo=s(Me);rt=l(eo,"For the moment, only the backbone is available."),eo.forEach(o),Kt.forEach(o),Pe=u(e),j=a(e,"P",{});var ge=s(j);it=l(ge,"This model was contributed by "),X=a(ge,"A",{href:!0,rel:!0});var to=s(X);lt=l(to,"nielsr"),to.forEach(o),dt=l(ge,`.
The original code can be found `),O=a(ge,"A",{href:!0,rel:!0});var oo=s(O);ct=l(oo,"here"),oo.forEach(o),mt=l(ge,"."),ge.forEach(o),Ue=u(e),z=a(e,"H2",{class:!0});var Ge=s(z);N=a(Ge,"A",{id:!0,class:!0,href:!0});var no=s(N);$e=a(no,"SPAN",{});var ao=s($e);V(L.$$.fragment,ao),ao.forEach(o),no.forEach(o),ht=u(Ge),ke=a(Ge,"SPAN",{});var so=s(ke);pt=l(so,"VitDetConfig"),so.forEach(o),Ge.forEach(o),Ne=u(e),w=a(e,"DIV",{class:!0});var G=s(w);V(Q.$$.fragment,G),ft=u(G),J=a(G,"P",{});var _e=s(J);ut=l(_e,"This is the configuration class to store the configuration of a "),me=a(_e,"A",{href:!0});var ro=s(me);gt=l(ro,"VitDetModel"),ro.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
`),K=a(_e,"A",{href:!0,rel:!0});var io=s(K);bt=l(io,"google/vitdet-base-patch16-224"),io.forEach(o),vt=l(_e," architecture."),_e.forEach(o),wt=u(G),Z=a(G,"P",{});var be=s(Z);yt=l(be,"Configuration objects inherit from "),he=a(be,"A",{href:!0});var lo=s(he);Tt=l(lo,"PretrainedConfig"),lo.forEach(o),Vt=l(be,` and can be used to control the model outputs. Read the
documentation from `),pe=a(be,"A",{href:!0});var co=s(pe);Mt=l(co,"PretrainedConfig"),co.forEach(o),$t=l(be," for more information."),be.forEach(o),kt=u(G),V(B.$$.fragment,G),G.forEach(o),Be=u(e),I=a(e,"H2",{class:!0});var Se=s(I);A=a(Se,"A",{id:!0,class:!0,href:!0});var mo=s(A);Ee=a(mo,"SPAN",{});var ho=s(Ee);V(ee.$$.fragment,ho),ho.forEach(o),mo.forEach(o),Et=u(Se),De=a(Se,"SPAN",{});var po=s(De);Dt=l(po,"VitDetModel"),po.forEach(o),Se.forEach(o),Ae=u(e),D=a(e,"DIV",{class:!0});var ve=s(D);V(te.$$.fragment,ve),Ct=u(ve),oe=a(ve,"P",{});var Ye=s(oe);jt=l(Ye,`The bare VitDet Transformer model outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ne=a(Ye,"A",{href:!0,rel:!0});var fo=s(ne);xt=l(fo,"torch.nn.Module"),fo.forEach(o),zt=l(Ye,` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),Ye.forEach(o),Jt=u(ve),y=a(ve,"DIV",{class:!0});var S=s(y);V(ae.$$.fragment,S),Zt=u(S),F=a(S,"P",{});var we=s(F);It=l(we,"The "),fe=a(we,"A",{href:!0});var uo=s(fe);Ft=l(uo,"VitDetModel"),uo.forEach(o),Wt=l(we," forward method, overrides the "),Ce=a(we,"CODE",{});var go=s(Ce);Pt=l(go,"__call__"),go.forEach(o),Ut=l(we," special method."),we.forEach(o),Nt=u(S),V(q.$$.fragment,S),Bt=u(S),V(R.$$.fragment,S),S.forEach(o),ve.forEach(o),this.h()},h(){d(m,"name","hf:doc:metadata"),d(m,"content",JSON.stringify(jo)),d(p,"id","vitdet"),d(p,"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(p,"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(x,"class","relative group"),d(H,"href","https://arxiv.org/abs/2203.16527"),d(H,"rel","nofollow"),d(re,"href","vit"),d(X,"href","https://huggingface.co/nielsr"),d(X,"rel","nofollow"),d(O,"href","https://github.com/facebookresearch/detectron2/tree/main/projects/ViTDet"),d(O,"rel","nofollow"),d(N,"id","transformers.VitDetConfig"),d(N,"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(N,"href","#transformers.VitDetConfig"),d(z,"class","relative group"),d(me,"href","/docs/transformers/main/en/model_doc/vitdet#transformers.VitDetModel"),d(K,"href","https://huggingface.co/google/vitdet-base-patch16-224"),d(K,"rel","nofollow"),d(he,"href","/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig"),d(pe,"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(A,"id","transformers.VitDetModel"),d(A,"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(A,"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(fe,"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(D,"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,p),t(p,b),M(r,b,null),t(g,_),t(g,P),t(P,Xe),h(e,ze,c),h(e,x,c),t(x,U),t(U,ye),M(Y,ye,null),t(x,Oe),t(x,Te),t(Te,Le),h(e,Je,c),h(e,C,c),t(C,Qe),t(C,H),t(H,Ke),t(C,et),t(C,re),t(re,tt),t(C,ot),h(e,Ze,c),h(e,ie,c),t(ie,nt),h(e,Ie,c),h(e,le,c),t(le,Ve),t(Ve,at),h(e,Fe,c),h(e,de,c),t(de,st),h(e,We,c),h(e,ce,c),t(ce,Me),t(Me,rt),h(e,Pe,c),h(e,j,c),t(j,it),t(j,X),t(X,lt),t(j,dt),t(j,O),t(O,ct),t(j,mt),h(e,Ue,c),h(e,z,c),t(z,N),t(N,$e),M(L,$e,null),t(z,ht),t(z,ke),t(ke,pt),h(e,Ne,c),h(e,w,c),M(Q,w,null),t(w,ft),t(w,J),t(J,ut),t(J,me),t(me,gt),t(J,_t),t(J,K),t(K,bt),t(J,vt),t(w,wt),t(w,Z),t(Z,yt),t(Z,he),t(he,Tt),t(Z,Vt),t(Z,pe),t(pe,Mt),t(Z,$t),t(w,kt),M(B,w,null),h(e,Be,c),h(e,I,c),t(I,A),t(A,Ee),M(ee,Ee,null),t(I,Et),t(I,De),t(De,Dt),h(e,Ae,c),h(e,D,c),M(te,D,null),t(D,Ct),t(D,oe),t(oe,jt),t(oe,ne),t(ne,xt),t(oe,zt),t(D,Jt),t(D,y),M(ae,y,null),t(y,Zt),t(y,F),t(F,It),t(F,fe),t(fe,Ft),t(F,Wt),t(F,Ce),t(Ce,Pt),t(F,Ut),t(y,Nt),M(q,y,null),t(y,Bt),M(R,y,null),qe=!0},p(e,[c]){const se={};c&2&&(se.$$scope={dirty:c,ctx:e}),B.$set(se);const je={};c&2&&(je.$$scope={dirty:c,ctx:e}),q.$set(je);const xe={};c&2&&(xe.$$scope={dirty:c,ctx:e}),R.$set(xe)},i(e){qe||($(r.$$.fragment,e),$(Y.$$.fragment,e),$(L.$$.fragment,e),$(Q.$$.fragment,e),$(B.$$.fragment,e),$(ee.$$.fragment,e),$(te.$$.fragment,e),$(ae.$$.fragment,e),$(q.$$.fragment,e),$(R.$$.fragment,e),qe=!0)},o(e){k(r.$$.fragment,e),k(Y.$$.fragment,e),k(L.$$.fragment,e),k(Q.$$.fragment,e),k(B.$$.fragment,e),k(ee.$$.fragment,e),k(te.$$.fragment,e),k(ae.$$.fragment,e),k(q.$$.fragment,e),k(R.$$.fragment,e),qe=!1},d(e){o(m),e&&o(v),e&&o(g),E(r),e&&o(ze),e&&o(x),E(Y),e&&o(Je),e&&o(C),e&&o(Ze),e&&o(ie),e&&o(Ie),e&&o(le),e&&o(Fe),e&&o(de),e&&o(We),e&&o(ce),e&&o(Pe),e&&o(j),e&&o(Ue),e&&o(z),E(L),e&&o(Ne),e&&o(w),E(Q),E(B),e&&o(Be),e&&o(I),E(ee),e&&o(Ae),e&&o(D),E(te),E(ae),E(q),E(R)}}}const jo={local:"vitdet",sections:[{local:"overview",title:"Overview"},{local:"transformers.VitDetConfig",title:"VitDetConfig"},{local:"transformers.VitDetModel",title:"VitDetModel"}],title:"ViTDet"};function xo(W){return Mo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Po extends wo{constructor(m){super();yo(this,m,xo,Co,To,{})}}export{Po as default,jo as metadata};
