Papers
Topics
Authors
Recent
Search
2000 character limit reached

Shifted Patch Tokenization (SPT) in Vision Transformers

Updated 15 March 2026
  • Shifted Patch Tokenization (SPT) is an embedding technique that aggregates overlapping spatial information from shifted image views to enhance locality in Vision Transformers.
  • It increases the effective receptive field without altering the self-attention mechanism, making it effective for low-level vision tasks and small-data regimes.
  • Empirical results show SPT boosts classification accuracy by up to 3.60% on Tiny-ImageNet and improves restoration metrics in tasks like denoising and inpainting.

Shifted Patch Tokenization (SPT) is an embedding technique designed to augment the locality bias and receptive field of patch-based Transformer architectures, especially Vision Transformers (ViT), by aggregating overlapping spatial information from shifted versions of the input. SPT addresses inherent deficiencies of standard non-overlapping patch tokenization—namely, the limited context captured by each token and the resulting inductive bias mismatch for low-level vision or small-data regimes. The approach enhances both model data efficiency and downstream task performance by directly integrating cross-patch spatial structures at the embedding stage, without modifying the self-attention mechanism or overall Transformer architecture (Lee et al., 2021, Verma et al., 2023).

1. Motivation and Underlying Principles

Standard ViT tokenization slices an image I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C} into non-overlapping PƗPP \times P patches, each of which is flattened and linearly projected. This arrangement provides each token with information from a strictly local PƗPP \times P region without access to spatially adjacent pixels, leading to the following limitations:

  • Limited local receptive field per token and no shared pixels across tokens, resulting in weak inductive locality bias.
  • The burden of learning local structures is transferred entirely to the Transformer’s self-attention, which is inefficient for small datasets or low-level vision tasks.

SPT addresses these deficits by introducing redundancy and spatial overlap at the tokenization step. By generating and concatenating several shifted versions of the input image (each displaced by a pre-defined offset), SPT allows each patch token to aggregate information from overlapping spatial neighborhoods. This approach raises the effective receptive field of each token and breaks the rigid partitioning boundaries present in vanilla ViT, enabling local continuity in the learned representations (Lee et al., 2021, Verma et al., 2023).

2. Mathematical Formulation

Let I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C} denote the input. Define a set of NsN_s shifts with offsets {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}, such as diagonal or cardinal directions, with shift size typically P/2P/2. For each offset Ī“\delta:

I(Ī“)=CropPad(Shift(I, Γ))I^{(\delta)} = \mathrm{CropPad}\bigl(\mathrm{Shift}(I,\,\delta)\bigr)

All shifted images, along with the unshifted II, are concatenated channel-wise:

PƗPP \times P0

This augmented tensor is partitioned into non-overlapping PƗPP \times P1 patches, each flattened to a vector PƗPP \times P2. Each vector passes through LayerNorm and a learned projection PƗPP \times P3:

PƗPP \times P4

The set PƗPP \times P5 forms the token sequence fed into the Transformer encoder. This procedure generalizes to internal pooling/token-merging layers by reshaping token maps and reapplying SPT (Lee et al., 2021, Verma et al., 2023).

3. Implementation and Hyperparameters

Typical SPT settings, empirically validated in multiple studies, include:

  • Number of Shifts PƗPP \times P6: Four, in either diagonal or cardinal directions.
  • Shift Magnitude: PƗPP \times P7 (half the patch size).
  • Padding Mode: Zero-padding out-of-bounds pixels after shifting.
  • Channel-Concatenation Factor: PƗPP \times P8, e.g., factor of PƗPP \times P9 for four shifts.
  • Projection Dimension PƗPP \times P0: Matches the ViT hidden size, e.g., PƗPP \times P1, PƗPP \times P2.
  • Patch Size PƗPP \times P3: Depends on downstream task; PƗPP \times P4 for standard ViT, PƗPP \times P5 for small datasets.
  • Shift Operator: Either circular or zero-padding, depending on experiment.

The following table summarizes these core parameters:

Hyperparameter Typical Value Description
Number of shifts 4 Directions: Diagonal or Cardinal
Shift magnitude PƗPP \times P6 Pixels per shift
Channel Factor 5 PƗPP \times P7 for four shifts
Padding Zero Out-of-bounds handling

4. Algorithmic Steps and Pseudocode

The essential algorithm is as follows (Verma et al., 2023, Lee et al., 2021):

P/2P/21

This function generalizes to any PƗPP \times P8, patch size PƗPP \times P9, and embedding dimension I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}0.

5. Empirical Results and Ablations

SPT consistently delivers measurable improvements over baseline ViT across both low-level vision and small-scale classification datasets. Selected findings:

  • Tiny-ImageNet (64Ɨ64 grayscale), no discriminator (Verma et al., 2023):
    • Denoising: PSNR improves from I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}1 to I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}2; SSIM from I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}3 to I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}4; NMSE falls from I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}5 to I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}6.
    • Inpainting: PSNR improves from I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}7 to I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}8; SSIM from I∈RHƗWƗCI \in \mathbb{R}^{H \times W \times C}9 to NsN_s0; NMSE from NsN_s1 to NsN_s2.
    • With adversarial loss, PSNR is further improved by NsN_s3 (denoising) and NsN_s4 (inpainting) over ViT+GAN.
  • Classification on CIFAR-100 and Tiny-ImageNet (Lee et al., 2021):
    • CIFAR-100: Baseline ViT NsN_s5 top-1 NsN_s6 NsN_s7 with SPT (NsN_s8).
    • Tiny-ImageNet: Baseline ViT NsN_s9 top-1 {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}0 {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}1 with SPT ({Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}2).
    • SPT yields {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}3–{Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}4 on ImageNet.

A plausible implication is that SPT effectively mitigates data inefficiency and locality bias without incurring substantial computational overhead at scale.

6. Computational Complexity and System Integration

Each shifted view increases the input channel dimension, expanding the pre-projection embedding by a factor of {Γi}i=1Ns\{\delta_i\}_{i=1}^{N_s}5. This results in:

  • Memory/Compute Overhead:
    • Patch embedding layer’s input grows linearly with {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}6, i.e., for {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}7, a {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}8 increase in pre-projection dimensionality.
    • Wall-clock and FLOPs: Patch embedding’s increased cost remains a minor fraction compared to attention and feedforward layers (Verma et al., 2023, Lee et al., 2021).
    • Temporary memory for concatenated feature maps.
  • Integration:
    • SPT is a drop-in replacement for standard ViT’s patch embedding, requiring no changes to downstream positional encodings, self-attention, or head structure.
    • Identical application to internal pooling or merging layers in hierarchical transformers (e.g., Swin, PiT).

7. Use Cases, Benefits, and Practical Recommendations

SPT is empirically shown to be most beneficial in these settings:

  • Transformers trained from scratch on small or medium datasets, where locality bias compensates for the lack of pretraining data.
  • Low-level, pixel-based vision tasks (denoising, inpainting) requiring preservation of fine spatial structures.
  • As a minimal architectural tweak, SPT is easily adoptable in any ViT family or patch-based model without requiring custom self-attention or nonstandard pooling.

Because SPT only modifies tokenization and marginally increases patch embedding cost, and because it yields consistent accuracy gains of {Ī“i}i=1Ns\{\delta_i\}_{i=1}^{N_s}9–P/2P/20 (classification) and measurable gains in PSNR/SSIM (restoration), it is recommended wherever locality bias is desirable but architectural simplicity and computational efficiency are priorities (Lee et al., 2021, Verma et al., 2023).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Shifted Patch Tokenization (SPT).