Self-Supervised Representation Learning via Neighborhood-Relational Encoding

Mohammad Sabokrou, Mohammad Khalooei, Ehsan Adeli

TL;DR

This paper introduces Neighborhood-Relational Encoding (NRE), a self-supervised learning strategy that forces autoencoders to preserve local neighborhood structures on the data manifold rather than just reconstructing isolated data points. By incorporating relationships between similar and dissimilar samples directly into the loss function, NRE learns highly discriminative features that significantly boost performance across downstream tasks like classification, object detection, adversarial defense, and anomaly detection.

What Problem Does This Paper Address?

Conventional unsupervised representation learning—particularly using autoencoders (AEs)—typically relies on a simple premise: minimize the error between the input and its reconstruction. While successful, this approach suffers from two major limitations:

  1. Pixel-level memorization: It forces the network to reconstruct every part of the input, including noise and task-irrelevant background details.
  2. Single-point abstraction: It treats each data point in total isolation, completely ignoring the rich semantic relationships between neighboring samples in a dataset.

The authors address this gap by proposing that the relative distance between data points on a local manifold can serve as a powerful metric for self-supervision, leading to cleaner, more structured latent spaces.

Methods

The core architecture consists of an encoder ($E_\phi$) and a decoder ($D$), trained jointly. Unlike a standard autoencoder, NRE modifies the objective function to be mindful of the data's local neighborhood.

To achieve this, the authors use a two-step process:

  1. Neighbor Discovery: They pre-train a standard autoencoder to map all data points into a preliminary latent space. Using cosine similarity in this space, they identify the nearest neighbor ($X_0$) and the farthest/most dissimilar sample ($X_\infty$) for any given input $X$.
  2. Relational Loss Optimization: They train the main network ($E_\phi + D$) using a tripartite loss function. This loss simultaneously minimizes the reconstruction error of $X$, minimizes the distance between the reconstructed output and the nearest neighbor ($X_0$), and maximizes the distance to the far-away sample ($X_\infty$).
Overview of the NRE architecture and training pipeline.

To scale this approach to massive datasets like ImageNet, where searching for exact neighbors for every sample is computationally prohibitive, the authors introduce a clever optimization: they cluster the dataset using $K$-means and restrict the nearest-neighbor search to the local cluster.

Datasets

The authors evaluated NRE across several standard benchmarks representing different computer vision challenges:

  • MNIST: Used for basic classification, latent space visualization, and black-box adversarial attack defense.
  • ImageNet: Used for large-scale self-supervised pre-training.
  • PASCAL VOC 2007 & 2012: Used to evaluate downstream performance on transfer learning tasks, specifically image classification, object detection (via Fast R-CNN), and semantic segmentation (via FCN).
  • UCSD Ped2: A video dataset used to benchmark frame-level anomaly detection.

Key Insights and Ideas

  • Semantic Regularization: By forcing the network to reconstruct an image such that it aligns closely with its semantic neighbors, the network is discouraged from memorizing pixel-level noise and is instead forced to learn broader categorical concepts.
  • Manifold Separability: Standard autoencoders often produce overlapping clusters in the latent space. NRE explicitly pulls similar samples together and pushes dissimilar ones away, resulting in a significantly more separable feature space without requiring manual labels.
Figure 1. Some samples from five classes of the Caltech dataset (top), latent space visualization using a regular AE (i.e., E(X); left), and our proposed AE that encodes the neighborhood rela- tions (i.e., Eφ(X); right). With the same classifier, E(X) leads to a classification accuracy of 92.2% and Eφ(X) 97.5%.
  • Adversarial Purification: Because NRE projects data onto a tightly constrained local manifold, it acts as an excellent "refiner" for adversarial examples. When an image corrupted by an adversarial attack is fed into NRE, the network naturally pulls it back toward the clean data cluster, neutralizing the attack.

Key Results

  • Downstream Classification: On the PASCAL VOC 2007 dataset, an AlexNet pre-trained with NRE achieved a classification accuracy of 74.4% mAP (all layers), outperforming prominent self-supervised methods like BiGAN (60.3%) and Context Encoders (56.5%).
  • Adversarial Defense: When subjected to a black-box Fast Gradient Sign Method (FGSM) attack ($\epsilon = 0.2$) on MNIST, a target classifier's accuracy dropped precipitously. Using MagNet as a defense restored accuracy to 61.4%, whereas NRE achieved a dominant 84.89% accuracy.
Figure 5. Some samples of adversarial examples created by FGSM [40] attack (ϵ = 0.2). First row: Original images; Second row: reconstruction of the adversarial examples by our method; Last row: the adversarial example.
  • Video Anomaly Detection: On the UCSD Ped2 dataset, NRE achieved an Equal Error Rate (EER) of 14%, which is competitive with highly complex, state-of-the-art spatio-temporal models, despite NRE being a much simpler spatial patch-based architecture.

Limitations and Future Work

While the clustering trick makes NRE viable for large datasets, the initial neighbor-discovery phase still relies on a pre-trained anchor network and a multi-step pipeline, which adds computational overhead.

Additionally, the hyperparameters balancing the loss terms ($\lambda_1, \lambda_2, \lambda_3$) currently require manual tuning based on the specific application (e.g., image enhancement vs. classification). The authors note that developing a dynamic scheduling method to automatically adjust these parameters during training is a promising direction for future work.

Summary updated

BibTeX
@inproceedings{sabokrou2019self,
  author = {Mohammad Sabokrou and Mohammad Khalooei and Ehsan Adeli},
  title = {{Self-Supervised Representation Learning via Neighborhood-Relational Encoding}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2019},
  doi = {10.1109/iccv.2019.00810},
}
Figure