merve HF Staff commited on
Commit
6139499
·
verified ·
1 Parent(s): 4798257

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -3
README.md CHANGED
@@ -1,3 +1,52 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: mask-generation
4
+ tags:
5
+ - sam2
6
+ ---
7
+
8
+ # SAM2-Hiera-small
9
+
10
+ This repository contains small variant of SAM2 model. SAM2 is the state-of-the-art mask generation model released by Meta.
11
+
12
+ ## Usage
13
+
14
+ You can use it like below. First install packaged version of SAM2.
15
+
16
+ ```bash
17
+ pip install samv2 huggingface_hub
18
+ ```
19
+
20
+ Each model requires different classes to infer.
21
+
22
+ ```python
23
+
24
+ from huggingface_hub import hf_hub_download
25
+ from sam2.build_sam import build_sam2
26
+ from sam2.sam2_image_predictor import SAM2ImagePredictor
27
+
28
+ hf_hub_download(repo_id = "merve/sam2-hiera-small", filename="sam2_hiera_small.pt", local_dir = "./")
29
+
30
+ ckpt = f"./sam2_hiera_small.pt"
31
+ config = "sam2_hiera_s.yaml"
32
+
33
+ sam2_model = build_sam2(config, ckpt, device="cuda", apply_postprocessing=False)
34
+ predictor = SAM2ImagePredictor(sam2_model)
35
+
36
+ # it accepts coco format
37
+ box = [x1, y1, w, h]
38
+ predictor.set_image(image)
39
+
40
+ masks = predictor.predict(box=box,
41
+ multimask_output=False)
42
+ ```
43
+
44
+ ## Resources
45
+
46
+ The team behind SAM2 made example notebooks for all tasks.
47
+
48
+ - See [image predictor example](https://github.com/facebookresearch/segment-anything-2/blob/main/notebooks/image_predictor_example.ipynb) for full example on prompting.
49
+
50
+ - See [automatic mask generation example](https://github.com/facebookresearch/segment-anything-2/blob/main/notebooks/automatic_mask_generator_example.ipynb) for generating all masks.
51
+
52
+ - See [video object segmentation example](https://github.com/facebookresearch/segment-anything-2/blob/main/notebooks/video_predictor_example.ipynb)