docstr: Returns:
  
  Examples:
  
  ```python
  >>> from transformers import AutoFeatureExtractor, ViTMSNForImageClassification
  >>> import torch
  >>> from PIL import Image
  >>> import requests
  
  >>> torch.manual_seed(2)  # doctest: +IGNORE_RESULT
  
  >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
  >>> image = Image.open(requests.get(url, stream=True).raw)
  
  >>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/vit-msn-small")
  >>> model = ViTMSNForImageClassification.from_pretrained("facebook/vit-msn-small")
  
  >>> inputs = feature_extractor(images=image, return_tensors="pt")
  >>> with torch.no_grad():
  ...     logits = model(**inputs).logits
  >>> # model predicts one of the 1000 ImageNet classes
  >>> predicted_label = logits.argmax(-1).item()
  >>> print(model.config.id2label[predicted_label])
  Kerry blue terrier
  ```
docstr_tok: ["Returns",":","Examples",":","``","`","python",">",">",">","from","transformers","import","AutoFeatureExtractor",",","ViTMSNForImageClassification",">",">",">","import","torch",">",">",">","from","PIL","import","Image",">",">",">","import","requests",">",">",">","torch.manual_seed","(","2",")","#","doctest",":","+IGNORE_RESULT",">",">",">","url","=","``","http",":","\/\/images.cocodataset.org\/val2017\/000000039769.jpg","''",">",">",">","image","=","Image.open","(","requests.get","(","url",",","stream=True",")",".raw",")",">",">",">","feature_extractor","=","AutoFeatureExtractor.from_pretrained","(","``","facebook\/vit-msn-small","''",")",">",">",">","model","=","ViTMSNForImageClassification.from_pretrained","(","``","facebook\/vit-msn-small","''",")",">",">",">","inputs","=","feature_extractor","(","images=image",",","return_tensors=","''","pt","''",")",">",">",">","with","torch.no_grad","(",")",":","...","logits","=","model","(","*","*","inputs",")",".logits",">",">",">","#","model","predicts","one","of","the","1000","ImageNet","classes",">",">",">","predicted_label","=","logits.argmax","(","-1",")",".item","(",")",">",">",">","print","(","model.config.id2label","[","predicted_label","]",")","Kerry","blue","terrier","``","`"]
code: def forward(
      self,
      pixel_values: Optional[torch.Tensor] = None,
      head_mask: Optional[torch.Tensor] = None,
      labels: Optional[torch.Tensor] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      interpolate_pos_encoding: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[tuple, ImageClassifierOutput]:
      r"""
      Returns:
  
      Examples:
  
      ```python
      >>> from transformers import AutoFeatureExtractor, ViTMSNForImageClassification
      >>> import torch
      >>> from PIL import Image
      >>> import requests
  
      >>> torch.manual_seed(2)  # doctest: +IGNORE_RESULT
  
      >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
      >>> image = Image.open(requests.get(url, stream=True).raw)
  
      >>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/vit-msn-small")
      >>> model = ViTMSNForImageClassification.from_pretrained("facebook/vit-msn-small")
  
      >>> inputs = feature_extractor(images=image, return_tensors="pt")
      >>> with torch.no_grad():
      ...     logits = model(**inputs).logits
      >>> # model predicts one of the 1000 ImageNet classes
      >>> predicted_label = logits.argmax(-1).item()
      >>> print(model.config.id2label[predicted_label])
      Kerry blue terrier
      ```"""
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      outputs = self.vit(
          pixel_values,
          head_mask=head_mask,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          interpolate_pos_encoding=interpolate_pos_encoding,
          return_dict=return_dict,
      )
  
      sequence_output = outputs[0]
  
      logits = self.classifier(sequence_output[:, 0, :])
  
      loss = None
      if labels is not None:
          if self.config.problem_type is None:
              if self.num_labels == 1:
                  self.config.problem_type = "regression"
              elif self.num_labels > 1 and (
                  labels.dtype == torch.long
                  or labels.dtype == torch.int
              ):
                  self.config.problem_type = (
                      "single_label_classification"
                  )
              else:
                  self.config.problem_type = (
                      "multi_label_classification"
                  )
  
          if self.config.problem_type == "regression":
              loss_fct = MSELoss()
              if self.num_labels == 1:
                  loss = loss_fct(logits.squeeze(), labels.squeeze())
              else:
                  loss = loss_fct(logits, labels)
          elif (
              self.config.problem_type == "single_label_classification"
          ):
              loss_fct = CrossEntropyLoss()
              loss = loss_fct(
                  logits.view(-1, self.num_labels), labels.view(-1)
              )
          elif self.config.problem_type == "multi_label_classification":
              loss_fct = BCEWithLogitsLoss()
              loss = loss_fct(logits, labels)
  
      if not return_dict:
          output = (logits,) + outputs[1:]
          return ((loss,) + output) if loss is not None else output
  
      return ImageClassifierOutput(
          loss=loss,
          logits=logits,
          hidden_states=outputs.hidden_states,
          attentions=outputs.attentions,
      )
  
imports: import collections.abc
  import math
  from typing import Dict, List, Optional, Set, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutput, ImageClassifierOutput
  from ...modeling_utils import PreTrainedModel
  from ...pytorch_utils import find_pruneable_heads_and_indices, prune_linear_layer
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_vit_msn import ViTMSNConfig
label_desc: Use image node_id 2 for calling the ViTMSNForImageClassification obj's underlying member method code with example usage: obj.forward(pixel_values, head_mask, labels, output_attentions, output_hidden_states, interpolate_pos_encoding, return_dict) and returns: ImageClassifierOutput, unknown