Inferring spatial relations from textual descriptions of images

Aitzol Elu, Gorka Azkune, Oier Lopez de Lacalle, Ignacio Arganda-Carreras, Aitor Soroa, Eneko Agirre · DOI

Abstract

Generating an image from its textual description requires both a certain level of language understanding and common sense knowledge about the spatial relations of the physical entities being described. In this work, we focus on inferring the spatial relation between entities, a key step in the process of composing scenes based on text. More specifically, given a caption containing a mention to a subject and the location and size of the bounding box of that subject, our goal is to predict the location and size of an object mentioned in the caption. Previous work did not use the caption text information, but a manually provided relation holding between the subject and the object. In fact, the used evaluation datasets contain manually annotated ontological triplets but no captions, making the exercise unrealistic: a manual step was required; and systems did not leverage the richer information in captions. Here we present a system that uses the full caption, and Relations in Captions (REC-COCO), a dataset derived from MS-COCO which allows to evaluate spatial relation inference from captions directly. Our experiments show that: (1) it is possible to infer the size and location of an object with respect to a given subject directly from the caption; (2) the use of full text allows to place the object better than using a manually annotated relation. Our work paves the way for systems that, given a caption, decide which entities need to be depicted and their respective location and sizes, in order to then generate the final image.

Introduction

Text-to-image generation is a complex task that extends beyond mere object recognition; it requires a sophisticated understanding of how objects are arranged in a scene. Central to this is the concept of spatial relations. For instance, a caption describing "a man sitting on a bench" implies a specific vertical and horizontal alignment between the man and the bench. Historically, research in this area has relied on simplified "concept triplets"—structured data such as (PERSON, ON, BENCH).

However, this approach suffers from two primary limitations. First, it is unrealistic, as real-world applications deal with descriptive, natural language captions rather than curated database entries. Second, triplets are often too sparse to capture the nuances of a scene. The difference between "a man resting on a bench" and "a man fixing a bench" is significant in terms of spatial layout, yet both might be mapped to the same triplet. This paper explores whether leveraging the full context of a caption can improve the inference of spatial layouts.

Methodology

The proposed system utilizes a neural network architecture designed for spatial regression. The model takes three inputs: a natural language caption, a specific subject token (e.g., "man"), and the bounding box coordinates of that subject. The objective is to predict the bounding box—both location and size—of a target object mentioned in the caption (e.g., "frisbee").

Figure 6: Examples from the REC-COCO dataset showing how different captions for the same subject (red box) lead to different predicted object locations (green box).

To process the textual input, the researchers evaluated three distinct Caption Encoders:

  • AVG: A baseline that averages word embeddings.
  • BiLSTM: A recurrent network that captures sequential dependencies and word order.
  • BERT: A pre-trained transformer model that uses attention mechanisms to understand deep contextual relationships.

The resulting text representation is concatenated with the subject's physical coordinates and processed through dense layers to output the predicted coordinates for the target object.

The REC-COCO Dataset

To facilitate this research, the authors introduced REC-COCO (Relations in Captions), a new benchmark derived from the MS-COCO and V-COCO datasets. Unlike previous datasets that relied on abstract ontological triplets, REC-COCO aligns specific words in captions with physical bounding boxes in images. This dataset contains 19,559 instances across 6,407 images, providing a realistic environment for testing how linguistic nuances influence spatial reasoning.

Results and Discussion

The experimental results demonstrate that full captions provide significantly richer information for spatial inference than simplified triplets. Using the BERT encoder, the model achieved an Intersection over Union (IoU) of 16.4, outperforming the 14.9 IoU achieved using manually provided conceptual relations.

Figure 1: Schematic representation of inferred spatial relations. The model learns that different verbs (e.g., "sitting" vs. "laying") imply distinct relative positions and sizes for the object.

Key findings include:

  • Contextual Cues: Verbs and adjectives provide implicit spatial information. The model successfully learns that "riding" implies a different vertical alignment than "walking beside."
  • Common Sense Reasoning: The model exhibits an emergent understanding of relative scales. For example, it learns that a "bench" is typically larger than a "person," adjusting its predictions accordingly even when not explicitly told the sizes.
  • Directional Accuracy: The models were particularly effective at vertical spatial reasoning, with the BiLSTM encoder reaching nearly 80% accuracy in determining whether an object should be above or below the subject.

Conclusion

This work proves that natural language captions are a powerful source of spatial information for scene composition. While the model currently struggles with complex issues like occlusion and requires a "seed" bounding box to begin, it represents a significant step toward fully autonomous text-to-image systems. Future research may involve integrating multimodal transformers to further refine the bridge between linguistic descriptions and visual grounding.

Summary updated

BibTeX
@article{elu2021inferring,
  author = {Aitzol Elu and Gorka Azkune and Oier Lopez de Lacalle and Ignacio Arganda-Carreras and Aitor Soroa and Eneko Agirre},
  title = {{Inferring spatial relations from textual descriptions of images}},
  journal = {Pattern Recognition},
  year = {2021},
  doi = {10.1016/j.patcog.2021.107847},
}
Figure