import{s as Ee,o as He,n as ve}from"../chunks/scheduler.18a86fab.js";import{S as Qe,i as Ae,g as m,s as i,r as M,A as Le,h,f as l,c as d,j as me,x as T,u as y,k as Te,l as qe,y as a,a as f,v as _,d as b,t as v,w}from"../chunks/index.98837b22.js";import{T as Xe}from"../chunks/Tip.77304350.js";import{D as We}from"../chunks/Docstring.6758ea23.js";import{C as Ue}from"../chunks/CodeBlock.8d0c2e8a.js";import{F as Se,M as Ve}from"../chunks/Markdown.ae01904b.js";import{E as Ye}from"../chunks/ExampleCodeBlock.0c42463f.js";import{H as Ge}from"../chunks/Heading.7e7e0c5b.js";import{H as Pe,a as De}from"../chunks/HfOption.6641485e.js";import{E as Oe}from"../chunks/index.499f366c.js";function Ke(U){let t,r="Click on the DINOv2 models in the right sidebar for more examples of how to apply DINOv2 to different vision tasks.";return{c(){t=m("p"),t.textContent=r},l(e){t=h(e,"P",{"data-svelte-h":!0}),T(t)!=="svelte-1npw7gp"&&(t.textContent=r)},m(e,s){f(e,t,s)},p:ve,d(e){e&&l(t)}}}function et(U){let t,r;return t=new Ue({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwcGlwZWxpbmUlMEElMEFwaXBlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwdGFzayUzRCUyMmltYWdlLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTIwJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0QlMjJmYWNlYm9vayUyRmRpbm92Mi1zbWFsbC1pbWFnZW5ldDFrLTEtbGF5ZXIlMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMEElMjAlMjAlMjAlMjBkZXZpY2UlM0QwJTBBKSUwQSUwQXBpcGUoJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmRhdGFzZXRzJTJGaHVnZ2luZ2ZhY2UlMkZkb2N1bWVudGF0aW9uLWltYWdlcyUyRnJlc29sdmUlMkZtYWluJTJGcGlwZWxpbmUtY2F0LWNob25rLmpwZWclMjIp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

pipe = pipeline(
    task=<span class="hljs-string">&quot;image-classification&quot;</span>, 
    model=<span class="hljs-string">&quot;facebook/dinov2-small-imagenet1k-1-layer&quot;</span>,
    torch_dtype=torch.float16,
    device=<span class="hljs-number">0</span>
)

pipe(<span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg&quot;</span>)`,wrap:!1}}),{c(){M(t.$$.fragment)},l(e){y(t.$$.fragment,e)},m(e,s){_(t,e,s),r=!0},p:ve,i(e){r||(b(t.$$.fragment,e),r=!0)},o(e){v(t.$$.fragment,e),r=!1},d(e){w(t,e)}}}function tt(U){let t,r;return t=new Ue({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b0ltYWdlUHJvY2Vzc29yJTJDJTIwQXV0b01vZGVsRm9ySW1hZ2VDbGFzc2lmaWNhdGlvbiUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQSUwQXVybCUyMCUzRCUyMCUyMmh0dHAlM0ElMkYlMkZpbWFnZXMuY29jb2RhdGFzZXQub3JnJTJGdmFsMjAxNyUyRjAwMDAwMDAzOTc2OS5qcGclMjIlMEFpbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4ocmVxdWVzdHMuZ2V0KHVybCUyQyUyMHN0cmVhbSUzRFRydWUpLnJhdyklMEElMEFwcm9jZXNzb3IlMjAlM0QlMjBBdXRvSW1hZ2VQcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKCUyMmZhY2Vib29rJTJGZGlub3YyLXNtYWxsLWltYWdlbmV0MWstMS1sYXllciUyMiklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmZhY2Vib29rJTJGZGlub3YyLXNtYWxsLWltYWdlbmV0MWstMS1sYXllciUyMiUyQyUyMCUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMCUwQSUyMCUyMCUyMCUyMGRldmljZV9tYXAlM0QlMjJhdXRvJTIyJTJDJTIwJTBBJTIwJTIwJTIwJTIwYXR0bl9pbXBsZW1lbnRhdGlvbiUzRCUyMnNkcGElMjIlMEEpJTBBJTBBaW5wdXRzJTIwJTNEJTIwcHJvY2Vzc29yKGltYWdlcyUzRGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEFsb2dpdHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cykubG9naXRzJTBBcHJlZGljdGVkX2NsYXNzX2lkeCUyMCUzRCUyMGxvZ2l0cy5hcmdtYXgoLTEpLml0ZW0oKSUwQXByaW50KCUyMlByZWRpY3RlZCUyMGNsYXNzJTNBJTIyJTJDJTIwbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCcHJlZGljdGVkX2NsYXNzX2lkeCU1RCk=",highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, AutoModelForImageClassification
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;facebook/dinov2-small-imagenet1k-1-layer&quot;</span>)
model = AutoModelForImageClassification.from_pretrained(
    <span class="hljs-string">&quot;facebook/dinov2-small-imagenet1k-1-layer&quot;</span>, 
    torch_dtype=torch.float16, 
    device_map=<span class="hljs-string">&quot;auto&quot;</span>, 
    attn_implementation=<span class="hljs-string">&quot;sdpa&quot;</span>
)

inputs = processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
logits = model(**inputs).logits
predicted_class_idx = logits.argmax(-<span class="hljs-number">1</span>).item()
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Predicted class:&quot;</span>, model.config.id2label[predicted_class_idx])`,wrap:!1}}),{c(){M(t.$$.fragment)},l(e){y(t.$$.fragment,e)},m(e,s){_(t,e,s),r=!0},p:ve,i(e){r||(b(t.$$.fragment,e),r=!0)},o(e){v(t.$$.fragment,e),r=!1},d(e){w(t,e)}}}function nt(U){let t,r,e,s;return t=new De({props:{id:"usage",option:"Pipeline",$$slots:{default:[et]},$$scope:{ctx:U}}}),e=new De({props:{id:"usage",option:"AutoModel",$$slots:{default:[tt]},$$scope:{ctx:U}}}),{c(){M(t.$$.fragment),r=i(),M(e.$$.fragment)},l(c){y(t.$$.fragment,c),r=d(c),y(e.$$.fragment,c)},m(c,o){_(t,c,o),f(c,r,o),_(e,c,o),s=!0},p(c,o){const C={};o&2&&(C.$$scope={dirty:o,ctx:c}),t.$set(C);const V={};o&2&&(V.$$scope={dirty:o,ctx:c}),e.$set(V)},i(c){s||(b(t.$$.fragment,c),b(e.$$.fragment,c),s=!0)},o(c){v(t.$$.fragment,c),v(e.$$.fragment,c),s=!1},d(c){c&&l(r),w(t,c),w(e,c)}}}function ot(U){let t,r="Example:",e,s,c;return s=new Ue({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERpbm92MkNvbmZpZyUyQyUyMERpbm92Mk1vZGVsJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMERpbm92MiUyMGRpbm92Mi1iYXNlLXBhdGNoMTYtMjI0JTIwc3R5bGUlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMERpbm92MkNvbmZpZygpJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMG1vZGVsJTIwKHdpdGglMjByYW5kb20lMjB3ZWlnaHRzKSUyMGZyb20lMjB0aGUlMjBkaW5vdjItYmFzZS1wYXRjaDE2LTIyNCUyMHN0eWxlJTIwY29uZmlndXJhdGlvbiUwQW1vZGVsJTIwJTNEJTIwRGlub3YyTW9kZWwoY29uZmlndXJhdGlvbiklMEElMEElMjMlMjBBY2Nlc3NpbmclMjB0aGUlMjBtb2RlbCUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwbW9kZWwuY29uZmln",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Dinov2Config, Dinov2Model

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a Dinov2 dinov2-base-patch16-224 style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = Dinov2Config()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the dinov2-base-patch16-224 style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = Dinov2Model(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`,wrap:!1}}),{c(){t=m("p"),t.textContent=r,e=i(),M(s.$$.fragment)},l(o){t=h(o,"P",{"data-svelte-h":!0}),T(t)!=="svelte-11lpom8"&&(t.textContent=r),e=d(o),y(s.$$.fragment,o)},m(o,C){f(o,t,C),f(o,e,C),_(s,o,C),c=!0},p:ve,i(o){c||(b(s.$$.fragment,o),c=!0)},o(o){v(s.$$.fragment,o),c=!1},d(o){o&&(l(t),l(e)),w(s,o)}}}function st(U){let t,r=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){t=m("p"),t.innerHTML=r},l(e){t=h(e,"P",{"data-svelte-h":!0}),T(t)!=="svelte-fincs2"&&(t.innerHTML=r)},m(e,s){f(e,t,s)},p:ve,d(e){e&&l(t)}}}function at(U){let t,r="Example:",e,s,c;return s=new Ue({props:{code:"",highlighted:"",wrap:!1}}),{c(){t=m("p"),t.textContent=r,e=i(),M(s.$$.fragment)},l(o){t=h(o,"P",{"data-svelte-h":!0}),T(t)!=="svelte-11lpom8"&&(t.textContent=r),e=d(o),y(s.$$.fragment,o)},m(o,C){f(o,t,C),f(o,e,C),_(s,o,C),c=!0},p:ve,i(o){c||(b(s.$$.fragment,o),c=!0)},o(o){v(s.$$.fragment,o),c=!1},d(o){o&&(l(t),l(e)),w(s,o)}}}function lt(U){let t,r=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){t=m("p"),t.innerHTML=r},l(e){t=h(e,"P",{"data-svelte-h":!0}),T(t)!=="svelte-fincs2"&&(t.innerHTML=r)},m(e,s){f(e,t,s)},p:ve,d(e){e&&l(t)}}}function rt(U){let t,r="Example:",e,s,c;return s=new Ue({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMERpbm92MkZvckltYWdlQ2xhc3NpZmljYXRpb24lMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBkYXRhc2V0cyUyMGltcG9ydCUyMGxvYWRfZGF0YXNldCUwQSUwQWRhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyaHVnZ2luZ2ZhY2UlMkZjYXRzLWltYWdlJTIyJTJDJTIwdHJ1c3RfcmVtb3RlX2NvZGUlM0RUcnVlKSUwQWltYWdlJTIwJTNEJTIwZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlNUIlMjJpbWFnZSUyMiU1RCU1QjAlNUQlMEElMEFpbWFnZV9wcm9jZXNzb3IlMjAlM0QlMjBBdXRvSW1hZ2VQcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRmRpbm92Mi1iYXNlLXBhdGNoMTYtMjI0JTIyKSUwQW1vZGVsJTIwJTNEJTIwRGlub3YyRm9ySW1hZ2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZGlub3YyLWJhc2UtcGF0Y2gxNi0yMjQlMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwbG9naXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpLmxvZ2l0cyUwQSUwQSUyMyUyMG1vZGVsJTIwcHJlZGljdHMlMjBvbmUlMjBvZiUyMHRoZSUyMDEwMDAlMjBJbWFnZU5ldCUyMGNsYXNzZXMlMEFwcmVkaWN0ZWRfbGFiZWwlMjAlM0QlMjBsb2dpdHMuYXJnbWF4KC0xKS5pdGVtKCklMEFwcmludChtb2RlbC5jb25maWcuaWQybGFiZWwlNUJwcmVkaWN0ZWRfbGFiZWwlNUQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, Dinov2ForImageClassification
<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>, trust_remote_code=<span class="hljs-literal">True</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;google/dinov2-base-patch16-224&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = Dinov2ForImageClassification.from_pretrained(<span class="hljs-string">&quot;google/dinov2-base-patch16-224&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>    logits = model(**inputs).logits

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># model predicts one of the 1000 ImageNet classes</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label = logits.argmax(-<span class="hljs-number">1</span>).item()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(model.config.id2label[predicted_label])
...`,wrap:!1}}),{c(){t=m("p"),t.textContent=r,e=i(),M(s.$$.fragment)},l(o){t=h(o,"P",{"data-svelte-h":!0}),T(t)!=="svelte-11lpom8"&&(t.textContent=r),e=d(o),y(s.$$.fragment,o)},m(o,C){f(o,t,C),f(o,e,C),_(s,o,C),c=!0},p:ve,i(o){c||(b(s.$$.fragment,o),c=!0)},o(o){v(s.$$.fragment,o),c=!1},d(o){o&&(l(t),l(e)),w(s,o)}}}function it(U){let t,r,e,s,c,o,C="The bare Dinov2 Model outputting raw hidden-states without any specific head on top.",V,E,he=`This model inherits from <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`,Je,H,fe=`This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`,je,F,R,ye,G,Ze='The <a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2Model">Dinov2Model</a> forward method, overrides the <code>__call__</code> special method.',_e,W,q,N,re,se,S,I,P,B,O,Q=`Dinov2 Model transformer with an image classification head on top (a linear layer on top of the final hidden state
of the [CLS] token) e.g. for ImageNet.`,ue,x,X=`This model inherits from <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`,ie,K,xe=`This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`,de,z,ce,ae,L,ge='The <a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2ForImageClassification">Dinov2ForImageClassification</a> forward method, overrides the <code>__call__</code> special method.',pe,A,$e,Y,ee;return t=new Ge({props:{title:"Dinov2Model",local:"transformers.Dinov2Model",headingTag:"h2"}}),s=new We({props:{name:"class transformers.Dinov2Model",anchor:"transformers.Dinov2Model",parameters:[{name:"config",val:": Dinov2Config"}],parametersDescription:[{anchor:"transformers.Dinov2Model.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2Config">Dinov2Config</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/dinov2/modeling_dinov2.py#L530"}}),R=new We({props:{name:"forward",anchor:"transformers.Dinov2Model.forward",parameters:[{name:"pixel_values",val:": typing.Optional[torch.Tensor] = None"},{name:"bool_masked_pos",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.Dinov2Model.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) &#x2014;
The tensors corresponding to the input images. Pixel values can be obtained using
<code>{image_processor_class}</code>. See <code>{image_processor_class}.__call__</code> for details (<code>{processor_class}</code> uses
<code>{image_processor_class}</code> for processing images).`,name:"pixel_values"},{anchor:"transformers.Dinov2Model.forward.bool_masked_pos",description:`<strong>bool_masked_pos</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Boolean masked positions. Indicates which patches are masked (1) and which aren&#x2019;t (0). Only relevant for
pre-training.`,name:"bool_masked_pos"},{anchor:"transformers.Dinov2Model.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.Tensor</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.Dinov2Model.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.Dinov2Model.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.Dinov2Model.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/dinov2/modeling_dinov2.py#L555",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling"
>transformers.modeling_outputs.BaseModelOutputWithPooling</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/dinov2#transformers.Dinov2Config"
>Dinov2Config</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>) — Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>pooler_output</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, hidden_size)</code>) — Last layer hidden-state of the first token of the sequence (classification token) after further processing
through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns
the classification token after processing through a linear layer and a tanh activation function. The linear
layer weights are trained from the next sentence prediction (classification) objective during pretraining.</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>) — 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>) — 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:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling"
>transformers.modeling_outputs.BaseModelOutputWithPooling</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),W=new Xe({props:{$$slots:{default:[st]},$$scope:{ctx:U}}}),N=new Ye({props:{anchor:"transformers.Dinov2Model.forward.example",$$slots:{default:[at]},$$scope:{ctx:U}}}),se=new Ge({props:{title:"Dinov2ForImageClassification",local:"transformers.Dinov2ForImageClassification",headingTag:"h2"}}),P=new We({props:{name:"class transformers.Dinov2ForImageClassification",anchor:"transformers.Dinov2ForImageClassification",parameters:[{name:"config",val:": Dinov2Config"}],parametersDescription:[{anchor:"transformers.Dinov2ForImageClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2Config">Dinov2Config</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/dinov2/modeling_dinov2.py#L611"}}),ce=new We({props:{name:"forward",anchor:"transformers.Dinov2ForImageClassification.forward",parameters:[{name:"pixel_values",val:": typing.Optional[torch.Tensor] = None"},{name:"head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"labels",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.Dinov2ForImageClassification.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) &#x2014;
The tensors corresponding to the input images. Pixel values can be obtained using
<code>{image_processor_class}</code>. See <code>{image_processor_class}.__call__</code> for details (<code>{processor_class}</code> uses
<code>{image_processor_class}</code> for processing images).`,name:"pixel_values"},{anchor:"transformers.Dinov2ForImageClassification.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.Tensor</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.Dinov2ForImageClassification.forward.labels",description:`<strong>labels</strong> (<code>torch.Tensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the image classification/regression loss. Indices should be in <code>[0, ..., config.num_labels - 1]</code>. If <code>config.num_labels == 1</code> a regression loss is computed (Mean-Square loss), If
<code>config.num_labels &gt; 1</code> a classification loss is computed (Cross-Entropy).`,name:"labels"},{anchor:"transformers.Dinov2ForImageClassification.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.Dinov2ForImageClassification.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.Dinov2ForImageClassification.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/dinov2/modeling_dinov2.py#L632",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.ImageClassifierOutput"
>transformers.modeling_outputs.ImageClassifierOutput</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/dinov2#transformers.Dinov2Config"
>Dinov2Config</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) — Classification (or regression if config.num_labels==1) loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.num_labels)</code>) — Classification (or regression if config.num_labels==1) scores (before SoftMax).</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>) — 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 stage) of shape <code>(batch_size, sequence_length, hidden_size)</code>. Hidden-states
(also called feature maps) of the model at the output of each stage.</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>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, patch_size, 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:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.ImageClassifierOutput"
>transformers.modeling_outputs.ImageClassifierOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),A=new Xe({props:{$$slots:{default:[lt]},$$scope:{ctx:U}}}),Y=new Ye({props:{anchor:"transformers.Dinov2ForImageClassification.forward.example",$$slots:{default:[rt]},$$scope:{ctx:U}}}),{c(){M(t.$$.fragment),r=i(),e=m("div"),M(s.$$.fragment),c=i(),o=m("p"),o.textContent=C,V=i(),E=m("p"),E.innerHTML=he,Je=i(),H=m("p"),H.innerHTML=fe,je=i(),F=m("div"),M(R.$$.fragment),ye=i(),G=m("p"),G.innerHTML=Ze,_e=i(),M(W.$$.fragment),q=i(),M(N.$$.fragment),re=i(),M(se.$$.fragment),S=i(),I=m("div"),M(P.$$.fragment),B=i(),O=m("p"),O.textContent=Q,ue=i(),x=m("p"),x.innerHTML=X,ie=i(),K=m("p"),K.innerHTML=xe,de=i(),z=m("div"),M(ce.$$.fragment),ae=i(),L=m("p"),L.innerHTML=ge,pe=i(),M(A.$$.fragment),$e=i(),M(Y.$$.fragment),this.h()},l(p){y(t.$$.fragment,p),r=d(p),e=h(p,"DIV",{class:!0});var $=me(e);y(s.$$.fragment,$),c=d($),o=h($,"P",{"data-svelte-h":!0}),T(o)!=="svelte-1jiibb0"&&(o.textContent=C),V=d($),E=h($,"P",{"data-svelte-h":!0}),T(E)!=="svelte-6pahdo"&&(E.innerHTML=he),Je=d($),H=h($,"P",{"data-svelte-h":!0}),T(H)!=="svelte-hswkmf"&&(H.innerHTML=fe),je=d($),F=h($,"DIV",{class:!0});var j=me(F);y(R.$$.fragment,j),ye=d(j),G=h(j,"P",{"data-svelte-h":!0}),T(G)!=="svelte-g9ij7n"&&(G.innerHTML=Ze),_e=d(j),y(W.$$.fragment,j),q=d(j),y(N.$$.fragment,j),j.forEach(l),$.forEach(l),re=d(p),y(se.$$.fragment,p),S=d(p),I=h(p,"DIV",{class:!0});var Z=me(I);y(P.$$.fragment,Z),B=d(Z),O=h(Z,"P",{"data-svelte-h":!0}),T(O)!=="svelte-1i57dtz"&&(O.textContent=Q),ue=d(Z),x=h(Z,"P",{"data-svelte-h":!0}),T(x)!=="svelte-6pahdo"&&(x.innerHTML=X),ie=d(Z),K=h(Z,"P",{"data-svelte-h":!0}),T(K)!=="svelte-hswkmf"&&(K.innerHTML=xe),de=d(Z),z=h(Z,"DIV",{class:!0});var D=me(z);y(ce.$$.fragment,D),ae=d(D),L=h(D,"P",{"data-svelte-h":!0}),T(L)!=="svelte-1olmd1j"&&(L.innerHTML=ge),pe=d(D),y(A.$$.fragment,D),$e=d(D),y(Y.$$.fragment,D),D.forEach(l),Z.forEach(l),this.h()},h(){Te(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Te(e,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Te(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Te(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(p,$){_(t,p,$),f(p,r,$),f(p,e,$),_(s,e,null),a(e,c),a(e,o),a(e,V),a(e,E),a(e,Je),a(e,H),a(e,je),a(e,F),_(R,F,null),a(F,ye),a(F,G),a(F,_e),_(W,F,null),a(F,q),_(N,F,null),f(p,re,$),_(se,p,$),f(p,S,$),f(p,I,$),_(P,I,null),a(I,B),a(I,O),a(I,ue),a(I,x),a(I,ie),a(I,K),a(I,de),a(I,z),_(ce,z,null),a(z,ae),a(z,L),a(z,pe),_(A,z,null),a(z,$e),_(Y,z,null),ee=!0},p(p,$){const j={};$&2&&(j.$$scope={dirty:$,ctx:p}),W.$set(j);const Z={};$&2&&(Z.$$scope={dirty:$,ctx:p}),N.$set(Z);const D={};$&2&&(D.$$scope={dirty:$,ctx:p}),A.$set(D);const te={};$&2&&(te.$$scope={dirty:$,ctx:p}),Y.$set(te)},i(p){ee||(b(t.$$.fragment,p),b(s.$$.fragment,p),b(R.$$.fragment,p),b(W.$$.fragment,p),b(N.$$.fragment,p),b(se.$$.fragment,p),b(P.$$.fragment,p),b(ce.$$.fragment,p),b(A.$$.fragment,p),b(Y.$$.fragment,p),ee=!0)},o(p){v(t.$$.fragment,p),v(s.$$.fragment,p),v(R.$$.fragment,p),v(W.$$.fragment,p),v(N.$$.fragment,p),v(se.$$.fragment,p),v(P.$$.fragment,p),v(ce.$$.fragment,p),v(A.$$.fragment,p),v(Y.$$.fragment,p),ee=!1},d(p){p&&(l(r),l(e),l(re),l(S),l(I)),w(t,p),w(s),w(R),w(W),w(N),w(se,p),w(P),w(ce),w(A),w(Y)}}}function dt(U){let t,r;return t=new Ve({props:{$$slots:{default:[it]},$$scope:{ctx:U}}}),{c(){M(t.$$.fragment)},l(e){y(t.$$.fragment,e)},m(e,s){_(t,e,s),r=!0},p(e,s){const c={};s&2&&(c.$$scope={dirty:s,ctx:e}),t.$set(c)},i(e){r||(b(t.$$.fragment,e),r=!0)},o(e){v(t.$$.fragment,e),r=!1},d(e){w(t,e)}}}function ct(U){let t,r=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){t=m("p"),t.innerHTML=r},l(e){t=h(e,"P",{"data-svelte-h":!0}),T(t)!=="svelte-fincs2"&&(t.innerHTML=r)},m(e,s){f(e,t,s)},p:ve,d(e){e&&l(t)}}}function pt(U){let t,r="Examples:",e,s,c;return s=new Ue({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMEZsYXhEaW5vdjJNb2RlbCUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQWltcG9ydCUyMHJlcXVlc3RzJTBBJTBBdXJsJTIwJTNEJTIwJTIyaHR0cCUzQSUyRiUyRmltYWdlcy5jb2NvZGF0YXNldC5vcmclMkZ2YWwyMDE3JTJGMDAwMDAwMDM5NzY5LmpwZyUyMiUwQWltYWdlJTIwJTNEJTIwSW1hZ2Uub3BlbihyZXF1ZXN0cy5nZXQodXJsJTJDJTIwc3RyZWFtJTNEVHJ1ZSkucmF3KSUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZkaW5vdjItYmFzZSUyMiklMEFtb2RlbCUyMCUzRCUyMEZsYXhEaW5vdjJNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZkaW5vdjItYmFzZSUyMiklMEElMEFpbnB1dHMlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMm5wJTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyklMEFsYXN0X2hpZGRlbl9zdGF0ZXMlMjAlM0QlMjBvdXRwdXRzLmxhc3RfaGlkZGVuX3N0YXRl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, FlaxDinov2Model
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

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

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(images=image, return_tensors=<span class="hljs-string">&quot;np&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)
<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state`,wrap:!1}}),{c(){t=m("p"),t.textContent=r,e=i(),M(s.$$.fragment)},l(o){t=h(o,"P",{"data-svelte-h":!0}),T(t)!=="svelte-kvfsh7"&&(t.textContent=r),e=d(o),y(s.$$.fragment,o)},m(o,C){f(o,t,C),f(o,e,C),_(s,o,C),c=!0},p:ve,i(o){c||(b(s.$$.fragment,o),c=!0)},o(o){v(s.$$.fragment,o),c=!1},d(o){o&&(l(t),l(e)),w(s,o)}}}function mt(U){let t,r=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){t=m("p"),t.innerHTML=r},l(e){t=h(e,"P",{"data-svelte-h":!0}),T(t)!=="svelte-fincs2"&&(t.innerHTML=r)},m(e,s){f(e,t,s)},p:ve,d(e){e&&l(t)}}}function ht(U){let t,r="Example:",e,s,c;return s=new Ue({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMEZsYXhEaW5vdjJGb3JJbWFnZUNsYXNzaWZpY2F0aW9uJTBBZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBaW1wb3J0JTIwamF4JTBBaW1wb3J0JTIwcmVxdWVzdHMlMEElMEF1cmwlMjAlM0QlMjAlMjJodHRwJTNBJTJGJTJGaW1hZ2VzLmNvY29kYXRhc2V0Lm9yZyUyRnZhbDIwMTclMkYwMDAwMDAwMzk3NjkuanBnJTIyJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBJTBBaW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRmRpbm92Mi1iYXNlLWltYWdlbmV0MWstMS1sYXllciUyMiklMEFtb2RlbCUyMCUzRCUyMEZsYXhEaW5vdjJGb3JJbWFnZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRmRpbm92Mi1iYXNlLWltYWdlbmV0MWstMS1sYXllciUyMiUyQyUyMGZyb21fcHQlM0RUcnVlKSUwQSUwQWlucHV0cyUyMCUzRCUyMGltYWdlX3Byb2Nlc3NvcihpbWFnZXMlM0RpbWFnZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIybnAlMjIpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQWxvZ2l0cyUyMCUzRCUyMG91dHB1dHMubG9naXRzJTBBJTBBJTIzJTIwbW9kZWwlMjBwcmVkaWN0cyUyMG9uZSUyMG9mJTIwdGhlJTIwMTAwMCUyMEltYWdlTmV0JTIwY2xhc3NlcyUwQXByZWRpY3RlZF9jbGFzc19pZHglMjAlM0QlMjBqYXgubnVtcHkuYXJnbWF4KGxvZ2l0cyUyQyUyMGF4aXMlM0QtMSklMEFwcmludCglMjJQcmVkaWN0ZWQlMjBjbGFzcyUzQSUyMiUyQyUyMG1vZGVsLmNvbmZpZy5pZDJsYWJlbCU1QnByZWRpY3RlZF9jbGFzc19pZHguaXRlbSgpJTVEKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, FlaxDinov2ForImageClassification
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> jax
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

<span class="hljs-meta">&gt;&gt;&gt; </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&quot;facebook/dinov2-base-imagenet1k-1-layer&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = FlaxDinov2ForImageClassification.from_pretrained(<span class="hljs-string">&quot;facebook/dinov2-base-imagenet1k-1-layer&quot;</span>, from_pt=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = image_processor(images=image, return_tensors=<span class="hljs-string">&quot;np&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = outputs.logits

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># model predicts one of the 1000 ImageNet classes</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_idx = jax.numpy.argmax(logits, axis=-<span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Predicted class:&quot;</span>, model.config.id2label[predicted_class_idx.item()])`,wrap:!1}}),{c(){t=m("p"),t.textContent=r,e=i(),M(s.$$.fragment)},l(o){t=h(o,"P",{"data-svelte-h":!0}),T(t)!=="svelte-11lpom8"&&(t.textContent=r),e=d(o),y(s.$$.fragment,o)},m(o,C){f(o,t,C),f(o,e,C),_(s,o,C),c=!0},p:ve,i(o){c||(b(s.$$.fragment,o),c=!0)},o(o){v(s.$$.fragment,o),c=!1},d(o){o&&(l(t),l(e)),w(s,o)}}}function ft(U){let t,r,e,s,c,o,C="The bare Dinov2 Model transformer outputting raw hidden-states without any specific head on top.",V,E,he=`This model inherits from <a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel">FlaxPreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading, saving and converting weights from PyTorch models)`,Je,H,fe=`This model is also a
<a href="https://flax.readthedocs.io/en/latest/api_reference/flax.linen/module.html" rel="nofollow">flax.linen.Module</a> subclass. Use it as
a regular Flax linen Module and refer to the Flax documentation for all matter related to general usage and
behavior.`,je,F,R="Finally, this model supports inherent JAX features such as:",ye,G,Ze='<li><a href="https://jax.readthedocs.io/en/latest/jax.html#just-in-time-compilation-jit" rel="nofollow">Just-In-Time (JIT) compilation</a></li> <li><a href="https://jax.readthedocs.io/en/latest/jax.html#automatic-differentiation" rel="nofollow">Automatic Differentiation</a></li> <li><a href="https://jax.readthedocs.io/en/latest/jax.html#vectorization-vmap" rel="nofollow">Vectorization</a></li> <li><a href="https://jax.readthedocs.io/en/latest/jax.html#parallelization-pmap" rel="nofollow">Parallelization</a></li>',_e,W,q,N,re,se="The <code>FlaxDinov2PreTrainedModel</code> forward method, overrides the <code>__call__</code> special method.",S,I,P,B,O,Q,ue,x,X,ie,K,xe=`Dinov2 Model transformer with an image classification head on top (a linear layer on top of the final hidden state of
the [CLS] token) e.g. for ImageNet.`,de,z,ce=`This model inherits from <a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel">FlaxPreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading, saving and converting weights from PyTorch models)`,ae,L,ge=`This model is also a
<a href="https://flax.readthedocs.io/en/latest/api_reference/flax.linen/module.html" rel="nofollow">flax.linen.Module</a> subclass. Use it as
a regular Flax linen Module and refer to the Flax documentation for all matter related to general usage and
behavior.`,pe,A,$e="Finally, this model supports inherent JAX features such as:",Y,ee,p='<li><a href="https://jax.readthedocs.io/en/latest/jax.html#just-in-time-compilation-jit" rel="nofollow">Just-In-Time (JIT) compilation</a></li> <li><a href="https://jax.readthedocs.io/en/latest/jax.html#automatic-differentiation" rel="nofollow">Automatic Differentiation</a></li> <li><a href="https://jax.readthedocs.io/en/latest/jax.html#vectorization-vmap" rel="nofollow">Vectorization</a></li> <li><a href="https://jax.readthedocs.io/en/latest/jax.html#parallelization-pmap" rel="nofollow">Parallelization</a></li>',$,j,Z,D,te,Be="The <code>FlaxDinov2PreTrainedModel</code> forward method, overrides the <code>__call__</code> special method.",ke,le,Ne,be,Me;return t=new Ge({props:{title:"FlaxDinov2Model",local:"transformers.FlaxDinov2Model",headingTag:"h2"}}),s=new We({props:{name:"class transformers.FlaxDinov2Model",anchor:"transformers.FlaxDinov2Model",parameters:[{name:"config",val:": Dinov2Config"},{name:"input_shape",val:" = None"},{name:"seed",val:": int = 0"},{name:"dtype",val:": dtype = <class 'jax.numpy.float32'>"},{name:"_do_init",val:": bool = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.FlaxDinov2Model.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2Config">Dinov2Config</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.FlaxPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.FlaxDinov2Model.dtype",description:`<strong>dtype</strong> (<code>jax.numpy.dtype</code>, <em>optional</em>, defaults to <code>jax.numpy.float32</code>) &#x2014;
The data type of the computation. Can be one of <code>jax.numpy.float32</code>, <code>jax.numpy.float16</code> (on GPUs) and
<code>jax.numpy.bfloat16</code> (on TPUs).</p>
<p>This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If
specified all the computation will be performed with the given <code>dtype</code>.</p>
<p><strong>Note that this only specifies the dtype of the computation and does not influence the dtype of model
parameters.</strong></p>
<p>If you wish to change the dtype of the model parameters, see <a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.to_fp16">to_fp16()</a> and
<a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.to_bf16">to_bf16()</a>.`,name:"dtype"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/dinov2/modeling_flax_dinov2.py#L670"}}),q=new We({props:{name:"__call__",anchor:"transformers.FlaxDinov2Model.__call__",parameters:[{name:"pixel_values",val:""},{name:"params",val:": typing.Optional[dict] = None"},{name:"dropout_rng",val:": <function PRNGKey at 0x7f9d10350ee0> = None"},{name:"train",val:": bool = False"},{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"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/dinov2/modeling_flax_dinov2.py#L591",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_flax_outputs.FlaxBaseModelOutputWithPooling"
>transformers.modeling_flax_outputs.FlaxBaseModelOutputWithPooling</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 (<code>&lt;class 'transformers.models.dinov2.configuration_dinov2.Dinov2Config'&gt;</code>) and inputs.</p>
<ul>
<li>
<p><strong>last_hidden_state</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>pooler_output</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, hidden_size)</code>) — Last layer hidden-state of the first token of the sequence (classification token) further processed by a
Linear layer and a Tanh activation function. The Linear layer weights are trained from the next sentence
prediction (classification) objective during pretraining.</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>jnp.ndarray</code> (one for the output of the embeddings + 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 initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>jnp.ndarray</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:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_flax_outputs.FlaxBaseModelOutputWithPooling"
>transformers.modeling_flax_outputs.FlaxBaseModelOutputWithPooling</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),I=new Xe({props:{$$slots:{default:[ct]},$$scope:{ctx:U}}}),B=new Ye({props:{anchor:"transformers.FlaxDinov2Model.__call__.example",$$slots:{default:[pt]},$$scope:{ctx:U}}}),Q=new Ge({props:{title:"FlaxDinov2ForImageClassification",local:"transformers.FlaxDinov2ForImageClassification",headingTag:"h2"}}),X=new We({props:{name:"class transformers.FlaxDinov2ForImageClassification",anchor:"transformers.FlaxDinov2ForImageClassification",parameters:[{name:"config",val:": Dinov2Config"},{name:"input_shape",val:" = None"},{name:"seed",val:": int = 0"},{name:"dtype",val:": dtype = <class 'jax.numpy.float32'>"},{name:"_do_init",val:": bool = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.FlaxDinov2ForImageClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2Config">Dinov2Config</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.FlaxPreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.FlaxDinov2ForImageClassification.dtype",description:`<strong>dtype</strong> (<code>jax.numpy.dtype</code>, <em>optional</em>, defaults to <code>jax.numpy.float32</code>) &#x2014;
The data type of the computation. Can be one of <code>jax.numpy.float32</code>, <code>jax.numpy.float16</code> (on GPUs) and
<code>jax.numpy.bfloat16</code> (on TPUs).</p>
<p>This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If
specified all the computation will be performed with the given <code>dtype</code>.</p>
<p><strong>Note that this only specifies the dtype of the computation and does not influence the dtype of model
parameters.</strong></p>
<p>If you wish to change the dtype of the model parameters, see <a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.to_fp16">to_fp16()</a> and
<a href="/docs/transformers/main/en/main_classes/model#transformers.FlaxPreTrainedModel.to_bf16">to_bf16()</a>.`,name:"dtype"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/dinov2/modeling_flax_dinov2.py#L757"}}),Z=new We({props:{name:"__call__",anchor:"transformers.FlaxDinov2ForImageClassification.__call__",parameters:[{name:"pixel_values",val:""},{name:"params",val:": typing.Optional[dict] = None"},{name:"dropout_rng",val:": <function PRNGKey at 0x7f9d10350ee0> = None"},{name:"train",val:": bool = False"},{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"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/dinov2/modeling_flax_dinov2.py#L591",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_flax_outputs.FlaxSequenceClassifierOutput"
>transformers.modeling_flax_outputs.FlaxSequenceClassifierOutput</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 (<code>&lt;class 'transformers.models.dinov2.configuration_dinov2.Dinov2Config'&gt;</code>) and inputs.</p>
<ul>
<li>
<p><strong>logits</strong> (<code>jnp.ndarray</code> of shape <code>(batch_size, config.num_labels)</code>) — Classification (or regression if config.num_labels==1) scores (before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>jnp.ndarray</code> (one for the output of the embeddings + 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 initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(jnp.ndarray)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>jnp.ndarray</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:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_flax_outputs.FlaxSequenceClassifierOutput"
>transformers.modeling_flax_outputs.FlaxSequenceClassifierOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),le=new Xe({props:{$$slots:{default:[mt]},$$scope:{ctx:U}}}),be=new Ye({props:{anchor:"transformers.FlaxDinov2ForImageClassification.__call__.example",$$slots:{default:[ht]},$$scope:{ctx:U}}}),{c(){M(t.$$.fragment),r=i(),e=m("div"),M(s.$$.fragment),c=i(),o=m("p"),o.textContent=C,V=i(),E=m("p"),E.innerHTML=he,Je=i(),H=m("p"),H.innerHTML=fe,je=i(),F=m("p"),F.textContent=R,ye=i(),G=m("ul"),G.innerHTML=Ze,_e=i(),W=m("div"),M(q.$$.fragment),N=i(),re=m("p"),re.innerHTML=se,S=i(),M(I.$$.fragment),P=i(),M(B.$$.fragment),O=i(),M(Q.$$.fragment),ue=i(),x=m("div"),M(X.$$.fragment),ie=i(),K=m("p"),K.textContent=xe,de=i(),z=m("p"),z.innerHTML=ce,ae=i(),L=m("p"),L.innerHTML=ge,pe=i(),A=m("p"),A.textContent=$e,Y=i(),ee=m("ul"),ee.innerHTML=p,$=i(),j=m("div"),M(Z.$$.fragment),D=i(),te=m("p"),te.innerHTML=Be,ke=i(),M(le.$$.fragment),Ne=i(),M(be.$$.fragment),this.h()},l(u){y(t.$$.fragment,u),r=d(u),e=h(u,"DIV",{class:!0});var J=me(e);y(s.$$.fragment,J),c=d(J),o=h(J,"P",{"data-svelte-h":!0}),T(o)!=="svelte-11pdceb"&&(o.textContent=C),V=d(J),E=h(J,"P",{"data-svelte-h":!0}),T(E)!=="svelte-3daxed"&&(E.innerHTML=he),Je=d(J),H=h(J,"P",{"data-svelte-h":!0}),T(H)!=="svelte-10nfsf3"&&(H.innerHTML=fe),je=d(J),F=h(J,"P",{"data-svelte-h":!0}),T(F)!=="svelte-1pplc4a"&&(F.textContent=R),ye=d(J),G=h(J,"UL",{"data-svelte-h":!0}),T(G)!=="svelte-1w7z84m"&&(G.innerHTML=Ze),_e=d(J),W=h(J,"DIV",{class:!0});var ne=me(W);y(q.$$.fragment,ne),N=d(ne),re=h(ne,"P",{"data-svelte-h":!0}),T(re)!=="svelte-13irhfr"&&(re.innerHTML=se),S=d(ne),y(I.$$.fragment,ne),P=d(ne),y(B.$$.fragment,ne),ne.forEach(l),J.forEach(l),O=d(u),y(Q.$$.fragment,u),ue=d(u),x=h(u,"DIV",{class:!0});var k=me(x);y(X.$$.fragment,k),ie=d(k),K=h(k,"P",{"data-svelte-h":!0}),T(K)!=="svelte-kzwbbb"&&(K.textContent=xe),de=d(k),z=h(k,"P",{"data-svelte-h":!0}),T(z)!=="svelte-3daxed"&&(z.innerHTML=ce),ae=d(k),L=h(k,"P",{"data-svelte-h":!0}),T(L)!=="svelte-10nfsf3"&&(L.innerHTML=ge),pe=d(k),A=h(k,"P",{"data-svelte-h":!0}),T(A)!=="svelte-1pplc4a"&&(A.textContent=$e),Y=d(k),ee=h(k,"UL",{"data-svelte-h":!0}),T(ee)!=="svelte-1w7z84m"&&(ee.innerHTML=p),$=d(k),j=h(k,"DIV",{class:!0});var oe=me(j);y(Z.$$.fragment,oe),D=d(oe),te=h(oe,"P",{"data-svelte-h":!0}),T(te)!=="svelte-13irhfr"&&(te.innerHTML=Be),ke=d(oe),y(le.$$.fragment,oe),Ne=d(oe),y(be.$$.fragment,oe),oe.forEach(l),k.forEach(l),this.h()},h(){Te(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Te(e,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Te(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Te(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(u,J){_(t,u,J),f(u,r,J),f(u,e,J),_(s,e,null),a(e,c),a(e,o),a(e,V),a(e,E),a(e,Je),a(e,H),a(e,je),a(e,F),a(e,ye),a(e,G),a(e,_e),a(e,W),_(q,W,null),a(W,N),a(W,re),a(W,S),_(I,W,null),a(W,P),_(B,W,null),f(u,O,J),_(Q,u,J),f(u,ue,J),f(u,x,J),_(X,x,null),a(x,ie),a(x,K),a(x,de),a(x,z),a(x,ae),a(x,L),a(x,pe),a(x,A),a(x,Y),a(x,ee),a(x,$),a(x,j),_(Z,j,null),a(j,D),a(j,te),a(j,ke),_(le,j,null),a(j,Ne),_(be,j,null),Me=!0},p(u,J){const ne={};J&2&&(ne.$$scope={dirty:J,ctx:u}),I.$set(ne);const k={};J&2&&(k.$$scope={dirty:J,ctx:u}),B.$set(k);const oe={};J&2&&(oe.$$scope={dirty:J,ctx:u}),le.$set(oe);const Ie={};J&2&&(Ie.$$scope={dirty:J,ctx:u}),be.$set(Ie)},i(u){Me||(b(t.$$.fragment,u),b(s.$$.fragment,u),b(q.$$.fragment,u),b(I.$$.fragment,u),b(B.$$.fragment,u),b(Q.$$.fragment,u),b(X.$$.fragment,u),b(Z.$$.fragment,u),b(le.$$.fragment,u),b(be.$$.fragment,u),Me=!0)},o(u){v(t.$$.fragment,u),v(s.$$.fragment,u),v(q.$$.fragment,u),v(I.$$.fragment,u),v(B.$$.fragment,u),v(Q.$$.fragment,u),v(X.$$.fragment,u),v(Z.$$.fragment,u),v(le.$$.fragment,u),v(be.$$.fragment,u),Me=!1},d(u){u&&(l(r),l(e),l(O),l(ue),l(x)),w(t,u),w(s),w(q),w(I),w(B),w(Q,u),w(X),w(Z),w(le),w(be)}}}function ut(U){let t,r;return t=new Ve({props:{$$slots:{default:[ft]},$$scope:{ctx:U}}}),{c(){M(t.$$.fragment)},l(e){y(t.$$.fragment,e)},m(e,s){_(t,e,s),r=!0},p(e,s){const c={};s&2&&(c.$$scope={dirty:s,ctx:e}),t.$set(c)},i(e){r||(b(t.$$.fragment,e),r=!0)},o(e){v(t.$$.fragment,e),r=!1},d(e){w(t,e)}}}function gt(U){let t,r,e,s,c,o='<div class="flex flex-wrap space-x-1"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&amp;logo=pytorch&amp;logoColor=white"/> <img alt="Flax" src="https://img.shields.io/badge/Flax-29a79b.svg?style=flat&amp;logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAMAAAANxBKoAAAC7lBMVEUAAADg5vYHPVgAoJH+/v76+v39/f9JbLP///9+AIgAnY3///+mcqzt8fXy9fgkXa3Ax9709fr+///9/f8qXq49qp5AaLGMwrv8/P0eW60VWawxYq8yqJzG2dytt9Wyu9elzci519Lf3O3S2efY3OrY0+Xp7PT///////+dqNCexMc6Z7AGpJeGvbenstPZ5ejQ1OfJzOLa7ejh4+/r8fT29vpccbklWK8PVa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/ISIJAVKhgNp+4b4veCFhYVJw4locdSjZCp9cPUhLF9EZ3KKzURepMEtCDPP3VcWFx4UIiZIklIpFNfHpdEafIF2aRmOcrUmjohbT2WUllbmRvgfbythbQO3222fpDJoufaQPncYYuqoGtUEsCJZL6/3PR5b4syeSjZMQG/T2maGANlXT2v8S4AULWaUkCxfLyW8iW4kdka+nEMjxpL2NCwsYNBp+Q61PF43zyDg9Bm9+3NNySn78jMZUUkumqE4Gp7JmFOdP1vc8PpRrzj9+wPinCy8K1PiJ4aYbnTYpCCbDkBSbzhu2QJ1Gd82t8jI8TH51+OzvXoWbnXUOBkNW+0mWFwGcGOUVpU81/n3TOHb5oMt2FgYGjzau0Nif0Ss7Q3XB33hjjQHjHA5E5aOyIQc8CBrLdQSs3j92VG+3nNEjbkbdbBr9zm04ruvw37vh0QKOdeGIkckc80fX3KH/h7PT4BOjgCty8VZ5ux1MoO5Cf5naca2LAsEgehI+drX8o/0Nu+W0m6K/I9gGPd/dfx/EN/wN62AhsBWuAAAAAElFTkSuQmCC"/> <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"/> <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&amp;logo=pytorch&amp;logoColor=white"/></div>',C,V,E,he,Je='<a href="https://huggingface.co/papers/2304.07193" rel="nofollow">DINOv2</a> is a vision foundation model that uses <a href="./vit">ViT</a> as a feature extractor for multiple downstream tasks like image classification and depth estimation. It focuses on stabilizing and accelerating training through techniques like a faster memory-efficient attention, sequence packing, improved stochastic depth, Fully Sharded Data Parallel (FSDP), and model distillation.',H,fe,je='You can find all the original DINOv2 checkpoints under the <a href="https://huggingface.co/collections/facebook/dinov2-6526c98554b3d2576e071ce3" rel="nofollow">Dinov2</a> collection.',F,R,ye,G,Ze='The example below demonstrates how to obtain an image embedding with <a href="/docs/transformers/main/en/main_classes/pipelines#transformers.Pipeline">Pipeline</a> or the <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoModel">AutoModel</a> class.',_e,W,q,N,re='Quantization reduces the memory burden of large models by representing the weights in a lower precision. Refer to the <a href="../quantization/overview">Quantization</a> overview for more available quantization backends.',se,S,I='The example below uses <a href="../quantization/torchao">torchao</a> to only quantize the weights to int4.',P,B,O,Q,ue,x,X,ie,K="The example below shows how to split the output tensor into:",xe,de,z=`<li>one embedding for the whole image, commonly referred to as a <code>CLS</code> token,
useful for classification and retrieval</li> <li>a set of local embeddings, one for each <code>14x14</code> patch of the input image,
useful for dense tasks, such as semantic segmentation</li>`,ce,ae,L,ge,pe,A=`Use <a href="https://pytorch.org/docs/stable/generated/torch.jit.trace.html" rel="nofollow">torch.jit.trace</a> to speedup inference.
However, it will produce some mismatched elements. The difference between the original and traced model is 1e-4.`,$e,Y,ee,p,$,j,Z,D,te,Be=`This is the configuration class to store the configuration of a <a href="/docs/transformers/main/en/model_doc/dinov2#transformers.Dinov2Model">Dinov2Model</a>. It is used to instantiate an
Dinov2 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 Dinov2
<a href="https://huggingface.co/google/dinov2-base-patch16-224" rel="nofollow">google/dinov2-base-patch16-224</a> architecture.`,ke,le,Ne=`Configuration objects inherit from <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> for more information.`,be,Me,u,J,ne,k,oe,Ie,Re;return V=new Ge({props:{title:"DINOv2",local:"dinov2",headingTag:"h1"}}),R=new Xe({props:{warning:!1,$$slots:{default:[Ke]},$$scope:{ctx:U}}}),W=new Pe({props:{id:"usage",options:["Pipeline","AutoModel"],$$slots:{default:[nt]},$$scope:{ctx:U}}}),B=new Ue({props:{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMHRvcmNoYW8lMEFpbXBvcnQlMjByZXF1ZXN0cyUwQWZyb20l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yMiUyQyUwQSUyMCUyMCUyMCUyMHF1YW50aXphdGlvbl9jb25maWclM0RxdWFudGl6YXRpb25fY29uZmlnJTBBKSUwQSUwQWlucHV0cyUyMCUzRCUyMHByb2Nlc3NvcihpbWFnZXMlM0RpbWFnZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCoqaW5wdXRzKSUwQWxvZ2l0cyUyMCUzRCUyMG91dHB1dHMubG9naXRzJTBBcHJlZGljdGVkX2NsYXNzX2lkeCUyMCUzRCUyMGxvZ2l0cy5hcmdtYXgoLTEpLml0ZW0oKSUwQXByaW50KCUyMlByZWRpY3RlZCUyMGNsYXNzJTNBJTIyJTJDJTIwbW9kZWwuY29uZmlnLmlkMmxhYmVsJTVCcHJlZGljdGVkX2NsYXNzX2lkeCU1RCk=",highlighted:`<span class="hljs-comment"># pip install torchao</span>
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TorchAoConfig, AutoImageProcessor, AutoModelForImageClassification
<span class="hljs-keyword">from</span> torchao.quantization <span class="hljs-keyword">import</span> Int4WeightOnlyConfig
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

url = <span class="hljs-string">&#x27;http://images.cocodataset.org/val2017/000000039769.jpg&#x27;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&#x27;facebook/dinov2-giant-imagenet1k-1-layer&#x27;</span>)

quant_config = Int4WeightOnlyConfig(group_size=<span class="hljs-number">128</span>)
quantization_config = TorchAoConfig(quant_type=quant_config)

model = AutoModelForImageClassification.from_pretrained(
    <span class="hljs-string">&#x27;facebook/dinov2-giant-imagenet1k-1-layer&#x27;</span>,
    torch_dtype=torch.bfloat16,
    device_map=<span class="hljs-string">&quot;auto&quot;</span>,
    quantization_config=quantization_config
)

inputs = processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
outputs = model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-<span class="hljs-number">1</span>).item()
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Predicted class:&quot;</span>, model.config.id2label[predicted_class_idx])`,wrap:!1}}),Q=new Ge({props:{title:"Notes",local:"notes",headingTag:"h2"}}),ae=new Ue({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMEF1dG9Nb2RlbCUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQWltcG9ydCUyMHJlcXVlc3RzJTBBJTBBdXJsJTIwJTNEJTIwJ2h0dHAlM0ElMkYlMkZpbWFnZXMuY29jb2RhdGFzZXQub3JnJTJGdmFsMjAxNyUyRjAwMDAwMDAzOTc2OS5qcGcnJTBBaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBcHJpbnQoaW1hZ2UuaGVpZ2h0JTJDJTIwaW1hZ2Uud2lkdGgpJTIwJTIwJTIzJTIwJTVCNDgwJTJDJTIwNjQwJTVEJTBBJTBBcHJvY2Vzc29yJTIwJTNEJTIwQXV0b0ltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCgnZmFjZWJvb2slMkZkaW5vdjItYmFzZScpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCdmYWNlYm9vayUyRmRpbm92Mi1iYXNlJyklMEFwYXRjaF9zaXplJTIwJTNEJTIwbW9kZWwuY29uZmlnLnBhdGNoX3NpemUlMEElMEFpbnB1dHMlMjAlM0QlMjBwcm9jZXNzb3IoaW1hZ2VzJTNEaW1hZ2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSU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VuKDElMkMlMjAobnVtX3BhdGNoZXNfaGVpZ2h0JTJDJTIwbnVtX3BhdGNoZXNfd2lkdGgpKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, AutoModel
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">import</span> requests

url = <span class="hljs-string">&#x27;http://images.cocodataset.org/val2017/000000039769.jpg&#x27;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
<span class="hljs-built_in">print</span>(image.height, image.width)  <span class="hljs-comment"># [480, 640]</span>

processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&#x27;facebook/dinov2-base&#x27;</span>)
model = AutoModel.from_pretrained(<span class="hljs-string">&#x27;facebook/dinov2-base&#x27;</span>)
patch_size = model.config.patch_size

inputs = processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-built_in">print</span>(inputs.pixel_values.shape)  <span class="hljs-comment"># [1, 3, 224, 224]</span>
batch_size, rgb, img_height, img_width = inputs.pixel_values.shape
num_patches_height, num_patches_width = img_height // patch_size, img_width // patch_size
num_patches_flat = num_patches_height * num_patches_width

outputs = model(**inputs)
last_hidden_states = outputs[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(last_hidden_states.shape)  <span class="hljs-comment"># [1, 1 + 256, 768]</span>
<span class="hljs-keyword">assert</span> last_hidden_states.shape == (batch_size, <span class="hljs-number">1</span> + num_patches_flat, model.config.hidden_size)

cls_token = last_hidden_states[:, <span class="hljs-number">0</span>, :]
patch_features = last_hidden_states[:, <span class="hljs-number">1</span>:, :].unflatten(<span class="hljs-number">1</span>, (num_patches_height, num_patches_width))`,wrap:!1}}),Y=new Ue({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b0ltYWdlUHJvY2Vzc29yJTJ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RCUyMHRyYWNlZF9tb2RlbChpbnB1dHMucGl4ZWxfdmFsdWVzKSUwQSUwQXByaW50KChsYXN0X2hpZGRlbl9zdGF0ZXMlMjAtJTIwdHJhY2VkX291dHB1dHMlNUIwJTVEKS5hYnMoKS5tYXgoKSk=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, AutoModel
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">import</span> requests

url = <span class="hljs-string">&#x27;http://images.cocodataset.org/val2017/000000039769.jpg&#x27;</span>
image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)

processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">&#x27;facebook/dinov2-base&#x27;</span>)
model = AutoModel.from_pretrained(<span class="hljs-string">&#x27;facebook/dinov2-base&#x27;</span>)

inputs = processor(images=image, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
outputs = model(**inputs)
last_hidden_states = outputs[<span class="hljs-number">0</span>]

<span class="hljs-comment"># We have to force return_dict=False for tracing</span>
model.config.return_dict = <span class="hljs-literal">False</span>

<span class="hljs-keyword">with</span> torch.no_grad():
    traced_model = torch.jit.trace(model, [inputs.pixel_values])
    traced_outputs = traced_model(inputs.pixel_values)

<span class="hljs-built_in">print</span>((last_hidden_states - traced_outputs[<span class="hljs-number">0</span>]).<span class="hljs-built_in">abs</span>().<span class="hljs-built_in">max</span>())`,wrap:!1}}),p=new Ge({props:{title:"Dinov2Config",local:"transformers.Dinov2Config",headingTag:"h2"}}),Z=new We({props:{name:"class transformers.Dinov2Config",anchor:"transformers.Dinov2Config",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:"hidden_dropout_prob",val:" = 0.0"},{name:"attention_probs_dropout_prob",val:" = 0.0"},{name:"initializer_range",val:" = 0.02"},{name:"layer_norm_eps",val:" = 1e-06"},{name:"image_size",val:" = 224"},{name:"patch_size",val:" = 14"},{name:"num_channels",val:" = 3"},{name:"qkv_bias",val:" = True"},{name:"layerscale_value",val:" = 1.0"},{name:"drop_path_rate",val:" = 0.0"},{name:"use_swiglu_ffn",val:" = False"},{name:"out_features",val:" = None"},{name:"out_indices",val:" = None"},{name:"apply_layernorm",val:" = True"},{name:"reshape_hidden_states",val:" = True"},{name:"use_mask_token",val:" = True"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.Dinov2Config.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.Dinov2Config.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.Dinov2Config.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.Dinov2Config.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Ratio of the hidden size of the MLPs relative to the <code>hidden_size</code>.`,name:"mlp_ratio"},{anchor:"transformers.Dinov2Config.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.Dinov2Config.hidden_dropout_prob",description:`<strong>hidden_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:"hidden_dropout_prob"},{anchor:"transformers.Dinov2Config.attention_probs_dropout_prob",description:`<strong>attention_probs_dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_probs_dropout_prob"},{anchor:"transformers.Dinov2Config.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.Dinov2Config.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-06) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.Dinov2Config.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.Dinov2Config.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, <em>optional</em>, defaults to 14) &#x2014;
The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.Dinov2Config.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.Dinov2Config.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.Dinov2Config.layerscale_value",description:`<strong>layerscale_value</strong> (<code>float</code>, <em>optional</em>, defaults to 1.0) &#x2014;
Initial value to use for layer scale.`,name:"layerscale_value"},{anchor:"transformers.Dinov2Config.drop_path_rate",description:`<strong>drop_path_rate</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Stochastic depth rate per sample (when applied in the main path of residual layers).`,name:"drop_path_rate"},{anchor:"transformers.Dinov2Config.use_swiglu_ffn",description:`<strong>use_swiglu_ffn</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use the SwiGLU feedforward neural network.`,name:"use_swiglu_ffn"},{anchor:"transformers.Dinov2Config.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. Must be in the
same order as defined in the <code>stage_names</code> attribute.`,name:"out_features"},{anchor:"transformers.Dinov2Config.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. Must be in the
same order as defined in the <code>stage_names</code> attribute.`,name:"out_indices"},{anchor:"transformers.Dinov2Config.apply_layernorm",description:`<strong>apply_layernorm</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to apply layer normalization to the feature maps in case the model is used as backbone.`,name:"apply_layernorm"},{anchor:"transformers.Dinov2Config.reshape_hidden_states",description:`<strong>reshape_hidden_states</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to reshape the feature maps to 4D tensors of shape <code>(batch_size, hidden_size, height, width)</code> in
case the model is used as backbone. If <code>False</code>, the feature maps will be 3D tensors of shape <code>(batch_size, seq_len, hidden_size)</code>.`,name:"reshape_hidden_states"},{anchor:"transformers.Dinov2Config.use_mask_token",description:`<strong>use_mask_token</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to use mask_token in embeddings.`,name:"use_mask_token"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/dinov2/configuration_dinov2.py#L31"}}),Me=new Ye({props:{anchor:"transformers.Dinov2Config.example",$$slots:{default:[ot]},$$scope:{ctx:U}}}),J=new Se({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[ut],pytorch:[dt]},$$scope:{ctx:U}}}),k=new Oe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/dinov2.md"}}),{c(){t=m("meta"),r=i(),e=m("p"),s=i(),c=m("div"),c.innerHTML=o,C=i(),M(V.$$.fragment),E=i(),he=m("p"),he.innerHTML=Je,H=i(),fe=m("p"),fe.innerHTML=je,F=i(),M(R.$$.fragment),ye=i(),G=m("p"),G.innerHTML=Ze,_e=i(),M(W.$$.fragment),q=i(),N=m("p"),N.innerHTML=re,se=i(),S=m("p"),S.innerHTML=I,P=i(),M(B.$$.fragment),O=i(),M(Q.$$.fragment),ue=i(),x=m("ul"),X=m("li"),ie=m("p"),ie.textContent=K,xe=i(),de=m("ul"),de.innerHTML=z,ce=i(),M(ae.$$.fragment),L=i(),ge=m("li"),pe=m("p"),pe.innerHTML=A,$e=i(),M(Y.$$.fragment),ee=i(),M(p.$$.fragment),$=i(),j=m("div"),M(Z.$$.fragment),D=i(),te=m("p"),te.innerHTML=Be,ke=i(),le=m("p"),le.innerHTML=Ne,be=i(),M(Me.$$.fragment),u=i(),M(J.$$.fragment),ne=i(),M(k.$$.fragment),oe=i(),Ie=m("p"),this.h()},l(n){const g=Le("svelte-u9bgzb",document.head);t=h(g,"META",{name:!0,content:!0}),g.forEach(l),r=d(n),e=h(n,"P",{}),me(e).forEach(l),s=d(n),c=h(n,"DIV",{style:!0,"data-svelte-h":!0}),T(c)!=="svelte-wl0ab7"&&(c.innerHTML=o),C=d(n),y(V.$$.fragment,n),E=d(n),he=h(n,"P",{"data-svelte-h":!0}),T(he)!=="svelte-i29kee"&&(he.innerHTML=Je),H=d(n),fe=h(n,"P",{"data-svelte-h":!0}),T(fe)!=="svelte-1ua7res"&&(fe.innerHTML=je),F=d(n),y(R.$$.fragment,n),ye=d(n),G=h(n,"P",{"data-svelte-h":!0}),T(G)!=="svelte-1qbz9s2"&&(G.innerHTML=Ze),_e=d(n),y(W.$$.fragment,n),q=d(n),N=h(n,"P",{"data-svelte-h":!0}),T(N)!=="svelte-nf5ooi"&&(N.innerHTML=re),se=d(n),S=h(n,"P",{"data-svelte-h":!0}),T(S)!=="svelte-w36i1c"&&(S.innerHTML=I),P=d(n),y(B.$$.fragment,n),O=d(n),y(Q.$$.fragment,n),ue=d(n),x=h(n,"UL",{});var Fe=me(x);X=h(Fe,"LI",{});var Ce=me(X);ie=h(Ce,"P",{"data-svelte-h":!0}),T(ie)!=="svelte-90ha2s"&&(ie.textContent=K),xe=d(Ce),de=h(Ce,"UL",{"data-svelte-h":!0}),T(de)!=="svelte-is7q7m"&&(de.innerHTML=z),ce=d(Ce),y(ae.$$.fragment,Ce),Ce.forEach(l),L=d(Fe),ge=h(Fe,"LI",{});var ze=me(ge);pe=h(ze,"P",{"data-svelte-h":!0}),T(pe)!=="svelte-1qoetgv"&&(pe.innerHTML=A),$e=d(ze),y(Y.$$.fragment,ze),ze.forEach(l),Fe.forEach(l),ee=d(n),y(p.$$.fragment,n),$=d(n),j=h(n,"DIV",{class:!0});var we=me(j);y(Z.$$.fragment,we),D=d(we),te=h(we,"P",{"data-svelte-h":!0}),T(te)!=="svelte-x3ratf"&&(te.innerHTML=Be),ke=d(we),le=h(we,"P",{"data-svelte-h":!0}),T(le)!=="svelte-o55m63"&&(le.innerHTML=Ne),be=d(we),y(Me.$$.fragment,we),we.forEach(l),u=d(n),y(J.$$.fragment,n),ne=d(n),y(k.$$.fragment,n),oe=d(n),Ie=h(n,"P",{}),me(Ie).forEach(l),this.h()},h(){Te(t,"name","hf:doc:metadata"),Te(t,"content",Mt),qe(c,"float","right"),Te(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(n,g){a(document.head,t),f(n,r,g),f(n,e,g),f(n,s,g),f(n,c,g),f(n,C,g),_(V,n,g),f(n,E,g),f(n,he,g),f(n,H,g),f(n,fe,g),f(n,F,g),_(R,n,g),f(n,ye,g),f(n,G,g),f(n,_e,g),_(W,n,g),f(n,q,g),f(n,N,g),f(n,se,g),f(n,S,g),f(n,P,g),_(B,n,g),f(n,O,g),_(Q,n,g),f(n,ue,g),f(n,x,g),a(x,X),a(X,ie),a(X,xe),a(X,de),a(X,ce),_(ae,X,null),a(x,L),a(x,ge),a(ge,pe),a(ge,$e),_(Y,ge,null),f(n,ee,g),_(p,n,g),f(n,$,g),f(n,j,g),_(Z,j,null),a(j,D),a(j,te),a(j,ke),a(j,le),a(j,be),_(Me,j,null),f(n,u,g),_(J,n,g),f(n,ne,g),_(k,n,g),f(n,oe,g),f(n,Ie,g),Re=!0},p(n,[g]){const Fe={};g&2&&(Fe.$$scope={dirty:g,ctx:n}),R.$set(Fe);const Ce={};g&2&&(Ce.$$scope={dirty:g,ctx:n}),W.$set(Ce);const ze={};g&2&&(ze.$$scope={dirty:g,ctx:n}),Me.$set(ze);const we={};g&2&&(we.$$scope={dirty:g,ctx:n}),J.$set(we)},i(n){Re||(b(V.$$.fragment,n),b(R.$$.fragment,n),b(W.$$.fragment,n),b(B.$$.fragment,n),b(Q.$$.fragment,n),b(ae.$$.fragment,n),b(Y.$$.fragment,n),b(p.$$.fragment,n),b(Z.$$.fragment,n),b(Me.$$.fragment,n),b(J.$$.fragment,n),b(k.$$.fragment,n),Re=!0)},o(n){v(V.$$.fragment,n),v(R.$$.fragment,n),v(W.$$.fragment,n),v(B.$$.fragment,n),v(Q.$$.fragment,n),v(ae.$$.fragment,n),v(Y.$$.fragment,n),v(p.$$.fragment,n),v(Z.$$.fragment,n),v(Me.$$.fragment,n),v(J.$$.fragment,n),v(k.$$.fragment,n),Re=!1},d(n){n&&(l(r),l(e),l(s),l(c),l(C),l(E),l(he),l(H),l(fe),l(F),l(ye),l(G),l(_e),l(q),l(N),l(se),l(S),l(P),l(O),l(ue),l(x),l(ee),l($),l(j),l(u),l(ne),l(oe),l(Ie)),l(t),w(V,n),w(R,n),w(W,n),w(B,n),w(Q,n),w(ae),w(Y),w(p,n),w(Z),w(Me),w(J,n),w(k,n)}}}const Mt='{"title":"DINOv2","local":"dinov2","sections":[{"title":"Notes","local":"notes","sections":[],"depth":2},{"title":"Dinov2Config","local":"transformers.Dinov2Config","sections":[],"depth":2},{"title":"Dinov2Model","local":"transformers.Dinov2Model","sections":[],"depth":2},{"title":"Dinov2ForImageClassification","local":"transformers.Dinov2ForImageClassification","sections":[],"depth":2},{"title":"FlaxDinov2Model","local":"transformers.FlaxDinov2Model","sections":[],"depth":2},{"title":"FlaxDinov2ForImageClassification","local":"transformers.FlaxDinov2ForImageClassification","sections":[],"depth":2}],"depth":1}';function yt(U){return He(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ct extends Qe{constructor(t){super(),Ae(this,t,yt,gt,Ee,{})}}export{Ct as component};
