merve HF staff commited on
Commit
04711d4
1 Parent(s): 6139499

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -0
README.md CHANGED
@@ -19,6 +19,8 @@ pip install samv2 huggingface_hub
19
 
20
  Each model requires different classes to infer.
21
 
 
 
22
  ```python
23
 
24
  from huggingface_hub import hf_hub_download
@@ -41,6 +43,23 @@ 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.
 
19
 
20
  Each model requires different classes to infer.
21
 
22
+ For prompting:
23
+
24
  ```python
25
 
26
  from huggingface_hub import hf_hub_download
 
43
  multimask_output=False)
44
  ```
45
 
46
+ For automatic mask generation:
47
+
48
+ ```python
49
+ from huggingface_hub import hf_hub_download
50
+ from sam2.build_sam import build_sam2
51
+ from sam2.automatic_mask_generator import SAM2AutomaticMaskGenerator
52
+
53
+ hf_hub_download(repo_id = "merve/sam2-hiera-small", filename="sam2_hiera_small.pt", local_dir = "./")
54
+ ckpt = f"./sam2_hiera_small.pt"
55
+ config = "sam2_hiera_s.yaml"
56
+
57
+ sam2 = build_sam2(model_cfg, sam2_checkpoint, device ='cuda', apply_postprocessing=False)
58
+
59
+ mask_generator = SAM2AutomaticMaskGenerator(sam2)
60
+ masks = mask_generator.generate(image)
61
+ ```
62
+
63
  ## Resources
64
 
65
  The team behind SAM2 made example notebooks for all tasks.