🚀 SAM 2:圖像和視頻中的任意分割模型
SAM 2 是由 FAIR 開發的基礎模型,旨在解決圖像和視頻中的可提示視覺分割問題。它能夠根據用戶的提示,在圖像和視頻中實現靈活的分割任務。更多信息請參考 SAM 2 論文。
官方代碼已在這個 倉庫 中公開。
🚀 快速開始
本項目提供了在圖像和視頻中進行分割預測的功能,以下是具體的使用方法。
💻 使用示例
基礎用法
圖像預測
import torch
from sam2.sam2_image_predictor import SAM2ImagePredictor
predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2-hiera-base-plus")
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)
視頻預測
import torch
from sam2.sam2_video_predictor import SAM2VideoPredictor
predictor = SAM2VideoPredictor.from_pretrained("facebook/sam2-hiera-base-plus")
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
state = predictor.init_state(<your_video>)
frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, <your_prompts>):
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
...
更多詳細信息請參考 演示筆記本。
引用
如果您想引用該論文、模型或軟件,請使用以下 BibTeX 格式:
@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}
}
📄 許可證
本項目採用 Apache-2.0 許可證。
屬性 |
詳情 |
模型類型 |
圖像和視頻分割模型 |
庫名稱 |
sam2 |
許可證 |
Apache-2.0 |
任務類型 |
掩碼生成 |