Geometrically Constrained and Token-Based Probabilistic Spatial Transformers

Johann Schmidt, Sebastian StoberarXiv 2025 · DOI

Vision Transformers (ViTs) have revolutionized image classification, yet they remain sensitive to spatial variations in fine-grained tasks. This paper introduces a Token-Based Probabilistic Spatial Transformer that stabilizes Spatial Transformer Networks (STNs) by decomposing complex affine transformations into constrained geometric components. By leveraging visual tokens and probabilistic sampling, the proposed method achieves state-of-the-art robustness in identifying moth species under extreme distortions, significantly outperforming traditional STN architectures.

The Challenge of Fine-Grained Classification

Fine-grained visual classification (FGVC) involves distinguishing between highly similar categories, such as insect species or aircraft models. In these scenarios, minute morphological details are critical. However, real-world data—such as biodiversity monitoring images—often features objects at random orientations, scales, and perspectives.

While standard models rely on heavy data augmentation to learn invariance, this approach places the entire computational burden on the classifier. Spatial Transformer Networks (STNs) were designed to "canonicalize" images—automatically straightening and aligning them—before classification. Unfortunately, traditional STNs are notoriously fragile, prone to training instability, and often collapse when faced with noisy backgrounds.

Methodology: Stability Through Decomposition

The authors propose several innovations to integrate STNs effectively with modern Vision Transformers. The core of their approach is the Token-based Spatial Transformer (TST), which reuses the visual tokens generated by the ViT’s own tokenizer, making the architecture backbone-agnostic and efficient.

Detailed architecture of the Token-based Spatial Transformer, showing the localization encoder and decomposed transformation heads.

Key technical pillars include:

  1. Component-wise Decomposition: Instead of predicting a single complex affine matrix, the model uses distinct heads for Rotation, Scaling, and Shearing. This simplifies the optimization landscape and allows for explicit geometric constraints (e.g., preventing excessive zooming).
  2. Probabilistic Regression: The model predicts a Gaussian distribution (mean and variance) for each transformation component. By sampling from these distributions during training and inference, the model effectively marginalizes spatial uncertainty, shielding the downstream classifier from noise.
  3. Geometric Alignment Loss: A novel loss function uses ground-truth augmentation parameters to guide the STN. For instance, if an image was rotated by 45° during augmentation, the alignment loss penalizes the STN if it fails to attempt a corrective counter-rotation.

Experimental Results

The researchers evaluated their method on specialized fine-grained benchmarks: EU-Moths and ECU-Moths. To test robustness, they created challenging variants of these datasets featuring random rotations, scaling, and perspective shearing.

Visual comparison of distorted input images (left) and the canonicalized outputs produced by the proposed model (right).

As shown above, the model successfully "undoes" complex distortions, aligning the moths into a standard pose that highlights distinguishing features. On the heavily distorted "ECU-Moth Sheared+Roto-scaled" test set, the vanilla ViT baseline accuracy dropped to 61.7%. The proposed method maintained 71.1%—a significant 9.4 percentage point improvement.

Conclusion

By breaking down the "black box" of affine transformations into interpretable, probabilistic components, this work provides a robust framework for spatial normalization in Vision Transformers. While currently limited to 2D planar transformations and requiring augmentation parameters for optimal training, the method sets a new standard for robustness in fine-grained visual classification tasks.

Summary updated

BibTeX
@misc{schmidt2025geometrically,
  author = {Johann Schmidt and Sebastian Stober},
  title = {{Geometrically Constrained and Token-Based Probabilistic Spatial Transformers}},
  year = {2025},
  eprint = {2509.11218},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.11218},
}
Figure