Skip to main content...
CV Depth: the Measurement Pipeline
25 min

Day 62: SAM/SAM2: promptable segmentation

The segmentation foundation model

SAM (Segment Anything Model) and its successor SAM2 are foundation models for segmentation: trained on billions of masks, they segment almost anything given a prompt — a point, a box, or text. This is a leap over Stage 0's GrabCut: where GrabCut used color statistics and often failed on similar-colored backgrounds, SAM has learned actual object structure. Prompt it with your YOLO person box and it returns a precise person mask.

Prompting SAM with the person box from detection
from ultralytics import SAM

sam = SAM("sam2_b.pt")
# prompt with the YOLO person box -> precise mask
result = sam("customer.jpg", bboxes=[[x1, y1, x2, y2]])
person_mask = result[0].masks.data[0].cpu().numpy()   # boolean HxW mask

Callback to Stage 0 Day 11

Remember GrabCut's failure modes — garment/background color overlap, cluttered scenes? SAM is precisely the neural upgrade that lesson promised. You felt where the classical method broke; now you see why a model trained on billions of masks doesn't break the same way. That contrast — classical vs learned — is worth articulating in an interview.

Key terms

SAM / SAM2
Segment Anything Model — a promptable segmentation foundation model trained on billions of masks.
Segmentation prompt
The input (point, box, or text) that tells SAM which object to segment.
Foundation model
A large model pretrained on massive data, adaptable to many tasks — here, segmenting almost any object.

Why does SAM handle a garment matching its background color far better than Stage 0's GrabCut?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 62: SAM/SAM2: promptable segmentation | RBTechIconX