---
title: 'RelayFormer: Unified Visual Manipulation Localization'
url: https://www.emergentmind.com/topics/relayformer
type: topic
---

# RelayFormer: Unified Visual Manipulation Localization

Searching arXiv for the exact papers and closely related context.
arXiv_search query: "RelayFormer visual manipulation localization 2508.09459"
RelayFormer most directly denotes a unified and modular architecture for visual manipulation localization across images and videos, introduced in “RelayFormer: A Unified Local-Global Attention Framework for Scalable Image and Video Manipulation Localization” [2508.09459]. In that work, the task is dense mask prediction of tampered regions in visual content, with a particular emphasis on subtle, sparse, high-frequency, and semantically simple forensic cues. The name should not be conflated with “Learned Relay Representations for Forward-Thinking Discrete Diffusion Models,” whose method is called “Relay,” not “RelayFormer,” and which addresses masked diffusion models for discrete sequence generation rather than visual forensics [2605.22967].

## 1. Nomenclature and problem formulation

RelayFormer is defined for **visual manipulation localization (VML)**: given an image or a video, predict a dense mask that localizes tampered regions. In the image setting, the target manipulations include splicing, copy-move, retouching, and inpainting. In the video setting, the paper focuses mainly on video inpainting localization, where manipulated regions must be localized frame by frame while also exploiting temporal consistency [2508.09459].

The motivating observation is that VML differs from conventional semantic segmentation. The discriminative evidence often resides in boundary inconsistencies, local texture disruptions, or forensic traces rather than in rich object-level semantics. Because these cues are fine-grained, aggressive resizing can destroy them. RelayFormer is therefore organized around three stated objectives: preserving fine local forensic evidence, supporting arbitrary input resolution and video length, scaling better than dense global attention, and remaining compatible with pretrained Transformer backbones.

A central claim of the work is that earlier VML systems are often modality-specific, fixed-resolution, or computationally burdened by dense global self-attention. RelayFormer addresses these issues through a single architecture that uses local processing units, relay-mediated global communication, and a lightweight query-based decoder. This suggests that the framework is intended less as a new standalone backbone than as a reusable VML adaptation layer for pretrained Transformer systems.

## 2. Local units and the relay-token abstraction

RelayFormer partitions an input frame of resolution \(H \times W\) into overlapping local units \(U\) of size \(P \times P\), with padding used when necessary so the whole image is covered. The number of units per frame is

$$
m = \lceil H/P \rceil \times \lceil W/P \rceil .
$$

For video, the same construction is extended to spatial-temporal units. The implementation details reported in the paper use image unit size \(512\times512\), video unit size \(224\times224\), and clip length \(4\) [2508.09459].

This unit-based construction is the first scalability mechanism. Rather than resizing every sample to a common large resolution or applying full-image attention, the model processes modular units at native detail. The paper attributes three benefits to this choice: resolution agnosticism, less redundant computation than padding all inputs to a fixed maximum size, and preservation of local information.

Within each unit \(U_i\), RelayFormer maintains patch-token features

$$
X_i \in \mathbb{R}^{N \times d},
$$

and appends a small set of learnable **Global Relay Tokens (GRTs)**

$$
T_i \in \mathbb{R}^{n \times d},
$$

where \(n\) is the number of GRTs per unit. The role of the GRTs is not to replace local patch features but to absorb unit-level manipulation cues and carry them into a global communication stage. The term “relay” is literal: information is transmitted across units indirectly through these compact token sets rather than through dense all-token attention.

The same abstraction is used for both images and videos. For images, units are spatial patches; for videos, units extend naturally over space and time. The paper explicitly states that GLoRA “naturally extends to temporal modeling,” which is the basis for the architecture’s cross-modal reuse [2508.09459].

## 3. Global-Local Relay Attention (GLoRA)

The core mechanism of RelayFormer is **Global-Local Relay Attention (GLoRA)**, which consists of two stages: **Local-aware Attention** and **Relay-based Global Attention**. GLoRA is inserted after standard Transformer blocks and is designed to reuse backbone weights while introducing lightweight LoRA-based adaptation to switch between local and global modes [2508.09459].

In the local stage, self-attention is applied within each unit over the concatenated sequence of relay tokens and patch tokens:

$$
[T_i^{(l)}, X_i^{(l)}] = \mathrm{SelfAttn}_{\text{local}}\left([T_i^{(l-1)}; X_i^{(l-1)}]\right),
$$

where \(l=1,\dots,L\) is the layer index and \([\cdot;\cdot]\) denotes concatenation. This means that patch tokens interact with other patch tokens in the same unit, while GRTs attend to local patch content and absorb local forensic evidence.

After local aggregation, all GRTs from all units are concatenated into

$$
T_{\text{flat}} = \mathrm{Concat}_{i=1}^{M} T_i \in \mathbb{R}^{(M\cdot n)\times d},
$$

and global communication is performed only over this relay-token sequence. To encode token identity together with spatial and temporal positions, the framework applies **4D Rotary Positional Embedding**:

$$
T_{\text{updated}} = \mathrm{SelfAttn}_{\text{global}}\left(\mathrm{RoPE}_{4D}(T_{\text{flat}})\right).
$$

The updated relay tokens are then redistributed back to their corresponding units for the next layer, where subsequent local attention diffuses the injected global context back into patch tokens. The resulting communication pattern is therefore: local unit \(\rightarrow\) local GRTs, global mixing among all GRTs, updated GRTs returned to units, and next-layer local attention spreads global context back into local tokens.

The paper gives the overall time complexity of GLoRA as

$$
\mathcal{O}\big(M\cdot (N+n)^2 + (M\cdot n)^2\big),
$$

with \(M\) denoting the number of units, \(N\) the number of patch tokens per unit, and \(n\) the number of GRTs per unit. The first term corresponds to local attention within units; the second corresponds to global attention among relay tokens. Because \(n \ll N\), the global communication channel is much smaller than the full patch-token sequence. In practice, the paper reports that \(n=2\) is sufficient to achieve the best accuracy in ablations [2508.09459].

The paper does not provide the internal multi-head attention equations for \(\mathrm{SelfAttn}_{\text{local}}\) or \(\mathrm{SelfAttn}_{\text{global}}\), nor the explicit LoRA parameterization equations inside GLoRA. It also does not formalize the token redistribution rule after \(T_{\text{updated}}\). Those omissions are implementation-relevant because they bound the level of exact reproducibility available from the main text alone.

## 4. Backbone adaptation and mask decoding

RelayFormer is not presented as a new backbone trained from scratch. It is a modular adapter framework for pretrained Transformer-based backbones, demonstrated with **ViT** and **SegFormer**, yielding **Relay-ViT** and **Relay-Seg** respectively. The paper states that GLoRA is inserted after standard Transformer blocks and uses two sets of LoRA adapters to enable switching between local and global modes with minimal parameter overhead. In the appendix, it further states that all Transformer blocks in the backbone are replaced with GLoRA modules [2508.09459].

The reported additional parameter counts are small relative to the base models: Relay-ViT is \(89.55 + 2.36\)M parameters, and Relay-Seg is \(45.90 + 2.39\)M. The intended effect is to preserve the original attention structure and pretrained weights while introducing lightweight task-specific adaptation. This is particularly relevant because VML datasets are much smaller than large-scale pretraining corpora, so preserving pretrained representations is beneficial.

For mask prediction, RelayFormer uses a lightweight query-based Transformer decoder inspired by Mask2Former-style decoding. Given the reassembled feature map

$$
F \in \mathbb{R}^{H_f \times W_f \times d},
$$

it is projected to a lower-dimensional representation

$$
\tilde{F} \in \mathbb{R}^{H_f \times W_f \times d_{\text{low}}}.
$$

A fixed set of learnable queries is then used:

$$
Q \in \mathbb{R}^{M_f \times d}.
$$

At decoder layer \(k\), the queries are updated by cross-attention and then self-attention with rotary positional encoding:

$$
Q' = \mathrm{CrossAttn}(Q^{(k-1)}, \tilde{F}),
$$

$$
Q^{(k)} = \mathrm{SelfAttn}(\mathrm{RoPE}(Q')).
$$

The appendix specifies decoder depth \(K=3\) and number of learnable queries \(=8\). A gating MLP assigns weights to each query to modulate its contribution to the final output. The paper does not provide the exact final mask-generation equation or the explicit gating MLP formula, and it does not describe Hungarian matching, bipartite assignment, or DETR-style set loss.

For video, RelayFormer adopts **one-shot inference**: a shared set of queries from the first frame is used to decode masks for the entire video clip via dot-product attention. The stated motivation is that VML has relatively low semantic complexity and fairly consistent feature structure across adjacent frames. The paper reports that this significantly reduces decoder GFLOPs while maintaining accuracy.

## 5. Optimization, supervision, and evaluation protocol

RelayFormer is trained with a combination of **binary cross-entropy** and **edge loss**:

$$
\mathcal{L} = \mathcal{L}_{\text{BCE}}(P, M) + \lambda \cdot \mathcal{L}_{\text{Edge}}(P \odot M_e, M \odot M_e),
$$

where \(P\) is the predicted mask, \(M\) is the ground-truth mask, and \(M_e\) is the edge mask. The edge term is itself BCE over the edge region:

$$
\mathcal{L}_{\text{Edge}}(P \odot M_e, M \odot M_e) = \mathcal{L}_{\text{BCE}}(P \odot M_e, M \odot M_e).
$$

The appendix sets \(\lambda = 20\) [2508.09459].

For images, the paper follows the standard cross-dataset protocol: training on **CASIA v2.0** and testing on **Coverage, Columbia, NIST16, CASIA v1.0, IMD2020**. For videos, training data is created from **DAVIS2016** using two video inpainting models, **OP** and **VI**, and testing is performed cross-dataset on **MOSE** validation clips edited by **E2FGVI**, **FuseFormer**, and **STTN**. The evaluation metrics are **F1** at threshold \(0.5\) and **IoU**.

Using IMDLBench, the optimization configuration is reported as follows: **AdamW**, **200** epochs, base learning rate \(1\times10^{-4}\), cosine decay, weight decay \(0.05\), warmup during the first 2 epochs, minimum learning rate \(5\times10^{-7}\), AMP mixed precision, **4 RTX 3090 GPUs**, per-GPU batch size 2, gradient accumulation 8 steps, and effective batch size 64. A stabilization step is used in the first epoch: pretrained parameters are frozen and only newly introduced parameters are trained.

The appendix states that augmentation follows IML-ViT and includes rescaling, horizontal flipping, Gaussian blur, random rotation, and synthetic copy-move and inpainting of rectangular regions within the same image. No test-time augmentation or post-processing is used.

The paper also notes a tension between the conceptual emphasis on avoiding interpolation and an implementation detail: for images larger than \(1024\times1024\), the longer side is resized to 1024 while preserving aspect ratio, then zero-padded to \(1024\times1024\). This does not negate the unit-based design, but it constrains the literal extent to which the implementation is entirely interpolation-free.

## 6. Empirical behavior, scaling properties, and relation to adjacent “relay” work

On image manipulation localization under the MVSS protocol, RelayFormer reports the best **average F1 = 0.543**, achieved by both **Relay-ViT** and **Relay-Seg**. Per-dataset highlights reported in the paper include Relay-Seg obtaining the best result on **Coverage** with **0.569**, Relay-ViT obtaining the best on **NIST16** with **0.299**, and Relay-Seg obtaining the best on **IMD2020** with **0.357**. On video manipulation localization on MOSE, **Relay-Seg** leads on **E2FGVI** with **0.561 / 0.698** (IoU/F1), while for **STTN**, Relay-ViT reaches **0.549 / 0.684** and Relay-Seg reaches **0.534 / 0.674** [2508.09459].

The ablations attribute the gains to both relay tokens and decoder design. The reported image ablation values are: no GRTs plus MLP decoder, average **0.454**; \(n=1\) plus MLP decoder, **0.521**; \(n=1\) plus proposed decoder, **0.532**; \(n=2\) plus proposed decoder, **0.543**; \(n=3\) plus proposed decoder, **0.524**. For the spatial and temporal branches on MOSE, the reported F1 values are **0.6124** with no spatial and no temporal branch, **0.6745** with spatial only, and **0.6877** with spatial plus temporal. Appendix results on layer replacement strategy show **73.24** for sparse insertion, **74.21** for latter-half insertion, and **75.50** for full replacement. The paper also reports an interpolation effect on IMD2020: **F1 = 0.453** at full resolution with no resize versus **F1 = 0.350** when resized to \(1024\times1024\).

The system-level complexity numbers are also reported explicitly. For **Relay-ViT**, GFLOPs are **119.18** at \(m=1\), **238.20** at \(m=2\), and **476.12** at \(m=4\). For **Relay-Seg**, they are **52.71**, **105.41**, and **210.83** respectively. The paper characterizes this as approximately linear scaling in the number of units at the system level and emphasizes that units can be grouped by count and processed with strong intra-group parallelism.

Several practical limitations are either stated or can be inferred from the reported setup. The paper is relatively light on explicit failure-case discussion. A plausible implication is that performance remains sensitive to the loss of high-frequency evidence, since resizing degrades IMD2020 performance substantially. Another plausible implication is that extreme long-range temporal behavior is not fully characterized, because the reported video clip length is \(4\). In addition, while GLoRA is more scalable than full attention, its global relay attention still contains a quadratic term in the total number of relay tokens, \((M\cdot n)^2\), so the improvement is one of compression rather than unbounded scalability.

The “relay” terminology in RelayFormer should also be distinguished from the unrelated use of “Relay” in discrete diffusion modeling. “Learned Relay Representations for Forward-Thinking Discrete Diffusion Models” introduces a differentiable per-token channel that propagates latent state across denoising rounds in masked diffusion models, with recurrence over \(s_k=(x_{t_k}, h_k)\) and training via truncated BPTT [2605.22967]. RelayFormer, by contrast, uses relay tokens to mediate sparse global communication across spatial-temporal units for VML. The shared vocabulary reflects a common intuition of passing intermediate information forward, but the problem domains, architectural objects, and training dynamics are distinct.

Source: https://www.emergentmind.com/topics/relayformer