code: def load_dataclass_dict_from_csv(
      input_csv_file_path: str,
      dataclass_class: type,
      dict_key_field: str,
      list_per_key: bool = False,
  ) -> Dict[Any, Union[Any, List[Any]]]:
      """
      Args:
          input_csv_file_path (str): File path of the csv to read from
          dataclass_class (type): The dataclass to read each row into.
          dict_key_field (str): The field of 'dataclass_class' to use as
              the dictionary key.
          list_per_key (bool) = False: If the output data structure
          contains a list of dataclass objects per key, rather than a
          single unique dataclass object.
  
      Returns:
          Dict[Any, Union[Any, List[Any]] mapping from the dataclass
          value at attr = dict_key_field to either:
  
          if 'list_per_key', a list of all dataclass objects that
          have equal values at attr = dict_key_field, equal to the key
  
          if not 'list_per_key', the unique dataclass object
          for which the value at attr = dict_key_field is equal to the key
  
      Raises:
          AssertionError: if not 'list_per_key' and there are
          dataclass obejcts with equal values at attr = dict_key_field
      """
  
      output_dict = defaultdict(list) if list_per_key else {}
      with g_pathmgr.open(input_csv_file_path) as dataclass_file:
          reader = csv.reader(
              dataclass_file, delimiter=",", quotechar='"'
          )
          column_index = {
              header: i for i, header in enumerate(next(reader))
          }
          for line in reader:
              datum = dataclass_class(
                  *(
                      line[column_index[field.name]]
                      for field in dataclass_fields(dataclass_class)
                  )
              )
              dict_key = getattr(datum, dict_key_field)
              if list_per_key:
                  output_dict[dict_key].append(datum)
              else:
                  assert (
                      dict_key not in output_dict
                  ), f"Multiple entries for {output_dict} in {dataclass_file}"
                  output_dict[dict_key] = datum
      return output_dict
  
imports: from __future__ import annotations
  import csv
  import itertools
  import logging
  import math
  import sys
  import threading
  from collections import defaultdict
  from dataclasses import Field, field, fields
  from fractions import Fraction
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import av
  import numpy
  import torch
  from iopath.common.file_io import g_pathmgr
label_desc: Use image node_id 6 for calling a global function with example usage: load_dataclass_dict_from_csv(input_csv_file_path, dataclass_class, dict_key_field, list_per_key) and returns: output_dict