import csv


def load_categories_from_csv_file(args):
  """Loads categories from a csv file.
  The CSV file should have one comma delimited numeric category id and string
  category name pair per line. For example:
  0,"cat"
  1,"dog"
  2,"bird"
  ...
  Args:
    csv_path: Path to the csv file to be parsed into categories.
  Returns:
    categories: A list of dictionaries representing all possible categories.
                The categories will contain an integer 'id' field and a string
                'name' field.
  Raises:
    ValueError: If the csv file is incorrectly formatted.
  """
  categories = []

  with open(args.label_map_csv_path, 'r') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for i,row in enumerate(reader):
      if not row:
        continue

      if len(row) != 2:
        raise ValueError('Expected 2 fields per row in csv: %s' % ','.join(row))

      category_id = int(i+1)
      category_name = row[0]
      category_display_name = row[1]
      categories.append({'id': category_id, 'name': category_name, 'display_name': category_display_name})

    return categories