S2 Transformer for Image Captioning

Pengpeng Zeng, Haonan Zhang, Jingkuan Song, Lianli Gao

Introduction

Image captioning requires models to bridge the gap between visual perception and natural language generation. While early models relied on region features extracted from pre-trained object detectors like Faster R-CNN, the field has recently pivoted toward grid features due to their computational efficiency and comprehensive image coverage. However, grid features face a significant challenge: when flattened into a 1D sequence for Transformer input, the inherent 2D spatial relationships are lost. Furthermore, standard Transformer architectures often neglect low-level visual semantics by only passing the final encoder layer's output to the decoder.

The $S^2$ Transformer (Spatial and Scale-aware Transformer) addresses these issues through two novel components: a clustering-based "pseudo-region" module to recover spatial structure and a multi-scale feature reinforcement strategy to integrate diverse semantic levels.

Comparison of visual features and high-level architectures. The proposed pseudo-region features (a-iii) and Scale-wise Reinforcement (SR) module (b-iii) provide significant performance improvements over vanilla Transformers.

Methodology

The $S^2$ Transformer enhances the standard Transformer architecture with two lightweight modules designed to improve spatial and scale awareness.

Spatial-aware Pseudo-supervised (SP) Module

To recover spatial information without the overhead of an external object detector, the SP module employs a learnable clustering mechanism. Inspired by NetVLAD, it groups grid features into $N$ "pseudo-regions" based on semantic similarity. This process allows the model to implicitly identify objects and structures within the image, creating a secondary feature set that preserves spatial context.

Scale-wise Reinforcement (SR) Module

Recognizing that different encoder layers capture information at varying scales—from low-level edges to high-level complex objects—the SR module aggregates features from all encoder layers. These features are processed through a Multi-Layer Perceptron (MLP) to determine their relative importance and are then integrated into the final representation via a weighted residual connection. This ensures the decoder has access to both fine-grained textures and high-level semantics.

Detailed architecture of the S2 Transformer, illustrating the integration of the Spatial-aware Pseudo-supervised (SP) and Scale-aware Reinforcement (SR) modules.

Experimental Setup

The model was evaluated on the MSCOCO dataset using the standard Karpathy split (113k training, 5k validation, and 5k test images). Performance was also measured on the MSCOCO Online Server leaderboard. Visual features were extracted using ResNet-101 and ResNext-101/152 backbones to ensure comparability with existing state-of-the-art methods.

Results and Analysis

The $S^2$ Transformer achieved state-of-the-art results on the MSCOCO benchmark, reaching a CIDEr score of 133.5 on the Karpathy test split. This outperforms established models such as the $M^2$ Transformer (131.2) and X-Transformer (132.8). On the competitive online leaderboard, the model achieved a CIDEr-D score of 132.6 using a ResNext152 backbone.

Key Insights

  • Efficiency: Despite its performance gains, the $S^2$ Transformer is remarkably parameter-efficient. It adds only approximately 1.07 million parameters to the baseline vanilla Transformer, whereas competing models like RSTNet add over 122 million.
  • Ablation Studies: The importance of both modules was confirmed through ablation testing. Removing the SP module resulted in a 2.0-point drop in CIDEr score, while removing the SR module led to a 1.8-point decrease.
  • Semantic Bridging: The SR module effectively bridges the "bottom-up" semantic gap, ensuring that the decoder retains access to raw visual details from early layers that are often lost in deeper representations.

Conclusion

The $S^2$ Transformer demonstrates that spatial awareness can be recovered from grid features through implicit clustering, and that multi-scale feature integration significantly boosts captioning quality. While the model sets new benchmarks, future work is needed to address potential adversarial vulnerabilities and to improve the interpretability of the learned pseudo-regions for real-world applications such as assistive technologies.

Summary updated

BibTeX
@inproceedings{zeng2022s,
  author = {Pengpeng Zeng and Haonan Zhang and Jingkuan Song and Lianli Gao},
  title = {{S2 Transformer for Image Captioning}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2022},
  doi = {10.24963/ijcai.2022/224},
}
Figure