NewsMacroBuilding an End-to-End OCR Pipeline with Baidu’s Unlimited-OCR for Images and PDFs

Building an End-to-End OCR Pipeline with Baidu’s Unlimited-OCR for Images and PDFs

Author: MarkTechPost·

Key Takeaways

  • MarkTechPost published a tutorial for running Baidu's 3B-parameter Unlimited-OCR vision-language model on document images and multi-page PDFs within Google Colab.
  • Unlimited-OCR performs end-to-end document understanding, reducing reliance on the separate text detection, recognition, and layout analysis stages required by traditional OCR engines.
  • The tutorial compares Gundam mode, which uses tiled image crops for dense layouts, against Base mode, which uses a single 1024-pixel view for faster processing of clean pages.
  • The pipeline extends to multi-page PDF parsing by rasterizing pages with PyMuPDF and passing them to a long-horizon inference function with widened repetition controls for stable decoding.
  • Results can be exported in multiple structured formats including Markdown, JSON, and MMD, supporting documentation, programmatic use, and diagram rendering workflows.
Building an End-to-End OCR Pipeline with Baidu’s Unlimited-OCR for Images and PDFs

A tutorial published by MarkTechPost describes how to build a complete workflow for running Baidu's Unlimited-OCR model on document images and multi-page PDFs. The pipeline is designed for Google Colab and covers environment setup, dependency installation, model loading, sample document generation, single-page OCR, and multi-page PDF parsing. Unlimited-OCR is part of a broader shift toward vision-language models that handle document understanding in a single end-to-end system, reducing the need for the multi-stage pipelines—text detection, recognition, and layout analysis—used by traditional OCR engines.

The workflow begins by configuring a GPU-enabled runtime and installing the libraries needed for Unlimited-OCR inference. It verifies that a CUDA-capable GPU is available, then automatically selects bfloat16 or float16 depending on hardware support. The tutorial loads the tokenizer and the 3B-parameter vision-language model from Hugging Face, switches the model to evaluation mode, and moves it to the GPU for inference. Hosting the model on Hugging Face allows developers to load pretrained weights directly, removing the need to train or fine-tune a document-recognition model from scratch.

To create reproducible test inputs, the tutorial sets up required input and output directories and generates three realistic sample document pages with PIL. These pages include headings, paragraphs, tables, and footnotes, allowing the pipeline to test recognition on structured, layout-rich content rather than only simple text blocks. The first generated page is previewed with Matplotlib before it is passed into the OCR workflow.

For single-image OCR, the tutorial first uses Gundam mode, which combines a global view of the document with tiled image crops. In this configuration, crop_mode is enabled and a smaller tile size is used to preserve fine text and improve recognition on dense layouts. The workflow also applies long-output generation settings and repetition controls so the model can produce stable, structured output when processing complex documents.

The same document is then processed with Base mode, which uses a single 1024-pixel image view. Image cropping is disabled in this mode to reduce inference complexity and improve processing speed on clean, clearly printed pages. The tutorial keeps the same output-length and repetition-control settings so Base mode can be compared directly with Gundam mode under consistent generation parameters.

The pipeline is then extended from image OCR to multi-page PDF parsing. The tutorial creates a three-page PDF from the generated document images and uses PyMuPDF to rasterize each page into a high-resolution PNG. The resulting page-image sequence is passed to infer_multi(), enabling the model to parse the full document in a single long-horizon inference run. The n-gram repetition window is widened to support stable decoding across multiple pages.

After running both single-page and multi-page inference, the tutorial inspects the output directories produced by the workflow. It lists each generated file and displays previews of supported text, Markdown, MMD, and JSON artifacts. It also includes a concise reference for selecting inference modes, recommending different configurations for dense images, clean pages, and multi-page PDFs. The ability to export results in multiple structured formats—Markdown for documentation, JSON for downstream programmatic use, and MMD for diagram rendering—makes the pipeline adaptable to different document-processing needs.

The completed workflow demonstrates how Unlimited-OCR can be used in Google Colab for high-detail single-page documents and longer multi-page PDFs. It compares Gundam and Base inference modes, converts PDFs into model-ready page images, performs long-horizon document parsing, and reviews the generated text, Markdown, and auxiliary artifacts from the output folders. The setup also adapts to different GPU capabilities while preserving the generation parameters needed for stable long-document decoding.

MarkTechPost said the workflow provides a reusable foundation for applying Unlimited-OCR to reports, scanned forms, technical documents, tables, and other layout-rich content without relying on a separate traditional OCR and layout-analysis stack. The full tutorial code is available on GitHub.