Views
No views yet
| Base Model | facebook/sam-vit-base (93.7M params) |
| Task | Binary polyp segmentation from endoscopy images |
| Strategy | Fine-tune mask decoder, freeze vision encoder + prompt encoder |
| Prompts | Bounding box (with random ±20px perturbation) |
| Dataset | Kvasir-SEG: 880 train / 120 val images |
| Loss | DiceCELoss (MONAI) |
| Optimizer | AdamW (lr=1e-05, wd=0.01) |
| Scheduler | Cosine Annealing |
| Epochs | 30 |
| Best Val Dice | 0.8355 |
1from transformers import SamModel, SamProcessor
2from PIL import Image
3import torch, numpy as np
4
5model = SamModel.from_pretrained("Mayank022/sam-vit-base-kvasir-polyp-segmentation")
6processor = SamProcessor.from_pretrained("Mayank022/sam-vit-base-kvasir-polyp-segmentation")
7
8image = Image.open("polyp.jpg").convert("RGB")
9input_boxes = [[[100, 100, 400, 400]]] # bounding box prompt
10
11inputs = processor(image, input_boxes=input_boxes, return_tensors="pt")
12with torch.no_grad():
13 outputs = model(**inputs, multimask_output=False)
14
15mask = (torch.sigmoid(outputs.pred_masks.squeeze()) > 0.5).cpu().numpy().astype(np.uint8)