Abstract
Spatial attention mechanisms are pivotal in modern computer vision, yet traditional position-wise approaches often produce unstable, irregular attention maps that hinder generalization. We present the Convolutional Rectangular Attention Module (CRAM), which replaces unconstrained pixel-wise maps with a stable, five-parameter rectangular support function. By enforcing a geometric prior, CRAM achieves better equivariance to image transformations and provides a highly interpretable "window" into the model's decision-making process. Evaluated on the Oxford-IIIT Pet dataset, CRAM demonstrates superior performance and stability compared to standard attention modules.
Addressing the Instability of Spatial Attention
In computer vision, spatial attention helps models focus on discriminative regions—such as a cat's face rather than the background. Most existing modules, including CBAM and BAM, generate these maps in a position-wise fashion, calculating an importance value for every pixel.
However, this approach often results in "jagged" boundaries that are highly sensitive to minor image perturbations. These maps can change drastically if an image is slightly rotated or scaled, which hampers the model's ability to generalize. Furthermore, these irregular shapes are often difficult for humans to interpret. CRAM addresses these issues by constraining the attention region to a mathematically grounded, regular geometric shape.
The CRAM Architecture
The core innovation of CRAM is the nearly-rectangular support function. Instead of predicting a full grid of values, the module predicts only five parameters:
- Center position ($x, y$)
- Height and Width ($\sigma_1, \sigma_2$)
- Orientation angle ($\alpha$)
To ensure compatibility with deep learning frameworks, the authors developed a differentiable window function based on the sigmoid. This creates a smooth rectangle where values are nearly 1 inside the box and nearly 0 outside, allowing gradients to flow back through the network during training.
Key technical components include equivariance constraints—an auxiliary loss function that forces the rectangle to "follow" the object during translation or rotation—and residual connections to ensure the model retains global information even if the rectangle is initially misplaced. Additionally, an energy rescaling step prevents feature distribution shifts when the rectangle changes size.
Key Insights and Interpretability
By forcing the attention map into a rectangle, CRAM applies a strong "geometric prior." This prevents the model from over-fitting to pixel-level noise and forces it to learn the global extent of the object.
This constraint provides "interpretability for free." The module effectively acts as a weakly-supervised object detector, learning to draw bounding boxes around important features using only class labels, without requiring human-annotated boxes. Furthermore, because CRAM only outputs five numbers, it is computationally efficient and can use aggressive sub-sampling to capture long-range spatial dependencies.
Experimental Results
The researchers evaluated CRAM using the Oxford-IIIT Pet dataset, featuring 37 breeds of cats and dogs in diverse poses. CRAM consistently outperformed both baseline CNNs (MobileNetV3, EfficientNet-b0) and standard position-wise attention models.
On MobileNetV3, CRAM achieved 93.23% accuracy, compared to 92.98% for position-wise attention and 92.63% for the baseline. Qualitatively, CRAM's attention maps remained stable and "locked on" to objects during sequences of rotations and scaling, whereas position-wise maps became erratic. The module proved particularly effective in shallower layers where features are less semantically rich, successfully locating objects where traditional methods failed.
Conclusion and Future Work
CRAM demonstrates that geometric regularization can significantly improve the stability and interpretability of spatial attention. While a single rectangle is a coarse tool for highly non-convex objects, future work may explore more diversified shapes or "multi-attention" maps that aggregate several rectangles to capture more complex regions while maintaining geometric stability.
Summary updated