tensorflow/models · error · ValueError

Model num_classes must be 2 when not for all classes.

Error message

Model num_classes must be 2 when not for all classes.

What it means

Config consistency check in PointPillarsTask.build_inputs: when model_config.classes is not 'all', the model must predict exactly 2 classes (the class subset machinery assumes binary heads); a mismatch between classes and num_classes raises this ValueError.

Solutions

  1. Set num_classes=2 when classes is a specific subset rather than 'all'
  2. Set classes='all' if all three Waymo classes should be predicted
  3. Reconcile the model config fields so they describe the same class setup
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/projects/pointpillars/tasks/pointpillars.py:140 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/2513ec0f6b85f99c. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/pointpillars/tasks/pointpillars.py:140

        ckpt_items.update(decoder=model.decoder)

      ckpt = tf.train.Checkpoint(**ckpt_items)
      status = ckpt.read(ckpt_dir_or_file)
      status.expect_partial().assert_existing_objects_matched()

    logging.info('Finished loading pretrained checkpoint from %s',
                 ckpt_dir_or_file)

  def build_inputs(
      self,
      params: cfg.DataConfig,
      input_context: Optional[tf.distribute.InputContext] = None
  ) -> tf.data.Dataset:
    """Build input dataset."""
    model_config = self.task_config.model
    if (model_config.classes != 'all' and
        model_config.num_classes != 2):
      raise ValueError('Model num_classes must be 2 when not for all classes.')

    decoder = decoders.ExampleDecoder(model_config.image, model_config.pillars)

    image_size = [model_config.image.height, model_config.image.width]
    anchor_sizes = [(a.length, a.width) for a in model_config.anchors]
    anchor_labeler_config = model_config.anchor_labeler
    parser = parsers.Parser(
        classes=model_config.classes,
        min_level=model_config.min_level,
        max_level=model_config.max_level,
        image_size=image_size,
        anchor_sizes=anchor_sizes,
        match_threshold=anchor_labeler_config.match_threshold,
        unmatched_threshold=anchor_labeler_config.unmatched_threshold,
        max_num_detections=model_config.detection_generator
        .max_num_detections,
        dtype=params.dtype,
    )

View on GitHub (pinned to e006f5f0d5)