我们使用 Base 模式以单个 1024 像素图像视图处理相同文档。我们关闭图像裁剪,以降低推理复杂度并提高处理速度,适用于干净、打印清晰的页面。我们保留相同的输出长度和重复控制设置,以便直接比较 Base 模式和 Gundam 模式。
我们使用生成的文档图像创建一个三页的 PDF,并使用 PyMuPDF 将 PDF 的每一页栅格化为高分辨率 PNG。然后我们将生成的页面图像序列传递给 infer_multi(),以便模型可以在一次长时程推理操作中解析完整文档。我们还扩大了 n-gram 重复窗口,以在多页之间保持稳定的解码。
我们检查由单页和多页推理运行创建的输出目录。我们列出每个生成的文件,并显示支持的文本、Markdown、MMD 和 JSON 文件的预览。我们以一个简明的参考总结工作流程,推荐针对密集图像、干净页面和多页 PDF 的推理模式。
总之,我们完成了一个实用的 OCR 流程,能够处理高细节的单页文档和长多页 PDF,并在 Google Colab 中运行。我们比较了 Gundam 和 Base 推理模式,将 PDF 栅格化为模型可用的页面图像,执行长时程文档解析,并直接从输出目录检查生成的文本、Markdown 和辅助文件。我们还配置了工作流程,使其能够适应不同的 GPU 功能,同时保留稳定长文档解码所需的生成参数。它为我们提供了一个可重复使用的基础,使 Unlimited-OCR 能够应用于报告、扫描表格、技术文档、表格及其他布局丰富的内容,而无需依赖单独的传统 OCR 和布局分析栈。
需要与我们合作推广您的 GitHub 仓库 OR Hugging Face 页面 OR 产品发布 OR 网络研讨会等吗?请联系: https://forms.gle/wbash1wF6efRj8G58
Sana Hassan 是 Marktechpost 的咨询实习生,同时也是 IIT Madras 的双学位学生,他热衷于将技术和 AI 应用于解决现实世界问题。凭借对解决实际问题的浓厚兴趣,他为 AI 与现实生活解决方案的交汇点带来了新的视角。
In this tutorial, we build a complete workflow for running Baidu’s Unlimited-OCR :https://huggingface.co/baidu/Unlimited-OCR model on document images and multi-page PDFs. We configure the GPU environment, install the required dependencies, load the 3B-parameter vision-language model with automatic selection of bfloat16 or float16, and generate structured sample documents for testing. We then evaluate both the tiled Gundam inference mode and the faster Base mode for single-page OCR before extending the pipeline to multi-page PDF parsing with PyMuPDF and infer_multi(). Throughout the workflow, we preserve long-context generation settings, repetition controls, and structured output handling to process dense layouts, tables, paragraphs, and cross-page content in a reproducible end-to-end pipeline.
We install the required libraries and prepare the Google Colab environment for Unlimited-OCR inference. We verify that a CUDA-enabled GPU is available and automatically choose bfloat16 or float16 based on hardware support. We then load the tokenizer and the 3B-parameter model from Hugging Face, switch them to evaluation mode, and move them to the GPU.
We create the required input and output directories and generate three realistic sample document pages with PIL. We add headings, paragraphs, tables, and footnotes to test the model on structured, layout-rich content. We also preview the first generated page with Matplotlib before sending it to the OCR pipeline.
We run single-image OCR using Gundam mode, which combines a global document view with tiled image crops. We enable crop_mode and use a smaller tile size to preserve fine text and improve recognition on dense document layouts. We also configure long-output generation and repetition controls to ensure the model produces stable, structured results.
We process the same document using Base mode with a single 1024-pixel image view. We turn off image cropping to reduce inference complexity and improve processing speed for clean, clearly printed pages. We retain the same output length and repetition-control settings to directly compare Base mode with Gundam mode.
We create a three-page PDF from the generated document images and rasterize each page of the PDF into a high-resolution PNG using PyMuPDF. We pass the resulting page-image sequence to infer_multi() so that the model can parse the complete document in a single long-horizon inference operation. We also widen the n-gram repetition window to maintain stable decoding across multiple pages.
We inspect the output directories created by the single-page and multi-page inference runs. We list every generated file and display previews of supported text, Markdown, MMD, and JSON artifacts. We conclude the workflow with a concise reference summarizing the recommended inference modes for dense images, clean pages, and multi-page PDFs.
In conclusion, we completed a practical OCR pipeline that handles both high-detail single-page documents and long multi-page PDFs within Google Colab. We compared Gundam and Base inference modes, rasterized PDFs into model-ready page images, ran long-horizon document parsing, and inspected the generated text, Markdown, and auxiliary artifacts directly from the output directories. We also configured the workflow to adapt to different GPU capabilities while retaining the generation parameters required for stable long-document decoding. It provides us with 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.
Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us :https://forms.gle/wbash1wF6efRj8G58
Sana Hassan, a consulting intern at Marktechpost and dual-degree student at IIT Madras, is passionate about applying technology and AI to address real-world challenges. With a keen interest in solving practical problems, he brings a fresh perspective to the intersection of AI and real-life solutions.