Pix2seq: A Language Modeling Framework for Object Detection

Ting Chen, Saurabh Saxena, Lala Li, David J. Fleet, Geoffrey Hinton

Introduction

Traditionally, visual object detection has been treated as a complex, multi-stage engineering problem. To find and identify objects, researchers have historically relied on hand-engineered components like region proposals, anchors, non-maximum suppression (NMS) to remove duplicates, and specialized loss functions for bounding box regression. Even modern end-to-end detectors like DETR still incorporate task-specific prior knowledge, such as "object queries."

Pix2seq offers a radical simplification of this paradigm by treating object detection as a pure language modeling problem. By converting bounding boxes and class labels into a sequence of discrete tokens, the authors demonstrate that a generic Transformer architecture can simply "read out" the objects in an image. This approach tackles a fundamental question in computer vision: can we perform object detection using a generic framework with minimal task-specific assumptions?

Pix2Seq casts object detection as a language modeling task, converting images into sequences of discrete tokens representing bounding boxes and classes.

Methodology

The core innovation of Pix2seq lies in its "quantization and serialization" scheme, which translates the continuous spatial domain of an image into a discrete vocabulary suitable for a language model.

  1. Quantization: Continuous image coordinates ($x_{min}, y_{min}, x_{max}, y_{max}$) are converted into discrete integers, or "bins." For example, a $600 \times 600$ image might be mapped to 600 bins. This effectively turns spatial coordinates into vocabulary words that a standard language model can predict.
  2. Serialization: A set of objects within an image is converted into a single sequence of tokens. Each object is represented sequentially as $[y_{min}, x_{min}, y_{max}, x_{max}, class]$.
  3. Architecture: The model employs a standard Encoder-Decoder Transformer. The encoder (which can be a ResNet or a Vision Transformer) perceives the image pixels, and the decoder generates the sequence of tokens autoregressively—one by one—just like a large language model generates text.
  4. Sequence Augmentation: To improve robustness and recall, the authors introduce a training trick where they add "noise" objects (random boxes) to the input sequence. The model is trained to identify these as a special "noise" class rather than real objects. This helps the model handle uncertainty and prevents premature termination of the generated sequence.
The Pix2seq training pipeline uses a standard encoder-decoder architecture optimized via next-token prediction.

Key Insights

  • Detection is "Reading": The fundamental intuition behind Pix2seq is that if a neural network understands "where" and "what" objects are, we simply need to teach it a language to describe them.
  • Random Ordering is Superior: Surprisingly, the authors found that randomizing the order of objects in the sequence during training works better than deterministic orderings (like sorting by area or position). This likely helps the model learn the underlying distribution of objects rather than overfitting to a specific sorting bias.
  • Task Agnosticism: Unlike almost every other detector, Pix2seq uses a standard maximum likelihood loss (softmax cross-entropy). There is no specialized "IoU loss" or "box regression loss."
  • Unified Interface: Because the output is just a sequence of tokens, this framework could theoretically handle object detection, image captioning, and keypoint detection simultaneously using the exact same architecture.

Datasets and Results

The model was primarily evaluated on the MS-COCO 2017 detection dataset (118k training images). To push performance further, the authors also utilized Objects365, a much larger dataset (1.7M images), for large-scale pre-training before fine-tuning on COCO.

When trained from scratch on COCO, Pix2seq using a ResNet-50 backbone achieved 43.0 AP, outperforming the original DETR (42.0 AP) and Faster R-CNN (40.2 AP). By pre-training on Objects365 and using a larger ViT-L (Vision Transformer) backbone, Pix2seq reached an impressive 50.0 AP on COCO. Furthermore, Pix2seq demonstrated a significant advantage (a 4-5 AP improvement) over DETR in detecting small objects, which is historically a common weakness for Transformer-based vision models.

Limitations and Future Work

While groundbreaking, the Pix2seq framework has current limitations. Because the model is autoregressive (generating one token at a time), inference is computationally expensive and slower than "single-shot" detectors, especially for images crowded with many objects. Additionally, long sequences increase the chance of errors accumulating during generation.

The authors suggest that future work is needed to accelerate the decoding process for real-time applications. Finally, the current approach relies entirely on human-annotated bounding boxes; reducing this dependence to leverage unlabeled data remains a promising future direction.

Summary updated

BibTeX
@inproceedings{chen2022pix,
  author = {Ting Chen and Saurabh Saxena and Lala Li and David J. Fleet and Geoffrey Hinton},
  title = {{Pix2seq: A Language Modeling Framework for Object Detection}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=e42KbIw6Wb},
}
Figure