tensorflow/models · error · ClassifierError

Checkpoint state dict is missing required key 'head.weight'.

Error message

Checkpoint state dict is missing required key 'head.weight'.

What it means

Schema check in _load_checkpoint_state_dict: model_state_dict was found, but its 'head.weight' tensor is missing. The classifier needs the final linear head's weight matrix both to infer the pooling strategy (from its input feature dimension) and to restore predictions; without it the checkpoint cannot reconstruct the classifier, so loading aborts. Typically a backbone-only checkpoint or a state dict filtered to encoder keys.

Solutions

  1. Use the fine-tuned checkpoint that includes the classification head, not backbone-only weights
  2. If the head was stripped, re-finetune or re-attach a head and re-save the checkpoint
  3. Inspect checkpoint['model_state_dict'].keys() to confirm 'head.weight' exists
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py:162 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/c00736b445fbaaff. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py:162

    checkpoint_path: Filesystem path to the checkpoint.
    device: Target device for `map_location`.

  Returns:
    The `model_state_dict` mapping from parameter name to tensor.

  Raises:
    ClassifierError: If the checkpoint is missing required keys.
  """
  checkpoint = torch.load(
      checkpoint_path, map_location=device, weights_only=True
  )
  if "model_state_dict" not in checkpoint:
    raise ClassifierError(
        "Checkpoint is missing required key 'model_state_dict'."
    )
  saved_state_dict = checkpoint["model_state_dict"]
  if "head.weight" not in saved_state_dict:
    raise ClassifierError(
        "Checkpoint state dict is missing required key 'head.weight'."
    )
  return saved_state_dict


def _build_image_transform(config: config_loader.DINOv3Config) -> v2.Compose:
  """Builds the preprocessing pipeline used to feed PIL images to the model.

  Args:
    config: DINOv3 model configuration providing image size and normalization
      statistics.

  Returns:
    A torchvision v2.Compose pipeline.
  """
  return v2.Compose([
      v2.ToImage(),
      v2.Resize(

View on GitHub (pinned to e006f5f0d5)