tensorflow/models · error · KeyError

Checkpoint at '{checkpoint_path}' is missing 'model_state_di

Error message

Checkpoint at '{checkpoint_path}' is missing 'model_state_dict'. Was it produced by our training scripts?

What it means

Error "Checkpoint at '{checkpoint_path}' is missing 'model_state_dict'. Was it produced by our training scripts?" thrown in tensorflow/models.

Source

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

    """Reads and validates the model state dict from a checkpoint.

    Args:
        checkpoint_path: Path to the checkpoint file.
        device: Torch device to map the loaded parameters to.

    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.

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:276 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/73d127cd6ffbd144. Report an issue: GitHub.