Tiled inference for small objects: averaging a global pass with 2×2 feathered tiles took shutter recall from 44 % to 76 %

My facade segmentation model sees each photo letterboxed to 512 px. A shutter 20 px wide on a 1600 px photo of a house ends up about 6 px wide after that, and the model lost more than half of them. Retraining at 640 px helped a little and doubled inference cost. Running the same model on overlapping tiles, and averaging those with the whole-image pass, helped a lot more without retraining.

TL;DR — Run the model once on the whole image, then on a grid of overlapping square tiles (side = 5/8 of the image’s short side, 25 % overlap). Stitch the tile softmax maps with a linear feather at the borders, and average the result with the global softmax before argmax. On 300 test shutters, recall went from 44 % to 76 % and precision from 57 % to 76 %, for 7 passes instead of 1. A finer 3×3 grid was worse.

The setup

The model labels each pixel as background, wall, roof, window, door or shutter (a swing leaf beside a window). It is a 3.2 M-parameter LR-ASPP MobileNetV3, exported to ONNX with a fixed 1×3×512×512 input, and it runs on a phone’s CPU. The app letterboxes any photo into that square: long side to 512, black bands on the rest. The app then counts objects: connected components per class, matched one-to-one to ground truth, found when IoU ≥ 0.5. Evaluation used 25 unseen photos containing 300 shutters and 264 windows, plus a real night photo of a house with 4 windows.

What I expected

Tiles alone, I thought: crop the image into pieces, run each at full model resolution, paste the labels back. Small objects get 2–3× more pixels.

What actually happens

Tiles alone lose context. A tile that holds only a patch of wall and half a window cannot tell a window from a dark door or a shadow, and tile borders cut objects in two. Hard pasting also leaves visible seams in the label map. The pieces that made it work:

  • Overlap, so every object is whole in at least one tile.
  • Feathering: each tile’s probabilities are weighted by a ramp that goes from ~0 at the tile edge to 1 at 15 % of the tile side. Border predictions, which see the least context, count least.
  • Averaging with the global pass, which keeps the big structures (sky, roof, which building is which) right.

Diagram: one pass on the whole letterboxed image, then overlapping tiles of 5/8 of the short side with 25 % overlap, each weighted by a trapezoidal feather; tile probabilities are stitched and averaged with the global probabilities

The fix

Trimmed from the evaluation script. run() letterboxes a crop, runs ONNX, and returns softmax probabilities resized back to the crop’s size:

def tiles(h, w, grid, overlap):
    side = min(int(min(h, w) / grid * (1 + overlap)), h, w)
    def starts(n):
        k = max(1, int(np.ceil((n - side) / (side * (1 - overlap)))) + 1)
        return [int(round(v)) for v in np.linspace(0, n - side, k)] if n > side else [0]
    return [(y, x, side) for y in starts(h) for x in starts(w)]

def feather(side):
    r = np.minimum(np.arange(side), np.arange(side)[::-1]) + 1.0
    r = np.minimum(r / (side * 0.15), 1.0)
    return np.outer(r, r).astype(np.float32)

def predict_tiled(img, grid=2, overlap=0.25):
    h, w = img.shape[:2]
    g = run(img)                                      # 6 x h x w probabilities
    acc = np.zeros_like(g); wsum = np.zeros((h, w), np.float32)
    for y, x, s in tiles(h, w, grid, overlap):
        f = feather(s)
        acc[:, y:y + s, x:x + s] += run(img[y:y + s, x:x + s]) * f
        wsum[y:y + s, x:x + s] += f
    p = (g + acc / np.maximum(wsum, 1e-6)) / 2
    return p.argmax(0).astype(np.uint8)

With grid=2 a square photo gets 2×2 tiles; a 4:3 photo gets 2 rows × 3 columns, so about 7 passes per image in total. Results with the fp16 model, same photos:

Global only Global + tiles (grid 2, mean)
Shutters found, recall / precision 0.44 / 0.57 0.76 / 0.76
Windows found, recall / precision 0.62 / 0.61 0.84 / 0.70
Shutter IoU (pixels) 0.645 0.761
mIoU, shutter test set 0.710 0.761
mIoU, general test set (few small objects) 0.695 0.703
Night photo, windows at IoU ≥ 0.5 4 / 4 4 / 4, 0 false positives
Passes per image × ms per pass (desktop CPU) 1 × 22 7 × 20

For comparison, the model retrained at 640 px reached 0.51 / 0.67 on shutters with a single global pass, at twice the cost per pass.

What did not work

Same model, other fusions (int8 export here, so compare rows with each other):

Fusion Passes General test mIoU Shutter test mIoU Window precision Night photo
global only 1 0.671 0.694 0.59 3 found, 1 false positive
grid 2, mean 7 0.679 0.752 0.71 3 found, 3 false positives
grid 2, tiles decide openings 7 0.652 0.743 0.68 3 found, 2 false positives
grid 3, mean 14 0.654 0.741 0.65 3 found, 1 false positive
grid 3, tiles decide openings 14 0.579 0.707 0.58 3 found, 2 false positives

The 3×3 grid found slightly more shutters (recall 0.82) but produced more false windows, lost 0.025 of general mIoU and cost twice as much. Its tiles are so small that many contain no context at all. Letting the tiles alone decide the opening classes, or keeping the max of the two passes for openings, also traded precision for recall. Plain averaging was the best of the variants I tried. (The night-photo misses in this int8 table are a quantisation problem with its own story.)

Why it works

The global pass knows what is where at coarse resolution; the tiles know exactly where small things are. Averaging softmax probabilities is a soft vote: a shutter that the global pass sees at 0.3 and a tile sees at 0.9 wins, a « window » that a context-free tile hallucinates on a dark wall loses to a confident global « wall ». Feathering removes the seams, because a pixel near one tile’s edge is near another tile’s centre thanks to the overlap.

What I did not test

Timings are from a desktop Ryzen CPU with 4 threads; on a phone, multiply by roughly 3–6. I did not try test-time flips, weighted averages other than 50/50, or tiles at the model’s native size without letterboxing. The test sets have 25 photos each, labelled by an automatic pipeline rather than by hand.

The models are being released under CC BY-NC 4.0 on a public model page that is being set up now. Caveat: the backbone was initialised from torchvision’s ImageNet weights, and ImageNet’s terms are for non-commercial research.

Facts

context: 512 px semantic segmentation (LR-ASPP MobileNetV3, ONNX) missing small objects on 1600 px photos
problem: Small shutters and windows are lost by letterboxing; tiles alone lose context and leave seams
solution: Global pass + grid-2 tiles (side 5/8 of short side, 25 % overlap), linear feather over 15 % of the tile side, average softmax with the global pass
verified_on: 2026-10-03
applies_to: [any fixed-input segmentation model on images much larger than its input, ONNX Runtime CPU]
does_not_apply_to: [real-time video budgets (7 passes per image), objects larger than a tile]

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut