Spatial Memory for Context Reasoning in Object Detection

Xinlei Chen, Abhinav Gupta

Abstract

Modeling instance-level context and object-object relationships is extremely challenging. It requires reasoning about bounding boxes of different classes, locations etc. Above all, instance-level spatial reasoning inherently requires modeling conditional distributions on previous detections. Unfortunately, our current object detection systems do not have any memory to remember what to condition on! The state-of-the-art object detectors still detect all object in parallel followed by non-maximal suppression (NMS). While memory has been used for tasks such as captioning, they mostly use image-level memory cells without capturing the spatial layout. On the other hand, modeling object-object relationships requires spatial reasoning – not only do we need a memory to store the spatial layout, but also a effective reasoning module to extract spatial patterns. This paper presents a conceptually simple yet powerful solution – Spatial Memory Network (SMN), to model the instance-level context efficiently and effectively. Our spatial memory essentially assembles object instances back into a pseudo “image” representation that is easy to be fed into another ConvNet for object-object context reasoning. This leads to a new sequential reasoning architecture where image and memory are processed in parallel to obtain detections which update the memory again. We show our SMN direction is promising as it provides 2.2% improvement over baseline Faster RCNN on the COCO dataset with VGG16.

Introduction

Standard object detection frameworks, such as Faster R-CNN, typically detect all objects in an image in parallel. While computationally efficient, this approach lacks instance-level context. Humans utilize spatial relationships constantly; for instance, if a detector identifies a tennis racket, it should be significantly more confident that a nearby blurry yellow blob is a tennis ball. Most AI models, however, treat every bounding box as an independent problem. Furthermore, current systems rely on hand-tuned heuristics like Non-Maximum Suppression (NMS) to remove duplicate detections. A true reasoning system should be capable of learning these relationships and de-duplication rules directly from data.

Methodology: The Spatial Memory Network

The Spatial Memory Network (SMN) transforms object detection into a sequential reasoning task through four primary components:

  1. Spatial Memory: A 2D grid (e.g., 20x20) where each cell contains a high-dimensional vector. This serves as a "pseudo-image" storing information about discovered objects at their specific spatial locations.
  2. Input & Writing: When an object is detected, its visual features and class scores are integrated into the memory using a Convolutional Gated Recurrent Unit (ConvGRU). This allows the model to dynamically decide which information to retain or overwrite.
  3. Context Model: A 5-layer ConvNet processes the memory grid. Because the memory preserves spatial layout, the ConvNet can efficiently identify patterns, such as a keyboard's typical placement relative to a monitor.
  4. Output Module: This module fuses original image features with context features from the memory to produce refined detection scores and bounding box coordinates.

The system operates iteratively: it identifies the most confident object, updates the memory, and uses that updated context to search for subsequent objects.

Experimental Results

The model was evaluated on the COCO (Common Objects in Context) benchmark and PASCAL VOC 2007. Key findings include:

  • Accuracy Improvement: The SMN achieved a 2.2% mAP improvement over the baseline Faster R-CNN on the COCO dataset (31.6% vs 29.4%).
  • Enhanced Recall: Significant gains were observed in Average Recall (AR), particularly for small and medium objects, demonstrating that context helps recover objects missed by the base detector.
  • Learning De-duplication: By remembering where objects have already been placed, the SMN naturally learns to suppress duplicate boxes, suggesting that hand-coded NMS can be replaced by a learned process.
Qualitative examples of context reasoning. The SMN uses spatial relationships to identify small or blurry objects like tennis balls and traffic lights, and can reason about contextually inconsistent detections.

Discussion and Qualitative Analysis

Contextual reasoning is most valuable for the "tails" of the distribution—objects that are small, blurry, or partially occluded. For a clear, large image of a car, context is redundant; however, for a tiny tennis ball or a distant traffic light, the presence of a player or a road provides critical cues. Qualitative results show that the SMN correctly increases confidence for objects that fit the spatial context and can suppress false positives (such as a person incorrectly detected on a train seat) when the surrounding environment does not support the detection.

Conclusion

The Spatial Memory Network provides a conceptually simple yet effective way to incorporate instance-level context into object detection. While the sequential nature of the model currently impacts computational speed compared to parallel detectors, the gains in accuracy and the ability to learn de-duplication are significant. Future work may explore using Reinforcement Learning to optimize the sequence of regions visited or increasing memory resolution to capture finer spatial details.

Summary updated

BibTeX
@inproceedings{chen2017spatial,
  author = {Xinlei Chen and Abhinav Gupta},
  title = {{Spatial Memory for Context Reasoning in Object Detection}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2017},
  url = {https://openreview.net/forum?id=ByVVzbMOZH},
}
Figure