{"record":{"id":"ecc115aaddd1eea3","repo":"tensorflow/models","slug":"cannot-infer-pooling-strategy-head-input-dim-hea","errorCode":null,"errorMessage":"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.","messagePattern":"Cannot infer pooling strategy: head input dim (.+?) matches neither (.+?) \\(cls\\) nor (.+?) \\(cls_mean_patch\\)\\. This usually means the checkpoint was trained with a different backbone than the one configured here\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py","lineNumber":321,"sourceCode":"\n    Raises:\n        ValueError: If the pooling strategy cannot be inferred from the head\n            dimensions.\n    \"\"\"\n    # Load a throwaway backbone only to read its hidden size, then discard it.\n    probe = _load_backbone(\n        dinov3_repo_dir=dinov3_repo_dir, model_name=model_name\n    )\n    backbone_hidden_size = probe.norm.normalized_shape[0]\n    del probe\n\n    head_input_features = state_dict[\"head.weight\"].shape[1]\n    if head_input_features == backbone_hidden_size:\n      return POOLING_CLS\n    if head_input_features == 2 * backbone_hidden_size:\n      return POOLING_CLS_MEAN_PATCH\n\n    raise ValueError(\n        \"Cannot infer pooling strategy: head input dim \"\n        f\"{head_input_features} matches neither {backbone_hidden_size} \"\n        f\"(cls) nor {2 * backbone_hidden_size} (cls_mean_patch). \"\n        \"This usually means the checkpoint was trained with a different \"\n        \"backbone than the one configured here.\"\n    )\n\n  @staticmethod\n  def _build_eval_transform(image_size: int) -> transforms.Compose:\n    \"\"\"Builds the transformation pipeline for evaluation image preprocessing.\n\n    Args:\n        image_size: Target square image size.\n\n    Returns:\n        A torchvision transforms Compose object.\n    \"\"\"\n    return transforms.Compose([","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py#L303-L339","documentation":"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.","triggerScenarios":"Thrown at official/projects/waste_identification_ml/Deploy/pet_grading_cloud_deployment/pet_grade_classifier.py:321 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"}