Segmentation-Aware Convolutional Networks Using Local Attention Masks

Adam W. Harley, Konstantinos G. Derpanis, Iasonas Kokkinos

Abstract

We introduce an approach to integrate segmentation information within a convolutional neural network (CNN). This counter-acts the tendency of CNNs to smooth information across regions and increases their spatial precision. To obtain segmentation information, we set up a CNN to provide an embedding space where region co-membership can be estimated based on Euclidean distance. We use these embeddings to compute a local attention mask relative to every neuron position. We incorporate such masks in CNNs and replace the convolution operation with a “segmentation-aware” variant that allows a neuron to selectively attend to inputs coming from its own region. We call the resulting network a segmentation-aware CNN because it adapts its filters at each image point according to local segmentation cues, while at the same time remaining fully-convolutional. We demonstrate the merit of our method on two widely different dense prediction tasks, that involve classification (semantic segmentation) and regression (optical flow). Our results show that in semantic segmentation we can replace DenseCRF inference with a cascade of segmentation-aware filters, and in optical flow we obtain clearly sharper responses than the ones obtained with comparable networks that do not use segmentation. In both cases segmentation-aware convolution yields systematic improvements over strong baselines.

Introduction

Convolutional Neural Networks (CNNs) are the backbone of modern computer vision, yet they suffer from a fundamental "smoothness" problem. Due to successive pooling and subsampling layers, CNNs tend to average information across spatial regions. While this abstraction aids in high-level classification, it is detrimental for dense prediction tasks like semantic segmentation or optical flow, where spatial precision is paramount. This often results in "bleeding" at object boundaries, where features from one object blur into another.

Historically, this has been addressed through post-processing techniques like Dense Conditional Random Fields (DenseCRFs). However, these methods are often computationally expensive and decoupled from the primary network's learning phase. This research proposes a "segmentation-aware" convolution that integrates boundary awareness directly into the network's architecture, preventing blurring before it occurs.

Methodology: Segmentation-Aware Convolutions

The proposed framework transforms the standard convolution into a segmentation-aware operation through a three-stage process:

  1. Learning Semantic Embeddings: A dedicated branch of the network learns to map each pixel into a high-dimensional embedding space (64D). Through a contrastive loss, the network is trained to ensure that pixels belonging to the same semantic region are clustered together, while pixels from different regions are separated.
  2. Local Attention Mask Generation: For every spatial position, the network calculates a "soft" attention mask based on the Euclidean distance between the embedding of the center pixel and its neighbors. High similarity results in a high weight (foreground), while low similarity masks out the neighbor (background).
  3. The Segmentation-Aware Operation: The standard convolution is replaced with a variant where input features are pointwise multiplied by these local attention masks before the filter is applied. This ensures that the filter only "attends" to relevant pixels within the same semantic region.
Segmentation-aware convolution mechanism. Local attention masks are derived from learned embeddings to ensure filters only process features from the same semantic region.

This approach is fully differentiable and can be trained end-to-end. Furthermore, standard convolution is a special case of this operation, allowing the network to learn the optimal degree of "segmentation-awareness" via a learnable hardness parameter ($\lambda$). Efficiency is maintained by casting mask creation as an "image-to-column" operation, similar to modern GPU convolution implementations.

Experimental Results

The method was evaluated on two distinct tasks: semantic segmentation (PASCAL VOC 2012) and optical flow (FlyingChairs).

Semantic Segmentation

Integrating segmentation-awareness into the DeepLab baseline improved the Mean Intersection-over-Union (mIOU) on PASCAL VOC 2012 from 66.33% to 69.01%. A ResNet-101 based model achieved a state-of-the-art 79.8% mIOU on the official test server. Notably, the method proved to be a faster and more effective alternative to traditional DenseCRF post-processing.

Optical Flow and Boundary Precision

In optical flow tasks, the method significantly reduced the Average End-Point Error (aEPE) by 18% (from 2.78 to 2.26) and slashed the Average Angular Error from 15.58 to 9.54. Trimap analysis confirmed that the most substantial improvements occurred within 5–10 pixels of object boundaries, where standard CNNs typically fail.

Comparison of standard coarse feature maps (FC8) and the sharpened output achieved using segmentation-aware embeddings.

Discussion and Conclusion

By utilizing learned semantic embeddings rather than hand-crafted color cues, the network remains robust against distracting textures and lighting changes. While the method introduces some computational overhead (100ms–500ms per image), its ability to produce sharp, spatially precise predictions without external post-processing is a significant advancement. Future work may extend this logic to other dense prediction tasks such as depth estimation or image restoration, where boundary preservation is equally critical.

Summary updated

BibTeX
@inproceedings{harley2017segmentation,
  author = {Adam W. Harley and Konstantinos G. Derpanis and Iasonas Kokkinos},
  title = {{Segmentation-Aware Convolutional Networks Using Local Attention Masks}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2017},
  url = {https://openreview.net/forum?id=HybTwZzO-H},
}
Figure