Instructions to use diffusionstudio/sam2.1-base-512-coreml with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use diffusionstudio/sam2.1-base-512-coreml with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained("diffusionstudio/sam2.1-base-512-coreml") 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("diffusionstudio/sam2.1-base-512-coreml") 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
SAM 2.1 base-plus, 512 px, Core ML
SAM 2.1 video tracking of one object, as five Core ML programs with fixed shapes for Diffusion Studio. The programs compute in fp16 and take and give fp32. They need macOS 15.
| Program | Input | Output |
|---|---|---|
vision_encoder |
image |
features_stride4, features_stride8, features_stride16, features_seed |
mask_decoder |
features_stride4, features_stride8, features, points |
field, score, iou, object_pointer |
memory_encoder |
features_stride16, field, score, prompted |
memory |
memory_attention |
features_stride16, memories, memory_rows, object_pointers, pointer_positions |
features |
pointer_position |
distances |
pointer_positions |
imageis the frame, stretched to 512 Γ 512. The program normalizes it.pointsholds 16 rows of x, y and a label. x and y are in 0..1 of the frame. Label 1 is on the object, 0 is not, 2 and 3 are the corners of a box, and β1 is a row without a point.featuresof the mask decoder isfeatures_seedfor a frame with points, and the output ofmemory_attentionfor a tracked frame.fieldis the mask as logits, 128 Γ 128.memoriesholds 7 outputs ofmemory_encoder.memory_rowsgives each one its row of the model's temporal table: row 6 for the frame with the points, and row k β 1 for the k-th newest tracked frame.distancesare the frame distances of the 16 object pointers, divided by the largest distance that the pointers can have.
constants.json holds the sizes. convert.py in the crates/segmenter folder of Diffusion Studio makes these files.
- Downloads last month
- 53
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support
Model tree for diffusionstudio/sam2.1-base-512-coreml
Base model
facebook/sam2.1-hiera-base-plus