tensorflow/models · error · KeyError

Checkpoint state dict is missing 'head.weight'; cannot infer

Error message

Checkpoint state dict is missing 'head.weight'; cannot infer pooling. Was the checkpoint produced by our Dinov3Classification?

What it means

Error "Checkpoint state dict is missing 'head.weight'; cannot infer pooling. Was the checkpoint produced by our Dinov3Classification?" thrown in tensorflow/models.

Source

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

    Returns:
        The state dict containing model weights.

    Raises:
        KeyError: If 'model_state_dict' or 'head.weight' is missing.
    """
    checkpoint = torch.load(
        checkpoint_path,
        map_location=device,
        weights_only=False,
    )
    if "model_state_dict" not in checkpoint:
      raise KeyError(
          f"Checkpoint at '{checkpoint_path}' is missing "
          "'model_state_dict'. Was it produced by our training scripts?"
      )
    state_dict = checkpoint["model_state_dict"]
    if "head.weight" not in state_dict:
      raise KeyError(
          "Checkpoint state dict is missing 'head.weight'; cannot infer "
          "pooling. Was the checkpoint produced by our Dinov3Classification?"
      )
    return state_dict

  @staticmethod
  def _detect_pooling(
      state_dict: dict[str, Any],
      dinov3_repo_dir: str,
      model_name: str,
  ) -> str:
    """Infers the pooling strategy from the shape of the saved head's weights.

    Args:
        state_dict: The model state dict loaded from checkpoint.
        dinov3_repo_dir: Path to the cloned DINOv3 repository.
        model_name: Name of the DINOv3 backbone variant.

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:282 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/e79ea44d0489591d. Report an issue: GitHub.