docstr: labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
      Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
      config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
      `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
  
  Returns:
  
  Examples:
  
  ```python
  >>> import av
  >>> import numpy as np
  >>> import torch
  
  >>> from transformers import VivitImageProcessor, VivitForVideoClassification
  >>> from huggingface_hub import hf_hub_download
  
  >>> np.random.seed(0)
  
  
  >>> def read_video_pyav(container, indices):
  ...     '''
  ...     Decode the video with PyAV decoder.
  ...     Args:
  ...         container (`av.container.input.InputContainer`): PyAV container.
  ...         indices (`List[int]`): List of frame indices to decode.
  ...     Returns:
  ...         result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
  ...     '''
  ...     frames = []
  ...     container.seek(0)
  ...     start_index = indices[0]
  ...     end_index = indices[-1]
  ...     for i, frame in enumerate(container.decode(video=0)):
  ...         if i > end_index:
  ...             break
  ...         if i >= start_index and i in indices:
  ...             frames.append(frame)
  ...     return np.stack([x.to_ndarray(format="rgb24") for x in frames])
  
  
  >>> def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
  ...     '''
  ...     Sample a given number of frame indices from the video.
  ...     Args:
  ...         clip_len (`int`): Total number of frames to sample.
  ...         frame_sample_rate (`int`): Sample every n-th frame.
  ...         seg_len (`int`): Maximum allowed index of sample's last frame.
  ...     Returns:
  ...         indices (`List[int]`): List of sampled frame indices
  ...     '''
  ...     converted_len = int(clip_len * frame_sample_rate)
  ...     end_idx = np.random.randint(converted_len, seg_len)
  ...     start_idx = end_idx - converted_len
  ...     indices = np.linspace(start_idx, end_idx, num=clip_len)
  ...     indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
  ...     return indices
  
  
  >>> # video clip consists of 300 frames (10 seconds at 30 FPS)
  >>> file_path = hf_hub_download(
  ...     repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
  ... )
  >>> container = av.open(file_path)
  
  >>> # sample 32 frames
  >>> indices = sample_frame_indices(clip_len=32, frame_sample_rate=4, seg_len=container.streams.video[0].frames)
  >>> video = read_video_pyav(container=container, indices=indices)
  
  >>> image_processor = VivitImageProcessor.from_pretrained("google/vivit-b-16x2-kinetics400")
  >>> model = VivitForVideoClassification.from_pretrained("google/vivit-b-16x2-kinetics400")
  
  >>> inputs = image_processor(list(video), return_tensors="pt")
  
  >>> with torch.no_grad():
  ...     outputs = model(**inputs)
  ...     logits = outputs.logits
  
  >>> # model predicts one of the 400 Kinetics-400 classes
  >>> predicted_label = logits.argmax(-1).item()
  >>> print(model.config.id2label[predicted_label])
  LABEL_116
  ```
docstr_tok: ["labels","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",",")","`",",","*","optional","*",")",":","Labels","for","computing","the","image","classification\/regression","loss",".","Indices","should","be","in","`","[","0",",","...",",","config.num_labels","-","1","]","`",".","If","`","config.num_labels","==","1","`","a","regression","loss","is","computed","(","Mean-Square","loss",")",",","If","`","config.num_labels",">","1","`","a","classification","loss","is","computed","(","Cross-Entropy",")",".","Returns",":","Examples",":","``","`","python",">",">",">","import","av",">",">",">","import","numpy","as","np",">",">",">","import","torch",">",">",">","from","transformers","import","VivitImageProcessor",",","VivitForVideoClassification",">",">",">","from","huggingface_hub","import","hf_hub_download",">",">",">","np.random.seed","(","0",")",">",">",">","def","read_video_pyav","(","container",",","indices",")",":","...","``","'","...","Decode","the","video","with","PyAV","decoder",".","...","Args",":","...","container","(","`","av.container.input.InputContainer","`",")",":","PyAV","container",".","...","indices","(","`","List","[","int","]","`",")",":","List","of","frame","indices","to","decode",".","...","Returns",":","...","result","(","np.ndarray",")",":","np","array","of","decoded","frames","of","shape","(","num_frames",",","height",",","width",",","3",")",".","...","``","'","...","frames","=","[","]","...","container.seek","(","0",")","...","start_index","=","indices","[","0","]","...","end_index","=","indices","[","-1","]","...","for","i",",","frame","in","enumerate","(","container.decode","(","video=0",")",")",":","...","if","i",">","end_index",":","...","break","...","if","i",">","=","start_index","and","i","in","indices",":","...","frames.append","(","frame",")","...","return","np.stack","(","[","x.to_ndarray","(","format=","''","rgb24","''",")","for","x","in","frames","]",")",">",">",">","def","sample_frame_indices","(","clip_len",",","frame_sample_rate",",","seg_len",")",":","...","``","'","...","Sample","a","given","number","of","frame","indices","from","the","video",".","...","Args",":","...","clip_len","(","`","int","`",")",":","Total","number","of","frames","to","sample",".","...","frame_sample_rate","(","`","int","`",")",":","Sample","every","n-th","frame",".","...","seg_len","(","`","int","`",")",":","Maximum","allowed","index","of","sample","'s","last","frame",".","...","Returns",":","...","indices","(","`","List","[","int","]","`",")",":","List","of","sampled","frame","indices","...","``","'","...","converted_len","=","int","(","clip_len","*","frame_sample_rate",")","...","end_idx","=","np.random.randint","(","converted_len",",","seg_len",")","...","start_idx","=","end_idx","-","converted_len","...","indices","=","np.linspace","(","start_idx",",","end_idx",",","num=clip_len",")","...","indices","=","np.clip","(","indices",",","start_idx",",","end_idx","-","1",")",".astype","(","np.int64",")","...","return","indices",">",">",">","#","video","clip","consists","of","300","frames","(","10","seconds","at","30","FPS",")",">",">",">","file_path","=","hf_hub_download","(","...","repo_id=","''","nielsr\/video-demo","''",",","filename=","''","eating_spaghetti.mp4","''",",","repo_type=","''","dataset","''","...",")",">",">",">","container","=","av.open","(","file_path",")",">",">",">","#","sample","32","frames",">",">",">","indices","=","sample_frame_indices","(","clip_len=32",",","frame_sample_rate=4",",","seg_len=container.streams.video","[","0","]",".frames",")",">",">",">","video","=","read_video_pyav","(","container=container",",","indices=indices",")",">",">",">","image_processor","=","VivitImageProcessor.from_pretrained","(","``","google\/vivit-b-16x2-kinetics400","''",")",">",">",">","model","=","VivitForVideoClassification.from_pretrained","(","``","google\/vivit-b-16x2-kinetics400","''",")",">",">",">","inputs","=","image_processor","(","list","(","video",")",",","return_tensors=","''","pt","''",")",">",">",">","with","torch.no_grad","(",")",":","...","outputs","=","model","(","*","*","inputs",")","...","logits","=","outputs.logits",">",">",">","#","model","predicts","one","of","the","400","Kinetics-400","classes",">",">",">","predicted_label","=","logits.argmax","(","-1",")",".item","(",")",">",">",">","print","(","model.config.id2label","[","predicted_label","]",")","LABEL_116","``","`"]
code: def forward(
      self,
      pixel_values: Optional[torch.FloatTensor] = None,
      head_mask: Optional[torch.FloatTensor] = None,
      labels: Optional[torch.LongTensor] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[Tuple[torch.FloatTensor], ImageClassifierOutput]:
      r"""
      labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
          Labels for computing the image classification/regression loss. Indices should be in `[0, ...,
          config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
          `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
  
      Returns:
  
      Examples:
  
      ```python
      >>> import av
      >>> import numpy as np
      >>> import torch
  
      >>> from transformers import VivitImageProcessor, VivitForVideoClassification
      >>> from huggingface_hub import hf_hub_download
  
      >>> np.random.seed(0)
  
  
      >>> def read_video_pyav(container, indices):
      ...     '''
      ...     Decode the video with PyAV decoder.
      ...     Args:
      ...         container (`av.container.input.InputContainer`): PyAV container.
      ...         indices (`List[int]`): List of frame indices to decode.
      ...     Returns:
      ...         result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
      ...     '''
      ...     frames = []
      ...     container.seek(0)
      ...     start_index = indices[0]
      ...     end_index = indices[-1]
      ...     for i, frame in enumerate(container.decode(video=0)):
      ...         if i > end_index:
      ...             break
      ...         if i >= start_index and i in indices:
      ...             frames.append(frame)
      ...     return np.stack([x.to_ndarray(format="rgb24") for x in frames])
  
  
      >>> def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
      ...     '''
      ...     Sample a given number of frame indices from the video.
      ...     Args:
      ...         clip_len (`int`): Total number of frames to sample.
      ...         frame_sample_rate (`int`): Sample every n-th frame.
      ...         seg_len (`int`): Maximum allowed index of sample's last frame.
      ...     Returns:
      ...         indices (`List[int]`): List of sampled frame indices
      ...     '''
      ...     converted_len = int(clip_len * frame_sample_rate)
      ...     end_idx = np.random.randint(converted_len, seg_len)
      ...     start_idx = end_idx - converted_len
      ...     indices = np.linspace(start_idx, end_idx, num=clip_len)
      ...     indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
      ...     return indices
  
  
      >>> # video clip consists of 300 frames (10 seconds at 30 FPS)
      >>> file_path = hf_hub_download(
      ...     repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
      ... )
      >>> container = av.open(file_path)
  
      >>> # sample 32 frames
      >>> indices = sample_frame_indices(clip_len=32, frame_sample_rate=4, seg_len=container.streams.video[0].frames)
      >>> video = read_video_pyav(container=container, indices=indices)
  
      >>> image_processor = VivitImageProcessor.from_pretrained("google/vivit-b-16x2-kinetics400")
      >>> model = VivitForVideoClassification.from_pretrained("google/vivit-b-16x2-kinetics400")
  
      >>> inputs = image_processor(list(video), return_tensors="pt")
  
      >>> with torch.no_grad():
      ...     outputs = model(**inputs)
      ...     logits = outputs.logits
  
      >>> # model predicts one of the 400 Kinetics-400 classes
      >>> predicted_label = logits.argmax(-1).item()
      >>> print(model.config.id2label[predicted_label])
      LABEL_116
      ```"""
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      outputs = self.vivit(
          pixel_values,
          head_mask=head_mask,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
      )
  
      sequence_output = outputs[0]
  
      logits = self.classifier(sequence_output[:, 0, :])
  
      loss = None
      if labels is not None:
          if self.num_labels == 1:
              #  We are doing regression
              loss_fct = MSELoss()
              loss = loss_fct(logits.view(-1), labels.view(-1))
          else:
              loss_fct = CrossEntropyLoss()
              loss = loss_fct(
                  logits.view(-1, self.num_labels), labels.view(-1)
              )
  
      if not return_dict:
          output = (logits,) + outputs[2:]
          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 math
  from typing import Optional, Set, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, 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_vivit import VivitConfig
label_desc: Use image node_id 2 for calling the VivitForVideoClassification obj's underlying member method code with example usage: obj.forward(pixel_values, head_mask, labels, output_attentions, output_hidden_states, return_dict) and returns: ImageClassifierOutput, unknown