Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,58 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
pipeline_tag: mask-generation
|
4 |
+
library_name: sam2
|
5 |
+
---
|
6 |
+
Model cloned from this [repo](https://github.com/facebookresearch/segment-anything-2/)
|
7 |
+
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](https://arxiv.org/abs/2408.00714) for more information.
|
8 |
+
|
9 |
+
The official code is publicly release in this [repo](https://github.com/facebookresearch/segment-anything-2/).
|
10 |
+
|
11 |
+
## Usage
|
12 |
+
|
13 |
+
For image prediction:
|
14 |
+
|
15 |
+
```python
|
16 |
+
import torch
|
17 |
+
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
18 |
+
|
19 |
+
predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2-hiera-tiny")
|
20 |
+
|
21 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
22 |
+
predictor.set_image(<your_image>)
|
23 |
+
masks, _, _ = predictor.predict(<input_prompts>)
|
24 |
+
```
|
25 |
+
|
26 |
+
For video prediction:
|
27 |
+
|
28 |
+
```python
|
29 |
+
import torch
|
30 |
+
from sam2.sam2_video_predictor import SAM2VideoPredictor
|
31 |
+
|
32 |
+
predictor = SAM2VideoPredictor.from_pretrained("facebook/sam2-hiera-tiny")
|
33 |
+
|
34 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
35 |
+
state = predictor.init_state(<your_video>)
|
36 |
+
|
37 |
+
# add new prompts and instantly get the output on the same frame
|
38 |
+
frame_idx, object_ids, masks = predictor.add_new_points_or_box(state, <your_prompts>):
|
39 |
+
|
40 |
+
# propagate the prompts to get masklets throughout the video
|
41 |
+
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
|
42 |
+
...
|
43 |
+
```
|
44 |
+
|
45 |
+
Refer to the [demo notebooks](https://github.com/facebookresearch/segment-anything-2/tree/main/notebooks) for details.
|
46 |
+
|
47 |
+
### Citation
|
48 |
+
|
49 |
+
To cite the paper, model, or software, please use the below:
|
50 |
+
```
|
51 |
+
@article{ravi2024sam2,
|
52 |
+
title={SAM 2: Segment Anything in Images and Videos},
|
53 |
+
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},
|
54 |
+
journal={arXiv preprint arXiv:2408.00714},
|
55 |
+
url={https://arxiv.org/abs/2408.00714},
|
56 |
+
year={2024}
|
57 |
+
}
|
58 |
+
```
|