class_docstr: Wrapper class for timm models to be used as backbones. This enables using the timm models interchangeably with the
  other models in the library keeping the same API.
class_docstr_tok: ["Wrapper","class","for","timm","models","to","be","used","as","backbones",".","This","enables","using","the","timm","models","interchangeably","with","the","other","models","in","the","library","keeping","the","same","API","."]
code: def forward(
      self,
      pixel_values: torch.FloatTensor,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
      **kwargs,
  ) -> Union[BackboneOutput, Tuple[Tensor, ...]]:
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
      output_hidden_states = (
          output_hidden_states
          if output_hidden_states is not None
          else self.config.output_hidden_states
      )
      output_attentions = (
          output_attentions
          if output_attentions is not None
          else self.config.output_attentions
      )
  
      if output_attentions:
          raise ValueError(
              "Cannot output attentions for timm backbones at the moment"
          )
  
      if output_hidden_states:
          # We modify the return layers to include all the stages of the backbone
          self._backbone.return_layers = self._all_layers
          hidden_states = self._backbone(pixel_values, **kwargs)
          self._backbone.return_layers = self._return_layers
          feature_maps = tuple(
              hidden_states[i] for i in self.out_indices
          )
      else:
          feature_maps = self._backbone(pixel_values, **kwargs)
          hidden_states = None
  
      feature_maps = tuple(feature_maps)
      hidden_states = (
          tuple(hidden_states) if hidden_states is not None else None
      )
  
      if not return_dict:
          output = (feature_maps,)
          if output_hidden_states:
              output = output + (hidden_states,)
          return output
  
      return BackboneOutput(
          feature_maps=feature_maps,
          hidden_states=hidden_states,
          attentions=None,
      )
  
file_path: transformers/src/transformers/models/timm_backbone/modeling_timm_backbone.py
imports: from typing import Optional, Tuple, Union
  import torch
  from ...modeling_outputs import BackboneOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import is_timm_available, is_torch_available, requires_backends
  from ...utils.backbone_utils import BackboneMixin
  from .configuration_timm_backbone import TimmBackboneConfig
label_desc: Use image node_id 6 for calling the TimmBackbone obj's underlying member method code with example usage: obj.forward(pixel_values, output_attentions, output_hidden_states, return_dict) and returns: BackboneOutput, output