Buckets:
| import"../chunks/DsnmJJEf.js";import{i as V,h as Y,C as H,H as n,D as i,E as X,s as L,a as f}from"../chunks/CD2rhSaz.js";import{p as Q,o as O,s as e,f as c,a as s,b as $,c as d,d as p,r as l,n as K}from"../chunks/DmjbnfDo.js";import{T as A}from"../chunks/B2suExpn.js";import{E as u}from"../chunks/B5qO6y4i.js";import{P as ee}from"../chunks/ouTRzEUV.js";const oe='{"title":"Dilated Neighborhood Attention Transformer","local":"dilated-neighborhood-attention-transformer","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage tips","local":"usage-tips","sections":[],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2},{"title":"DinatConfig","local":"transformers.DinatConfig","sections":[],"depth":2},{"title":"DinatModel","local":"transformers.DinatModel","sections":[],"depth":2},{"title":"DinatForImageClassification","local":"transformers.DinatForImageClassification","sections":[],"depth":2}],"depth":1}';var te=p('<meta name="hf:doc:metadata"/>'),_=p("<p>Example:</p> <!>",1),G=p(`<p>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.</p>`),ae=p(`<p></p> <p><em>This model was published in HF papers on 2022-09-29 and contributed to Hugging Face Transformers on 2022-11-18.</em></p> <!> <!> <!> <p>DiNAT was proposed in <a href="https://huggingface.co/papers/2209.15001" rel="nofollow">Dilated Neighborhood Attention Transformer</a> by Ali Hassani and Humphrey Shi.</p> <p>It extends <a href="nat">NAT</a> by adding a Dilated Neighborhood Attention pattern to capture global context, | |
| and shows significant performance improvements over it.</p> <p>The abstract from the paper is the following:</p> <p><em>Transformers are quickly becoming one of the most heavily applied deep learning architectures across modalities, | |
| domains, and tasks. In vision, on top of ongoing efforts into plain transformers, hierarchical transformers have | |
| also gained significant attention, thanks to their performance and easy integration into existing frameworks. | |
| These models typically employ localized attention mechanisms, such as the sliding-window Neighborhood Attention (NA) | |
| or Swin Transformer’s Shifted Window Self Attention. While effective at reducing self attention’s quadratic complexity, | |
| local attention weakens two of the most desirable properties of self attention: long range inter-dependency modeling, | |
| and global receptive field. In this paper, we introduce Dilated Neighborhood Attention (DiNA), a natural, flexible and | |
| efficient extension to NA that can capture more global context and expand receptive fields exponentially at no | |
| additional cost. NA’s local attention and DiNA’s sparse global attention complement each other, and therefore we | |
| introduce Dilated Neighborhood Attention Transformer (DiNAT), a new hierarchical vision transformer built upon both. | |
| DiNAT variants enjoy significant improvements over strong baselines such as NAT, Swin, and ConvNeXt. | |
| Our large model is faster and ahead of its Swin counterpart by 1.5% box AP in COCO object detection, | |
| 1.3% mask AP in COCO instance segmentation, and 1.1% mIoU in ADE20K semantic segmentation. | |
| Paired with new frameworks, our large variant is the new state of the art panoptic segmentation model on COCO (58.2 PQ) | |
| and ADE20K (48.5 PQ), and instance segmentation model on Cityscapes (44.5 AP) and ADE20K (35.4 AP) (no extra data). | |
| It also matches the state of the art specialized semantic segmentation models on ADE20K (58.2 mIoU), | |
| and ranks second on Cityscapes (84.5 mIoU) (no extra data).</em></p> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/dilated-neighborhood-attention-pattern.jpg" alt="drawing" width="600"/> <small>Neighborhood Attention with different dilation values. | |
| Taken from the <a href="https://huggingface.co/papers/2209.15001">original paper</a>.</small> <p>This model was contributed by <a href="https://huggingface.co/alihassanijr" rel="nofollow">Ali Hassani</a>. | |
| The original code can be found <a href="https://github.com/SHI-Labs/Neighborhood-Attention-Transformer" rel="nofollow">here</a>.</p> <!> <p>DiNAT can be used as a <em>backbone</em>. When <code>output_hidden_states = True</code>, | |
| it will output both <code>hidden_states</code> and <code>reshaped_hidden_states</code>. The <code>reshaped_hidden_states</code> have a shape of <code>(batch, num_channels, height, width)</code> rather than <code>(batch_size, height, width, num_channels)</code>.</p> <p>Notes:</p> <ul><li>DiNAT depends on <a href="https://github.com/SHI-Labs/NATTEN/" rel="nofollow">NATTEN</a>’s implementation of Neighborhood Attention and Dilated Neighborhood Attention. | |
| You can install it with pre-built wheels for Linux by referring to <a href="https://shi-labs.com/natten" rel="nofollow">shi-labs.com/natten</a>, or build on your system by running <code>pip install natten</code>. | |
| Note that the latter will likely take time to compile. NATTEN does not support Windows devices yet.</li> <li>Patch size of 4 is only supported at the moment.</li></ul> <!> <p>A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with DiNAT.</p> <!> <ul><li><a href="/docs/transformers/pr_47708/en/model_doc/dinat#transformers.DinatForImageClassification">DinatForImageClassification</a> is supported by this <a href="https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-classification" rel="nofollow">example script</a> and <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/image_classification.ipynb" rel="nofollow">notebook</a>.</li> <li>See also: <a href="../tasks/image_classification">Image classification task guide</a></li></ul> <p>If you’re interested in submitting a resource to be included here, please feel free to open a Pull Request and we’ll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a DinatModel. It is used to instantiate a Dinat | |
| 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 <a href="https://huggingface.co/shi-labs/dinat-mini-in1k-224" rel="nofollow">shi-labs/dinat-mini-in1k-224</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_47708/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/pr_47708/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The bare Dinat Model outputting raw hidden-states without any specific head on top.</p> <p>This model inherits from <a href="/docs/transformers/pr_47708/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.)</p> <p>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.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_47708/en/model_doc/dinat#transformers.DinatModel">DinatModel</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) — 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>, <em>optional</em>, returned when <code>add_pooling_layer=True</code> is passed) — Average pooling of the last layer hidden-state.</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> <li><p><strong>reshaped_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 + one for the output of each stage) of | |
| shape <code>(batch_size, hidden_size, height, width)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to | |
| include the spatial dimensions.</p></li></ul> <!></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Dinat 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.</p> <p>This model inherits from <a href="/docs/transformers/pr_47708/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.)</p> <p>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.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_47708/en/model_doc/dinat#transformers.DinatForImageClassification">DinatForImageClassification</a> forward method, overrides the <code>__call__</code> special method.</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 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> <li><p><strong>reshaped_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 + one for the output of each stage) of | |
| shape <code>(batch_size, hidden_size, height, width)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the initial embedding outputs reshaped to | |
| include the spatial dimensions.</p></li></ul> <!></div></div> <!> <p></p>`,1);function ce(P,R){Q(R,!1),O(()=>{new URLSearchParams(window.location.search).get("fw")}),V();var b=ae();Y("1mspofy",o=>{var a=te();L(a,"content",oe),s(o,a)});var y=e(c(b),4);H(y,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var v=e(y,2);n(v,{title:"Dilated Neighborhood Attention Transformer",local:"dilated-neighborhood-attention-transformer",headingTag:"h1"});var T=e(v,2);n(T,{title:"Overview",local:"overview",headingTag:"h2"});var w=e(T,16);n(w,{title:"Usage tips",local:"usage-tips",headingTag:"h2"});var M=e(w,8);n(M,{title:"Resources",local:"resources",headingTag:"h2"});var D=e(M,4);ee(D,{pipeline:"image-classification"});var C=e(D,6);n(C,{title:"DinatConfig",local:"transformers.DinatConfig",headingTag:"h2"});var h=e(C,2),N=d(h);i(N,{name:"class transformers.DinatConfig",anchor:"transformers.DinatConfig",source:"https://github.com/huggingface/transformers/blob/vr_47708/src/transformers/models/dinat/configuration_dinat.py#L25",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": typing.Optional[typing.Literal['regression', 'single_label_classification', 'multi_label_classification']] = None"},{name:"patch_size",val:": int | list[int] | tuple[int, int] = 4"},{name:"num_channels",val:": int = 3"},{name:"embed_dim",val:": int = 64"},{name:"depths",val:": list[int] | tuple[int, ...] = (3, 4, 6, 5)"},{name:"num_heads",val:": list[int] | tuple[int, ...] = (2, 4, 8, 16)"},{name:"kernel_size",val:": int = 7"},{name:"dilations",val:": list | tuple | None = None"},{name:"mlp_ratio",val:": float = 3.0"},{name:"qkv_bias",val:": bool = True"},{name:"hidden_dropout_prob",val:": float | int = 0.0"},{name:"attention_probs_dropout_prob",val:": float | int = 0.0"},{name:"drop_path_rate",val:": float | int = 0.1"},{name:"hidden_act",val:": str = 'gelu'"},{name:"initializer_range",val:": float = 0.02"},{name:"layer_norm_eps",val:": float = 1e-05"},{name:"layer_scale_init_value",val:": float = 0.0"},{name:"_out_features",val:": list[str] | None = None"},{name:"_out_indices",val:": list[int] | None = None"}],parametersDescription:[{anchor:"transformers.DinatConfig.patch_size",description:`<strong>patch_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>4</code>) — | |
| The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.DinatConfig.num_channels",description:`<strong>num_channels</strong> (<code>int</code>, <em>optional</em>, defaults to <code>3</code>) — | |
| The number of input channels.`,name:"num_channels"},{anchor:"transformers.DinatConfig.embed_dim",description:`<strong>embed_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>64</code>) — | |
| Dimensionality of the embeddings and hidden states.`,name:"embed_dim"},{anchor:"transformers.DinatConfig.depths",description:`<strong>depths</strong> (<code>Union[list[int], tuple[int, ...]]</code>, <em>optional</em>, defaults to <code>(3, 4, 6, 5)</code>) — | |
| Depth of each layer in the Transformer.`,name:"depths"},{anchor:"transformers.DinatConfig.num_heads",description:`<strong>num_heads</strong> (<code>Union[list[int], tuple[int, ...]]</code>, <em>optional</em>, defaults to <code>(2, 4, 8, 16)</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_heads"},{anchor:"transformers.DinatConfig.kernel_size",description:`<strong>kernel_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>7</code>) — | |
| The size of the convolutional kernel.`,name:"kernel_size"},{anchor:"transformers.DinatConfig.dilations",description:`<strong>dilations</strong> (<code>list[list[int]]</code>, <em>optional</em>, defaults to <code>[[1, 8, 1], [1, 4, 1, 4], [1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1]]</code>) — | |
| Dilation value of each NA layer in the Transformer encoder.`,name:"dilations"},{anchor:"transformers.DinatConfig.mlp_ratio",description:`<strong>mlp_ratio</strong> (<code>float</code>, <em>optional</em>, defaults to <code>3.0</code>) — | |
| Ratio of the MLP hidden dim to the embedding dim.`,name:"mlp_ratio"},{anchor:"transformers.DinatConfig.qkv_bias",description:`<strong>qkv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to add a bias to the queries, keys and values.`,name:"qkv_bias"},{anchor:"transformers.DinatConfig.hidden_dropout_prob",description:`<strong>hidden_dropout_prob</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"hidden_dropout_prob"},{anchor:"transformers.DinatConfig.attention_probs_dropout_prob",description:`<strong>attention_probs_dropout_prob</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| The dropout ratio for the attention probabilities.`,name:"attention_probs_dropout_prob"},{anchor:"transformers.DinatConfig.drop_path_rate",description:`<strong>drop_path_rate</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.1</code>) — | |
| Drop path rate for the patch fusion.`,name:"drop_path_rate"},{anchor:"transformers.DinatConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>gelu</code>) — | |
| The non-linear activation function (function or string) in the decoder. For example, <code>"gelu"</code>, | |
| <code>"relu"</code>, <code>"silu"</code>, etc.`,name:"hidden_act"},{anchor:"transformers.DinatConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.02</code>) — | |
| The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.DinatConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-05</code>) — | |
| The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.DinatConfig.layer_scale_init_value",description:`<strong>layer_scale_init_value</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| Scale to use in the self-attention layers. 0.1 for base, 1e-6 for large. Set 0 to disable layer scale.`,name:"layer_scale_init_value"}]});var B=e(N,6);u(B,{anchor:"transformers.DinatConfig.example",children:(o,a)=>{var t=_(),r=e(c(t),2);f(r,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERpbmF0Q29uZmlnJTJDJTIwRGluYXRNb2RlbCUwQSUwQSUyMyUyMEluaXRpYWxpemluZyUyMGElMjBEaW5hdCUyMHNoaS1sYWJzJTJGZGluYXQtbWluaS1pbjFrLTIyNCUyMHN0eWxlJTIwY29uZmlndXJhdGlvbiUwQWNvbmZpZ3VyYXRpb24lMjAlM0QlMjBEaW5hdENvbmZpZygpJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMG1vZGVsJTIwKHdpdGglMjByYW5kb20lMjB3ZWlnaHRzKSUyMGZyb20lMjB0aGUlMjBzaGktbGFicyUyRmRpbmF0LW1pbmktaW4xay0yMjQlMjBzdHlsZSUyMGNvbmZpZ3VyYXRpb24lMEFtb2RlbCUyMCUzRCUyMERpbmF0TW9kZWwoY29uZmlndXJhdGlvbiklMEElMEElMjMlMjBBY2Nlc3NpbmclMjB0aGUlMjBtb2RlbCUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwbW9kZWwuY29uZmln",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DinatConfig, DinatModel | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a Dinat shi-labs/dinat-mini-in1k-224 style configuration</span> | |
| <span class="hljs-meta">>>> </span>configuration = DinatConfig() | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a model (with random weights) from the shi-labs/dinat-mini-in1k-224 style configuration</span> | |
| <span class="hljs-meta">>>> </span>model = DinatModel(configuration) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Accessing the model configuration</span> | |
| <span class="hljs-meta">>>> </span>configuration = model.config`,lang:"python",wrap:!1}),s(o,t)},$$slots:{default:!0}}),l(h);var x=e(h,2);n(x,{title:"DinatModel",local:"transformers.DinatModel",headingTag:"h2"});var m=e(x,2),I=d(m);i(I,{name:"class transformers.DinatModel",anchor:"transformers.DinatModel",source:"https://github.com/huggingface/transformers/blob/vr_47708/src/transformers/models/dinat/modeling_dinat.py#L541",parameters:[{name:"config",val:""},{name:"add_pooling_layer",val:" = True"}],parametersDescription:[{anchor:"transformers.DinatModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_47708/en/model_doc/dinat#transformers.DinatModel">DinatModel</a>) — | |
| 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/pr_47708/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"},{anchor:"transformers.DinatModel.add_pooling_layer",description:`<strong>add_pooling_layer</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to add a pooling layer`,name:"add_pooling_layer"}]});var F=e(I,8),W=d(F);i(W,{name:"forward",anchor:"transformers.DinatModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_47708/src/transformers/models/dinat/modeling_dinat.py#L567",parameters:[{name:"pixel_values",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_attentions",val:": bool | None = None"},{name:"output_hidden_states",val:": bool | None = None"},{name:"return_dict",val:": bool | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DinatModel.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) — | |
| The tensors corresponding to the input images. Pixel values can be obtained using | |
| <a href="/docs/transformers/pr_47708/en/model_doc/vit#transformers.ViTImageProcessor">ViTImageProcessor</a>. See <code>ViTImageProcessor.__call__()</code> for details (<code>processor_class</code> uses | |
| <a href="/docs/transformers/pr_47708/en/model_doc/vit#transformers.ViTImageProcessor">ViTImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DinatModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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.DinatModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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.DinatModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) — | |
| Whether or not to return a <a href="/docs/transformers/pr_47708/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>DinatModelOutput</code> 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/pr_47708/en/model_doc/dinat#transformers.DinatConfig" | |
| >DinatConfig</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>DinatModelOutput</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var j=e(W,4);A(j,{children:(o,a)=>{var t=G();s(o,t)},$$slots:{default:!0}});var S=e(j,4);u(S,{anchor:"transformers.DinatModel.forward.example",children:(o,a)=>{var t=_(),r=e(c(t),2);f(r,{code:"",highlighted:"",lang:"python",wrap:!1}),s(o,t)},$$slots:{default:!0}}),l(F),l(m);var U=e(m,2);n(U,{title:"DinatForImageClassification",local:"transformers.DinatForImageClassification",headingTag:"h2"});var g=e(U,2),J=d(g);i(J,{name:"class transformers.DinatForImageClassification",anchor:"transformers.DinatForImageClassification",source:"https://github.com/huggingface/transformers/blob/vr_47708/src/transformers/models/dinat/modeling_dinat.py#L622",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.DinatForImageClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_47708/en/model_doc/dinat#transformers.DinatForImageClassification">DinatForImageClassification</a>) — | |
| 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/pr_47708/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var z=e(J,8),k=d(z);i(k,{name:"forward",anchor:"transformers.DinatForImageClassification.forward",source:"https://github.com/huggingface/transformers/blob/vr_47708/src/transformers/models/dinat/modeling_dinat.py#L639",parameters:[{name:"pixel_values",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_attentions",val:": bool | None = None"},{name:"output_hidden_states",val:": bool | None = None"},{name:"return_dict",val:": bool | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.DinatForImageClassification.forward.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, image_size, image_size)</code>, <em>optional</em>) — | |
| The tensors corresponding to the input images. Pixel values can be obtained using | |
| <a href="/docs/transformers/pr_47708/en/model_doc/vit#transformers.ViTImageProcessor">ViTImageProcessor</a>. See <code>ViTImageProcessor.__call__()</code> for details (<code>processor_class</code> uses | |
| <a href="/docs/transformers/pr_47708/en/model_doc/vit#transformers.ViTImageProcessor">ViTImageProcessor</a> for processing images).`,name:"pixel_values"},{anchor:"transformers.DinatForImageClassification.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) — | |
| 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 > 1</code> a classification loss is computed (Cross-Entropy).`,name:"labels"},{anchor:"transformers.DinatForImageClassification.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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.DinatForImageClassification.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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.DinatForImageClassification.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) — | |
| Whether or not to return a <a href="/docs/transformers/pr_47708/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>DinatImageClassifierOutput</code> 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/pr_47708/en/model_doc/dinat#transformers.DinatConfig" | |
| >DinatConfig</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>DinatImageClassifierOutput</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `});var Z=e(k,4);A(Z,{children:(o,a)=>{var t=G();s(o,t)},$$slots:{default:!0}});var E=e(Z,4);u(E,{anchor:"transformers.DinatForImageClassification.forward.example",children:(o,a)=>{var t=_(),r=e(c(t),2);f(r,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9JbWFnZVByb2Nlc3NvciUyQyUyMERpbmF0Rm9ySW1hZ2VDbGFzc2lmaWNhdGlvbiUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJodWdnaW5nZmFjZSUyRmNhdHMtaW1hZ2UlMjIpJTBBaW1hZ2UlMjAlM0QlMjBkYXRhc2V0JTVCJTIydGVzdCUyMiU1RCU1QiUyMmltYWdlJTIyJTVEJTVCMCU1RCUwQSUwQWltYWdlX3Byb2Nlc3NvciUyMCUzRCUyMEF1dG9JbWFnZVByb2Nlc3Nvci5mcm9tX3ByZXRyYWluZWQoJTIyc2hpLWxhYnMlMkZkaW5hdC1taW5pLWluMWstMjI0JTIyKSUwQW1vZGVsJTIwJTNEJTIwRGluYXRGb3JJbWFnZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMjJzaGktbGFicyUyRmRpbmF0LW1pbmktaW4xay0yMjQlMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwbG9naXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpLmxvZ2l0cyUwQSUwQSUyMyUyMG1vZGVsJTIwcHJlZGljdHMlMjBvbmUlMjBvZiUyMHRoZSUyMDEwMDAlMjBJbWFnZU5ldCUyMGNsYXNzZXMlMEFwcmVkaWN0ZWRfbGFiZWwlMjAlM0QlMjBsb2dpdHMuYXJnbWF4KC0xKS5pdGVtKCklMEFwcmludChtb2RlbC5jb25maWcuaWQybGFiZWwlNUJwcmVkaWN0ZWRfbGFiZWwlNUQp",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoImageProcessor, DinatForImageClassification | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset | |
| <span class="hljs-meta">>>> </span>dataset = load_dataset(<span class="hljs-string">"huggingface/cats-image"</span>) | |
| <span class="hljs-meta">>>> </span>image = dataset[<span class="hljs-string">"test"</span>][<span class="hljs-string">"image"</span>][<span class="hljs-number">0</span>] | |
| <span class="hljs-meta">>>> </span>image_processor = AutoImageProcessor.from_pretrained(<span class="hljs-string">"shi-labs/dinat-mini-in1k-224"</span>) | |
| <span class="hljs-meta">>>> </span>model = DinatForImageClassification.from_pretrained(<span class="hljs-string">"shi-labs/dinat-mini-in1k-224"</span>) | |
| <span class="hljs-meta">>>> </span>inputs = image_processor(image, return_tensors=<span class="hljs-string">"pt"</span>) | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">with</span> torch.no_grad(): | |
| <span class="hljs-meta">... </span> logits = model(**inputs).logits | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># model predicts one of the 1000 ImageNet classes</span> | |
| <span class="hljs-meta">>>> </span>predicted_label = logits.argmax(-<span class="hljs-number">1</span>).item() | |
| <span class="hljs-meta">>>> </span><span class="hljs-built_in">print</span>(model.config.id2label[predicted_label]) | |
| ...`,lang:"python",wrap:!1}),s(o,t)},$$slots:{default:!0}}),l(z),l(g);var q=e(g,2);X(q,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/dinat.md"}),K(2),s(P,b),$()}export{ce as component}; | |
Xet Storage Details
- Size:
- 34.2 kB
- Xet hash:
- 3be0d432393427a8852b8bc819dd72aa39f2613a2e96a8561abc5eadc2fec5e8
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.