tensorflow/models · error · ClassifierError

Cannot infer pooling strategy. Head input dimension {head_in

Error message

Cannot infer pooling strategy. Head input dimension {head_input_features} does not match hidden size {hidden_size} or {2 * hidden_size}.

What it means

Error "Cannot infer pooling strategy. Head input dimension {head_input_features} does not match hidden size {hidden_size} or {2 * hidden_size}." thrown in tensorflow/models.

Source

Thrown at official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py:131

  """Infers the pooling strategy from the shape of the saved head weights.

  Args:
    saved_state_dict: The checkpoint's model state dict.
    hidden_size: Backbone hidden dimensionality.

  Returns:
    The inferred pooling strategy.

  Raises:
    ClassifierError: If the head input dimension matches neither the CLS nor
      the CLS_MEAN_PATCH expectation.
  """
  head_input_features = saved_state_dict["head.weight"].shape[1]
  if head_input_features == hidden_size:
    return PoolingStrategy.CLS
  if head_input_features == 2 * hidden_size:
    return PoolingStrategy.CLS_MEAN_PATCH
  raise ClassifierError(
      "Cannot infer pooling strategy. Head input dimension "
      f"{head_input_features} does not match hidden size {hidden_size} or "
      f"{2 * hidden_size}."
  )


def _load_checkpoint_state_dict(
    checkpoint_path: pathlib.Path | str, device: torch.device
) -> dict[str, torch.Tensor]:
  """Loads the model state dict from a checkpoint file.

  Args:
    checkpoint_path: Filesystem path to the checkpoint.
    device: Target device for `map_location`.

  Returns:
    The `model_state_dict` mapping from parameter name to tensor.

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py:131 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/557f8314badbd24b. Report an issue: GitHub.