tensorflow/models · error · ValueError

Each row of the csv label map file must be in `id,name`…

Error message

Each row of the csv label map file must be in `id,name` format. length = {}

What it means

Raised in _process_csv when a row of the CSV label map does not have exactly two fields in 'id,name' format.

Solutions

  1. Fix the CSV so every row is 'id,name' with exactly two columns
  2. Remove header lines, comments, or malformed rows
  3. Escape or quote commas inside label names
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/vision/dataloaders/tf_example_label_map_decoder.py:57 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/8afefcb9dfd24cf3. Report an issue: GitHub.

Appendix: source

Thrown at official/vision/dataloaders/tf_example_label_map_decoder.py:57

        tf.lookup.KeyValueTensorInitializer(
            keys=tf.constant(list(name_to_id.keys()), dtype=tf.string),
            values=tf.constant(list(name_to_id.values()), dtype=tf.int64)),
        default_value=-1)

  def _process_label_map(self, label_map):
    if label_map.endswith('.csv'):
      name_to_id = self._process_csv(label_map)
    else:
      raise ValueError('The label map file is in incorrect format.')
    return name_to_id

  def _process_csv(self, label_map):
    name_to_id = {}
    with tf.io.gfile.GFile(label_map, 'r') as f:
      reader = csv.reader(f, delimiter=',')
      for row in reader:
        if len(row) != 2:
          raise ValueError('Each row of the csv label map file must be in '
                           '`id,name` format. length = {}'.format(len(row)))
        id_index = int(row[0])
        name = row[1]
        name_to_id[name] = id_index
    return name_to_id

  def _decode_classes(self, parsed_tensors):
    return self._name_to_id_table.lookup(
        parsed_tensors['image/object/class/text'])

View on GitHub (pinned to e006f5f0d5)