Layout Generation and Completion with Self-attention

Kamal Gupta, Alessandro Achille, Justin Lazarow, Larry Davis, Vijay Mahadevan, Abhinav Shrivastava

Abstract

LayoutTransformer is a novel autoregressive model that leverages self-attention to generate and complete scene layouts across diverse domains, including 3D objects, natural images, documents, and mobile applications. By discretizing bounding box coordinates and predicting layout attributes sequentially, the model achieves state-of-the-art results while naturally learning semantic relationships between object categories based purely on spatial co-occurrence.

Problem Statement

Generating realistic scenes—whether synthetic photographs, 3D models, or user interface (UI) designs—requires more than just high-quality pixels or textures. A fundamental component of realism is the layout: the contextual arrangement and sizing of objects. For instance, a dining table is typically surrounded by chairs, and a website header is usually positioned at the top. Existing generative models often struggle with this structural comprehension, either requiring dense proxy inputs or relying on domain-specific constraints. This paper introduces a unified, domain-agnostic model capable of understanding contextual relationships to build or complete layouts from scratch.

Methodology

The authors frame layout generation as a sequence modeling problem, drawing inspiration from large language models. The process involves three key steps:

  1. Layout Representation: A layout is treated as a set of graphical primitives defined by category and geometric parameters (x, y, width, height).
  2. Discretization: Continuous spatial coordinates are converted into discrete tokens using 8-bit uniform quantization (values 0-255). This allows the model to express multimodal probability distributions, which is crucial for complex layouts.
  3. LayoutTransformer Architecture: Attributes are flattened into a 1D sequence and processed by a masked Transformer decoder. The model predicts the next attribute based on all previous ones, similar to how GPT predicts the next word in a sentence.
The LayoutTransformer architecture treats layout generation as a sequence modeling task by predicting discrete geometric tokens.

By decoupling attributes and predicting them individually, the self-attention mechanism can assign specific weights to coordinate dimensions. For example, when generating a column of text, the model can attend heavily to the horizontal (x) coordinate of the previous box while ignoring its vertical (y) position.

Datasets and Evaluation

To demonstrate the model's domain-agnostic nature, it was evaluated on four highly diverse datasets:

  • PartNet: 3D shapes (chairs and lamps) decomposed into semantic parts.
  • COCO Bounding Boxes: Natural image scenes from the COCO Panoptic 2017 dataset.
  • Rico: Mobile app UI wireframes (buttons, text, images).
  • PubLayNet: Document layouts including text, titles, lists, and figures.

Analysis of Learned Representations

A significant finding of the research is that semantics emerge from spatial data. By training purely on object placement, the model's learned embedding space naturally captures semantic relationships. It can solve analogies like snowboard : snow :: surfboard : ? (returning "sea" or "sand") without ever being trained on text. Spatial co-occurrence serves as a proxy for semantic meaning.

Progressive generation of a natural scene layout from sky to sea to surfboard, demonstrating the model's contextual understanding.

Quantization, while introducing minor approximation errors, enables the model to align UI elements perfectly, avoiding the "jittery" boxes common in continuous regression models. This precision is vital for structured domains like document and mobile app design.

Quantitative Results

The model consistently outperformed or matched state-of-the-art domain-specific models across all benchmarks:

  • Natural Scenes (COCO): When paired with a downstream image generator, LayoutTransformer achieved an Inception Score (IS) of 7.6 and a FID of 57.0, outperforming baselines like LayoutVAE.
  • Documents & UIs: On the Rico dataset, it achieved a Negative Log-Likelihood (NLL) of 1.07, significantly better than LayoutVAE (2.54) and ObjGAN (4.21).
  • 3D Shapes (PartNet): It reached state-of-the-art performance in generating 3D chair point clouds, scoring a Jensen-Shannon Divergence (JSD) of 0.81.

Discussion and Future Work

Despite its success, the model requires scenes to be neatly decomposable into compositional primitives, which may not apply to amorphous natural scenes like forests. Additionally, the autoregressive nature imposes a strict sequence order on what is naturally an order-invariant set. Future work may explore joint training of part auto-encoders and layout generators to prevent issues like floating or disconnected parts in 3D generation.

Summary updated

Abstract

We address the problem of scene layout generation for diverse domains such as images, mobile applications, documents, and 3D objects. Most complex scenes, natural or human-designed, can be expressed as a meaningful arrangement of simpler compositional graphical primitives. Generating a new layout or extending an existing layout requires understanding the relationships between these primitives. To do this, we propose LayoutTransformer, a novel framework that leverages self-attention to learn contextual relationships between layout elements and generate novel layouts in a given domain. Our framework allows us to generate a new layout either from an empty set or from an initial seed set of primitives, and can easily scale to support an arbitrary of primitives per layout. Furthermore, our analyses show that the model is able to automatically capture the semantic properties of the primitives. We propose simple improvements in both representation of layout primitives, as well as training methods to demonstrate competitive performance in very diverse data domains such as object bounding boxes in natural images(COCO bounding box), documents (PubLayNet), mobile applications (RICO dataset) as well as 3D shapes (Part-Net). Code and other materials will be made available at https://kampta.github.io/layout.
BibTeX
@inproceedings{gupta2021layout,
  author = {Kamal Gupta and Alessandro Achille and Justin Lazarow and Larry Davis and Vijay Mahadevan and Abhinav Shrivastava},
  title = {{Layout Generation and Completion with Self-attention}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  doi = {10.1109/iccv48922.2021.00104},
}
Figure