Spending Attention on Contact Zones: Boundary-Guided Token Allocation for Separating Touching Instances

Many images that matter in practice are crowded with touching objects of the same kind: farm fields that share a hedge line, cells packed against one another, fragments of a fractured bone. A common way to separate such objects without a detector predicts three labels per pixel: object interior, boundary, and background. Seeds grown from the interiors, using a flood-fill method called the watershed transform, then become individual instances. This works only if the predicted boundary forms a closed wall. A single missing pixel lets two fields or two cells flood into one blob. The boundary pixels that decide the outcome are a tiny fraction of the image. Telling whether a faint line is a real wall between two objects or texture inside one object often requires context from far away, such as the shape of the field, the regular spacing of cells, or the layout of neighboring parcels.

Transformers, models built on attention (every image patch compares itself to every other patch), offer exactly this long-range context. The cost of those comparisons grows with the square of the number of patches, so using them on large high-resolution scenes is impractical. The usual remedies spend resolution in the wrong places. They either compress everywhere, or they keep fine detail where the image looks busy. Touching objects of the same type are exactly where the image does not look busy.

We propose to spend fine-resolution tokens (the image patches a transformer processes) only where the model believes two instances meet. Everything else, including object interiors and background, is represented by coarse tokens that carry global context cheaply. We also forbid any token merging across a predicted wall.

Core Claim

A transformer can be made to separate touching instances better at a fixed compute budget. The method lets a cheap coarse pass predict a three-class map and a "contact likelihood" for each region. It then refines only high-contact regions into fine tokens that read global context from the coarse grid through cross-attention. The claim has two testable parts.

The first part is about efficiency. At matched compute, boundary-guided allocation reduces merge errors (one predicted instance covering two or more true instances) relative to uniform tokenization, entropy-based adaptive patching, and salience-based reallocation.

The second part is about context. The gain over a full-resolution convolutional network should concentrate on boundaries that are locally ambiguous, meaning low contrast across the interface. That is where long-range context should matter.

If neither holds, the extra machinery is not worth building, and the experiments are set up to show that.

Relation to Prior Work

The closest existing system is the Boundary-Enhanced Patch-Merging Transformer (BPT). It merges homogeneous patches by clustering and adds an edge loss supervised by Canny edges during training. BPT differs from our proposal in three ways:

  • It discards its boundary module at inference.
  • It is evaluated only on semantic segmentation, reaching 77.1% mIoU on Inria Aerial against 74.2% for ISDNet.
  • Its clustering adds runtime overhead the authors flag themselves.

BPT therefore motivates our proposal: merging tokens in homogeneous regions works for high-resolution segmentation. In our design, by contrast, the boundary prediction decides where tokens go at inference, and merging is constrained so it never crosses a predicted wall. We evaluate instance separation, not mIoU.

Three token-efficiency methods supply mechanisms but also constrain the design:

  • Adaptive Patch Sizes (APT) assigns small patches to high-entropy regions. It removes about 30% of tokens on COCO and ADE20K without loss. However, a wall between two spectrally identical fields has low entropy and would be coarsened.
  • SG-Former reallocates tokens by learned salience and beats Swin-B by +3.0 mIoU on ADE20K. Its salience tracks objects, though, not the interfaces between them.
  • LookupViT lets a small compressed token set and a large high-resolution set exchange information through cross-attention, at cost proportional to their product rather than the square. Its authors say it was not extended to dense prediction because 25 tokens lose localization.

We reuse LookupViT's cross-attention pattern but change both streams. The compressed stream becomes a coarse spatial grid rather than 25 global tokens. The high-resolution stream is restricted to contact zones rather than the whole image.

PatchDCT supplies the routing idea. It classifies 8×8 patches as foreground, background, or mixed, and refines only the mixed ones, gaining +7.0 Boundary AP over Mask R-CNN on Cityscapes. It does this as a head on a detector, not inside the backbone's attention. It also reports holes when patches are misclassified, which is the failure mode our split rule must guard against.

The three-class formulation and the watershed decoding come from earlier work: CNN-based watershed preprocessing for 3D microscopy, Fields of The World (FTW), and the core-plus-boundary fragment models in PENGWIN 2024. All of them use convolutional networks with fixed receptive fields.

Interactive Dual-Branch Transformer (IDBT) shows that letting boundary and semantic features talk to each other sharpens parcel delineation. It does so with two full parallel backbones. BPT argues this layout causes cross-stream confusion and doubles memory. Our single stream with two token resolutions is a direct test of whether that interaction can be had without a second backbone.

Research Program

The model runs in two stages.

Coarse stage. The image is cut into large patches of side $P_c$, giving $N_c = HW/P_c^2$ tokens. This number is small enough for full global attention. A head on these tokens predicts a low-resolution interior/boundary/background map and a scalar contact score per coarse patch. The contact score is trained to fire where the ground-truth boundary separates two distinct instances, as opposed to an object–background edge.

Fine stage. Patches whose contact score exceeds a threshold are split into fine patches of side $P_f$ in quadtree fashion, using a budget-controlled top-k. Fine tokens attend to each other in local windows and read from all coarse tokens by cross-attention. Coarse tokens are updated in turn, as in LookupViT.

The per-layer cost is

$$C \approx N_c^2 + \rho\, r^2 N_c \cdot N_c + \rho\, r^2 N_c \cdot w^2,$$

where the terms are:

  • $\rho$ is the fraction of coarse patches that are split.
  • $r = P_c/P_f$ is the refinement factor, so $\rho r^2 N_c$ is the number of fine tokens.
  • $w^2$ is the local window size.

The first term is global coarse attention, the second is fine-to-coarse cross-attention, and the third is local fine attention. We should be honest about what this buys. Splitting cuts the cost of covering the image at fine resolution roughly by the factor $\rho$, which depends on instance density, not on image size. The cost still grows with image area. On sparse field scenes $\rho$ may be well under a third. On densely packed cells it may approach one, and the method should then degrade gracefully to uniform fine tokenization. Reporting $\rho$ for every dataset is part of the result.

Topology constraint. Any coarse-patch merging used in interiors and background is masked so that two patches cannot merge if the coarse boundary probability between them exceeds a threshold.

Training the split decision. The split is not differentiable. We train it with scheduled teacher forcing. Early in training, regions are split using ground-truth contact zones dilated by a margin. The model is then annealed toward its own predictions, while a small random fraction of extra regions is still split so that coarse-stage misses can be recovered.

Decoding. Decoding is the standard marker-controlled watershed on the fused full-resolution three-class map, upsampled from fine tokens where present and from coarse tokens elsewhere.

Loss. On top of per-pixel cross-entropy with boundary reweighting, we add a merge-aware penalty on ground-truth contact pixels. Where two instances touch, the boundary probability must exceed the interior probability along the entire shared edge. We implement this as a soft minimum along each contact segment, so that the weakest pixel in the wall, not the average pixel, carries the gradient. This targets the leakage failure documented in CNNs Fusion for Building Detection. It is our cheap, differentiable stand-in for the structured boundary verification that Ceb performs with CPU graph search at roughly 4.8 s per image.

Baselines

Naive reference. The do-nothing reference is the FTW convolutional U-Net with an EfficientNet-b3 encoder, trained on the same three-class targets and decoded with the same watershed. The FTW paper reports 0.83 pixel IoU for this model on France and South Africa. That figure measures pixel overlap, not separation. No object-level or merge-rate number was found on Lacuna for FTW, so we will compute these ourselves for every model.

This baseline is a serious competitor, not a straw man. A convolutional network at full resolution already costs time linear in pixel count, has no quadratic problem to solve, and may separate fields perfectly well. We will also run a wider U-Net scaled up to our model's measured FLOPs. Beating it means a statistically reliable reduction in merge rate at equal FLOPs and equal training epochs, not just higher pixel IoU.

Strongest existing interaction method. The strongest published method on parcel delineation in the file is IDBT. It reports 83.7% IoU and 51.3% boundary F1 on AI4Boundaries. We will retrain it on our splits with its published targets, decoded with our watershed. On AI4Boundaries we will also compare against its reported numbers. Beating it means matching its IoU and exceeding its boundary F1 and object-level F1 with fewer FLOPs and less peak memory.

Strongest token-efficient method. This is BPT, run as a three-class model with its boundary module kept as an output head so that it can produce instances.

Allocation ablations. These isolate the key ingredient. We keep our architecture and token budget exactly fixed and change only what decides which regions are split:

  • uniform fine tokens everywhere (the compute ceiling),
  • random splits at the same $\rho$,
  • APT-style entropy splits,
  • SG-Former-style learned salience splits,
  • our contact-score splits with and without the no-merge-across-walls mask and the soft-minimum loss.

All models share pretraining initialization where architectures allow. Each gets the same hyperparameter search budget (equal numbers of trials) and three seeds.

Why not just…?

Why not just use a full-resolution U-Net and skip attention? This is the real threat. Pixel IoU of 0.83 on FTW suggests convolutional networks already do well. Our answer is empirical rather than argued. If global context matters, the advantage should appear specifically on contact edges with low local contrast. We will stratify every contact edge by the intensity difference across it and report merge rate per stratum. If the compute-matched U-Net equals us in the low-contrast strata, then long-range attention adds nothing for this task and we will report that.

Why not just use entropy-based adaptive patches? APT's heuristic is designed around visual busyness. The concern is that same-type touching objects present nearly uniform intensity across their interface. The entropy-split ablation at identical $\rho$ tests this directly. We predict it matches us on high-contrast boundaries and loses on low-contrast ones. If it does not lose, the learned contact score is unnecessary, and we would adopt the simpler heuristic.

Why not just use windowed attention, as in Swin? Windows make attention linear but give every region, interior or contact zone, the same resolution. Windows also limit how far context travels per layer. SG-Former's +3.0 mIoU over Swin-B on ADE20K suggests adaptive allocation helps, though that result is on semantic segmentation. Our uniform-fine-token control with windowed attention plays this role. If it matches us at equal FLOPs, the allocation idea fails.

Why not just refine boundaries after the fact? Boundary Patch Refinement (Look Closer To Segment Better) adds about 211 ms per image and refines crops around an existing mask. It cannot create a seed that the base model never produced, so a merged pair stays merged. We will apply it to the U-Net baseline and count how many merges it actually fixes. Our expectation is few, since refinement acts locally on an already merged mask.

Proposed Experiments

Main experiment. The main experiment is on FTW, using the multi-temporal Sentinel-2 RGB+NIR chips across all 24 countries. There, 10 m pixels make shared field borders one or two pixels wide, so leakage is common. We report:

  • pixel IoU, for comparability with the 0.83 baseline,
  • object-level F1 at IoU 0.5,
  • merge rate and split rate,
  • boundary F1,
  • FLOPs, peak memory, and measured latency on the same GPU.

Generalization. AI4Boundaries tests whether the method transfers to 1 m imagery and allows direct comparison to IDBT's 83.7% IoU and 51.3% boundary F1. Its cross-region transfer setting addresses the generalization gap IDBT reported.

Dense packing. TissueNet tests the dense regime where $\rho$ approaches one. We compare against Ceb's pipeline using AP and wall-clock time. Ceb reports a 6.9% AP improvement with a Res2Net backbone; no absolute AP was found on Lacuna, so we will rerun it.

Scaling with resolution. We train at one resolution and evaluate FTW and Inria-style aerial tiles at increasing input sizes, plotting merge rate against FLOPs. The method succeeds if its curve lies below every baseline's.

Decisive checks. There are three, beyond the low-contrast stratification already described in "Why not just…?":

  • Allocation at fixed budget. Contact-guided splitting must beat random and entropy splitting at identical $\rho$. Otherwise the gain comes from the architecture, not the allocation.
  • Recall of contact zones. We measure what fraction of true contact zones the coarse stage misses, and how many of those misses become merges. This bounds the cost of a hard split decision and tests whether the random extra splits recover them.
  • Single stream versus dual branch. Our single-stream model must reach IDBT's boundary F1 with less memory. This settles the disagreement between IDBT and BPT about whether separate boundary and semantic backbones are needed.