{"record":{"id":"e79ea44d0489591d","repo":"tensorflow/models","slug":"checkpoint-state-dict-is-missing-head-weight-ca","errorCode":null,"errorMessage":"Checkpoint state dict is missing 'head.weight'; cannot infer pooling. Was the checkpoint produced by our Dinov3Classification?","messagePattern":"Checkpoint state dict is missing 'head\\.weight'; cannot infer pooling\\. Was the checkpoint produced by our Dinov3Classification\\?","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py","lineNumber":282,"sourceCode":"    Returns:\n        The state dict containing model weights.\n\n    Raises:\n        KeyError: If 'model_state_dict' or 'head.weight' is missing.\n    \"\"\"\n    checkpoint = torch.load(\n        checkpoint_path,\n        map_location=device,\n        weights_only=False,\n    )\n    if \"model_state_dict\" not in checkpoint:\n      raise KeyError(\n          f\"Checkpoint at '{checkpoint_path}' is missing \"\n          \"'model_state_dict'. Was it produced by our training scripts?\"\n      )\n    state_dict = checkpoint[\"model_state_dict\"]\n    if \"head.weight\" not in state_dict:\n      raise KeyError(\n          \"Checkpoint state dict is missing 'head.weight'; cannot infer \"\n          \"pooling. Was the checkpoint produced by our Dinov3Classification?\"\n      )\n    return state_dict\n\n  @staticmethod\n  def _detect_pooling(\n      state_dict: dict[str, Any],\n      dinov3_repo_dir: str,\n      model_name: str,\n  ) -> str:\n    \"\"\"Infers the pooling strategy from the shape of the saved head's weights.\n\n    Args:\n        state_dict: The model state dict loaded from checkpoint.\n        dinov3_repo_dir: Path to the cloned DINOv3 repository.\n        model_name: Name of the DINOv3 backbone variant.\n","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py#L264-L300","documentation":"Error \"Checkpoint state dict is missing 'head.weight'; cannot infer pooling. Was the checkpoint produced by our Dinov3Classification?\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py:282 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}