I had 526 facade photos and no labels. Hand-drawing masks for windows, doors, shutters, roofs and buildings would have taken weeks. Claude can read images and write coordinates; SAM (Meta’s Segment Anything) can snap a box to an object’s edges. Together they produced every training mask for the model, but only after I stopped letting SAM decide on large surfaces.
TL;DR — Draw a labelled coordinate grid on the photo, have Claude write a box per opening and a polygon per roof and building, prompt SAM with each box, and keep SAM’s mask only for compact objects that pass three checks: IoU with Claude ≥ 0.6, area ratio 0.5–1.3, solidity ≥ 0.9. For roofs require IoU ≥ 0.85, and never use SAM for whole buildings.
The setup
The target is a 6-class mask per photo: 0 background, 1 wall/building, 2 roof, 3 window, 4 door, 5 shutter. The masks train a small segmentation network for an Android app. Two class conventions matter for everything below:
- A window is the whole opening, whatever covers it. A lowered roller shutter, closed shutters or a blind still count as window.
- A shutter is a swing leaf, opened beside its window, one polygon per leaf. A roller shutter is never a shutter.
Doors include garage and barn doors and the glazed transom above a front door. The wall is not drawn: it is whatever remains of the building once roof and openings are removed.
What I expected
I expected SAM to be the precise half and Claude the rough half everywhere. Give SAM Claude’s box and take its mask.
What actually happens
On a 10-photo pilot (19 buildings, 22 roofs, 93 windows, 15 doors, 66 shutters), I measured the agreement between SAM’s mask and Claude’s polygon:
| Class | n | median IoU | IoU < 0.6 |
|---|---|---|---|
| window | 93 | 0.81 | 2 |
| door | 15 | 0.83 | 1 |
| shutter | 66 | 0.85 | 3 |
| roof | 22 | 0.65 | 8 |
| building | 19 | 0.90 | 0 |
Openings were a clear win for SAM: it hugged the frame where Claude included the surround. Roofs were not. In 8 of 22 cases SAM picked the whole gable, the face of a dormer, or the sky (IoU 0.003 on one photo). A roof box contains several plausible objects, and SAM picks one. Buildings looked fine on IoU (0.90 median) but SAM leaked into a fence, a neighbour’s house and the gutters. IoU could not separate good from bad: a bad building scored 0.88, a good one 0.87.
Claude’s own errors were small on openings, about 3 px on a 1600 px photo, up to 10–30 px on wide windows. Complex roofs were off by 10–30 px along the ridges. The worst habit was drawing buildings around cars, boats and fences, which turns those pixels into « wall ». That became a rule: go around large occluders that hide more than about 10 % of the facade.

The fix
Claude never sees bare pixels. A script draws a line every 100 px, labelled in original image coordinates, and a --crop … --zoom 2 --step 50 mode for dense areas. Claude writes JSON like this (an excerpt from one real pilot photo; the notches in the roof polygon are two dormers), then renders it back on the photo to check it:
{"image": "0030.jpg", "width": 1600, "height": 1067, "elements": [
{"type": "window", "box": [561, 364, 673, 564]},
{"type": "shutter", "box": [99, 631, 156, 826]},
{"type": "roof", "polygon": [[15, 420], [210, 235], [1375, 222], [1565, 418], [975, 420],
[970, 345], [890, 272], [800, 330], [800, 418], [710, 418], [700, 330], [615, 280],
[535, 340], [530, 425], [15, 432]]}]}
SAM gets each box, plus a positive point at its centre when the centre lies inside Claude’s shape, and returns three candidates; the best-scored one wins. Then the merge rule, straight from the pipeline:
def choose(c, s):
if s is None or s.get("sam_failed") or s["type"] != c["type"]:
return c, "claude"
if c.get("keep") in ("claude", "sam"): # manual override after review
return (s, "sam") if c["keep"] == "sam" else (c, "claude")
if c["type"] in ("window", "door", "shutter"):
ratio = area(s["polygon"]) / area(c["polygon"])
if s["iou_claude"] >= 0.6 and 0.5 <= ratio <= 1.3 and solidity(s["polygon"]) >= 0.9:
return s, "sam"
return c, "claude"
if c["type"] == "roof" and s["iou_claude"] >= 0.85:
return s, "sam"
return c, "claude" # buildings: always Claude
Solidity is area divided by convex-hull area. It is near 1 for a clean window and drops when SAM merges two windows with their shutters or bites into a sill. On the pilot, 164 of 174 openings came from SAM and 6 of 22 roofs.
Scaling it out
Each batch of photos went to a separate Claude Code agent with a short brief: read the procedure, grid, annotate, render a check, fix, run SAM, review at least a third of the final overlays, write a report. Measured on the pilot: 30–60 s of Claude time per photo, double on rich facades with 40-odd elements. About 9,000 tokens per photo, including one check render. SAM ViT-B took about 2 s per photo on a laptop iGPU.
That sizing put 40 photos in one agent with a 1M-token context, or 15–18 with 200k. The 291 photos of the first round went through the pilot plus 7 parallel batches, and the 235 shutter photos through 7 more. Several agents share one GPU, so the SAM step is serialised with flock and memory-capped:
flock /tmp/facade-sam.lock systemd-run --user --scope -q -p MemoryMax=5G -p MemorySwapMax=512M \
.venv/bin/python annotate/sam_refine.py "$BATCH/claude" "$BATCH/sam"
Why it works
SAM is trained to find an object in a prompt. A window box contains essentially one object with strong edges, so SAM’s answer is the right one. A roof or building box contains many, so SAM’s answer is a guess. Claude has the scene understanding and SAM the edge accuracy. The merge rule takes each where it is reliable, and the shape checks reject SAM’s fusions without a human in the loop.
What I did not test
None of this was checked against hand-corrected ground truth; quality was judged by eye and by Claude/SAM agreement. The models trained on these masks still reached 0.69 mIoU on held-out photos, but their test labels came from the same pipeline. Openings under about 15 px wide on very oblique facades were left out on purpose rather than guessed. I only tried SAM ViT-B, not ViT-H.
The resulting segmentation models are being released under CC BY-NC 4.0 on a public model page that is being set up now, with one caveat: the backbone starts from torchvision’s ImageNet weights, whose training data is licensed for non-commercial research.
Facts
context: Labelling 526 facade photos for 6-class semantic segmentation without hand annotation
problem: SAM refines boxes well on compact objects but picks the wrong object for roofs and whole buildings
solution: Claude writes boxes/polygons on a coordinate grid; keep SAM masks only if IoU>=0.6, area ratio 0.5-1.3, solidity>=0.9 (roofs IoU>=0.85, buildings never)
verified_on: 2026-10-03
applies_to: [SAM ViT-B box prompts, multimodal Claude via Claude Code agents, facade photos up to 1600 px]
does_not_apply_to: [hand-verified ground truth, thin or very small objects under ~15 px]