Deep Neural Networks Can Learn Generalizable Same-Different Visual Relations

Alexa R. Tartaglini, Sheridan Feucht, Michael A. Lepori, Wai Keen Vong, Charles Lovering, Brenden M. Lake, Ellie Pavlick · DOI

Introduction

Humans and even honeybees can easily recognize if two objects are identical or different, regardless of the objects' specific features. This "same-different" relation is a cornerstone of abstract reasoning. However, the AI community has long observed a "relational gap": deep learning models that excel at standard benchmarks often fail at this simple task. Previous studies found that Convolutional Neural Networks (CNNs) tend to memorize specific training shapes rather than learning the abstract rule. This paper investigates whether this is a fundamental limitation of neural networks or a result of specific architectures and training recipes.

Methodology

The researchers conducted a massive "stress test" of the same-different task by varying three key dimensions:

  1. Architectures: Comparing the classic ResNet-50 (a CNN) against the ViT-B/16 (a Vision Transformer).
  2. Pretraining: Testing models initialized randomly, models pretrained on ImageNet (supervised), and models pretrained with CLIP (contrastive language-image pretraining).
  3. Fine-tuning Stimuli: Training models on different "flavors" of data to see which fostered the best abstraction.

The task was a binary classification: given an image containing two objects, the model must determine if they form a "same" or "different" pair.

Datasets and Task Design

The study utilized four primary 2D datasets for training and cross-evaluation, ranging from abstract contours to naturalistic images:

  • Squiggles (SQU): Randomly generated closed black-and-white contours.
  • Alphanumeric (ALPH): Handwritten characters from the Omniglot dataset.
  • Shapes (SHA): 2D shapes with varying colors and textures.
  • Naturalistic (NAT): Photos of real-world objects on white backgrounds.
Examples of the four 2D datasets (SQU, ALPH, SHA, NAT) used to test same-different relational reasoning across different visual domains.

Crucially, the researchers introduced a Photorealistic 3D dataset created in Blender. This served as the ultimate "out-of-distribution" (OOD) test, featuring complex lighting, shadows, and 3D rotations where "sameness" cannot be determined by simple pixel-matching.

Key Insights

Transformers as "Relational Natives"

Unlike CNNs, which process images through local filters, Transformers use self-attention. This allows the model to compare any two parts of an image immediately in the very first layer. This architectural bias appears crucial for learning relations.

The Power of CLIP

CLIP pretraining proved to be the "secret sauce." By training on a massive variety of internet images and text, CLIP develops a more flexible and robust visual vocabulary than models trained only on ImageNet labels. This flexibility allows the model to recognize "sameness" even when objects are viewed from different angles or in different contexts.

Abstract Training Advantage

Counter-intuitively, fine-tuning on simple, feature-poor stimuli (like Squiggles) led to better generalization than training on rich, naturalistic images. Training on "easy" features like color or texture often acts as a "shortcut," preventing the model from learning the harder, more abstract concept of shape-based equality.

Results and Generalization

The results were striking. CLIP-pretrained ViTs fine-tuned on the Squiggles dataset achieved nearly 100% accuracy when tested on Alphanumeric, Shapes, and Naturalistic datasets. Most impressively, these same models generalized to the 3D photorealistic dataset with 80-90% accuracy without any additional training. In contrast, ResNets and non-CLIP models largely failed this transfer, highlighting the importance of both the Transformer architecture and multimodal pretraining for relational reasoning.

Conclusion and Future Work

This research demonstrates that deep neural networks are capable of learning abstract visual relations that generalize far beyond their training data. While these models remain more data-inefficient than humans—requiring thousands of examples where a human might need only a few—the findings suggest that the gap between AI and biological abstract reasoning is closing. Future work may focus on incorporating more human-like inductive biases to improve learning efficiency and robustness.

Summary updated

BibTeX
@inproceedings{tartaglini2025deep,
  author = {Alexa R. Tartaglini and Sheridan Feucht and Michael A. Lepori and Wai Keen Vong and Charles Lovering and Brenden M. Lake and Ellie Pavlick},
  title = {{Deep Neural Networks Can Learn Generalizable Same-Different Visual Relations}},
  booktitle = {CCN Proceedings asProceedingsPoster},
  year = {2025},
  url = {https://openreview.net/forum?id=6AXLkRzcy6},
}
Figure