class_docstr: Base class for all model outputs as dataclass. Has a `__getitem__` that allows indexing by integer or slice (like a
  tuple) or strings (like a dictionary) that will ignore the `None` attributes. Otherwise behaves like a regular
  python dictionary.
  
  <Tip warning={true}>
  
  You can't unpack a `ModelOutput` directly. Use the [`~utils.ModelOutput.to_tuple`] method to convert it to a tuple
  before.
  
  </Tip>
class_docstr_tok: ["Base","class","for","all","model","outputs","as","dataclass",".","Has","a","`","__getitem__","`","that","allows","indexing","by","integer","or","slice","(","like","a","tuple",")","or","strings","(","like","a","dictionary",")","that","will","ignore","the","`","None","`","attributes",".","Otherwise","behaves","like","a","regular","python","dictionary",".","<","Tip","warning=","{","true","}",">","You","ca","n't","unpack","a","`","ModelOutput","`","directly",".","Use","the","[","`","~utils.ModelOutput.to_tuple","`","]","method","to","convert","it","to","a","tuple","before",".","<","\/Tip",">"]
docstr: Check the ModelOutput dataclass.
  
  Only occurs if @dataclass decorator has been used.
docstr_tok: ["Check","the","ModelOutput","dataclass",".","Only","occurs","if","@","dataclass","decorator","has","been","used","."]
code: def __post_init__(self):
      """Check the ModelOutput dataclass.
  
      Only occurs if @dataclass decorator has been used.
      """
      class_fields = fields(self)
  
      # Safety and consistency checks
      if not len(class_fields):
          raise ValueError(f"{self.__class__.__name__} has no fields.")
      if not all(field.default is None for field in class_fields[1:]):
          raise ValueError(
              f"{self.__class__.__name__} should not have more than one required field."
          )
  
      first_field = getattr(self, class_fields[0].name)
      other_fields_are_none = all(
          getattr(self, field.name) is None
          for field in class_fields[1:]
      )
  
      if other_fields_are_none and not is_tensor(first_field):
          if isinstance(first_field, dict):
              iterator = first_field.items()
              first_field_iterator = True
          else:
              try:
                  iterator = iter(first_field)
                  first_field_iterator = True
              except TypeError:
                  first_field_iterator = False
  
          # if we provided an iterator as first field and the iterator is a (key, value) iterator
          # set the associated fields
          if first_field_iterator:
              for idx, element in enumerate(iterator):
                  if (
                      not isinstance(element, (list, tuple))
                      or not len(element) == 2
                      or not isinstance(element[0], str)
                  ):
                      if idx == 0:
                          # If we do not have an iterator of key/values, set it as attribute
                          self[class_fields[0].name] = first_field
                      else:
                          # If we have a mixed iterator, raise an error
                          raise ValueError(
                              f"Cannot set key/value for {element}. It needs to be a tuple (key, value)."
                          )
                      break
                  setattr(self, element[0], element[1])
                  if element[1] is not None:
                      self[element[0]] = element[1]
          elif first_field is not None:
              self[class_fields[0].name] = first_field
      else:
          for field in class_fields:
              v = getattr(self, field.name)
              if v is not None:
                  self[field.name] = v
  
imports: import inspect
  import tempfile
  from collections import OrderedDict, UserDict
  from collections.abc import MutableMapping
  from contextlib import ExitStack, contextmanager
  from dataclasses import fields, is_dataclass
  from enum import Enum
  from typing import Any, ContextManager, Iterable, List, Tuple
  import numpy
  from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy
label_desc: Use image node_id 3 for calling the ModelOutput obj's underlying member method code with example usage: obj.__post_init__() without return types