Probabilistic Spatial Transformer Networks

Pola Schwöbel, Frederik Rahbæk Warburg, Martin Jørgensen, Kristoffer Hougaard Madsen, Søren HaubergUAI 2022

Abstract: Spatial Transformer Networks (STNs) estimate image transformations that can improve downstream tasks by 'zooming in' on relevant regions in an image. However, STNs are hard to train and sensitive to mis-predictions of transformations. To circumvent these limitations, we propose a probabilistic extension that estimates a stochastic transformation rather than a deterministic one. Marginalizing transformations allows us to consider each image at multiple poses, which makes the localization task easier and the training more robust. As an additional benefit, the stochastic transformations act as a localized, learned data augmentation that improves the downstream tasks. We show across standard imaging benchmarks and on a challenging real-world dataset that these two properties lead to improved classification performance, robustness and model calibration. We further demonstrate that the approach generalizes to non-visual domains by improving model performance on time-series data.

Introduction: The Brittleness of Deterministic Attention

Spatial Transformer Networks (STNs) were designed to allow neural networks to actively "look" at relevant parts of an image by learning to crop, rotate, and scale data dynamically. However, in practice, STNs are notoriously finicky. The core issue is their brittleness: an STN consists of a localizer (predicting transformation parameters $\theta$) and a classifier (acting on the transformed image).

Because the process is deterministic, the localizer must be correct immediately. If it predicts a crop that misses the object of interest, the classifier receives zero signal, gradients vanish, and the model fails to learn. This creates a "sharp" loss landscape with many local minima, often leading to a "failure to launch" where the localizer simply defaults to an identity transform.

Methods: A Stochastic Reformulation

To address these limitations, researchers from DTU and Oxford proposed Probabilistic Spatial Transformer Networks (P-STNs). They shift from a deterministic "best guess" transformation to a stochastic distribution of transformations, turning a brittle architecture into a robust, self-augmenting system.

The P-STN architecture: A localizer predicts distribution parameters (mean and precision), from which multiple transformation samples are drawn. These samples are processed by the classifier and marginalized to produce the final prediction.

The P-STN reformulates the network as a hierarchical Bayesian model:

  1. Stochastic Transformations: Instead of predicting a single $\theta$, the localizer predicts the parameters of a distribution—specifically a mean $\mu(I)$ and a precision $\lambda$.
  2. The Distribution: By modeling $\theta$ as a Gaussian conditioned on $\lambda$ (which follows a Gamma distribution), the marginalized transformation $\theta$ follows a Student’s t-distribution.
  3. Variational Inference: The model is trained end-to-end using the Evidence Lower Bound (ELBO). A KL-divergence term acts as a regularizer, preventing uncertainty from collapsing to zero.
  4. Monte Carlo Marginalization: At both training and test time, the model draws $S$ samples from the transformation distribution. The classifier processes all $S$ versions, and results are averaged. This effectively "smooths" the loss landscape because even if one sample misses the target, others likely won't.

Key Insights: Smoothing and Self-Augmentation

By sampling multiple transformations, the model "probes" the area around its current guess. This provides a much smoother gradient signal to the localizer, helping it escape local minima that would trap a standard STN.

Comparison of STN (top) and P-STN (bottom) on the Mapillary Traffic Sign Dataset. P-STN draws multiple samples (red boxes), resulting in a significantly smoother negative log-likelihood landscape that facilitates easier training and better localization.

Beyond robustness, P-STN introduces Learned, Per-Image Data Augmentation. Unlike global augmentation (like random flipping), P-STN learns an augmentation strategy specific to each image. If an image is ambiguous, the model naturally increases the variance of its samples to cover more possibilities. This uncertainty is informative; predicted variance correlates with localization difficulty, providing a signal for model interpretability.

Results and Performance

The authors evaluated P-STN across several challenging benchmarks:

  • Real-World Traffic Signs: On the Mapillary Traffic Sign Dataset (MTSD), P-STN achieved 92.2% accuracy, significantly outperforming the standard STN (90.6%) and a baseline CNN (76.0%).
  • Data Efficiency: On a tiny version of MNIST (30 images), P-STN reached 81.0% accuracy, while the standard STN performed worse than a basic CNN (69.3% vs 70.1%) due to training instability.
  • Model Calibration: P-STN reduced the Expected Calibration Error (ECE) from 0.116 to 0.027, meaning its confidence scores much more accurately reflect its true performance.
  • Generalization: The approach generalizes beyond pixels; it successfully learned to "warp" time-series data, improving mean accuracy across UCR datasets from 86.48% to 89.18%.

Limitations and Future Work

While robust, P-STN introduces computational overhead, as sampling $S$ transformations requires running the classifier $S$ times. Additionally, the model is sensitive to the weight of the KL-term in the ELBO, requiring careful hyperparameter tuning. Future work may explore more complex transformation families or apply this probabilistic framework to 3D data and video.

Summary updated

BibTeX
@inproceedings{schwobel2022probabilistic,
  author = {Pola Schwöbel and Frederik Rahbæk Warburg and Martin Jørgensen and Kristoffer Hougaard Madsen and Søren Hauberg},
  title = {{Probabilistic Spatial Transformer Networks}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2022},
  url = {https://openreview.net/forum?id=HFUxb_Uiqec},
}
Figure