{"record":{"id":"557f8314badbd24b","repo":"tensorflow/models","slug":"cannot-infer-pooling-strategy-head-input-dimensio","errorCode":null,"errorMessage":"Cannot infer pooling strategy. Head input dimension {head_input_features} does not match hidden size {hidden_size} or {2 * hidden_size}.","messagePattern":"Cannot infer pooling strategy\\. Head input dimension (.+?) does not match hidden size (.+?) or (.+?)\\.","errorType":"exception","errorClass":"ClassifierError","httpStatus":null,"severity":"error","filePath":"official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py","lineNumber":131,"sourceCode":"  \"\"\"Infers the pooling strategy from the shape of the saved head weights.\n\n  Args:\n    saved_state_dict: The checkpoint's model state dict.\n    hidden_size: Backbone hidden dimensionality.\n\n  Returns:\n    The inferred pooling strategy.\n\n  Raises:\n    ClassifierError: If the head input dimension matches neither the CLS nor\n      the CLS_MEAN_PATCH expectation.\n  \"\"\"\n  head_input_features = saved_state_dict[\"head.weight\"].shape[1]\n  if head_input_features == hidden_size:\n    return PoolingStrategy.CLS\n  if head_input_features == 2 * hidden_size:\n    return PoolingStrategy.CLS_MEAN_PATCH\n  raise ClassifierError(\n      \"Cannot infer pooling strategy. Head input dimension \"\n      f\"{head_input_features} does not match hidden size {hidden_size} or \"\n      f\"{2 * hidden_size}.\"\n  )\n\n\ndef _load_checkpoint_state_dict(\n    checkpoint_path: pathlib.Path | str, device: torch.device\n) -> dict[str, torch.Tensor]:\n  \"\"\"Loads the model state dict from a checkpoint file.\n\n  Args:\n    checkpoint_path: Filesystem path to the checkpoint.\n    device: Target device for `map_location`.\n\n  Returns:\n    The `model_state_dict` mapping from parameter name to tensor.\n","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py#L113-L149","documentation":"Sentinel in _infer_pooling_from_state_dict: the classifier infers the pooling strategy by comparing the checkpoint head's input feature dimension against the backbone hidden size — equality means CLS (single CLS token), 2x means CLS_MEAN_PATCH (concatenated CLS and mean patch tokens). The saved head.weight input dimension matches neither, so the checkpoint does not correspond to this backbone variant (different hidden size) or was saved with an unknown head architecture.","triggerScenarios":"Thrown at official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py:131 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the checkpoint was trained with the same DINOv3 backbone variant being loaded (a ViT-S checkpoint on a ViT-L backbone mismatches hidden size)","Check that the correct backbone — and thus hidden_size — is configured","Re-train or re-export the checkpoint with a supported pooling strategy so the head dimension matches","Manually inspect saved_state_dict['head.weight'].shape to confirm the mismatch"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}