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",">"]
code: def __post_init__(self):
      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 element in iterator:
                  if (
                      not isinstance(element, (list, tuple))
                      or not len(element) == 2
                      or not isinstance(element[0], str)
                  ):
                      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
  from enum import Enum
  from typing import Any, ContextManager, 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 1 for calling the ModelOutput obj's underlying member method code with example usage: obj.__post_init__() without return types