Where Do the Attention Windows Look?

In deformable cross-attention, each attention window of one image does not have to look at the same place in the other image: a small network predicts an offset for every token, and the window is resampled there before attention. This page runs a 2D version of TransMorph-DCA, trained for this page, on brain MRI. Misalign the moving image, then compare where a block’s windows move (cyan) with the deformation the network finally predicts (amber), and see what happens when the offsets are switched off.

Loading…
Image pair
Moving
Fixed
Misalign the moving image
What to show Block
Attention head
Arrows
Arrow length
Fixed image with the block’s attention windows. Hover to pick a window.
Moving, misaligned
Registered
Offsets set to zero

Left: the hovered window (white outline) and, for each of its tokens, two arrows. Cyan: where that token’s query is sampled in the moving image (its learned offset). Amber: where the final deformation says the token corresponds. Second panel: the same window (dashed) and its deformed footprint in the moving image: the cyan outline and dots are where its queries are sampled, the amber outline is where the deformation maps the window. Fusion panels: fixed in green, moving in magenta.

Offsets vs deformation, correlation
–
Offset length / deformation length
–
Dice gained by the offsets
–
Deformation change without offsets
–

Statistics for this pair, block and head, over brain tokens. Correlation pools both vector components.

What you are looking at

A Swin-style registration Transformer compares the two images inside fixed windows, so a structure that has moved outside its window cannot be matched there. Deformable cross-attention (TransMorph-DCA) keeps the window shape but lets every token of one image sample its query from an offset position in the other image; the offsets come from a small convolutional network that sees both feature maps. The two image streams do this symmetrically; this page shows the stream whose queries are sampled from the moving image.

Offsets and deformation share a convention: a fixed-image token at x should look at x + u(x) in the moving image, where u is the predicted displacement. If the windows have learned to follow the anatomy, the cyan arrows point the same way as the amber ones.

What we found when testing this model

Before building this page we tested, against the true deformation, whether the offsets really track it. They do when the images start misaligned and the network has to search: in the second block of stages 1 and 2 (shown here) the offsets correlate with the true displacement (r ≈ 0.7–0.8) but cover only about 40% of it (regression slope), and switching them off costs about 0.07 Dice. The other blocks show little tracking, and the attention weights themselves did not point at the correct correspondence. On pre-aligned images, offsets matter far less. Expect this page to follow the same pattern.

The network is a small 2D model trained for this page (IXI slices, MSE + diffusion, random affine misalignment up to ±8 px and ±5°), not the 3D model from the paper; windows are sampled so that zero offsets reproduce the regular windows exactly. Brain slices: IXI (CC BY-SA 3.0). The model (31 MB) runs locally with ONNX Runtime Web.

Continue the story All demos

This demo is step 3 of 6: Which network, and where does it look?

Previous · step 3, Learn MIR model arena: one interface, many registration networks Which network, and where does it look? Next · step 4, Regularize Spatially varying regularization for image registration How smooth should the deformation be?
  1. 1Represent
  2. 2Compare
  3. 3Learn
  4. 4Regularize
  5. 5Trust
  6. 6Measure