Long Short-Term Memory Spatial Transformer Network

Shiyang Feng, Tianyue Chen, Hao SunarXiv 2019 · DOI

Abstract

Spatial transformer networks (STNs) have traditionally been used in a feedforward manner to enable models to transform data spatially. In this paper, we propose a novel architecture that combines an STN with a Long Short-Term Memory (LSTM) network to classify digit sequences formed by MNIST elements. This LSTM-STN model leverages a top-down attention mechanism provided by the LSTM layer, allowing the STN to isolate and transform individual elements sequentially. This approach avoids the geometric distortion often caused when attempting to transform an entire sequence at once. Our results demonstrate a significant improvement in accuracy, achieving a single-digit error rate of 1.6% compared to 2.2% for a standard STN-CNN model.

Introduction

Spatial Transformer Networks (STNs) are powerful modules that allow neural networks to actively perform spatial transformations—such as rotation, scaling, or cropping—on input data to simplify subsequent classification tasks. However, standard STNs are purely feedforward and lack a "top-down" attention mechanism.

When processing images containing multiple objects, such as a sequence of digits, a standard STN often attempts to transform the entire scene simultaneously. This frequently results in significant geometric distortion or "boundary effects" that hinder the performance of the classifier. To address this, we propose integrating an LSTM as a controller for the STN, enabling the network to "focus" on one element at a time and process the image sequentially.

Methodology

The proposed LSTM-STN model integrates three primary components to achieve sequential spatial transformation:

  1. Feature Extraction: The input image ($U$) is processed by a convolutional layer to generate a high-level feature map.
  2. LSTM Localization Network: Instead of a traditional feedforward localization network, an LSTM acts as the controller. It receives the feature map and its own internal state to determine the next region of interest.
  3. Spatial Transformation and Down-sampling: A Feed-Forward Network (FFN) maps the LSTM’s hidden state ($h_t$) to affine transformation parameters ($A_\theta$). The STN then extracts and transforms the specified region. A down-sampling strategy ensures the resolution of these "glimpses" is consistent for the final classifier.
  4. Classification: Each transformed glimpse ($V$) is passed to a standard Convolutional Neural Network (CNN) for final digit classification.
The LSTM-STN architecture, showing the localization network using an LSTM to generate transformation parameters sequentially.

Experimental Setup

The model was evaluated using a custom dataset derived from MNIST. Each 100x100 pixel canvas contains four random 28x28 MNIST digits placed at random positions and rotation angles. To increase difficulty, 10 "noise" blocks (6x6 pixels of handwriting-like noise) were added to each image. The dataset consists of 60,000 training samples, 20,000 validation samples, and 2,000 test samples.

Key Insights and Results

The core innovation of the LSTM-STN is its ability to utilize sequential saliency. By tracking its state through the LSTM, the model can systematically move its attention across the canvas, isolating salient elements one by one. This prevents the "warping" effect seen in standard STNs because the model only needs to perform simple transformations on individual digits rather than complex global warps.

Visual examples of the LSTM-STN isolating and normalizing individual digits from noisy, cluttered sequences.

The LSTM-STN significantly outperformed both standard CNNs and feedforward STN models. As shown in the table below, the model achieved its best performance with a down-sampling factor of $d=2$.

Model Down-sampling (d) Error Rate (%)
LSTM-STN-CNN 2 1.6
FFN-STN-CNN 2 2.2
Standard CNN N/A 2.7

Conclusion

By integrating LSTM units into the STN framework, we have developed a model capable of sophisticated top-down attention. This allows for the sequential isolation and transformation of individual objects within a cluttered scene, significantly reducing distortion and improving classification accuracy on complex sequences. Future work will explore the model's performance on overlapping objects and its robustness in even higher-interference environments.

Summary updated

BibTeX
@misc{feng2019long,
  author = {Shiyang Feng and Tianyue Chen and Hao Sun},
  title = {{Long Short-Term Memory Spatial Transformer Network}},
  year = {2019},
  eprint = {1901.02273},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1901.02273},
}
Figure