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).
code: def forward(
      self,
      pixel_values: Optional[torch.FloatTensor] = None,
      labels: Optional[torch.LongTensor] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[Tuple, ImageClassifierOutputWithNoAttention]:
      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).
      """
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      outputs = self.poolformer(
          pixel_values,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
      )
  
      sequence_output = outputs[0]
  
      logits = self.classifier(
          self.norm(sequence_output).mean([-2, -1])
      )
  
      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[2:]
          return ((loss,) + output) if loss is not None else output
  
      return ImageClassifierOutputWithNoAttention(
          loss=loss, logits=logits, hidden_states=outputs.hidden_states
      )
  
imports: import collections.abc
  from typing import Optional, 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 BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_poolformer import PoolFormerConfig
label_desc: Use image node_id 2 for calling the PoolFormerForImageClassification obj's underlying member method code with example usage: obj.forward(pixel_values, labels, output_hidden_states, return_dict) and returns: ImageClassifierOutputWithNoAttention, unknown