tensorflow/models · error · ValueError

num_classes should be given when requesting one hot label.

Error message

num_classes should be given when requesting one hot label.

What it means

Error "num_classes should be given when requesting one hot label." thrown in tensorflow/models.

Source

Thrown at official/projects/videoglue/datasets/common/utils.py:588

      for different label features.
    output_label_name_feature_name: Name of the label name feature in the
      output features dictionary. Exposing this as an argument allows using this
      function for different label features.
    num_frames: The number of frames. If the num_frames > 1, the labels will be
      duplicated.
    num_instances_per_frame: The number of label instances per frames.
    zero_based_index: Whether the raw index are zero based. If not, converted to
      the zero based index as the output.
    one_hot_label: Return labels as one hot tensors. If is_multi_label is True,
      one hot tensor might have multiple ones.
    num_classes: Total number of classes in the dataset. It has to be procided
      if one_hot_label is True.
    add_label_name: Also return the name of the label. Not yet supported for
      multi label.
  """
  # Validate parameters.
  if one_hot_label and not num_classes:
    raise ValueError(
        'num_classes should be given when requesting one hot label.')

  # Parse label.
  parser_builder.parse_feature(
      feature_name=input_label_index_feature_name,
      feature_type=tf.io.VarLenFeature(dtype=tf.int64),
      output_name=output_label_index_feature_name,
      is_context=True)

  # Densify labels tensor in order to support multi label case.
  sampler_builder.add_fn(
      fn=lambda x: tf.sparse.to_dense(x, default_value=-1),
      feature_name=output_label_index_feature_name,
      fn_name='{}_sparse_to_dense'.format(output_label_index_feature_name))

  # Crop or pad labels to max_num_instance.
  crop_or_pad_features_fn = functools.partial(
      processors.crop_or_pad_features,

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/videoglue/datasets/common/utils.py:588 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/f716cbe579e902ab. Report an issue: GitHub.