Views
No views yet
pip install samv2 huggingface_hub1
2from huggingface_hub import hf_hub_download
3from sam2.build_sam import build_sam2
4from sam2.sam2_image_predictor import SAM2ImagePredictor
5
6hf_hub_download(repo_id = "merve/sam2-hiera-small", filename="sam2_hiera_small.pt", local_dir = "./")
7
8ckpt = f"./sam2_hiera_small.pt"
9config = "sam2_hiera_s.yaml"
10
11sam2_model = build_sam2(config, ckpt, device="cuda", apply_postprocessing=False)
12predictor = SAM2ImagePredictor(sam2_model)
13
14# it accepts coco format
15box = [x1, y1, w, h]
16predictor.set_image(image)
17
18masks = predictor.predict(box=box,
19multimask_output=False)1from huggingface_hub import hf_hub_download
2from sam2.build_sam import build_sam2
3from sam2.automatic_mask_generator import SAM2AutomaticMaskGenerator
4
5hf_hub_download(repo_id = "merve/sam2-hiera-small", filename="sam2_hiera_small.pt", local_dir = "./")
6ckpt = f"./sam2_hiera_small.pt"
7config = "sam2_hiera_s.yaml"
8
9sam2 = build_sam2(model_cfg, sam2_checkpoint, device ='cuda', apply_postprocessing=False)
10
11mask_generator = SAM2AutomaticMaskGenerator(sam2)
12masks = mask_generator.generate(image)