tensorflow/models · error · ValueError

Invalid label field: !

Error message

Invalid label field: {self._label_field}!

What it means

Label-specification guard in _add_labels_specification (invoked from the parser's __init__): self._label_field did not match any recognized label source ('ids', 'rgb', 'audio'). The label field decides which context feature carries the ground-truth labels; an unrecognized string leaves no labels spec, so training would parse examples with no targets — rejected up front instead.

Solutions

  1. Set label_field to 'ids', 'rgb', or 'audio' in the input config
  2. Fix casing and typos in the label field string
  3. Ensure the chosen label source is also declared in feature_names/feature_sources
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/projects/yt8m/dataloaders/yt8m_input.py:308 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/a634a5a4e20a0fc8. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/yt8m/dataloaders/yt8m_input.py:308

        feature_type = tf.io.FixedLenSequenceFeature([], dtype=tf.string)
      else:
        dtype = tf.dtypes.as_dtype(self._feature_dtypes[i])
        feature_shape = [self._feature_sizes[i]]
        if self._feature_sources[i] == "feature":
          feature_type = tf.io.FixedLenSequenceFeature(feature_shape, dtype)
        else:
          feature_type = tf.io.FixedLenFeature(feature_shape, dtype)
      if self._feature_sources[i] == "feature":
        self._sequence_features[name] = feature_type
      elif self._feature_sources[i] == "context":
        self._context_features[name] = feature_type
      else:
        raise ValueError(
            f"Unknown feature source {self._feature_sources[i]} for {name}")

  def _add_labels_specification(self):
    if not self._label_field:
      raise ValueError(f"Invalid label field: {self._label_field}!")
    self._context_features.update(
        {self._label_field: tf.io.VarLenFeature(tf.int64)})

  def decode(self,
             serialized_example: tf.train.SequenceExample) -> Dict[str, Any]:
    """Parses a single tf.train.SequenceExample into video and label tensors."""
    contexts, features = tf.io.parse_single_sequence_example(
        serialized_example,
        context_features=self._context_features,
        sequence_features=self._sequence_features)
    decoded_tensor = {**contexts, **features}
    for i, name in enumerate(self._feature_names):
      # Convert the VarLen feature to dense tensor.
      if self._feature_from_bytes[i]:
        dtype = tf.dtypes.as_dtype(self._feature_dtypes[i])
        decoded_tensor[name] = tf.cast(
            tf.io.decode_raw(decoded_tensor[name], out_type=dtype), tf.float32
        )

View on GitHub (pinned to e006f5f0d5)