core/nn/vision/sam_loader library

Loader for HuggingFace / Facebook Research SAM safetensors.

Reads a .safetensors file dumped from a torch checkpoint (either sam_vit_b_01ec64.pth via scripts/convert_sam_pt_to_safetensors.py or the HF facebook/sam-vit-base bundle) and binds it to a triple of SamImageEncoder + SamPromptEncoder + SamMaskDecoder.

Prefixes vary across sources:

  • Original sam_vit_b_01ec64.pth uses no prefix on the three submodels (keys start with image_encoder., prompt_encoder., mask_decoder.).
  • The HF facebook/sam-vit-base bundle uses the same top-level names; the wrapper module is called sam. in the joint model but is dropped when the vision submodel is loaded alone.

The loader auto-detects the sam. prefix.