SAM, explained · Part 6 of 6 · Covers §8, Conclusion, and five later papers: SAM 2, MobileSAM, HQ-SAM, MedSAM, SAM 3
After SAM: Impact, Limits and Summary
Where SAM fails, measured with the released model on a bicycle, a drawn wheel and an edge with teeth. Then five later papers that fixed those limits, and the whole paper in one page.
Segment Anything. Alexander Kirillov, Eric Mintun, Nikhila Ravi, Hanzi Mao, Chloe Rolland, Laura Gustafson, Tete Xiao, Spencer Whitehead, Alexander C. Berg, Wan-Yen Lo, Piotr Dollár, Ross Girshick. ICCV 2023, 2023. arXiv:2304.02643
The last page of the paper is honest: it lists what SAM cannot do. We test each limit on the released model, then follow five later papers that took up those limits one by one.
All three faults have one cause that we met in Part 3. The mask decoder predicts the mask on a grid of 256 × 256 cells, and the final mask is that grid, enlarged by interpolation. For a 1024 × 1024 picture, one cell covers 4 × 4 pixels. Anything thinner than a cell has no cell of its own.
We tested the three faults with the released ViT-H and ViT-B models.
A bicycle is the classic test: a wheel is mostly empty space with thin spokes. We took a photo from the COCO dataset. SAM got two prompts: a box around the whole bicycle, and one point on the rear tyre.
plain text
ViT-H: box [195, 8, 497, 388] -> 1 mask, predicted IoU 0.972, 61,124 pixelsViT-H: point (482, 270) on the rear tyre -> mask 2 (the wheel), predicted IoU 1.003, 34,976 pixels; holes inside it: 6 (77 pixels)
SAM ViT-H on a COCO photo. Both masks paint each wheel as a solid disc: the road seen between the spokes becomes "bicycle". The wheel mask has only 6 tiny holes (77 pixels in total).
The predicted IoU is 0.972 for the box and 1.003 for the wheel: SAM is very sure. But look at the wheels. The road between the spokes is pink. To SAM, the wheel is a disc.
A photo cannot tell us how wrong this is, because nobody drew the exact correct mask for every spoke. So we drew a wheel ourselves, where we know every pixel. The picture is 1024 × 1024 pixels with a dark rim, a hub and 24 spokes. We drew it eight times, with spokes 1 to 16 pixels wide, and gave SAM a box around the wheel each time.
Two numbers grade each mask. Spoke recall is the share of spoke pixels that the mask covers. Gap fill is the share of the empty pixels between the spokes that the mask covers. The correct mask has a spoke recall of 1 and a gap fill of 0.
plain text
model spoke width spoke px score spoke recall gap fill IoU best of 3 IoUViT-H 1 px 7,907 0.917 0.000 0.000 0.835 0.839ViT-H 2 px 16,188 0.733 0.208 0.014 0.745 0.771ViT-H 3 px 26,062 0.756 0.620 0.534 0.263 0.709ViT-H 4 px 34,234 0.893 0.988 0.991 0.193 0.656ViT-H 6 px 52,289 0.989 1.000 1.000 0.222 0.569ViT-H 8 px 69,115 0.994 1.000 1.000 0.249 0.586ViT-B 3 px 26,062 0.871 0.506 0.046 0.681 0.708ViT-B 4 px 34,234 0.915 0.888 0.402 0.358 0.681ViT-H: widths with spoke recall > 0.9 and gap fill < 0.1 (the correct shape): noneViT-B: widths with spoke recall > 0.9 and gap fill < 0.1 (the correct shape): none
The drawn wheel. Thin spokes vanish (only the rim is masked). Thick spokes turn the wheel into a solid disc. In between, the mask is a blotchy mix. No width gives spokes without gaps.Spoke recall and gap fill against the spoke width, for ViT-H and ViT-B. All four lines stay near 0 for thin spokes and jump to near 1 between 3 and 8 pixels. The correct answer (recall 1, gap fill 0) never appears.
The result has two sides, and both are wrong. With spokes of 1 or 2 pixels, SAM does not see them: recall 0.000 and 0.208. With spokes of 6 pixels or more, SAM sees them and fills the whole disc: gap fill 1.000. The switch happens at 3 to 4 pixels, which is one cell of the 256 × 256 grid.
That is the grid at work. A gap between two spokes is wide near the rim and narrow near the hub. Near the hub, a cell holds spoke and gap together, and it can only say "in" or "out". The decoder learned from SA-1B that a wheel is usually one object, so it says "in" everywhere.
The IoU column hides all this. For 1-pixel spokes, the IoU is 0.835, a fine score, because the rim and the hub are most of the pixels. A good average can hide a total failure on the thin parts. The column "best of 3" gives the best of the three ambiguity masks; none of them is correct either.
ViT-B is closer at 3 pixels: recall 0.506 with a gap fill of only 0.046. That is not a general win for the small model. It only shows that the two models switch at slightly different widths.
What this test cannot show: a drawn wheel on a flat grey ground is not a photo. Real spokes have shadows, blur and a busy background. But the bicycle photo shows the same solid disc.
The second fault is "small disconnected components". A connected component is a group of mask pixels that touch each other (Part 4 defines it fully). A mask of one cat should be one component. Extra small islands are pixels that SAM marks as "object" far from the object.
We clicked a regular grid of 16 × 16 = 256 points on each of two photos, the bicycle and the two cats of Part 1. For each click we kept the mask with the highest predicted IoU and counted its components. An island under 100 pixels that is not the main piece is a "stray piece".
plain text
bike ViT-H: 256 prompts, 152 masks with more than one piece (59%), 145 with stray pieces under 100 pixels (57%), 1051 such pieces in total, median size 5 pixelscats ViT-H: 256 prompts, 154 masks with more than one piece (60%), 87 with stray pieces under 100 pixels (34%), 1195 such pieces in total, median size 4 pixelscats ViT-B: 256 prompts, 210 masks with more than one piece (82%), 209 with stray pieces under 100 pixels (82%), 9212 such pieces in total, median size 4 pixels
Stray pieces in confident ViT-H masks. Top: a click on the blanket gives a mask with 395 islands under 100 pixels on the red cloth (predicted IoU 0.959). Bottom: a click on the sidewalk gives 57 islands on the bricks (predicted IoU 0.924).
The pictures show where the islands come from. They sit on textures that look a little like the clicked surface: the red cloth beside the blanket, the bricks beside the sidewalk. The logit there is just above 0, and the threshold turns each lucky pixel into an island. The median island has 4 or 5 pixels.
The paper knew this. Appendix B estimates that "4% of masks include small, spurious components" in the automatic stage of the data engine. It removes islands under 100 pixels and fills holes under 100 pixels. It also keeps only masks with a predicted IoU above 0.88 and a high stability score (Part 4 explains both). We applied the two filters to our masks:
plain text
bike ViT-H: only masks with predicted IoU > 0.88: 231 masks, 125 with stray pieces under 100 pixels (54%) and also stable (IoU of the masks at logit +1 and -1 >= 0.95): 153 masks, 57 with stray pieces under 100 pixels (37%)cats ViT-B: only masks with predicted IoU > 0.88: 224 masks, 182 with stray pieces under 100 pixels (81%) and also stable (IoU of the masks at logit +1 and -1 >= 0.95): 37 masks, 3 with stray pieces under 100 pixels (8%)
The share of masks with stray pieces under 100 pixels, for both photos and both models: all masks, then masks with predicted IoU above 0.88, then masks that are also stable. The filters lower the share, most for ViT-B, but they never remove it.
The stability filter helps most, because an island of 4 pixels with a logit near 0 is exactly what "unstable" means. For ViT-B on the cats it removes most masks: 37 of 224 survive. The predicted IoU alone barely helps. SAM gives a mask full of islands a score of 0.959.
Our 37% to 8% is far above the paper's 4%, and the two numbers are not comparable. The paper counted on the original photos, about 1500 pixels on the short side, with a special SAM trained for automatic generation. We counted on photos of 640 pixels, with raw single clicks and no crops. The lesson is the same: islands are common in raw masks, and a short clean-up step removes them.
The third fault is the exact line of the edge. We zoomed into the tyre of the bicycle, 64 × 64 pixels, and drew four views of the same place:
The tyre edge in four views. The final mask (third) is the 256 × 256 grid (second) with its steps smoothed; it adds no new detail. The probability (fourth) is uncertain only in a thin band at the edge.
plain text
ViT-H: low-resolution logits (256, 256); one cell covers 2.50 x 2.50 photo pixelsViT-H: wheel mask edge 1,060 pixels long; pixels with probability between 0.1 and 0.9: 3,768; mean width of the soft band 3.55 pixelsViT-H: the final mask and the 256 x 256 cell mask (blown up without interpolation) differ in 648 pixels, 1.9% of the mask area
The photo is 640 pixels wide, so one cell covers 2.5 × 2.5 photo pixels. The final mask and the blocky cell mask differ in only 1.9% of the mask's pixels. Interpolation rounds the corners of the blocks, but it cannot add a knob of the tread that the grid did not have.
The "soft band" is the strip where SAM is unsure: the probability is between 0.1 and 0.9. We divide its area by the length of the edge to get its average width. It is 3.55 pixels for ViT-H and 8.54 for ViT-B. Inside that band, the exact position of the line is a guess.
To measure crispness with a known answer, we drew a dark block with teeth on its top edge, 16 pixels high. The teeth and the gaps between them have the same width t. We graded tooth recall and gap fill, as for the spokes:
plain text
model t tooth recall gap fill edge error (no teeth)ViT-H none 2.27 pxViT-H 1 px 0.968 0.968ViT-H 2 px 0.986 0.989ViT-H 4 px 0.993 0.985ViT-H 8 px 0.916 0.469ViT-H 16 px 0.384 0.011ViT-H 32 px 0.807 0.004
The edge with teeth, ViT-H. Up to 4 pixels the mask draws a straight line over the tips. At 8 pixels it starts to follow the teeth, with round corners. At 16 pixels it cuts the teeth down to rounded bumps.Tooth recall and gap fill against the tooth width. Up to 4 pixels both are near 1: the mask is a straight line over the tips. At 8 pixels the mask starts to follow the teeth. At 16 pixels it keeps only 38% of the tooth pixels (ViT-H).
Up to 4 pixels, the mask is a straight line over the tips: recall and gap fill both near 1. At 8 pixels, two cells per tooth, the mask starts to follow the teeth. Even at 32 pixels, the mask misses 19% of the tooth pixels, mostly at the sharp corners. Even a straight edge with no teeth is off by 2.27 pixels on average.
A zoom-in method would fix this. It would cut a window around the edge from the full photo and run a second, sharper pass on it. SAM chose one pass for speed.
Our script counted the weights of the two released models:
plain text
ViT-H: 641,090,864 weights, of which image encoder 637,026,048, prompt encoder + mask decoder 4,064,816ViT-B: 93,735,728 weights, of which image encoder 89,670,912, prompt encoder + mask decoder 4,064,816ViT-H has 7.1 x the encoder weights of ViT-B
The decoder is the same size in both. Only the encoder changes. So does the small encoder give the same masks? We compared ViT-B with ViT-H on the same 256 clicks per photo, with ViT-H's top mask as the reference:
plain text
bike, ViT-B top mask: 256 prompts, mean IoU with the ViT-H top mask 0.753, median 0.915, 54% above 0.9, 18% below 0.5bike, closest of 3 ViT-B masks: 256 prompts, mean IoU with the ViT-H top mask 0.884, median 0.944, 69% above 0.9, 5% below 0.5cats, ViT-B top mask: 256 prompts, mean IoU with the ViT-H top mask 0.810, median 0.936, 58% above 0.9, 11% below 0.5
The median is high: the typical click gets nearly the same mask. The mean is lower, because 18% of the bicycle clicks get a very different mask. Most of those are ambiguity, not failure. When we let ViT-B pick the closest of its three masks, only 5% stay below 0.5. The small model often finds the same object, but ranks the part and the whole in another order.
Part 5 reads Figure 13 of the paper: ViT-H gains a lot over ViT-B, but little over ViT-L. Its caption adds that "smaller image encoders may be preferred in certain settings". Those settings are the phone and the video, and two later papers took them up.
Five limits of Section 8 and five later papers. SAM 2 adds a memory for video. MobileSAM trains a small encoder to copy ViT-H. HQ-SAM adds one output token for sharper masks. MedSAM fine-tunes SAM on medical images. SAM 3 finds all instances of a noun phrase.
The 44,000 training masks are tiny next to SA-1B's 1.1 billion. But the paper calls them "extremely accurate", taken from six existing datasets. A small set of very exact masks taught what a billion good masks did not.
Six parts ago, we started with a photo, a click and three masks. Here is the paper again, in one picture and a few paragraphs.
The paper in one picture: the task (Part 2), the model (Part 3), the data engine and SA-1B (Part 4) and the zero-shot experiments (Part 5). The model makes the data, the data trains the model, and the prompt lets one model do many tasks.
The task (Part 2). Give the model any prompt, a point, a box, a rough mask or text. It must return a valid mask. If the prompt is ambiguous, any sensible object counts, so the model returns three masks: a part, a larger part and the whole. Language models learned from "predict the next word"; SAM learns from "predict the mask for this prompt".
The model (Part 3). A heavy ViT-H encoder reads the picture once and writes a 256 × 64 × 64 embedding. A light prompt encoder and mask decoder read that embedding for each click, fast enough for a person to click and see. The split into "once per picture" and "once per click" is the economic idea of the whole design.
The data engine and the dataset (Part 4). No dataset of the right size existed, so the team built one with the model in the loop. Annotators first clicked with SAM's help, then corrected SAM's automatic masks, and at the end SAM made masks alone. The result, SA-1B, has 11 million photos and 1.1 billion masks.
The experiments (Part 5). With no extra training, SAM was tested on 23 datasets and on other tasks: edges, object proposals, instance segmentation and text. It does not win every score, but people rate its masks highly, and one model covers all the tasks through prompts.
The limits (this part). SAM misses thin structures, makes small islands, draws edges at the resolution of a 256 × 256 grid and needs a heavy encoder. The later papers kept SAM's idea and fixed one limit each.
And the Background told where all this came from. Before SAM, there were two roads. Some models found and cut out a fixed list of things. Interactive tools cut out whatever you clicked. SAM joined the two roads, and it is still a central reference for the work that followed.
Run it yourself
The script code/papers/sam/sam_part6.py runs ViT-H and ViT-B on the bicycle photo, which it downloads from COCO. It draws the spoked wheel and the edge with teeth. It counts the islands in 512 masks per model, measures the soft band at the tyre edge and compares the two models. Every number of this part is in results/part6.json. We ran it on a laptop GPU (Apple MPS); no timing numbers are used, because other jobs ran at the same time.