Sub topic 12
Limitations and Failure Modes
Assume you know basic Python and NumPy, can load a pretrained PyTorch model, and understand the difference between segmentation, detection, and classification. SAM is powerful, but “segment anything” does not mean “understand everything.”
SAM does not provide semantic understanding
SAM predicts a region that matches a prompt. It does not automatically tell you what the region means. A mask may cover a person, a tire, or a shadow, but SAM does not assign a class name such as person or tire.
A detector can provide labels and boxes. SAM can then turn a selected box into a more accurate mask. In a practical system, detection and segmentation often work together:
- A detector finds objects and gives class labels.
- SAM refines the detector's boxes into pixel masks.
- Application code checks the masks and attaches the detector's labels.
Zero-shot transfer means that SAM can respond to unfamiliar objects without retraining for each object category. It does not guarantee that every unfamiliar object will be segmented correctly.
Prompt ambiguity causes the wrong mask
A point prompt contains very little information. If several objects touch the point, SAM may return several plausible masks. The returned scores are predicted quality scores, not ground-truth measurements. The highest score is useful, but it is not proof that the mask is correct.
A box can also be ambiguous. For example, a box around two overlapping objects may produce one combined mask or select only one object. Add foreground points inside the desired object and background points outside it when the boundary is unclear.
Boundaries and small objects are difficult
SAM may fail when the object is very small relative to the image, heavily blurred, transparent, reflective, or partly hidden. Thin structures such as wires, hair, plant stems, and bicycle spokes can disappear. Similar colors between an object and its background can cause the mask to leak into nearby regions.
Low-resolution inputs and aggressive resizing make these problems worse. A mask that looks reasonable at the model's working resolution may lose narrow details when converted back to the original image.
The model can also split one object into several masks or merge touching objects. Check the result against the image rather than trusting the mask's shape.
Automatic mask generation needs filtering
SamAutomaticMaskGenerator samples many points across the image. It can produce overlapping masks, duplicate masks, fragments, and masks for background texture. Its fields help rank and filter results:
| Field | Meaning | Important limitation |
|---|---|---|
| `area` | Number of pixels in the mask | Large does not mean correct |
| `bbox` | Box in `[x, y, width, height]` format | It is not `[x1, y1, x2, y2]` |
| `predicted_iou` | Estimated mask quality | It is a prediction, not measured IoU |
| `stability_score` | Resistance to threshold changes | Stable masks can still represent the wrong region |
Use application-specific rules such as minimum area, maximum overlap, expected shape, or a detector's class label. Always inspect representative outputs before using automatic masks as training labels.
Domain shift and resource costs
SAM was trained on a very large and varied image collection, but unusual domains can still cause domain shift. Medical scans, satellite images, infrared frames, microscopy, and documents may differ greatly from its training data. A prompt that works on photographs may fail in these settings.
The image encoder is expensive and requires substantial memory. The embedding is reused for many prompts on one image, but a new image requires another encoder pass. Automatic generation is more expensive than one interactive prediction because it evaluates many prompts.
Video and changing scenes
A still-image predictor does not automatically maintain object identity across video frames. Running it independently on every frame can cause flicker, missed objects, and inconsistent boundaries. SAM 2 extends the promptable idea to images and video by adding mechanisms for propagating information through a sequence, but it still inherits challenges from blur, occlusion, and scene changes.
Exercise
A point prompt produces three masks with similar scores, and the point lies near two touching objects. What should you do?
Show answer
Add foreground points inside the intended object and background points on the other object, then compare the new masks with the image. Do not select a mask using the score alone.