Instructions to use ccllr/MP-SAM2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use ccllr/MP-SAM2 with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("ccllr/MP-SAM2") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained("ccllr/MP-SAM2") with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>) # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
MP-SAM2
Fine-tuned models for A Multi-Prompt Transfer Learning Framework Based on Segment Anything Model 2 for Microcrack Segmentation in Engineered Cementitious Composite Images and Videos.
Source and installation · Training settings · Model architecture
MP-SAM2 combines an automatic threshold mask, SP-Box, and EDT positive/negative point prompts with progressive SAM2 transfer learning. The GitHub repository provides training, image inference, video propagation, and evaluation scripts.
Checkpoints
| File | Training images |
|---|---|
| mp_sam2_5.torch | 5 |
| mp_sam2_10.torch | 10 |
| mp_sam2_50.torch | 50 |
| mp_sam2_full.torch | 186 (full data) |
Each file is approximately 898 MB and contains the complete model state for the
bundled sam2_hiera_l.yaml architecture. Each file is an individual trained
model; the paper's few-shot results summarize repeated training runs.
A 20-image checkpoint is not included. SHA256SUMS lists the file hashes.
Usage
Follow the source installation instructions. From the source repository root:
python scripts/download_checkpoints.py --variant full
python scripts/infer_image.py \
--input path/to/image.png \
--checkpoint checkpoints/mp_sam2_full.torch \
--config configs/prompt.yaml \
--output outputs/image
Use --variant 5, 10, 50, or all for other checkpoints. Direct downloads
are also linked above. The download helper verifies MP-SAM2 file checksums.
Training and video inference also need Meta's original
SAM2.1 Hiera Large checkpoint.
Download it into checkpoints/ with:
python scripts/download_checkpoints.py --variant full --include-base
The transfer loader selects matching SAM2.1 tensors for the bundled MP-SAM2
architecture, excluding SAM2.1-specific spatial and pointer-projection heads.
Use this repository's runtime and configuration with these weights. The files
are custom PyTorch state dictionaries loaded by the MP-SAM2 scripts; a
Transformers AutoModel interface is not supplied.
configs/prompt.yaml controls automatic prompts for image inference and the
first video frame. configs/fewshot.yaml and configs/full.yaml control the
respective training schedules. Full instructions, data layout, and evaluation
commands are in the README.
Scope and license
The intended application is microcrack segmentation in engineered cementitious composite images and laboratory videos. The original Meta checkpoint is obtained from upstream.
The four fine-tuned files are distributed under Apache License 2.0. See LICENSE
and the upstream SAM2 attribution in NOTICE. Citation metadata is provided in
the source repository's CITATION.cff.
- Downloads last month
- -