tensorflow/models · error · ClassifierError
Checkpoint is missing required key 'model_state_dict'.
Error message
Checkpoint is missing required key 'model_state_dict'.
What it means
Key-presence check in _load_checkpoint_state_dict: torch.load succeeded, but the loaded object is a dict without the 'model_state_dict' entry. Training code saves checkpoints as {'model_state_dict': ..., plus optimizer/epoch metadata}; its absence means the file is not a training checkpoint for this module — e.g. a raw state_dict saved directly, a torch.hub weight file, or an optimizer-only checkpoint.
Solutions
- Point checkpoint_path at the checkpoint saved by the training script (contains model_state_dict)
- If you have a raw state dict, re-wrap it: torch.save({'model_state_dict': sd}, path)
- Verify the file was produced by the matching fine-tuning code, not a different pipeline
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:157 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/10ca522be21b0970.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/waste_identification_ml/model_inference_with_tracking/sam3_dinov3_tracking_pipeline/dinov3_classifier.py:157
checkpoint_path: pathlib.Path | str, device: torch.device
) -> dict[str, torch.Tensor]:
"""Loads the model state dict from a checkpoint file.
Args:
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:View on GitHub (pinned to e006f5f0d5)