tensorflow/models · error · ValueError

Cannot infer pooling strategy: head input dim {head_input_fe

Error message

Cannot infer pooling strategy: head input dim {head_input_features} matches neither {backbone_hidden_size} (cls) nor {2 * backbone_hidden_size} (cls_mean_patch). This usually means the checkpoint was trained with a different backbone than the one configured here.

What it means

Error "Cannot infer pooling strategy: head input dim {head_input_features} matches neither {backbone_hidden_size} (cls) nor {2 * backbone_hidden_size} (cls_mean_patch). This usually means the checkpoint was trained with a different backbone than the one configured here." thrown in tensorflow/models.

Source

Thrown at official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py:321

    Raises:
        ValueError: If the pooling strategy cannot be inferred from the head
            dimensions.
    """
    # Load a throwaway backbone only to read its hidden size, then discard it.
    probe = _load_backbone(
        dinov3_repo_dir=dinov3_repo_dir, model_name=model_name
    )
    backbone_hidden_size = probe.norm.normalized_shape[0]
    del probe

    head_input_features = state_dict["head.weight"].shape[1]
    if head_input_features == backbone_hidden_size:
      return POOLING_CLS
    if head_input_features == 2 * backbone_hidden_size:
      return POOLING_CLS_MEAN_PATCH

    raise ValueError(
        "Cannot infer pooling strategy: head input dim "
        f"{head_input_features} matches neither {backbone_hidden_size} "
        f"(cls) nor {2 * backbone_hidden_size} (cls_mean_patch). "
        "This usually means the checkpoint was trained with a different "
        "backbone than the one configured here."
    )

  @staticmethod
  def _build_eval_transform(image_size: int) -> transforms.Compose:
    """Builds the transformation pipeline for evaluation image preprocessing.

    Args:
        image_size: Target square image size.

    Returns:
        A torchvision transforms Compose object.
    """
    return transforms.Compose([

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py:321 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/ecc115aaddd1eea3. Report an issue: GitHub.