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

Error "Model num_classes must be 2 when not for all classes." thrown in tensorflow/models.

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)

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.