{"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":"Error \"Cannot infer pooling strategy. Head input dimension {head_input_features} does not match hidden size {hidden_size} or {2 * hidden_size}.\" thrown in tensorflow/models.","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":[],"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"}