DocSAM: Unified Document Image Segmentation via Query Decomposition and Heterogeneous Mixed Learning

Xiao-Hui Li, Fei Yin, Cheng-Lin LiuCVPR 2025

Introduction

Document Image Segmentation (DIS) is a foundational step for OCR and document understanding. Historically, the field has been fragmented, with researchers building specialized models for specific tasks: identifying paragraphs (Layout Analysis), finding words (Text Detection), or parsing rows and columns (Table Structure Recognition). This "one model per task" approach suffers from limited generalization, significant resource wastage, and static architectures that cannot easily adapt to new categories.

DocSAM handles a wide range of document segmentation tasks, from layout analysis to scene text detection.

DocSAM (Document Segment Anything Model) addresses these challenges by consolidating diverse document image segmentation tasks into a single, unified transformer-based framework. By treating all segmentation tasks as a unified problem of predicting masks and labels, DocSAM achieves state-of-the-art generalization across both modern digital PDFs and historical manuscripts.

Methodology: The DocSAM Framework

The core innovation of DocSAM lies in its architecture, which is designed to handle the multi-scale nature of document elements, from full-page figures to tiny characters. The model is built upon four primary modules:

  • Vision Backbone & Deformable Encoder: Utilizes a Swin-Transformer and deformable attention to extract high-resolution, multi-scale features.
  • Query Decomposition: Unlike traditional models that use only learnable instance queries (representing where an object is), DocSAM introduces Semantic Queries. It uses Sentence-BERT to map natural language class names (e.g., "table," "caption") into a high-dimensional embedding space.
  • Hybrid Query Decoder (HQD): Instance and semantic queries interact through self-attention before being cross-attended with image features. This allows the semantic embeddings to act as "prototypes" that guide the search for specific objects.
  • Heterogeneous Mixed Learning: To stabilize training across nearly 50 datasets, the authors employ SimMIM pre-training, curriculum learning, and Instance Query Selection (IQS) to filter low-probability queries early.
The DocSAM architecture featuring the Hybrid Query Decoder and Semantic Query decomposition.

Large-Scale Heterogeneous Training

The study utilizes 48 different datasets for training, covering four major domains:

  1. Layout Analysis: PubLayNet, DocBank, M6Doc.
  2. Historical/Handwritten: SCUT-CAB, MTHv2, CASIA-HWDB.
  3. Table Recognition: PubTabNet, FinTabNet, TableBank.
  4. Scene Text: CTW1500, Total-Text, ICDAR2015.

By training on this heterogeneous mix, DocSAM develops a significantly more robust visual backbone than models trained on a single domain, enabling impressive zero-shot capabilities on unseen datasets like IIIT-AR-13K.

Key Results and Insights

DocSAM-large outperformed specialized state-of-the-art models on major benchmarks, including M6Doc (mAP of 0.663) and SCUT-CAB. Key insights from the evaluation include:

  • Open-Set Segmentation: By using class names as prototypes, classification becomes a dot-product between instance and semantic queries. This allows the model to recognize new classes simply by being provided their names.
  • Task Unification: The results prove that layout analysis and table parsing are mathematically similar problems at different granularities, which a single Hybrid Query Decoder can handle simultaneously.
  • Efficiency: A single DocSAM model can replace dozens of specialized models, drastically reducing storage and deployment overhead for large-scale processing pipelines.

Conclusion and Future Work

DocSAM demonstrates that a unified approach to document segmentation is not only feasible but superior to fragmented, task-specific models. While the model currently relies solely on visual features, future iterations aim to incorporate textual features (OCR) directly into the query process. This multi-modal approach will better handle logically complex documents, such as those requiring specific reading orders across multiple columns.

Summary updated

BibTeX
@inproceedings{li2025docsam,
  author = {Xiao-Hui Li and Fei Yin and Cheng-Lin Liu},
  title = {{DocSAM: Unified Document Image Segmentation via Query Decomposition and Heterogeneous Mixed Learning}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2025},
  doi = {10.1109/cvpr52734.2025.01399},
}
Figure