Repository for SAM 2: Segment Anything in Images and Videos, a foundation model towards solving promptable visual segmentation in images and videos from FAIR. See the
SAM 2 paper
for more information.
The official code is publicly release in this
repo
.
Usage
For image prediction:
import torch
from sam2.sam2_image_predictor import SAM2ImagePredictor
predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2-hiera-tiny")
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)
For video prediction:
import torch
from sam2.sam2_video_predictor import SAM2VideoPredictor
predictor = SAM2VideoPredictor.from_pretrained("facebook/sam2-hiera-tiny")
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_or_box(state, <your_prompts>):
# propagate the prompts to get masklets throughout the videofor frame_idx, object_ids, masks in predictor.propagate_in_video(state):
...
To cite the paper, model, or software, please use the below:
@article{ravi2024sam2,
title={SAM 2: Segment Anything in Images and Videos},
author={Ravi, Nikhila and Gabeur, Valentin and Hu, Yuan-Ting and Hu, Ronghang and Ryali, Chaitanya and Ma, Tengyu and Khedr, Haitham and R{\"a}dle, Roman and Rolland, Chloe and Gustafson, Laura and Mintun, Eric and Pan, Junting and Alwala, Kalyan Vasudev and Carion, Nicolas and Wu, Chao-Yuan and Girshick, Ross and Doll{\'a}r, Piotr and Feichtenhofer, Christoph},
journal={arXiv preprint arXiv:2408.00714},
url={https://arxiv.org/abs/2408.00714},
year={2024}
}
Runs of facebook sam2.1-hiera-tiny on huggingface.co
113.7K
Total runs
0
24-hour runs
0
3-day runs
411
7-day runs
2.3K
30-day runs
More Information About sam2.1-hiera-tiny huggingface.co Model
sam2.1-hiera-tiny huggingface.co is an AI model on huggingface.co that provides sam2.1-hiera-tiny's model effect (), which can be used instantly with this facebook sam2.1-hiera-tiny model. huggingface.co supports a free trial of the sam2.1-hiera-tiny model, and also provides paid use of the sam2.1-hiera-tiny. Support call sam2.1-hiera-tiny model through api, including Node.js, Python, http.
sam2.1-hiera-tiny huggingface.co is an online trial and call api platform, which integrates sam2.1-hiera-tiny's modeling effects, including api services, and provides a free online trial of sam2.1-hiera-tiny, you can try sam2.1-hiera-tiny online for free by clicking the link below.
facebook sam2.1-hiera-tiny online free url in huggingface.co:
sam2.1-hiera-tiny is an open source model from GitHub that offers a free installation service, and any user can find sam2.1-hiera-tiny on GitHub to install. At the same time, huggingface.co provides the effect of sam2.1-hiera-tiny install, users can directly use sam2.1-hiera-tiny installed effect in huggingface.co for debugging and trial. It also supports api for free installation.