tao.mo

MinerU源码上传

mt
2025年10月31日14:20:47
1 +# 解决 numpy>=1.21.6 安装错误
2 +
3 +## 问题描述
4 +在安装 MinerU 项目依赖时遇到错误:
5 +```
6 +ERROR: Could not find a version that satisfies the requirement numpy>=1.21.6
7 +```
8 +
9 +## 解决方案
10 +
11 +### 方案 1:使用 --user 选项安装(推荐)
12 +
13 +由于 Windows 权限问题,推荐使用 `--user` 选项安装到用户目录:
14 +
15 +```bash
16 +python -m pip install --user --upgrade pip
17 +python -m pip install --user numpy>=1.21.6
18 +```
19 +
20 +### 方案 2:使用国内镜像源(推荐中国用户)
21 +
22 +如果网络较慢,可以使用国内镜像源加速安装:
23 +
24 +#### 临时使用镜像源:
25 +```bash
26 +# 使用清华大学镜像源
27 +python -m pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple numpy>=1.21.6
28 +
29 +# 或者使用阿里云镜像源
30 +python -m pip install --user -i https://mirrors.aliyun.com/pypi/simple/ numpy>=1.21.6
31 +
32 +# 或者使用中科大镜像源
33 +python -m pip install --user -i https://pypi.mirrors.ustc.edu.cn/simple/ numpy>=1.21.6
34 +```
35 +
36 +#### 永久配置镜像源:
37 +创建或编辑 pip 配置文件:
38 +- Windows: `%APPDATA%\pip\pip.ini`
39 +- 或在用户目录下创建 `pip.ini`
40 +
41 +添加以下内容:
42 +```ini
43 +[global]
44 +index-url = https://pypi.tuna.tsinghua.edu.cn/simple
45 +[install]
46 +trusted-host = pypi.tuna.tsinghua.edu.cn
47 +```
48 +
49 +### 方案 3:安装完整项目依赖
50 +
51 +如果需要安装整个 MinerU 项目,可以:
52 +
53 +```bash
54 +# 使用 --user 选项
55 +python -m pip install --user -e .
56 +
57 +# 或使用国内镜像源
58 +python -m pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple -e .
59 +```
60 +
61 +### 方案 4:修复 pip 警告(可选)
62 +
63 +如果看到如下警告:
64 +```
65 +WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages)
66 +```
67 +
68 +可以尝试修复:
69 +
70 +```bash
71 +# 找到损坏的包目录(通常是 ~ip 或 ~ 开头)
72 +# 然后手动删除它们,或运行:
73 +python -m pip cache purge
74 +```
75 +
76 +### 方案 5:以管理员权限运行(如果上述方案都不行)
77 +
78 +1. 右键点击命令提示符或 PowerShell
79 +2. 选择"以管理员身份运行"
80 +3. 然后执行安装命令
81 +
82 +## 验证安装
83 +
84 +安装完成后,可以验证:
85 +
86 +```bash
87 +python -c "import numpy; print(numpy.__version__)"
88 +```
89 +
90 +应该输出类似:`2.3.4` 或更高版本
91 +
92 +## 注意事项
93 +
94 +1. **Python 版本要求**:MinerU 要求 Python >=3.10,<3.14,当前版本 3.12.1 符合要求
95 +2. **权限问题**:Windows 上安装全局包可能需要管理员权限,推荐使用 `--user` 选项
96 +3. **网络问题**:如果下载速度慢,强烈建议使用国内镜像源
97 +4. **PATH 配置**:升级 pip 后,如果提示 PATH 问题,可以手动添加到环境变量,或使用 `python -m pip` 代替 `pip`
98 +
99 +## 常用镜像源
100 +
101 +- 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
102 +- 阿里云:https://mirrors.aliyun.com/pypi/simple/
103 +- 中科大:https://pypi.mirrors.ustc.edu.cn/simple
104 +- 豆瓣:https://pypi.douban.com/simple/
105 +
106 +
1 +Metadata-Version: 2.4
2 +Name: mineru
3 +Version: 2.6.2
4 +Summary: A practical tool for converting PDF to Markdown
5 +License: AGPL-3.0
6 +Project-URL: homepage, https://mineru.net/
7 +Project-URL: documentation, https://opendatalab.github.io/MinerU/
8 +Project-URL: repository, https://github.com/opendatalab/MinerU
9 +Project-URL: issues, https://github.com/opendatalab/MinerU/issues
10 +Keywords: magic-pdf,mineru,MinerU,convert,pdf,markdown
11 +Classifier: Programming Language :: Python :: 3.10
12 +Classifier: Programming Language :: Python :: 3.11
13 +Classifier: Programming Language :: Python :: 3.12
14 +Classifier: Programming Language :: Python :: 3.13
15 +Requires-Python: <3.14,>=3.10
16 +Description-Content-Type: text/markdown
17 +License-File: LICENSE.md
18 +Requires-Dist: boto3>=1.28.43
19 +Requires-Dist: click>=8.1.7
20 +Requires-Dist: loguru>=0.7.2
21 +Requires-Dist: numpy>=1.21.6
22 +Requires-Dist: pdfminer.six==20250506
23 +Requires-Dist: tqdm>=4.67.1
24 +Requires-Dist: requests
25 +Requires-Dist: httpx
26 +Requires-Dist: pillow>=11.0.0
27 +Requires-Dist: pypdfium2>=4.30.0
28 +Requires-Dist: pypdf>=5.6.0
29 +Requires-Dist: reportlab
30 +Requires-Dist: pdftext>=0.6.2
31 +Requires-Dist: modelscope>=1.26.0
32 +Requires-Dist: huggingface-hub>=0.32.4
33 +Requires-Dist: json-repair>=0.46.2
34 +Requires-Dist: opencv-python>=4.11.0.86
35 +Requires-Dist: fast-langdetect<0.3.0,>=0.2.3
36 +Requires-Dist: scikit-image<1.0.0,>=0.25.0
37 +Requires-Dist: openai<3,>=1.70.0
38 +Requires-Dist: beautifulsoup4<5,>=4.13.5
39 +Requires-Dist: magika<0.7.0,>=0.6.2
40 +Requires-Dist: mineru-vl-utils<1,>=0.1.14
41 +Provides-Extra: test
42 +Requires-Dist: mineru[core]; extra == "test"
43 +Requires-Dist: pytest; extra == "test"
44 +Requires-Dist: pytest-cov; extra == "test"
45 +Requires-Dist: coverage; extra == "test"
46 +Requires-Dist: fuzzywuzzy; extra == "test"
47 +Provides-Extra: vlm
48 +Requires-Dist: torch<3,>=2.6.0; extra == "vlm"
49 +Requires-Dist: transformers<5.0.0,>=4.51.1; extra == "vlm"
50 +Requires-Dist: accelerate>=1.5.1; extra == "vlm"
51 +Provides-Extra: vllm
52 +Requires-Dist: vllm<0.12,>=0.10.1.1; extra == "vllm"
53 +Provides-Extra: pipeline
54 +Requires-Dist: matplotlib<4,>=3.10; extra == "pipeline"
55 +Requires-Dist: ultralytics<9,>=8.3.48; extra == "pipeline"
56 +Requires-Dist: doclayout_yolo==0.0.4; extra == "pipeline"
57 +Requires-Dist: dill<1,>=0.3.8; extra == "pipeline"
58 +Requires-Dist: PyYAML<7,>=6.0.2; extra == "pipeline"
59 +Requires-Dist: ftfy<7,>=6.3.1; extra == "pipeline"
60 +Requires-Dist: shapely<3,>=2.0.7; extra == "pipeline"
61 +Requires-Dist: pyclipper<2,>=1.3.0; extra == "pipeline"
62 +Requires-Dist: omegaconf<3,>=2.3.0; extra == "pipeline"
63 +Requires-Dist: torch<3,>=2.6.0; extra == "pipeline"
64 +Requires-Dist: torchvision; extra == "pipeline"
65 +Requires-Dist: transformers!=4.51.0,<5.0.0,>=4.49.0; extra == "pipeline"
66 +Requires-Dist: onnxruntime>1.17.0; extra == "pipeline"
67 +Provides-Extra: api
68 +Requires-Dist: fastapi; extra == "api"
69 +Requires-Dist: python-multipart; extra == "api"
70 +Requires-Dist: uvicorn; extra == "api"
71 +Provides-Extra: gradio
72 +Requires-Dist: gradio<6,>=5.34; extra == "gradio"
73 +Requires-Dist: gradio-pdf>=0.0.22; extra == "gradio"
74 +Provides-Extra: core
75 +Requires-Dist: mineru[vlm]; extra == "core"
76 +Requires-Dist: mineru[pipeline]; extra == "core"
77 +Requires-Dist: mineru[api]; extra == "core"
78 +Requires-Dist: mineru[gradio]; extra == "core"
79 +Provides-Extra: all
80 +Requires-Dist: mineru[core]; extra == "all"
81 +Requires-Dist: mineru[vllm]; extra == "all"
82 +Dynamic: license-file
83 +
84 +<div align="center" xmlns="http://www.w3.org/1999/html">
85 +<!-- logo -->
86 +<p align="center">
87 + <img src="https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docs/images/MinerU-logo.png" width="300px" style="vertical-align:middle;">
88 +</p>
89 +
90 +<!-- icon -->
91 +
92 +[![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU)
93 +[![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU)
94 +[![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues)
95 +[![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues)
96 +[![PyPI version](https://img.shields.io/pypi/v/mineru)](https://pypi.org/project/mineru/)
97 +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mineru)](https://pypi.org/project/mineru/)
98 +[![Downloads](https://static.pepy.tech/badge/mineru)](https://pepy.tech/project/mineru)
99 +[![Downloads](https://static.pepy.tech/badge/mineru/month)](https://pepy.tech/project/mineru)
100 +[![OpenDataLab](https://img.shields.io/badge/webapp_on_mineru.net-blue?logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTM0IiBoZWlnaHQ9IjEzNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJtMTIyLDljMCw1LTQsOS05LDlzLTktNC05LTksNC05LDktOSw5LDQsOSw5eiIgZmlsbD0idXJsKCNhKSIvPjxwYXRoIGQ9Im0xMjIsOWMwLDUtNCw5LTksOXMtOS00LTktOSw0LTksOS05LDksNCw5LDl6IiBmaWxsPSIjMDEwMTAxIi8+PHBhdGggZD0ibTkxLDE4YzAsNS00LDktOSw5cy05LTQtOS05LDQtOSw5LTksOSw0LDksOXoiIGZpbGw9InVybCgjYikiLz48cGF0aCBkPSJtOTEsMThjMCw1LTQsOS05LDlzLTktNC05LTksNC05LDktOSw5LDQsOSw5eiIgZmlsbD0iIzAxMDEwMSIvPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJtMzksNjJjMCwxNiw4LDMwLDIwLDM4LDctNiwxMi0xNiwxMi0yNlY0OWMwLTQsMy03LDYtOGw0Ni0xMmM1LTEsMTEsMywxMSw4djMxYzAsMzctMzAsNjYtNjYsNjYtMzcsMC02Ni0zMC02Ni02NlY0NmMwLTQsMy03LDYtOGwyMC02YzUtMSwxMSwzLDExLDh2MjF6bS0yOSw2YzAsMTYsNiwzMCwxNyw0MCwzLDEsNSwxLD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0b3AtY29sb3I9IiNmZmYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiMyZTJlMmUiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48L3N2Zz4=&labelColor=white)](https://mineru.net/OpenSourceTools/Extractor?source=github)
101 +[![HuggingFace](https://img.shields.io/badge/Demo_on_HuggingFace-yellow.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF8AAABYCAMAAACkl9t/AAAAk1BMVEVHcEz/nQv/nQv/nQr/nQv/nQr/nQv/nQv/nQr/wRf/txT/pg7/yRr/rBD/zRz/ngv/oAz/zhz/nwv/txT/ngv/0B3+zBz/nQv/0h7/wxn/vRb/thXkuiT/rxH/pxD/ogzcqyf/nQvTlSz/czCxky7/SjifdjT/Mj3+Mj3wMj15aTnDNz+DSD9RTUBsP0FRO0Q6O0WyIxEIAAAAGHRSTlMADB8zSWF3krDDw8TJ1NbX5efv8ff9/fxKDJ9uAAAGKklEQVR42u2Z63qjOAyGC4RwCOfB2JAGqrSb2WnTw/1f3UaWcSGYNKTdf/P+mOkTrE+yJBulvfvLT2A5ruenaVHyIks33npl/6C4s/ZLAM45SOi/1FtZPyFur1OYofBX3w7d54Bxm+E8db+nDr12ttmESZ4zludJEG5S7TO72YPlKZFyE+YCYUJTBZsMiNS5Sd7NlDmKM2Eg2JQg8awbglfqgbhArjxkS7dgp2RH6hc9AMLdZYUtZN5DJr4molC8BfKrEkPKEnEVjLbgW1fLy77ZVOJagoIcLIl+IxaQZGjiX597HopF5CkaXVMDO9Pyix3AFV3kw4lQLCbHuMovz8FallbcQIJ5Ta0vks9RnolbCK84BtjKRS5uA43hYoZcOBGIG2Epbv6CvFVQ8m8loh66WNySsnN7htL58LNp+NXT8/PhXiBXPMjLSxtwp8W9f/1AngRierBkA+kk/IpUSOeKByzn8y3kAAAfh//0oXgV4roHm/kz4E2z//zRc3/lgwBzbM2mJxQEa5pqgX7d1L0htrhx7LKxOZlKbwcAWyEOWqY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Paz0IGcOvTHvUIlE2+prqAxLSQxZlU2stql1NqCCLdIiIN/i1DBEHUoElM9dBravbiAnKqgpi4IBkw+utSPIoBijDXJipSVV7MpOEJUAc5Qmm3BnUN+w3hteEieYKfRZSIUcXKMVf0u5wD4EwsUNVvZOtUT7A2GkffHjByWpHqvRBYrTV72a6j8zZ6W0DTE86Hn04bmyWX3Ri9WH7ZU6Q7h+ZHo0nHUAcsQvVhXRDZHChwiyi/hnPuOsSEF6Exk3o6Y9DT1eZ+6cASXk2Y9k+6EOQMDGm6WBK10wOQJCBwren86cPPWUcRAnTVjGcU1LBgs9FURiX/e6479yZcLwCBmTxiawEwrOcleuu12t3tbLv/N4RLYIBhYexm7Fcn4OJcn0+zc+s8/VfPeddZHAGN6TT8eGczHdR/Gts1/MzDkThr23zqrVfAMFT33Nx1RJsx1k5zuWILLnG/vsH+Fv5D4NTVcp1Gzo8AAAAAElFTkSuQmCC&labelColor=white)](https://huggingface.co/spaces/opendatalab/MinerU)
102 +[![ModelScope](https://img.shields.io/badge/Demo_on_ModelScope-purple?logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjIzIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KCiA8Zz4KICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgPHBhdGggaWQ9InN2Z18xNCIgZmlsbD0iIzYyNGFmZiIgZD0ibTAsODkuODRsMjUuNjUsMGwwLDI1LjY0OTk5bC0yNS42NSwwbDAsLTI1LjY0OTk5eiIvPgogIDxwYXRoIGlkPSJzdmdfMTUiIGZpbGw9IiM2MjRhZmYiIGQ9Im05OS4xNCwxMTUuNDlsMjUuNjUsMGwwLDI1LjY1bC0yNS42NSwwbDAsLTI1LjY1eiIvPgogIDxwYXRoIGlkPSJzdmdfMTYiIGZpbGw9IiM2MjRhZmYiIGQ9Im0xNzYuMDksMTQxLjE0bC0yNS42NDk5OSwwbDAsMjIuMTl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wtMjIuMTksMGwwLDQ3Ljg0bDQ3Ljg0LDBsMCwtMjIuMTlsLTI1LjY1LDBsMCwtMjUuNjV6Ii8+CiA8L2c+Cjwvc3ZnPg==&labelColor=white)](https://www.modelscope.cn/studios/OpenDataLab/MinerU)
103 +[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/myhloli/a3cb16570ab3cfeadf9d8f0ac91b4fca/mineru_demo.ipynb)
104 +[![arXiv](https://img.shields.io/badge/MinerU-Technical%20Report-b31b1b.svg?logo=arXiv)](https://arxiv.org/abs/2409.18839)
105 +[![arXiv](https://img.shields.io/badge/MinerU2.5-Technical%20Report-b31b1b.svg?logo=arXiv)](https://arxiv.org/abs/2509.22186)
106 +[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/opendatalab/MinerU)
107 +
108 +
109 +<a href="https://trendshift.io/repositories/11174" target="_blank"><img src="https://trendshift.io/api/badge/repositories/11174" alt="opendatalab%2FMinerU | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
110 +
111 +<!-- language -->
112 +
113 +[English](README.md) | [简体中文](README_zh-CN.md)
114 +
115 +<!-- hot link -->
116 +
117 +<p align="center">
118 +🚀<a href="https://mineru.net/?source=github">Access MinerU Now→✅ Zero-Install Web Version ✅ Full-Featured Desktop Client ✅ Instant API Access; Skip deployment headaches – get all product formats in one click. Developers, dive in!</a>
119 +</p>
120 +
121 +<!-- join us -->
122 +
123 +<p align="center">
124 + 👋 join us on <a href="https://discord.gg/Tdedn9GTXq" target="_blank">Discord</a> and <a href="https://mineru.net/community-portal/?aliasId=3c430f94" target="_blank">WeChat</a>
125 +</p>
126 +
127 +</div>
128 +
129 +# Changelog
130 +- 2025/10/24 2.6.2 Release
131 + - `pipeline` backend optimizations
132 + - Added experimental support for Chinese formulas, which can be enabled by setting the environment variable `export MINERU_FORMULA_CH_SUPPORT=1`. This feature may cause a slight decrease in MFR speed and failures in recognizing some long formulas. It is recommended to enable it only when parsing Chinese formulas is needed. To disable this feature, set the environment variable to `0`.
133 + - `OCR` speed significantly improved by 200%~300%, thanks to the optimization solution provided by [@cjsdurj](https://github.com/cjsdurj)
134 + - `OCR` models optimized for improved accuracy and coverage of Latin script recognition, and updated Cyrillic, Arabic, Devanagari, Telugu (te), and Tamil (ta) language systems to `ppocr-v5` version, with accuracy improved by over 40% compared to previous models
135 + - `vlm` backend optimizations
136 + - `table_caption` and `table_footnote` matching logic optimized to improve the accuracy of table caption and footnote matching and reading order rationality in scenarios with multiple consecutive tables on a page
137 + - Optimized CPU resource usage during high concurrency when using `vllm` backend, reducing server pressure
138 + - Adapted to `vllm` version 0.11.0
139 + - General optimizations
140 + - Cross-page table merging effect optimized, added support for cross-page continuation table merging, improving table merging effectiveness in multi-column merge scenarios
141 + - Added environment variable configuration option `MINERU_TABLE_MERGE_ENABLE` for table merging feature. Table merging is enabled by default and can be disabled by setting this variable to `0`
142 +
143 +- 2025/09/26 2.5.4 released
144 + - 🎉🎉 The MinerU2.5 [Technical Report](https://arxiv.org/abs/2509.22186) is now available! We welcome you to read it for a comprehensive overview of its model architecture, training strategy, data engineering and evaluation results.
145 + - Fixed an issue where some `PDF` files were mistakenly identified as `AI` files, causing parsing failures
146 +
147 +- 2025/09/20 2.5.3 Released
148 + - Dependency version range adjustment to enable Turing and earlier architecture GPUs to use vLLM acceleration for MinerU2.5 model inference.
149 + - `pipeline` backend compatibility fixes for torch 2.8.0.
150 + - Reduced default concurrency for vLLM async backend to lower server pressure and avoid connection closure issues caused by high load.
151 + - More compatibility-related details can be found in the [announcement](https://github.com/opendatalab/MinerU/discussions/3548)
152 +
153 +- 2025/09/19 2.5.2 Released
154 +
155 + We are officially releasing MinerU2.5, currently the most powerful multimodal large model for document parsing.
156 + With only 1.2B parameters, MinerU2.5's accuracy on the OmniDocBench benchmark comprehensively surpasses top-tier multimodal models like Gemini 2.5 Pro, GPT-4o, and Qwen2.5-VL-72B. It also significantly outperforms leading specialized models such as dots.ocr, MonkeyOCR, and PP-StructureV3.
157 + The model has been released on [HuggingFace](https://huggingface.co/opendatalab/MinerU2.5-2509-1.2B) and [ModelScope](https://modelscope.cn/models/opendatalab/MinerU2.5-2509-1.2B) platforms. Welcome to download and use!
158 + - Core Highlights:
159 + - SOTA Performance with Extreme Efficiency: As a 1.2B model, it achieves State-of-the-Art (SOTA) results that exceed models in the 10B and 100B+ classes, redefining the performance-per-parameter standard in document AI.
160 + - Advanced Architecture for Across-the-Board Leadership: By combining a two-stage inference pipeline (decoupling layout analysis from content recognition) with a native high-resolution architecture, it achieves SOTA performance across five key areas: layout analysis, text recognition, formula recognition, table recognition, and reading order.
161 + - Key Capability Enhancements:
162 + - Layout Detection: Delivers more complete results by accurately covering non-body content like headers, footers, and page numbers. It also provides more precise element localization and natural format reconstruction for lists and references.
163 + - Table Parsing: Drastically improves parsing for challenging cases, including rotated tables, borderless/semi-structured tables, and long/complex tables.
164 + - Formula Recognition: Significantly boosts accuracy for complex, long-form, and hybrid Chinese-English formulas, greatly enhancing the parsing capability for mathematical documents.
165 +
166 + Additionally, with the release of vlm 2.5, we have made some adjustments to the repository:
167 + - The vlm backend has been upgraded to version 2.5, supporting the MinerU2.5 model and no longer compatible with the MinerU2.0-2505-0.9B model. The last version supporting the 2.0 model is mineru-2.2.2.
168 + - VLM inference-related code has been moved to [mineru_vl_utils](https://github.com/opendatalab/mineru-vl-utils), reducing coupling with the main mineru repository and facilitating independent iteration in the future.
169 + - The vlm accelerated inference framework has been switched from `sglang` to `vllm`, achieving full compatibility with the vllm ecosystem, allowing users to use the MinerU2.5 model and accelerated inference on any platform that supports the vllm framework.
170 + - Due to major upgrades in the vlm model supporting more layout types, we have made some adjustments to the structure of the parsing intermediate file `middle.json` and result file `content_list.json`. Please refer to the [documentation](https://opendatalab.github.io/MinerU/reference/output_files/) for details.
171 +
172 + Other repository optimizations:
173 + - Removed file extension whitelist validation for input files. When input files are PDF documents or images, there are no longer requirements for file extensions, improving usability.
174 +
175 +<details>
176 + <summary>History Log</summary>
177 +
178 + <details>
179 + <summary>2025/09/10 2.2.2 Released</summary>
180 + <ul>
181 + <li>Fixed the issue where the new table recognition model would affect the overall parsing task when some table parsing failed</li>
182 + </ul>
183 + </details>
184 +
185 + <details>
186 + <summary>2025/09/08 2.2.1 Released</summary>
187 + <ul>
188 + <li>Fixed the issue where some newly added models were not downloaded when using the model download command.</li>
189 + </ul>
190 + </details>
191 +
192 + <details>
193 + <summary>2025/09/05 2.2.0 Released</summary>
194 + <ul>
195 + <li>
196 + Major Updates
197 + <ul>
198 + <li>In this version, we focused on improving table parsing accuracy by introducing a new <a href="https://github.com/RapidAI/TableStructureRec">wired table recognition model</a> and a brand-new hybrid table structure parsing algorithm, significantly enhancing the table recognition capabilities of the <code>pipeline</code> backend.</li>
199 + <li>We also added support for cross-page table merging, which is supported by both <code>pipeline</code> and <code>vlm</code> backends, further improving the completeness and accuracy of table parsing.</li>
200 + </ul>
201 + </li>
202 + <li>
203 + Other Updates
204 + <ul>
205 + <li>The <code>pipeline</code> backend now supports 270-degree rotated table parsing, bringing support for table parsing in 0/90/270-degree orientations</li>
206 + <li><code>pipeline</code> added OCR capability support for Thai and Greek, and updated the English OCR model to the latest version. English recognition accuracy improved by 11%, Thai recognition model accuracy is 82.68%, and Greek recognition model accuracy is 89.28% (by PPOCRv5)</li>
207 + <li>Added <code>bbox</code> field (mapped to 0-1000 range) in the output <code>content_list.json</code>, making it convenient for users to directly obtain position information for each content block</li>
208 + <li>Removed the <code>pipeline_old_linux</code> installation option, no longer supporting legacy Linux systems such as <code>CentOS 7</code>, to provide better support for <code>uv</code>'s <code>sync</code>/<code>run</code> commands</li>
209 + </ul>
210 + </li>
211 + </ul>
212 + </details>
213 +
214 + <details>
215 + <summary>2025/08/01 2.1.10 Released</summary>
216 + <ul>
217 + <li>Fixed an issue in the <code>pipeline</code> backend where block overlap caused the parsing results to deviate from expectations #3232</li>
218 + </ul>
219 + </details>
220 +
221 + <details>
222 + <summary>2025/07/30 2.1.9 Released</summary>
223 + <ul>
224 + <li><code>transformers</code> 4.54.1 version adaptation</li>
225 + </ul>
226 + </details>
227 +
228 + <details>
229 + <summary>2025/07/28 2.1.8 Released</summary>
230 + <ul>
231 + <li><code>sglang</code> 0.4.9.post5 version adaptation</li>
232 + </ul>
233 + </details>
234 +
235 + <details>
236 + <summary>2025/07/27 2.1.7 Released</summary>
237 + <ul>
238 + <li><code>transformers</code> 4.54.0 version adaptation</li>
239 + </ul>
240 + </details>
241 +
242 + <details>
243 + <summary>2025/07/26 2.1.6 Released</summary>
244 + <ul>
245 + <li>Fixed table parsing issues in handwritten documents when using <code>vlm</code> backend</li>
246 + <li>Fixed visualization box position drift issue when document is rotated #3175</li>
247 + </ul>
248 + </details>
249 +
250 + <details>
251 + <summary>2025/07/24 2.1.5 Released</summary>
252 + <ul>
253 + <li><code>sglang</code> 0.4.9 version adaptation, synchronously upgrading the dockerfile base image to sglang 0.4.9.post3</li>
254 + </ul>
255 + </details>
256 +
257 + <details>
258 + <summary>2025/07/23 2.1.4 Released</summary>
259 + <ul>
260 + <li><strong>Bug Fixes</strong>
261 + <ul>
262 + <li>Fixed the issue of excessive memory consumption during the <code>MFR</code> step in the <code>pipeline</code> backend under certain scenarios #2771</li>
263 + <li>Fixed the inaccurate matching between <code>image</code>/<code>table</code> and <code>caption</code>/<code>footnote</code> under certain conditions #3129</li>
264 + </ul>
265 + </li>
266 + </ul>
267 + </details>
268 +
269 + <details>
270 + <summary>2025/07/16 2.1.1 Released</summary>
271 + <ul>
272 + <li><strong>Bug fixes</strong>
273 + <ul>
274 + <li>Fixed text block content loss issue that could occur in certain <code>pipeline</code> scenarios #3005</li>
275 + <li>Fixed issue where <code>sglang-client</code> required unnecessary packages like <code>torch</code> #2968</li>
276 + <li>Updated <code>dockerfile</code> to fix incomplete text content parsing due to missing fonts in Linux #2915</li>
277 + </ul>
278 + </li>
279 + <li><strong>Usability improvements</strong>
280 + <ul>
281 + <li>Updated <code>compose.yaml</code> to facilitate direct startup of <code>sglang-server</code>, <code>mineru-api</code>, and <code>mineru-gradio</code> services</li>
282 + <li>Launched brand new <a href="https://opendatalab.github.io/MinerU/">online documentation site</a>, simplified readme, providing better documentation experience</li>
283 + </ul>
284 + </li>
285 + </ul>
286 + </details>
287 +
288 + <details>
289 + <summary>2025/07/05 2.1.0 Released</summary>
290 + <ul>
291 + <li>This is the first major update of MinerU 2, which includes a large number of new features and improvements, covering significant performance optimizations, user experience enhancements, and bug fixes. The detailed update contents are as follows:</li>
292 + <li><strong>Performance Optimizations:</strong>
293 + <ul>
294 + <li>Significantly improved preprocessing speed for documents with specific resolutions (around 2000 pixels on the long side).</li>
295 + <li>Greatly enhanced post-processing speed when the <code>pipeline</code> backend handles batch processing of documents with fewer pages (&lt;10 pages).</li>
296 + <li>Layout analysis speed of the <code>pipeline</code> backend has been increased by approximately 20%.</li>
297 + </ul>
298 + </li>
299 + <li><strong>Experience Enhancements:</strong>
300 + <ul>
301 + <li>Built-in ready-to-use <code>fastapi service</code> and <code>gradio webui</code>. For detailed usage instructions, please refer to <a href="https://opendatalab.github.io/MinerU/usage/quick_usage/#advanced-usage-via-api-webui-sglang-clientserver">Documentation</a>.</li>
302 + <li>Adapted to <code>sglang</code> version <code>0.4.8</code>, significantly reducing the GPU memory requirements for the <code>vlm-sglang</code> backend. It can now run on graphics cards with as little as <code>8GB GPU memory</code> (Turing architecture or newer).</li>
303 + <li>Added transparent parameter passing for all commands related to <code>sglang</code>, allowing the <code>sglang-engine</code> backend to receive all <code>sglang</code> parameters consistently with the <code>sglang-server</code>.</li>
304 + <li>Supports feature extensions based on configuration files, including <code>custom formula delimiters</code>, <code>enabling heading classification</code>, and <code>customizing local model directories</code>. For detailed usage instructions, please refer to <a href="https://opendatalab.github.io/MinerU/usage/quick_usage/#extending-mineru-functionality-with-configuration-files">Documentation</a>.</li>
305 + </ul>
306 + </li>
307 + <li><strong>New Features:</strong>
308 + <ul>
309 + <li>Updated the <code>pipeline</code> backend with the PP-OCRv5 multilingual text recognition model, supporting text recognition in 37 languages such as French, Spanish, Portuguese, Russian, and Korean, with an average accuracy improvement of over 30%. <a href="https://paddlepaddle.github.io/PaddleOCR/latest/en/version3.x/algorithm/PP-OCRv5/PP-OCRv5_multi_languages.html">Details</a></li>
310 + <li>Introduced limited support for vertical text layout in the <code>pipeline</code> backend.</li>
311 + </ul>
312 + </li>
313 + </ul>
314 + </details>
315 +
316 + <details>
317 + <summary>2025/06/20 2.0.6 Released</summary>
318 + <ul>
319 + <li>Fixed occasional parsing interruptions caused by invalid block content in <code>vlm</code> mode</li>
320 + <li>Fixed parsing interruptions caused by incomplete table structures in <code>vlm</code> mode</li>
321 + </ul>
322 + </details>
323 +
324 + <details>
325 + <summary>2025/06/17 2.0.5 Released</summary>
326 + <ul>
327 + <li>Fixed the issue where models were still required to be downloaded in the <code>sglang-client</code> mode</li>
328 + <li>Fixed the issue where the <code>sglang-client</code> mode unnecessarily depended on packages like <code>torch</code> during runtime.</li>
329 + <li>Fixed the issue where only the first instance would take effect when attempting to launch multiple <code>sglang-client</code> instances via multiple URLs within the same process</li>
330 + </ul>
331 + </details>
332 +
333 + <details>
334 + <summary>2025/06/15 2.0.3 released</summary>
335 + <ul>
336 + <li>Fixed a configuration file key-value update error that occurred when downloading model type was set to <code>all</code></li>
337 + <li>Fixed the issue where the formula and table feature toggle switches were not working in <code>command line mode</code>, causing the features to remain enabled.</li>
338 + <li>Fixed compatibility issues with sglang version 0.4.7 in the <code>sglang-engine</code> mode.</li>
339 + <li>Updated Dockerfile and installation documentation for deploying the full version of MinerU in sglang environment</li>
340 + </ul>
341 + </details>
342 +
343 + <details>
344 + <summary>2025/06/13 2.0.0 Released</summary>
345 + <ul>
346 + <li><strong>New Architecture</strong>: MinerU 2.0 has been deeply restructured in code organization and interaction methods, significantly improving system usability, maintainability, and extensibility.
347 + <ul>
348 + <li><strong>Removal of Third-party Dependency Limitations</strong>: Completely eliminated the dependency on <code>pymupdf</code>, moving the project toward a more open and compliant open-source direction.</li>
349 + <li><strong>Ready-to-use, Easy Configuration</strong>: No need to manually edit JSON configuration files; most parameters can now be set directly via command line or API.</li>
350 + <li><strong>Automatic Model Management</strong>: Added automatic model download and update mechanisms, allowing users to complete model deployment without manual intervention.</li>
351 + <li><strong>Offline Deployment Friendly</strong>: Provides built-in model download commands, supporting deployment requirements in completely offline environments.</li>
352 + <li><strong>Streamlined Code Structure</strong>: Removed thousands of lines of redundant code, simplified class inheritance logic, significantly improving code readability and development efficiency.</li>
353 + <li><strong>Unified Intermediate Format Output</strong>: Adopted standardized <code>middle_json</code> format, compatible with most secondary development scenarios based on this format, ensuring seamless ecosystem business migration.</li>
354 + </ul>
355 + </li>
356 + <li><strong>New Model</strong>: MinerU 2.0 integrates our latest small-parameter, high-performance multimodal document parsing model, achieving end-to-end high-speed, high-precision document understanding.
357 + <ul>
358 + <li><strong>Small Model, Big Capabilities</strong>: With parameters under 1B, yet surpassing traditional 72B-level vision-language models (VLMs) in parsing accuracy.</li>
359 + <li><strong>Multiple Functions in One</strong>: A single model covers multilingual recognition, handwriting recognition, layout analysis, table parsing, formula recognition, reading order sorting, and other core tasks.</li>
360 + <li><strong>Ultimate Inference Speed</strong>: Achieves peak throughput exceeding 10,000 tokens/s through <code>sglang</code> acceleration on a single NVIDIA 4090 card, easily handling large-scale document processing requirements.</li>
361 + <li><strong>Online Experience</strong>: You can experience our brand-new VLM model on <a href="https://mineru.net/OpenSourceTools/Extractor">MinerU.net</a>, <a href="https://huggingface.co/spaces/opendatalab/MinerU">Hugging Face</a>, and <a href="https://www.modelscope.cn/studios/OpenDataLab/MinerU">ModelScope</a>.</li>
362 + </ul>
363 + </li>
364 + <li><strong>Incompatible Changes Notice</strong>: To improve overall architectural rationality and long-term maintainability, this version contains some incompatible changes:
365 + <ul>
366 + <li>Python package name changed from <code>magic-pdf</code> to <code>mineru</code>, and the command-line tool changed from <code>magic-pdf</code> to <code>mineru</code>. Please update your scripts and command calls accordingly.</li>
367 + <li>For modular system design and ecosystem consistency considerations, MinerU 2.0 no longer includes the LibreOffice document conversion module. If you need to process Office documents, we recommend converting them to PDF format through an independently deployed LibreOffice service before proceeding with subsequent parsing operations.</li>
368 + </ul>
369 + </li>
370 + </ul>
371 + </details>
372 + <details>
373 + <summary>2025/05/24 Release 1.3.12</summary>
374 + <ul>
375 + <li>Added support for PPOCRv5 models, updated <code>ch_server</code> model to <code>PP-OCRv5_rec_server</code>, and <code>ch_lite</code> model to <code>PP-OCRv5_rec_mobile</code> (model update required)
376 + <ul>
377 + <li>In testing, we found that PPOCRv5(server) has some improvement for handwritten documents, but has slightly lower accuracy than v4_server_doc for other document types, so the default ch model remains unchanged as <code>PP-OCRv4_server_rec_doc</code>.</li>
378 + <li>Since PPOCRv5 has enhanced recognition capabilities for handwriting and special characters, you can manually choose the PPOCRv5 model for Japanese-Traditional Chinese mixed scenarios and handwritten documents</li>
379 + <li>You can select the appropriate model through the lang parameter <code>lang='ch_server'</code> (Python API) or <code>--lang ch_server</code> (command line):
380 + <ul>
381 + <li><code>ch</code>: <code>PP-OCRv4_server_rec_doc</code> (default) (Chinese/English/Japanese/Traditional Chinese mixed/15K dictionary)</li>
382 + <li><code>ch_server</code>: <code>PP-OCRv5_rec_server</code> (Chinese/English/Japanese/Traditional Chinese mixed + handwriting/18K dictionary)</li>
383 + <li><code>ch_lite</code>: <code>PP-OCRv5_rec_mobile</code> (Chinese/English/Japanese/Traditional Chinese mixed + handwriting/18K dictionary)</li>
384 + <li><code>ch_server_v4</code>: <code>PP-OCRv4_rec_server</code> (Chinese/English mixed/6K dictionary)</li>
385 + <li><code>ch_lite_v4</code>: <code>PP-OCRv4_rec_mobile</code> (Chinese/English mixed/6K dictionary)</li>
386 + </ul>
387 + </li>
388 + </ul>
389 + </li>
390 + <li>Added support for handwritten documents through optimized layout recognition of handwritten text areas
391 + <ul>
392 + <li>This feature is supported by default, no additional configuration required</li>
393 + <li>You can refer to the instructions above to manually select the PPOCRv5 model for better handwritten document parsing results</li>
394 + </ul>
395 + </li>
396 + <li>The <code>huggingface</code> and <code>modelscope</code> demos have been updated to versions that support handwriting recognition and PPOCRv5 models, which you can experience online</li>
397 + </ul>
398 + </details>
399 +
400 + <details>
401 + <summary>2025/04/29 Release 1.3.10</summary>
402 + <ul>
403 + <li>Added support for custom formula delimiters, which can be configured by modifying the <code>latex-delimiter-config</code> section in the <code>magic-pdf.json</code> file in your user directory.</li>
404 + </ul>
405 + </details>
406 +
407 + <details>
408 + <summary>2025/04/27 Release 1.3.9</summary>
409 + <ul>
410 + <li>Optimized formula parsing functionality, improved formula rendering success rate</li>
411 + </ul>
412 + </details>
413 +
414 + <details>
415 + <summary>2025/04/23 Release 1.3.8</summary>
416 + <ul>
417 + <li>The default <code>ocr</code> model (<code>ch</code>) has been updated to <code>PP-OCRv4_server_rec_doc</code> (model update required)
418 + <ul>
419 + <li><code>PP-OCRv4_server_rec_doc</code> is trained on a mixture of more Chinese document data and PP-OCR training data based on <code>PP-OCRv4_server_rec</code>, adding recognition capabilities for some traditional Chinese characters, Japanese, and special characters. It can recognize over 15,000 characters and improves both document-specific and general text recognition abilities.</li>
420 + <li><a href="https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/text_recognition.html#_3">Performance comparison of PP-OCRv4_server_rec_doc/PP-OCRv4_server_rec/PP-OCRv4_mobile_rec</a></li>
421 + <li>After verification, the <code>PP-OCRv4_server_rec_doc</code> model shows significant accuracy improvements in Chinese/English/Japanese/Traditional Chinese in both single language and mixed language scenarios, with comparable speed to <code>PP-OCRv4_server_rec</code>, making it suitable for most use cases.</li>
422 + <li>In some pure English scenarios, <code>PP-OCRv4_server_rec_doc</code> may have word adhesion issues, while <code>PP-OCRv4_server_rec</code> performs better in these cases. Therefore, we've kept the <code>PP-OCRv4_server_rec</code> model, which users can access by adding the parameter <code>lang='ch_server'</code> (Python API) or <code>--lang ch_server</code> (command line).</li>
423 + </ul>
424 + </li>
425 + </ul>
426 + </details>
427 +
428 + <details>
429 + <summary>2025/04/22 Release 1.3.7</summary>
430 + <ul>
431 + <li>Fixed the issue where the lang parameter was ineffective during table parsing model initialization</li>
432 + <li>Fixed the significant speed reduction of OCR and table parsing in <code>cpu</code> mode</li>
433 + </ul>
434 + </details>
435 +
436 + <details>
437 + <summary>2025/04/16 Release 1.3.4</summary>
438 + <ul>
439 + <li>Slightly improved OCR-det speed by removing some unnecessary blocks</li>
440 + <li>Fixed page-internal sorting errors caused by footnotes in certain cases</li>
441 + </ul>
442 + </details>
443 +
444 + <details>
445 + <summary>2025/04/12 Release 1.3.2</summary>
446 + <ul>
447 + <li>Fixed dependency version incompatibility issues when installing on Windows with Python 3.13</li>
448 + <li>Optimized memory usage during batch inference</li>
449 + <li>Improved parsing of tables rotated 90 degrees</li>
450 + <li>Enhanced parsing of oversized tables in financial report samples</li>
451 + <li>Fixed the occasional word adhesion issue in English text areas when OCR language is not specified (model update required)</li>
452 + </ul>
453 + </details>
454 +
455 + <details>
456 + <summary>2025/04/08 Release 1.3.1</summary>
457 + <ul>
458 + <li>Fixed several compatibility issues
459 + <ul>
460 + <li>Added support for Python 3.13</li>
461 + <li>Made final adaptations for outdated Linux systems (such as CentOS 7) with no guarantee of continued support in future versions, <a href="https://github.com/opendatalab/MinerU/issues/1004">installation instructions</a></li>
462 + </ul>
463 + </li>
464 + </ul>
465 + </details>
466 +
467 + <details>
468 + <summary>2025/04/03 Release 1.3.0</summary>
469 + <ul>
470 + <li>Installation and compatibility optimizations
471 + <ul>
472 + <li>Resolved compatibility issues caused by <code>detectron2</code> by removing <code>layoutlmv3</code> usage in layout</li>
473 + <li>Extended torch version compatibility to 2.2~2.6 (excluding 2.5)</li>
474 + <li>Added CUDA compatibility for versions 11.8/12.4/12.6/12.8 (CUDA version determined by torch), solving compatibility issues for users with 50-series and H-series GPUs</li>
475 + <li>Extended Python compatibility to versions 3.10~3.12, fixing the issue of automatic downgrade to version 0.6.1 when installing in non-3.10 environments</li>
476 + <li>Optimized offline deployment process, eliminating the need to download any model files after successful deployment</li>
477 + </ul>
478 + </li>
479 + <li>Performance optimizations
480 + <ul>
481 + <li>Enhanced parsing speed for batches of small files by supporting batch processing of multiple PDF files (<a href="demo/batch_demo.py">script example</a>), with formula parsing speed improved by up to 1400% and overall parsing speed improved by up to 500% compared to version 1.0.1</li>
482 + <li>Reduced memory usage and improved parsing speed by optimizing MFR model loading and usage (requires re-running the <a href="docs/how_to_download_models_zh_cn.md">model download process</a> to get incremental updates to model files)</li>
483 + <li>Optimized GPU memory usage, requiring only 6GB minimum to run this project</li>
484 + <li>Improved running speed on MPS devices</li>
485 + </ul>
486 + </li>
487 + <li>Parsing effect optimizations
488 + <ul>
489 + <li>Updated MFR model to <code>unimernet(2503)</code>, fixing line break loss issues in multi-line formulas</li>
490 + </ul>
491 + </li>
492 + <li>Usability optimizations
493 + <ul>
494 + <li>Completely replaced the <code>paddle</code> framework and <code>paddleocr</code> in the project by using <code>paddleocr2torch</code>, resolving conflicts between <code>paddle</code> and <code>torch</code>, as well as thread safety issues caused by the <code>paddle</code> framework</li>
495 + <li>Added real-time progress bar display during parsing, allowing precise tracking of parsing progress and making the waiting process more bearable</li>
496 + </ul>
497 + </li>
498 + </ul>
499 + </details>
500 + <details>
501 + <summary>2025/03/03 1.2.1 released</summary>
502 + <ul>
503 + <li>Fixed the impact on punctuation marks during full-width to half-width conversion of letters and numbers</li>
504 + <li>Fixed caption matching inaccuracies in certain scenarios</li>
505 + <li>Fixed formula span loss issues in certain scenarios</li>
506 + </ul>
507 + </details>
508 +
509 + <details>
510 + <summary>2025/02/24 1.2.0 released</summary>
511 + <p>This version includes several fixes and improvements to enhance parsing efficiency and accuracy:</p>
512 + <ul>
513 + <li><strong>Performance Optimization</strong>
514 + <ul>
515 + <li>Increased classification speed for PDF documents in auto mode.</li>
516 + </ul>
517 + </li>
518 + <li><strong>Parsing Optimization</strong>
519 + <ul>
520 + <li>Improved parsing logic for documents containing watermarks, significantly enhancing the parsing results for such documents.</li>
521 + <li>Enhanced the matching logic for multiple images/tables and captions within a single page, improving the accuracy of image-text matching in complex layouts.</li>
522 + </ul>
523 + </li>
524 + <li><strong>Bug Fixes</strong>
525 + <ul>
526 + <li>Fixed an issue where image/table spans were incorrectly filled into text blocks under certain conditions.</li>
527 + <li>Resolved an issue where title blocks were empty in some cases.</li>
528 + </ul>
529 + </li>
530 + </ul>
531 + </details>
532 +
533 + <details>
534 + <summary>2025/01/22 1.1.0 released</summary>
535 + <p>In this version we have focused on improving parsing accuracy and efficiency:</p>
536 + <ul>
537 + <li><strong>Model capability upgrade</strong> (requires re-executing the <a href="https://github.com/opendatalab/MinerU/blob/master/docs/how_to_download_models_en.md">model download process</a> to obtain incremental updates of model files)
538 + <ul>
539 + <li>The layout recognition model has been upgraded to the latest <code>doclayout_yolo(2501)</code> model, improving layout recognition accuracy.</li>
540 + <li>The formula parsing model has been upgraded to the latest <code>unimernet(2501)</code> model, improving formula recognition accuracy.</li>
541 + </ul>
542 + </li>
543 + <li><strong>Performance optimization</strong>
544 + <ul>
545 + <li>On devices that meet certain configuration requirements (16GB+ VRAM), by optimizing resource usage and restructuring the processing pipeline, overall parsing speed has been increased by more than 50%.</li>
546 + </ul>
547 + </li>
548 + <li><strong>Parsing effect optimization</strong>
549 + <ul>
550 + <li>Added a new heading classification feature (testing version, enabled by default) to the online demo (<a href="https://mineru.net/OpenSourceTools/Extractor">mineru.net</a>/<a href="https://huggingface.co/spaces/opendatalab/MinerU">huggingface</a>/<a href="https://www.modelscope.cn/studios/OpenDataLab/MinerU">modelscope</a>), which supports hierarchical classification of headings, thereby enhancing document structuring.</li>
551 + </ul>
552 + </li>
553 + </ul>
554 + </details>
555 +
556 + <details>
557 + <summary>2025/01/10 1.0.1 released</summary>
558 + <p>This is our first official release, where we have introduced a completely new API interface and enhanced compatibility through extensive refactoring, as well as a brand new automatic language identification feature:</p>
559 + <ul>
560 + <li><strong>New API Interface</strong>
561 + <ul>
562 + <li>For the data-side API, we have introduced the Dataset class, designed to provide a robust and flexible data processing framework. This framework currently supports a variety of document formats, including images (.jpg and .png), PDFs, Word documents (.doc and .docx), and PowerPoint presentations (.ppt and .pptx). It ensures effective support for data processing tasks ranging from simple to complex.</li>
563 + <li>For the user-side API, we have meticulously designed the MinerU processing workflow as a series of composable Stages. Each Stage represents a specific processing step, allowing users to define new Stages according to their needs and creatively combine these stages to customize their data processing workflows.</li>
564 + </ul>
565 + </li>
566 + <li><strong>Enhanced Compatibility</strong>
567 + <ul>
568 + <li>By optimizing the dependency environment and configuration items, we ensure stable and efficient operation on ARM architecture Linux systems.</li>
569 + <li>We have deeply integrated with Huawei Ascend NPU acceleration, providing autonomous and controllable high-performance computing capabilities. This supports the localization and development of AI application platforms in China. <a href="https://github.com/opendatalab/MinerU/blob/master/docs/README_Ascend_NPU_Acceleration_zh_CN.md">Ascend NPU Acceleration</a></li>
570 + </ul>
571 + </li>
572 + <li><strong>Automatic Language Identification</strong>
573 + <ul>
574 + <li>By introducing a new language recognition model, setting the <code>lang</code> configuration to <code>auto</code> during document parsing will automatically select the appropriate OCR language model, improving the accuracy of scanned document parsing.</li>
575 + </ul>
576 + </li>
577 + </ul>
578 + </details>
579 +
580 + <details>
581 + <summary>2024/11/22 0.10.0 released</summary>
582 + <p>Introducing hybrid OCR text extraction capabilities:</p>
583 + <ul>
584 + <li>Significantly improved parsing performance in complex text distribution scenarios such as dense formulas, irregular span regions, and text represented by images.</li>
585 + <li>Combines the dual advantages of accurate content extraction and faster speed in text mode, and more precise span/line region recognition in OCR mode.</li>
586 + </ul>
587 + </details>
588 +
589 + <details>
590 + <summary>2024/11/15 0.9.3 released</summary>
591 + <p>Integrated <a href="https://github.com/RapidAI/RapidTable">RapidTable</a> for table recognition, improving single-table parsing speed by more than 10 times, with higher accuracy and lower GPU memory usage.</p>
592 + </details>
593 +
594 + <details>
595 + <summary>2024/11/06 0.9.2 released</summary>
596 + <p>Integrated the <a href="https://huggingface.co/U4R/StructTable-InternVL2-1B">StructTable-InternVL2-1B</a> model for table recognition functionality.</p>
597 + </details>
598 +
599 + <details>
600 + <summary>2024/10/31 0.9.0 released</summary>
601 + <p>This is a major new version with extensive code refactoring, addressing numerous issues, improving performance, reducing hardware requirements, and enhancing usability:</p>
602 + <ul>
603 + <li>Refactored the sorting module code to use <a href="https://github.com/ppaanngggg/layoutreader">layoutreader</a> for reading order sorting, ensuring high accuracy in various layouts.</li>
604 + <li>Refactored the paragraph concatenation module to achieve good results in cross-column, cross-page, cross-figure, and cross-table scenarios.</li>
605 + <li>Refactored the list and table of contents recognition functions, significantly improving the accuracy of list blocks and table of contents blocks, as well as the parsing of corresponding text paragraphs.</li>
606 + <li>Refactored the matching logic for figures, tables, and descriptive text, greatly enhancing the accuracy of matching captions and footnotes to figures and tables, and reducing the loss rate of descriptive text to near zero.</li>
607 + <li>Added multi-language support for OCR, supporting detection and recognition of 84 languages. For the list of supported languages, see <a href="https://paddlepaddle.github.io/PaddleOCR/latest/en/ppocr/blog/multi_languages.html#5-support-languages-and-abbreviations">OCR Language Support List</a>.</li>
608 + <li>Added memory recycling logic and other memory optimization measures, significantly reducing memory usage. The memory requirement for enabling all acceleration features except table acceleration (layout/formula/OCR) has been reduced from 16GB to 8GB, and the memory requirement for enabling all acceleration features has been reduced from 24GB to 10GB.</li>
609 + <li>Optimized configuration file feature switches, adding an independent formula detection switch to significantly improve speed and parsing results when formula detection is not needed.</li>
610 + <li>Integrated <a href="https://github.com/opendatalab/PDF-Extract-Kit">PDF-Extract-Kit 1.0</a>:
611 + <ul>
612 + <li>Added the self-developed <code>doclayout_yolo</code> model, which speeds up processing by more than 10 times compared to the original solution while maintaining similar parsing effects, and can be freely switched with <code>layoutlmv3</code> via the configuration file.</li>
613 + <li>Upgraded formula parsing to <code>unimernet 0.2.1</code>, improving formula parsing accuracy while significantly reducing memory usage.</li>
614 + <li>Due to the repository change for <code>PDF-Extract-Kit 1.0</code>, you need to re-download the model. Please refer to <a href="https://github.com/opendatalab/MinerU/blob/master/docs/how_to_download_models_en.md">How to Download Models</a> for detailed steps.</li>
615 + </ul>
616 + </li>
617 + </ul>
618 + </details>
619 +
620 + <details>
621 + <summary>2024/09/27 Version 0.8.1 released</summary>
622 + <p>Fixed some bugs, and providing a <a href="https://github.com/opendatalab/MinerU/blob/master/projects/web_demo/README.md">localized deployment version</a> of the <a href="https://opendatalab.com/OpenSourceTools/Extractor/PDF/">online demo</a> and the <a href="https://github.com/opendatalab/MinerU/blob/master/projects/web/README.md">front-end interface</a>.</p>
623 + </details>
624 +
625 + <details>
626 + <summary>2024/09/09 Version 0.8.0 released</summary>
627 + <p>Supporting fast deployment with Dockerfile, and launching demos on Huggingface and Modelscope.</p>
628 + </details>
629 +
630 + <details>
631 + <summary>2024/08/30 Version 0.7.1 released</summary>
632 + <p>Add paddle tablemaster table recognition option</p>
633 + </details>
634 +
635 + <details>
636 + <summary>2024/08/09 Version 0.7.0b1 released</summary>
637 + <p>Simplified installation process, added table recognition functionality</p>
638 + </details>
639 +
640 + <details>
641 + <summary>2024/08/01 Version 0.6.2b1 released</summary>
642 + <p>Optimized dependency conflict issues and installation documentation</p>
643 + </details>
644 +
645 + <details>
646 + <summary>2024/07/05 Initial open-source release</summary>
647 + </details>
648 +</details>
649 +
650 +# MinerU
651 +
652 +## Project Introduction
653 +
654 +MinerU is a tool that converts PDFs into machine-readable formats (e.g., markdown, JSON), allowing for easy extraction into any format.
655 +MinerU was born during the pre-training process of [InternLM](https://github.com/InternLM/InternLM). We focus on solving symbol conversion issues in scientific literature and hope to contribute to technological development in the era of large models.
656 +Compared to well-known commercial products, MinerU is still young. If you encounter any issues or if the results are not as expected, please submit an issue on [issue](https://github.com/opendatalab/MinerU/issues) and **attach the relevant PDF**.
657 +
658 +https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
659 +
660 +## Key Features
661 +
662 +- Remove headers, footers, footnotes, page numbers, etc., to ensure semantic coherence.
663 +- Output text in human-readable order, suitable for single-column, multi-column, and complex layouts.
664 +- Preserve the structure of the original document, including headings, paragraphs, lists, etc.
665 +- Extract images, image descriptions, tables, table titles, and footnotes.
666 +- Automatically recognize and convert formulas in the document to LaTeX format.
667 +- Automatically recognize and convert tables in the document to HTML format.
668 +- Automatically detect scanned PDFs and garbled PDFs and enable OCR functionality.
669 +- OCR supports detection and recognition of 84 languages.
670 +- Supports multiple output formats, such as multimodal and NLP Markdown, JSON sorted by reading order, and rich intermediate formats.
671 +- Supports various visualization results, including layout visualization and span visualization, for efficient confirmation of output quality.
672 +- Supports running in a pure CPU environment, and also supports GPU(CUDA)/NPU(CANN)/MPS acceleration
673 +- Compatible with Windows, Linux, and Mac platforms.
674 +
675 +# Quick Start
676 +
677 +If you encounter any installation issues, please first consult the <a href="#faq">FAQ</a>. </br>
678 +If the parsing results are not as expected, refer to the <a href="#known-issues">Known Issues</a>. </br>
679 +
680 +## Online Experience
681 +
682 +### Official online web application
683 +The official online version has the same functionality as the client, with a beautiful interface and rich features, requires login to use
684 +
685 +- [![OpenDataLab](https://img.shields.io/badge/webapp_on_mineru.net-blue?logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTM0IiBoZWlnaHQ9IjEzNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJtMTIyLDljMCw1LTQsOS05LDlzLTktNC05LTksNC05LDktOSw5LDQsOSw5eiIgZmlsbD0idXJsKCNhKSIvPjxwYXRoIGQ9Im0xMjIsOWMwLDUtNCw5LTksOXMtOS00LTktOSw0LTksOS05LDksNCw5LDl6IiBmaWxsPSIjMDEwMTAxIi8+PHBhdGggZD0ibTkxLDE4YzAsNS00LDktOSw5cy05LTQtOS05LDQtOSw5LTksOSw0LDksOXoiIGZpbGw9InVybCgjYikiLz48cGF0aCBkPSJtOTEsMThjMCw1LTQsOS05LDlzLTktNC05LTksNC05LDktOSw5LDQsOSw5eiIgZmlsbD0iIzAxMDEwMSIvPjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJtMzksNjJjMCwxNi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0b3AtY29sb3I9IiNmZmYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiMyZTJlMmUiLz48L2xpbmVhckdyYWRpZW50PjxsaW5lYXJHcmFkaWVudCBpZD0iYyIgeDE9Ijg0IiB5MT0iNDEiIHgyPSI3NSIgeTI9IjEyMCIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPjxzdG9wIHN0b3AtY29sb3I9IiNmZmYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiMyZTJlMmUiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48L3N2Zz4=&labelColor=white)](https://mineru.net/OpenSourceTools/Extractor?source=github)
686 +
687 +### Gradio-based online demo
688 +A WebUI developed based on Gradio, with a simple interface and only core parsing functionality, no login required
689 +
690 +- [![ModelScope](https://img.shields.io/badge/Demo_on_ModelScope-purple?logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjIzIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KCiA8Zz4KICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgPHBhdGggaWQ9InN2Z18xNCIgZmlsbD0iIzYyNGFmZiIgZD0ibTAsODkuODRsMjUuNjUsMGwwLDI1LjY0OTk5bC0yNS42NSwwbDAsLTI1LjY0OTk5eiIvPgogIDxwYXRoIGlkPSJzdmdfMTUiIGZpbGw9IiM2MjRhZmYiIGQ9Im05OS4xNCwxMTUuNDlsMjUuNjUsMGwwLDI1LjY1bC0yNS42NSwwbDAsLTI1LjY1eiIvPgogIDxwYXRoIGlkPSJzdmdfMTYiIGZpbGw9IiM2MjRhZmYiIGQ9Im0xNzYuMDksMTQxLjE0bC0yNS42NDk5OSwwbDAsMjIuMTlsNDcuODQsMGwwLC00Ny44NGwtMjIuMTksMGwwLDI1LjY1eiIvPgogIDxwYXRoIGlkPSJzdmdfMTciIGZpbGw9IiMzN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+Cjwvc3ZnPg==&labelColor=white)](https://www.modelscope.cn/studios/OpenDataLab/MinerU)
691 +- [![HuggingFace](https://img.shields.io/badge/Demo_on_HuggingFace-yellow.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF8AAABYCAMAAACkl9t/AAAAk1BMVEVHcEz/nQv/nQv/nQr/nQv/nQr/nQv/nQv/nQr/wRf/txT/pg7/yRr/rBD/zRz/ngv/oAz/zhz/nwv/txT/ngv/0B3+zBz/nQv/0h7/wxn/vRb/thXkuiT/rxH/pxD/ogzcqyf/nQvTlSz/czCxky7/SjifdjT/Mj3+Mj3wMj15aTnDNz+DSD9RTUBsP0FRO0Q6O0WyIxEIAAAAGHRSTlMADB8zSWF3krDDw8TJ1NbX5efv8ff9/fxKDJ9uAAAGKklEQVR42u2Z63qjOAyGC4RwCOfB2JAGqrSb2WnTw/1f3UaWcSGYNKTdf/P+mOkTrE+yJBulvfvLT2A5ruenaVHyIks33npl/6C4s/ZLAM45SOi/1FtZPyFur1OYofBX3w7d54Bxm+E8db+nDr12ttmESZ4zludJEG5S7TO72YPlKZFyE+YCYUJTBZsMiNS5Sd7NlDmKM2Eg2JQg8awbglfqgbhArjxkS7dgp2RH6hc9AMLdZYUtZN5DJr4molC8BfKrEkPKEnEVjLbgW1fLy77ZVOJagoIcLIl+IxaQZGjiX597HopF5CkaXVMDO9Pyix3AFV3kw4lQLCbHuMovz8FallbcQIJ5Ta0vks9RnolbCK84BtjKRS5uA43hYoZcOBGIG2Epbv6CvFVQ8m8loh66WNySsnN7htL58LNp+NXT8/PhXiBXPMjLSxtwp8W9f/1AngRierBkA+kk/IpUSOeKByzn8y3kAAAfh//0oXgV4roHm/kz4E2z//zRc3/lgwBzbM2mJxQEa5pqgX7d1L0htrhx7LKxOZlKbwcAWyEOWqYSI8YPtgDQVjpB5nvaHaSnBaQSD6hweDi8PosxD6/PT09YY3xQA7LTCTKfYX+QHpA0GCcqmEHvr/cyfKQTEuwgbs2kPxJEB0iNj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c5Qmm3BnUN+w3hteEieYKfRZSIUcXKMVf0u5wD4EwsUNVvZOtUT7A2GkffHjByWpHqvRBYrTV72a6j8zZ6W0DTE86Hn04bmyWX3Ri9WH7ZU6Q7h+ZHo0nHUAcsQvVhXRDZHChwiyi/hnPuOsSEF6Exk3o6Y9DT1eZ+6cASXk2Y9k+6EOQMDGm6WBK10wOQJCBwren86cPPWUcRAnTVjGcU1LBgs9FURiX/e6479yZcLwCBmTxiawEwrOcleuu12t3tbLv/N4RLYIBhYexm7Fcn4OJcn0+zc+s8/VfPeddZHAGN6TT8eGczHdR/Gts1/MzDkThr23zqrVfAMFT33Nx1RJsx1k5zuWILLnG/vsH+Fv5D4NTVcp1Gzo8AAAAAElFTkSuQmCC&labelColor=white)](https://huggingface.co/spaces/opendatalab/MinerU)
692 +
693 +## Local Deployment
694 +
695 +
696 +> [!WARNING]
697 +> **Pre-installation Notice—Hardware and Software Environment Support**
698 +>
699 +> To ensure the stability and reliability of the project, we only optimize and test for specific hardware and software environments during development. This ensures that users deploying and running the project on recommended system configurations will get the best performance with the fewest compatibility issues.
700 +>
701 +> By focusing resources on the mainline environment, our team can more efficiently resolve potential bugs and develop new features.
702 +>
703 +> In non-mainline environments, due to the diversity of hardware and software configurations, as well as third-party dependency compatibility issues, we cannot guarantee 100% project availability. Therefore, for users who wish to use this project in non-recommended environments, we suggest carefully reading the documentation and FAQ first. Most issues already have corresponding solutions in the FAQ. We also encourage community feedback to help us gradually expand support.
704 +
705 +<table>
706 + <tr>
707 + <td>Parsing Backend</td>
708 + <td>pipeline</td>
709 + <td>vlm-transformers</td>
710 + <td>vlm-vllm</td>
711 + </tr>
712 + <tr>
713 + <td>Operating System</td>
714 + <td>Linux / Windows / macOS</td>
715 + <td>Linux / Windows</td>
716 + <td>Linux / Windows (via WSL2)</td>
717 + </tr>
718 + <tr>
719 + <td>CPU Inference Support</td>
720 + <td>✅</td>
721 + <td colspan="2">❌</td>
722 + </tr>
723 + <tr>
724 + <td>GPU Requirements</td>
725 + <td>Turing architecture and later, 6GB+ VRAM or Apple Silicon</td>
726 + <td colspan="2">Turing architecture and later, 8GB+ VRAM</td>
727 + </tr>
728 + <tr>
729 + <td>Memory Requirements</td>
730 + <td colspan="3">Minimum 16GB+, recommended 32GB+</td>
731 + </tr>
732 + <tr>
733 + <td>Disk Space Requirements</td>
734 + <td colspan="3">20GB+, SSD recommended</td>
735 + </tr>
736 + <tr>
737 + <td>Python Version</td>
738 + <td colspan="3">3.10-3.13</td>
739 + </tr>
740 +</table>
741 +
742 +### Install MinerU
743 +
744 +#### Install MinerU using pip or uv
745 +```bash
746 +pip install --upgrade pip
747 +pip install uv
748 +uv pip install -U "mineru[core]"
749 +```
750 +
751 +#### Install MinerU from source code
752 +```bash
753 +git clone https://github.com/opendatalab/MinerU.git
754 +cd MinerU
755 +uv pip install -e .[core]
756 +```
757 +
758 +> [!TIP]
759 +> `mineru[core]` includes all core features except `vLLM` acceleration, compatible with Windows / Linux / macOS systems, suitable for most users.
760 +> If you need to use `vLLM` acceleration for VLM model inference or install a lightweight client on edge devices, please refer to the documentation [Extension Modules Installation Guide](https://opendatalab.github.io/MinerU/quick_start/extension_modules/).
761 +
762 +---
763 +
764 +#### Deploy MinerU using Docker
765 +MinerU provides a convenient Docker deployment method, which helps quickly set up the environment and solve some tricky environment compatibility issues.
766 +You can get the [Docker Deployment Instructions](https://opendatalab.github.io/MinerU/quick_start/docker_deployment/) in the documentation.
767 +
768 +---
769 +
770 +### Using MinerU
771 +
772 +The simplest command line invocation is:
773 +```bash
774 +mineru -p <input_path> -o <output_path>
775 +```
776 +
777 +You can use MinerU for PDF parsing through various methods such as command line, API, and WebUI. For detailed instructions, please refer to the [Usage Guide](https://opendatalab.github.io/MinerU/usage/).
778 +
779 +# TODO
780 +
781 +- [x] Reading order based on the model
782 +- [x] Recognition of `index` and `list` in the main text
783 +- [x] Table recognition
784 +- [x] Heading Classification
785 +- [x] Handwritten Text Recognition
786 +- [x] Vertical Text Recognition
787 +- [x] Latin Accent Mark Recognition
788 +- [x] Code block recognition in the main text
789 +- [x] [Chemical formula recognition](docs/chemical_knowledge_introduction/introduction.pdf)(mineru.net)
790 +- [ ] Geometric shape recognition
791 +
792 +# Known Issues
793 +
794 +- Reading order is determined by the model based on the spatial distribution of readable content, and may be out of order in some areas under extremely complex layouts.
795 +- Limited support for vertical text.
796 +- Tables of contents and lists are recognized through rules, and some uncommon list formats may not be recognized.
797 +- Code blocks are not yet supported in the layout model.
798 +- Comic books, art albums, primary school textbooks, and exercises cannot be parsed well.
799 +- Table recognition may result in row/column recognition errors in complex tables.
800 +- OCR recognition may produce inaccurate characters in PDFs of lesser-known languages (e.g., diacritical marks in Latin script, easily confused characters in Arabic script).
801 +- Some formulas may not render correctly in Markdown.
802 +
803 +# FAQ
804 +
805 +- If you encounter any issues during usage, you can first check the [FAQ](https://opendatalab.github.io/MinerU/faq/) for solutions.
806 +- If your issue remains unresolved, you may also use [DeepWiki](https://deepwiki.com/opendatalab/MinerU) to interact with an AI assistant, which can address most common problems.
807 +- If you still cannot resolve the issue, you are welcome to join our community via [Discord](https://discord.gg/Tdedn9GTXq) or [WeChat](https://mineru.net/community-portal/?aliasId=3c430f94) to discuss with other users and developers.
808 +
809 +# All Thanks To Our Contributors
810 +
811 +<a href="https://github.com/opendatalab/MinerU/graphs/contributors">
812 + <img src="https://contrib.rocks/image?repo=opendatalab/MinerU" />
813 +</a>
814 +
815 +# License Information
816 +
817 +[LICENSE.md](LICENSE.md)
818 +
819 +Currently, some models in this project are trained based on YOLO. However, since YOLO follows the AGPL license, it may impose restrictions on certain use cases. In future iterations, we plan to explore and replace these with models under more permissive licenses to enhance user-friendliness and flexibility.
820 +
821 +# Acknowledgments
822 +
823 +- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit)
824 +- [DocLayout-YOLO](https://github.com/opendatalab/DocLayout-YOLO)
825 +- [UniMERNet](https://github.com/opendatalab/UniMERNet)
826 +- [RapidTable](https://github.com/RapidAI/RapidTable)
827 +- [TableStructureRec](https://github.com/RapidAI/TableStructureRec)
828 +- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
829 +- [PaddleOCR2Pytorch](https://github.com/frotms/PaddleOCR2Pytorch)
830 +- [layoutreader](https://github.com/ppaanngggg/layoutreader)
831 +- [xy-cut](https://github.com/Sanster/xy-cut)
832 +- [fast-langdetect](https://github.com/LlmKira/fast-langdetect)
833 +- [pypdfium2](https://github.com/pypdfium2-team/pypdfium2)
834 +- [pdftext](https://github.com/datalab-to/pdftext)
835 +- [pdfminer.six](https://github.com/pdfminer/pdfminer.six)
836 +- [pypdf](https://github.com/py-pdf/pypdf)
837 +- [magika](https://github.com/google/magika)
838 +
839 +# Citation
840 +
841 +```bibtex
842 +@misc{niu2025mineru25decoupledvisionlanguagemodel,
843 + title={MinerU2.5: A Decoupled Vision-Language Model for Efficient High-Resolution Document Parsing},
844 + author={Junbo Niu and Zheng Liu and Zhuangcheng Gu and Bin Wang and Linke Ouyang and Zhiyuan Zhao and Tao Chu and Tianyao He and Fan Wu and Qintong Zhang and Zhenjiang Jin and Guang Liang and Rui Zhang and Wenzheng Zhang and Yuan Qu and Zhifei Ren and Yuefeng Sun and Yuanhong Zheng and Dongsheng Ma and Zirui Tang and Boyu Niu and Ziyang Miao and Hejun Dong and Siyi Qian and Junyuan Zhang and Jingzhou Chen and Fangdong Wang and Xiaomeng Zhao and Liqun Wei and Wei Li and Shasha Wang and Ruiliang Xu and Yuanyuan Cao and Lu Chen and Qianqian Wu and Huaiyu Gu and Lindong Lu and Keming Wang and Dechen Lin and Guanlin Shen and Xuanhe Zhou and Linfeng Zhang and Yuhang Zang and Xiaoyi Dong and Jiaqi Wang and Bo Zhang and Lei Bai and Pei Chu and Weijia Li and Jiang Wu and Lijun Wu and Zhenxiang Li and Guangyu Wang and Zhongying Tu and Chao Xu and Kai Chen and Yu Qiao and Bowen Zhou and Dahua Lin and Wentao Zhang and Conghui He},
845 + year={2025},
846 + eprint={2509.22186},
847 + archivePrefix={arXiv},
848 + primaryClass={cs.CV},
849 + url={https://arxiv.org/abs/2509.22186},
850 +}
851 +
852 +@misc{wang2024mineruopensourcesolutionprecise,
853 + title={MinerU: An Open-Source Solution for Precise Document Content Extraction},
854 + author={Bin Wang and Chao Xu and Xiaomeng Zhao and Linke Ouyang and Fan Wu and Zhiyuan Zhao and Rui Xu and Kaiwen Liu and Yuan Qu and Fukai Shang and Bo Zhang and Liqun Wei and Zhihao Sui and Wei Li and Botian Shi and Yu Qiao and Dahua Lin and Conghui He},
855 + year={2024},
856 + eprint={2409.18839},
857 + archivePrefix={arXiv},
858 + primaryClass={cs.CV},
859 + url={https://arxiv.org/abs/2409.18839},
860 +}
861 +
862 +@article{he2024opendatalab,
863 + title={Opendatalab: Empowering general artificial intelligence with open datasets},
864 + author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua},
865 + journal={arXiv preprint arXiv:2407.13773},
866 + year={2024}
867 +}
868 +```
869 +
870 +# Star History
871 +
872 +<a>
873 + <picture>
874 + <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date&theme=dark" />
875 + <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
876 + <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
877 + </picture>
878 +</a>
879 +
880 +
881 +# Links
882 +- [Easy Data Preparation with latest LLMs-based Operators and Pipelines](https://github.com/OpenDCAI/DataFlow)
883 +- [Vis3 (OSS browser based on s3)](https://github.com/opendatalab/Vis3)
884 +- [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU)
885 +- [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM)
886 +- [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit)
887 +- [OmniDocBench (A Comprehensive Benchmark for Document Parsing and Evaluation)](https://github.com/opendatalab/OmniDocBench)
888 +- [Magic-HTML (Mixed web page extraction tool)](https://github.com/opendatalab/magic-html)
889 +- [Magic-Doc (Fast speed ppt/pptx/doc/docx/pdf extraction tool)](https://github.com/InternLM/magic-doc)
890 +- [Dingo: A Comprehensive AI Data Quality Evaluation Tool](https://github.com/MigoXLab/dingo)
1 +LICENSE.md
2 +README.md
3 +pyproject.toml
4 +mineru/__init__.py
5 +mineru/version.py
6 +mineru.egg-info/PKG-INFO
7 +mineru.egg-info/SOURCES.txt
8 +mineru.egg-info/dependency_links.txt
9 +mineru.egg-info/entry_points.txt
10 +mineru.egg-info/not-zip-safe
11 +mineru.egg-info/requires.txt
12 +mineru.egg-info/top_level.txt
13 +mineru/backend/__init__.py
14 +mineru/backend/utils.py
15 +mineru/backend/customs/__init__.py
16 +mineru/backend/customs/exporter.py
17 +mineru/backend/pipeline/__init__.py
18 +mineru/backend/pipeline/batch_analyze.py
19 +mineru/backend/pipeline/model_init.py
20 +mineru/backend/pipeline/model_json_to_middle_json.py
21 +mineru/backend/pipeline/model_list.py
22 +mineru/backend/pipeline/para_split.py
23 +mineru/backend/pipeline/pipeline_analyze.py
24 +mineru/backend/pipeline/pipeline_magic_model.py
25 +mineru/backend/pipeline/pipeline_middle_json_mkcontent.py
26 +mineru/backend/vlm/__init__.py
27 +mineru/backend/vlm/model_output_to_middle_json.py
28 +mineru/backend/vlm/utils.py
29 +mineru/backend/vlm/vlm_analyze.py
30 +mineru/backend/vlm/vlm_magic_model.py
31 +mineru/backend/vlm/vlm_middle_json_mkcontent.py
32 +mineru/cli/__init__.py
33 +mineru/cli/client.py
34 +mineru/cli/common.py
35 +mineru/cli/fast_api.py
36 +mineru/cli/gradio_app.py
37 +mineru/cli/models_download.py
38 +mineru/cli/vlm_vllm_server.py
39 +mineru/data/__init__.py
40 +mineru/data/data_reader_writer/__init__.py
41 +mineru/data/data_reader_writer/base.py
42 +mineru/data/data_reader_writer/dummy.py
43 +mineru/data/data_reader_writer/filebase.py
44 +mineru/data/data_reader_writer/multi_bucket_s3.py
45 +mineru/data/data_reader_writer/s3.py
46 +mineru/data/io/__init__.py
47 +mineru/data/io/base.py
48 +mineru/data/io/http.py
49 +mineru/data/io/s3.py
50 +mineru/data/utils/__init__.py
51 +mineru/data/utils/exceptions.py
52 +mineru/data/utils/path_utils.py
53 +mineru/data/utils/schemas.py
54 +mineru/model/__init__.py
55 +mineru/model/layout/__init__.py
56 +mineru/model/layout/doclayoutyolo.py
57 +mineru/model/mfd/__init__.py
58 +mineru/model/mfd/yolo_v8.py
59 +mineru/model/mfr/__init__.py
60 +mineru/model/mfr/utils.py
61 +mineru/model/mfr/pp_formulanet_plus_m/__init__.py
62 +mineru/model/mfr/pp_formulanet_plus_m/predict_formula.py
63 +mineru/model/mfr/pp_formulanet_plus_m/processors.py
64 +mineru/model/mfr/unimernet/Unimernet.py
65 +mineru/model/mfr/unimernet/__init__.py
66 +mineru/model/mfr/unimernet/unimernet_hf/__init__.py
67 +mineru/model/mfr/unimernet/unimernet_hf/modeling_unimernet.py
68 +mineru/model/mfr/unimernet/unimernet_hf/unimer_mbart/__init__.py
69 +mineru/model/mfr/unimernet/unimernet_hf/unimer_mbart/configuration_unimer_mbart.py
70 +mineru/model/mfr/unimernet/unimernet_hf/unimer_mbart/modeling_unimer_mbart.py
71 +mineru/model/mfr/unimernet/unimernet_hf/unimer_mbart/tokenization_unimer_mbart.py
72 +mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/__init__.py
73 +mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/configuration_unimer_swin.py
74 +mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/image_processing_unimer_swin.py
75 +mineru/model/mfr/unimernet/unimernet_hf/unimer_swin/modeling_unimer_swin.py
76 +mineru/model/ocr/__init__.py
77 +mineru/model/ocr/paddleocr2pytorch/__init__.py
78 +mineru/model/ocr/paddleocr2pytorch/pytorch_paddle.py
79 +mineru/model/ori_cls/__init__.py
80 +mineru/model/ori_cls/paddle_ori_cls.py
81 +mineru/model/reading_order/__init__.py
82 +mineru/model/reading_order/layout_reader.py
83 +mineru/model/reading_order/xycut.py
84 +mineru/model/table/__init__.py
85 +mineru/model/table/cls/__init__.py
86 +mineru/model/table/cls/paddle_table_cls.py
87 +mineru/model/table/rec/RapidTable.py
88 +mineru/model/table/rec/__init__.py
89 +mineru/model/table/rec/slanet_plus/__init__.py
90 +mineru/model/table/rec/slanet_plus/main.py
91 +mineru/model/table/rec/slanet_plus/matcher.py
92 +mineru/model/table/rec/slanet_plus/matcher_utils.py
93 +mineru/model/table/rec/slanet_plus/table_structure.py
94 +mineru/model/table/rec/slanet_plus/table_structure_utils.py
95 +mineru/model/table/rec/unet_table/__init__.py
96 +mineru/model/table/rec/unet_table/main.py
97 +mineru/model/table/rec/unet_table/table_recover.py
98 +mineru/model/table/rec/unet_table/table_structure_unet.py
99 +mineru/model/table/rec/unet_table/utils.py
100 +mineru/model/table/rec/unet_table/utils_table_line_rec.py
101 +mineru/model/table/rec/unet_table/utils_table_recover.py
102 +mineru/model/utils/__init__.py
103 +mineru/model/utils/pytorchocr/__init__.py
104 +mineru/model/utils/pytorchocr/base_ocr_v20.py
105 +mineru/model/utils/pytorchocr/data/__init__.py
106 +mineru/model/utils/pytorchocr/data/imaug/__init__.py
107 +mineru/model/utils/pytorchocr/data/imaug/operators.py
108 +mineru/model/utils/pytorchocr/modeling/__init__.py
109 +mineru/model/utils/pytorchocr/modeling/common.py
110 +mineru/model/utils/pytorchocr/modeling/architectures/__init__.py
111 +mineru/model/utils/pytorchocr/modeling/architectures/base_model.py
112 +mineru/model/utils/pytorchocr/modeling/backbones/__init__.py
113 +mineru/model/utils/pytorchocr/modeling/backbones/det_mobilenet_v3.py
114 +mineru/model/utils/pytorchocr/modeling/backbones/rec_donut_swin.py
115 +mineru/model/utils/pytorchocr/modeling/backbones/rec_hgnet.py
116 +mineru/model/utils/pytorchocr/modeling/backbones/rec_lcnetv3.py
117 +mineru/model/utils/pytorchocr/modeling/backbones/rec_mobilenet_v3.py
118 +mineru/model/utils/pytorchocr/modeling/backbones/rec_mv1_enhance.py
119 +mineru/model/utils/pytorchocr/modeling/backbones/rec_pphgnetv2.py
120 +mineru/model/utils/pytorchocr/modeling/backbones/rec_svtrnet.py
121 +mineru/model/utils/pytorchocr/modeling/heads/__init__.py
122 +mineru/model/utils/pytorchocr/modeling/heads/cls_head.py
123 +mineru/model/utils/pytorchocr/modeling/heads/det_db_head.py
124 +mineru/model/utils/pytorchocr/modeling/heads/rec_ctc_head.py
125 +mineru/model/utils/pytorchocr/modeling/heads/rec_multi_head.py
126 +mineru/model/utils/pytorchocr/modeling/heads/rec_ppformulanet_head.py
127 +mineru/model/utils/pytorchocr/modeling/heads/rec_unimernet_head.py
128 +mineru/model/utils/pytorchocr/modeling/necks/__init__.py
129 +mineru/model/utils/pytorchocr/modeling/necks/db_fpn.py
130 +mineru/model/utils/pytorchocr/modeling/necks/intracl.py
131 +mineru/model/utils/pytorchocr/modeling/necks/rnn.py
132 +mineru/model/utils/pytorchocr/postprocess/__init__.py
133 +mineru/model/utils/pytorchocr/postprocess/cls_postprocess.py
134 +mineru/model/utils/pytorchocr/postprocess/db_postprocess.py
135 +mineru/model/utils/pytorchocr/postprocess/rec_postprocess.py
136 +mineru/model/utils/pytorchocr/utils/__init__.py
137 +mineru/model/utils/pytorchocr/utils/resources/arch_config.yaml
138 +mineru/model/utils/pytorchocr/utils/resources/models_config.yml
139 +mineru/model/utils/pytorchocr/utils/resources/pp_formulanet_arch_config.yaml
140 +mineru/model/utils/pytorchocr/utils/resources/dict/ka_dict.txt
141 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv4_doc_dict.txt
142 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_arabic_dict.txt
143 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_cyrillic_dict.txt
144 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_devanagari_dict.txt
145 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_dict.txt
146 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_el_dict.txt
147 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_en_dict.txt
148 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_eslav_dict.txt
149 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_korean_dict.txt
150 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_latin_dict.txt
151 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_ta_dict.txt
152 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_te_dict.txt
153 +mineru/model/utils/pytorchocr/utils/resources/dict/ppocrv5_th_dict.txt
154 +mineru/model/utils/tools/__init__.py
155 +mineru/model/utils/tools/infer/__init__.py
156 +mineru/model/utils/tools/infer/predict_cls.py
157 +mineru/model/utils/tools/infer/predict_det.py
158 +mineru/model/utils/tools/infer/predict_rec.py
159 +mineru/model/utils/tools/infer/predict_system.py
160 +mineru/model/utils/tools/infer/pytorchocr_utility.py
161 +mineru/model/vlm_vllm_model/__init__.py
162 +mineru/model/vlm_vllm_model/server.py
163 +mineru/resources/header.html
164 +mineru/resources/fasttext-langdetect/lid.176.ftz
165 +mineru/utils/__init__.py
166 +mineru/utils/block_pre_proc.py
167 +mineru/utils/block_sort.py
168 +mineru/utils/boxbase.py
169 +mineru/utils/cli_parser.py
170 +mineru/utils/config_reader.py
171 +mineru/utils/cut_image.py
172 +mineru/utils/draw_bbox.py
173 +mineru/utils/enum_class.py
174 +mineru/utils/format_utils.py
175 +mineru/utils/guess_suffix_or_lang.py
176 +mineru/utils/hash_utils.py
177 +mineru/utils/language.py
178 +mineru/utils/llm_aided.py
179 +mineru/utils/magic_model_utils.py
180 +mineru/utils/model_utils.py
181 +mineru/utils/models_download_utils.py
182 +mineru/utils/ocr_utils.py
183 +mineru/utils/pdf_classify.py
184 +mineru/utils/pdf_image_tools.py
185 +mineru/utils/pdf_reader.py
186 +mineru/utils/pdf_text_tool.py
187 +mineru/utils/run_async.py
188 +mineru/utils/span_block_fix.py
189 +mineru/utils/span_pre_proc.py
190 +mineru/utils/table_merge.py
...\ No newline at end of file ...\ No newline at end of file
1 +[console_scripts]
2 +mineru = mineru.cli:client.main
3 +mineru-api = mineru.cli.fast_api:main
4 +mineru-gradio = mineru.cli.gradio_app:main
5 +mineru-models-download = mineru.cli.models_download:download_models
6 +mineru-vllm-server = mineru.cli.vlm_vllm_server:main
1 +boto3>=1.28.43
2 +click>=8.1.7
3 +loguru>=0.7.2
4 +numpy>=1.21.6
5 +pdfminer.six==20250506
6 +tqdm>=4.67.1
7 +requests
8 +httpx
9 +pillow>=11.0.0
10 +pypdfium2>=4.30.0
11 +pypdf>=5.6.0
12 +reportlab
13 +pdftext>=0.6.2
14 +modelscope>=1.26.0
15 +huggingface-hub>=0.32.4
16 +json-repair>=0.46.2
17 +opencv-python>=4.11.0.86
18 +fast-langdetect<0.3.0,>=0.2.3
19 +scikit-image<1.0.0,>=0.25.0
20 +openai<3,>=1.70.0
21 +beautifulsoup4<5,>=4.13.5
22 +magika<0.7.0,>=0.6.2
23 +mineru-vl-utils<1,>=0.1.14
24 +
25 +[all]
26 +mineru[core]
27 +mineru[vllm]
28 +
29 +[api]
30 +fastapi
31 +python-multipart
32 +uvicorn
33 +
34 +[core]
35 +mineru[vlm]
36 +mineru[pipeline]
37 +mineru[api]
38 +mineru[gradio]
39 +
40 +[gradio]
41 +gradio<6,>=5.34
42 +gradio-pdf>=0.0.22
43 +
44 +[pipeline]
45 +matplotlib<4,>=3.10
46 +ultralytics<9,>=8.3.48
47 +doclayout_yolo==0.0.4
48 +dill<1,>=0.3.8
49 +PyYAML<7,>=6.0.2
50 +ftfy<7,>=6.3.1
51 +shapely<3,>=2.0.7
52 +pyclipper<2,>=1.3.0
53 +omegaconf<3,>=2.3.0
54 +torch<3,>=2.6.0
55 +torchvision
56 +transformers!=4.51.0,<5.0.0,>=4.49.0
57 +onnxruntime>1.17.0
58 +
59 +[test]
60 +mineru[core]
61 +pytest
62 +pytest-cov
63 +coverage
64 +fuzzywuzzy
65 +
66 +[vllm]
67 +vllm<0.12,>=0.10.1.1
68 +
69 +[vlm]
70 +torch<3,>=2.6.0
71 +transformers<5.0.0,>=4.51.1
72 +accelerate>=1.5.1
...@@ -13,6 +13,7 @@ from ...utils.model_utils import crop_img, get_res_list_from_layout_res, clean_v ...@@ -13,6 +13,7 @@ from ...utils.model_utils import crop_img, get_res_list_from_layout_res, clean_v
13 from ...utils.ocr_utils import merge_det_boxes, update_det_boxes, sorted_boxes 13 from ...utils.ocr_utils import merge_det_boxes, update_det_boxes, sorted_boxes
14 from ...utils.ocr_utils import get_adjusted_mfdetrec_res, get_ocr_result_list, OcrConfidence, get_rotate_crop_image 14 from ...utils.ocr_utils import get_adjusted_mfdetrec_res, get_ocr_result_list, OcrConfidence, get_rotate_crop_image
15 from ...utils.pdf_image_tools import get_crop_np_img 15 from ...utils.pdf_image_tools import get_crop_np_img
16 +from ...utils.table_cell_bbox import compute_table_cells
16 17
17 YOLO_LAYOUT_BASE_BATCH_SIZE = 1 18 YOLO_LAYOUT_BASE_BATCH_SIZE = 1
18 MFD_BASE_BATCH_SIZE = 1 19 MFD_BASE_BATCH_SIZE = 1
...@@ -106,6 +107,7 @@ class BatchAnalyze: ...@@ -106,6 +107,7 @@ class BatchAnalyze:
106 'lang':_lang, 107 'lang':_lang,
107 'table_img':wireless_table_img, 108 'table_img':wireless_table_img,
108 'wired_table_img':wired_table_img, 109 'wired_table_img':wired_table_img,
110 + 'page_index': index, # 记录页码索引,用于后续关联
109 }) 111 })
110 112
111 # 表格识别 table recognition 113 # 表格识别 table recognition
...@@ -235,6 +237,81 @@ class BatchAnalyze: ...@@ -235,6 +237,81 @@ class BatchAnalyze:
235 end_index = html_code.rfind("</table>") + len("</table>") 237 end_index = html_code.rfind("</table>") + len("</table>")
236 table_res_dict["table_res"]["html"] = html_code[start_index:end_index] 238 table_res_dict["table_res"]["html"] = html_code[start_index:end_index]
237 239
240 + # 计算表格单元格的bbox和score
241 + try:
242 + html_final = table_res_dict["table_res"].get("html", "")
243 + if html_final:
244 + # 获取表格bbox(从poly转换为[x1, y1, x2, y2])
245 + table_res = table_res_dict.get("table_res", {})
246 + poly = table_res.get("poly", [])
247 + x_coords = None
248 + y_coords = None
249 +
250 + # 安全地检查poly长度和处理numpy数组
251 + try:
252 + poly_len = len(poly) if hasattr(poly, '__len__') else 0
253 + if poly_len >= 8:
254 + # 转换为列表并提取坐标,确保处理numpy数组
255 + poly_list = list(poly) if not isinstance(poly, list) else poly
256 + x_coords = [float(poly_list[0]), float(poly_list[2]), float(poly_list[4]), float(poly_list[6])]
257 + y_coords = [float(poly_list[1]), float(poly_list[3]), float(poly_list[5]), float(poly_list[7])]
258 + table_bbox = [min(x_coords), min(y_coords), max(x_coords), max(y_coords)]
259 + else:
260 + # 如果没有poly,尝试从bbox字段获取
261 + bbox_list = table_res.get("bbox", [])
262 + if hasattr(bbox_list, '__len__') and len(bbox_list) >= 4:
263 + table_bbox = [float(bbox_list[0]), float(bbox_list[1]), float(bbox_list[2]), float(bbox_list[3])]
264 + else:
265 + table_bbox = [0, 0, 0, 0]
266 + except (ValueError, TypeError, IndexError) as e:
267 + logger.warning(f"Error processing table bbox from poly: {e}")
268 + # 回退到bbox字段
269 + bbox_list = table_res.get("bbox", [])
270 + if hasattr(bbox_list, '__len__') and len(bbox_list) >= 4:
271 + table_bbox = [float(bbox_list[0]), float(bbox_list[1]), float(bbox_list[2]), float(bbox_list[3])]
272 + else:
273 + table_bbox = [0, 0, 0, 0]
274 +
275 + # 获取score
276 + # 如果score未定义或为0,使用合理的默认值
277 + raw_score = table_res.get("score", 0.8)
278 + span_score = float(raw_score)
279 +
280 + # 如果score为0或未定义,使用默认值
281 + if span_score <= 0:
282 + logger.warning(f"Invalid table score: {span_score}, using default 0.8")
283 + span_score = 0.8
284 +
285 + # 获取OCR结果
286 + ocr_result = table_res_dict.get("ocr_result", None)
287 +
288 + # 计算裁剪偏移量(OCR结果坐标是相对于裁剪后的表格图像的)
289 + crop_info = None
290 + if x_coords is not None and y_coords is not None:
291 + try:
292 + crop_info = {
293 + 'crop_xmin': min(x_coords),
294 + 'crop_ymin': min(y_coords),
295 + }
296 + except Exception as e:
297 + logger.warning(f"Error creating crop_info: {e}")
298 + crop_info = None
299 +
300 + # 计算cells
301 + cells = compute_table_cells(
302 + html_final,
303 + table_bbox,
304 + span_score,
305 + ocr_result,
306 + crop_info=crop_info
307 + )
308 +
309 + # 将cells添加到table_res中(table_res是layout_res中table项的引用,会自动同步)
310 + table_res_dict["table_res"]["cells"] = cells
311 + except Exception as e:
312 + logger.warning(f"Failed to compute table cells: {e}")
313 + table_res_dict["table_res"]["cells"] = []
314 +
238 # OCR det 315 # OCR det
239 if self.enable_ocr_det_batch: 316 if self.enable_ocr_det_batch:
240 # 批处理模式 - 按语言和分辨率分组 317 # 批处理模式 - 按语言和分辨率分组
......
...@@ -338,6 +338,10 @@ class MagicModel: ...@@ -338,6 +338,10 @@ class MagicModel:
338 span['latex'] = latex 338 span['latex'] = latex
339 elif html: 339 elif html:
340 span['html'] = html 340 span['html'] = html
341 + # 获取单元格级信息(bbox和score)
342 + cells = layout_det.get('cells', None)
343 + if cells:
344 + span['cells'] = cells
341 span['type'] = ContentType.TABLE 345 span['type'] = ContentType.TABLE
342 elif category_id == CategoryId.InlineEquation: 346 elif category_id == CategoryId.InlineEquation:
343 span['content'] = layout_det['latex'] 347 span['content'] = layout_det['latex']
......
1 +# Copyright (c) Opendatalab. All rights reserved.
2 +"""
3 +计算表格HTML中每个td单元格的bbox和score
4 +"""
5 +import re
6 +from typing import List, Dict, Optional, Tuple
7 +try:
8 + from bs4 import BeautifulSoup
9 +except ImportError:
10 + BeautifulSoup = None
11 +from loguru import logger
12 +import numpy as np
13 +
14 +
15 +def parse_html_to_grid(html: str) -> List[Dict]:
16 + """解析HTML表格,返回行列结构"""
17 + if BeautifulSoup is None:
18 + logger.warning("BeautifulSoup not available, using simple regex parsing")
19 + return _parse_html_simple(html)
20 +
21 + try:
22 + soup = BeautifulSoup(html, 'html.parser')
23 + rows = []
24 + row_idx = -1
25 +
26 + for tr in soup.find_all('tr'):
27 + row_idx += 1
28 + cols = []
29 + col_idx = 0
30 +
31 + for cell in tr.find_all(['td', 'th']):
32 + text = cell.get_text(strip=True)
33 + rowspan = int(cell.get('rowspan', 1))
34 + colspan = int(cell.get('colspan', 1))
35 +
36 + cols.append({
37 + 'col_index': col_idx,
38 + 'rowspan': rowspan,
39 + 'colspan': colspan,
40 + 'text': text
41 + })
42 +
43 + col_idx += 1
44 +
45 + if cols:
46 + rows.append({
47 + 'row_index': row_idx,
48 + 'cols': cols
49 + })
50 +
51 + return rows
52 + except Exception as e:
53 + logger.warning(f"Failed to parse HTML with BeautifulSoup: {e}, using simple parser")
54 + return _parse_html_simple(html)
55 +
56 +
57 +def _parse_html_simple(html: str) -> List[Dict]:
58 + """简单的正则解析作为备选"""
59 + rows = []
60 + row_idx = -1
61 +
62 + # 提取所有tr块
63 + tr_pattern = r'<tr>(.*?)</tr>'
64 + tr_matches = re.findall(tr_pattern, html, re.DOTALL)
65 +
66 + for tr_content in tr_matches:
67 + row_idx += 1
68 + cols = []
69 + col_idx = 0
70 +
71 + # 提取td/th
72 + td_pattern = r'<t[dh](?:\s+[^>]*)?>(.*?)</t[dh]>'
73 + td_matches = re.findall(td_pattern, tr_content, re.DOTALL)
74 +
75 + # 提取rowspan和colspan
76 + td_full_pattern = r'<t[dh]([^>]*)>(.*?)</t[dh]>'
77 + td_full_matches = re.findall(td_full_pattern, tr_content, re.DOTALL)
78 +
79 + for attr_str, content in td_full_matches:
80 + rowspan = 1
81 + colspan = 1
82 +
83 + rowspan_match = re.search(r'rowspan\s*=\s*(\d+)', attr_str)
84 + if rowspan_match:
85 + rowspan = int(rowspan_match.group(1))
86 +
87 + colspan_match = re.search(r'colspan\s*=\s*(\d+)', attr_str)
88 + if colspan_match:
89 + colspan = int(colspan_match.group(1))
90 +
91 + text = re.sub(r'<[^>]+>', '', content).strip()
92 +
93 + cols.append({
94 + 'col_index': col_idx,
95 + 'rowspan': rowspan,
96 + 'colspan': colspan,
97 + 'text': text
98 + })
99 +
100 + col_idx += 1
101 +
102 + if cols:
103 + rows.append({
104 + 'row_index': row_idx,
105 + 'cols': cols
106 + })
107 +
108 + return rows
109 +
110 +
111 +def infer_max_row_col(rows: List[Dict]) -> Tuple[int, int]:
112 + """推断表格的最大行列数"""
113 + max_row = len(rows)
114 + max_col = 0
115 +
116 + for row in rows:
117 + last_col = row['cols'][-1] if row['cols'] else None
118 + if last_col:
119 + max_col = max(max_col, last_col['col_index'] + last_col['colspan'])
120 +
121 + return max_row, max_col
122 +
123 +
124 +def uniform_bounds(start: float, end: float, count: int) -> List[float]:
125 + """均匀分割区间"""
126 + if count <= 0:
127 + return [start, end]
128 +
129 + step = (end - start) / count
130 + bounds = [start + i * step for i in range(count + 1)]
131 + return bounds
132 +
133 +
134 +def map_ocr_boxes_to_page(ocr_result: List, table_bbox: List, crop_info: Dict = None) -> List[Dict]:
135 + """将OCR检测框从表格子图坐标映射到页面坐标"""
136 + if not ocr_result:
137 + return []
138 +
139 + # 提取表格裁剪信息
140 + # 如果crop_info为None,说明OCR坐标已经是页面坐标(无需转换)
141 + if crop_info is None:
142 + crop_xmin = 0
143 + crop_ymin = 0
144 + else:
145 + crop_xmin = crop_info.get('crop_xmin', 0)
146 + crop_ymin = crop_info.get('crop_ymin', 0)
147 +
148 + page_boxes = []
149 + for item in ocr_result:
150 + if len(item) < 3:
151 + continue
152 +
153 + dt_box = item[0]
154 + text = item[1] if len(item) > 1 else ""
155 + score = item[2] if len(item) > 2 else 0.0
156 +
157 + # dt_box可能是多边形或bbox
158 + if isinstance(dt_box, (list, np.ndarray)):
159 + box_array = np.array(dt_box)
160 + # 检查数组形状和大小
161 + if box_array.ndim == 1 and len(box_array) == 4: # [x1, y1, x2, y2]
162 + x1, y1, x2, y2 = float(box_array[0]), float(box_array[1]), float(box_array[2]), float(box_array[3])
163 + elif box_array.ndim == 2 and box_array.shape[0] == 4 and box_array.shape[1] == 2: # [[x1,y1], [x2,y1], [x2,y2], [x1,y2]]
164 + x1, y1 = float(box_array[0][0]), float(box_array[0][1])
165 + x2, y2 = float(box_array[2][0]), float(box_array[2][1])
166 + else:
167 + continue
168 +
169 + # 映射到页面坐标
170 + page_x1 = crop_xmin + x1
171 + page_y1 = crop_ymin + y1
172 + page_x2 = crop_xmin + x2
173 + page_y2 = crop_ymin + y2
174 +
175 + page_boxes.append({
176 + 'bbox': [page_x1, page_y1, page_x2, page_y2],
177 + 'text': text,
178 + 'score': float(score) if isinstance(score, (int, float)) else 0.0,
179 + 'center_x': (page_x1 + page_x2) / 2,
180 + 'center_y': (page_y1 + page_y2) / 2
181 + })
182 +
183 + return page_boxes
184 +
185 +
186 +def infer_row_boundaries_from_ocr(page_boxes: List[Dict], max_row: int) -> List[float]:
187 + """从OCR框推断行边界"""
188 + if not page_boxes or max_row <= 0:
189 + return []
190 +
191 + # 收集所有y坐标
192 + y_centers = [box['center_y'] for box in page_boxes]
193 + if not y_centers:
194 + return []
195 +
196 + y_centers = sorted(y_centers)
197 +
198 + # 简单的K-means聚类来分组(或使用更简单的分位数方法)
199 + if max_row <= 1:
200 + return [min(y_centers), max(y_centers)]
201 +
202 + # 使用分位数方法:将y坐标分成max_row组
203 + y_sorted = sorted(y_centers)
204 + step = len(y_sorted) / max_row
205 +
206 + boundaries = []
207 + for i in range(max_row + 1):
208 + idx = int(i * step)
209 + if idx >= len(y_sorted):
210 + idx = len(y_sorted) - 1
211 + if i == 0:
212 + boundaries.append(y_sorted[idx] - 5) # 向上扩展一点
213 + elif i == max_row:
214 + boundaries.append(y_sorted[idx] + 5) # 向下扩展一点
215 + else:
216 + boundaries.append(y_sorted[idx])
217 +
218 + return sorted(boundaries)
219 +
220 +
221 +def infer_col_boundaries_from_ocr(page_boxes: List[Dict], max_col: int) -> List[float]:
222 + """从OCR框推断列边界"""
223 + if not page_boxes or max_col <= 0:
224 + return []
225 +
226 + x_centers = [box['center_x'] for box in page_boxes]
227 + if not x_centers:
228 + return []
229 +
230 + x_sorted = sorted(x_centers)
231 +
232 + if max_col <= 1:
233 + return [min(x_sorted), max(x_sorted)]
234 +
235 + step = len(x_sorted) / max_col
236 +
237 + boundaries = []
238 + for i in range(max_col + 1):
239 + idx = int(i * step)
240 + if idx >= len(x_sorted):
241 + idx = len(x_sorted) - 1
242 + if i == 0:
243 + boundaries.append(x_sorted[idx] - 5)
244 + elif i == max_col:
245 + boundaries.append(x_sorted[idx] + 5)
246 + else:
247 + boundaries.append(x_sorted[idx])
248 +
249 + return sorted(boundaries)
250 +
251 +
252 +def calculate_iou(bbox1: List[float], bbox2: List[float]) -> float:
253 + """计算两个bbox的交并比(IoU)"""
254 + x1_1, y1_1, x2_1, y2_1 = bbox1[:4]
255 + x1_2, y1_2, x2_2, y2_2 = bbox2[:4]
256 +
257 + # 计算交集
258 + inter_x1 = max(x1_1, x1_2)
259 + inter_y1 = max(y1_1, y1_2)
260 + inter_x2 = min(x2_1, x2_2)
261 + inter_y2 = min(y2_1, y2_2)
262 +
263 + if inter_x2 <= inter_x1 or inter_y2 <= inter_y1:
264 + return 0.0
265 +
266 + inter_area = (inter_x2 - inter_x1) * (inter_y2 - inter_y1)
267 +
268 + # 计算并集
269 + area1 = (x2_1 - x1_1) * (y2_1 - y1_1)
270 + area2 = (x2_2 - x1_2) * (y2_2 - y1_2)
271 + union_area = area1 + area2 - inter_area
272 +
273 + if union_area <= 0:
274 + return 0.0
275 +
276 + return inter_area / union_area
277 +
278 +
279 +def aggregate_ocr_scores_in_bbox(page_boxes: List[Dict], bbox: List[float], default_score: float = 0.0) -> float:
280 + """聚合bbox区域内的OCR框的score,使用IoU加权平均"""
281 + if not page_boxes:
282 + # 如果没有OCR框,使用提供的default_score(应该是span_score)
283 + return default_score
284 +
285 + # 如果default_score为0或太小,使用更合理的默认值
286 + if default_score <= 0:
287 + default_score = 0.8
288 +
289 + x1, y1, x2, y2 = bbox[:4]
290 + weighted_scores = []
291 + total_weight = 0.0
292 +
293 + for box in page_boxes:
294 + box_x1, box_y1, box_x2, box_y2 = box['bbox'][:4]
295 +
296 + # 计算IoU作为权重
297 + iou = calculate_iou(bbox, [box_x1, box_y1, box_x2, box_y2])
298 +
299 + # 只考虑有重叠的框(IoU > 0)
300 + if iou > 0:
301 + weight = iou
302 + box_score = box['score'] if 'score' in box and box['score'] > 0 else default_score
303 + weighted_scores.append(box_score * weight)
304 + total_weight += weight
305 +
306 + if total_weight > 0 and weighted_scores:
307 + # 返回加权平均分
308 + weighted_avg = sum(weighted_scores) / total_weight
309 + return float(weighted_avg)
310 +
311 + return default_score
312 +
313 +
314 +def compute_table_cells(
315 + html: str,
316 + table_bbox: List[float],
317 + span_score: float = 0.0,
318 + ocr_result: Optional[List] = None,
319 + crop_info: Optional[Dict] = None
320 +) -> List[Dict]:
321 + """
322 + 计算表格HTML中每个td单元格的bbox和score
323 +
324 + Args:
325 + html: 表格HTML字符串
326 + table_bbox: 表格在页面中的bbox [x1, y1, x2, y2]
327 + span_score: 表格整体的score
328 + ocr_result: OCR结果列表(可选),格式为 [[dt_box, text, score], ...]
329 + crop_info: 裁剪信息(可选),包含crop_xmin, crop_ymin等
330 +
331 + Returns:
332 + 单元格列表,每个包含:row_index, col_index, rowspan, colspan, text, bbox, score
333 + """
334 + if not html:
335 + return []
336 +
337 + # 安全地检查table_bbox长度
338 + try:
339 + bbox_len = len(table_bbox) if hasattr(table_bbox, '__len__') else 0
340 + if bbox_len < 4:
341 + return []
342 + except (TypeError, ValueError):
343 + return []
344 +
345 + # 解析HTML
346 + rows = parse_html_to_grid(html)
347 + if not rows:
348 + return []
349 +
350 + max_row, max_col = infer_max_row_col(rows)
351 + if max_row == 0 or max_col == 0:
352 + return []
353 +
354 + # 安全地提取坐标,处理numpy数组
355 + try:
356 + bbox_list = list(table_bbox[:4]) if not isinstance(table_bbox, list) else table_bbox[:4]
357 + x1, y1, x2, y2 = float(bbox_list[0]), float(bbox_list[1]), float(bbox_list[2]), float(bbox_list[3])
358 + except (ValueError, TypeError, IndexError) as e:
359 + logger.warning(f"Error extracting table bbox coordinates: {e}")
360 + return []
361 +
362 + # 计算行边界和列边界
363 + if ocr_result:
364 + # 方法B: OCR引导的分割
365 + page_boxes = map_ocr_boxes_to_page(ocr_result, table_bbox, crop_info)
366 +
367 + if page_boxes:
368 + row_bounds = infer_row_boundaries_from_ocr(page_boxes, max_row)
369 + col_bounds = infer_col_boundaries_from_ocr(page_boxes, max_col)
370 + else:
371 + # 回退到均匀分割
372 + row_bounds = uniform_bounds(y1, y2, max_row)
373 + col_bounds = uniform_bounds(x1, x2, max_col)
374 + else:
375 + # 方法A: 均匀分割
376 + row_bounds = uniform_bounds(y1, y2, max_row)
377 + col_bounds = uniform_bounds(x1, x2, max_col)
378 +
379 + # 如果边界数量不足,补充
380 + while len(row_bounds) < max_row + 1:
381 + if len(row_bounds) == 0:
382 + row_bounds = [y1, y2]
383 + else:
384 + step = (y2 - y1) / max_row
385 + row_bounds = [y1 + i * step for i in range(max_row + 1)]
386 + break
387 +
388 + while len(col_bounds) < max_col + 1:
389 + if len(col_bounds) == 0:
390 + col_bounds = [x1, x2]
391 + else:
392 + step = (x2 - x1) / max_col
393 + col_bounds = [x1 + i * step for i in range(max_col + 1)]
394 + break
395 +
396 + # 生成单元格bbox和score
397 + cells = []
398 + page_boxes_cache = map_ocr_boxes_to_page(ocr_result, table_bbox, crop_info) if ocr_result else []
399 +
400 + for row in rows:
401 + for col in row['cols']:
402 + row_idx = row['row_index']
403 + col_idx = col['col_index']
404 +
405 + # 计算bbox(保留为整数)
406 + try:
407 + row_start = row_idx
408 + row_end = min(row_idx + col['rowspan'], len(row_bounds) - 1)
409 + col_start = col_idx
410 + col_end = min(col_idx + col['colspan'], len(col_bounds) - 1)
411 +
412 + cell_y1 = row_bounds[row_start] if row_start < len(row_bounds) else y1
413 + cell_y2 = row_bounds[row_end] if row_end < len(row_bounds) else y2
414 + cell_x1 = col_bounds[col_start] if col_start < len(col_bounds) else x1
415 + cell_x2 = col_bounds[col_end] if col_end < len(col_bounds) else x2
416 +
417 + # bbox坐标四舍五入为整数
418 + cell_bbox = [
419 + int(round(cell_x1)),
420 + int(round(cell_y1)),
421 + int(round(cell_x2)),
422 + int(round(cell_y2))
423 + ]
424 + except (IndexError, ValueError) as e:
425 + logger.warning(f"Error calculating cell bbox: {e}, using table bbox")
426 + cell_bbox = [
427 + int(round(x1)),
428 + int(round(y1)),
429 + int(round(x2)),
430 + int(round(y2))
431 + ]
432 +
433 + # ============================================
434 + # 单元格score计算逻辑
435 + # ============================================
436 + # 基于spans['score']的计算公式调整cell['score']
437 + #
438 + # 公式说明:
439 + # cell_score = base_score * content_factor * structure_factor * quality_factor
440 + #
441 + # 其中:
442 + # base_score: 基于spans['score']的基础置信度(通过IoU加权OCR或直接继承)
443 + # content_factor: 内容因子(根据文本内容调整)
444 + # structure_factor: 结构因子(根据单元格结构合理性调整)
445 + # quality_factor: 质量因子(根据单元格bbox质量调整)
446 + # ============================================
447 +
448 + # 先使用临时浮点bbox计算score(用于IoU计算)
449 + temp_bbox = [float(cell_bbox[0]), float(cell_bbox[1]), float(cell_bbox[2]), float(cell_bbox[3])]
450 +
451 + # 获取单元格文本
452 + cell_text = col['text'].strip()
453 +
454 + # -----------------------------------------------------
455 + # 步骤1: 计算base_score(基础置信度)
456 + # -----------------------------------------------------
457 + # 基于spans['score']的逻辑:spans['score'] = layout_det['score']
458 + # 对于cells,我们使用表格整体的span_score作为基准
459 + # 然后通过OCR结果(如果有)进行细粒度调整
460 + # -----------------------------------------------------
461 + # 处理span_score为0或未定义的情况,使用合理的默认值
462 + if span_score <= 0:
463 + logger.warning(f"Invalid span_score: {span_score}, using default 0.8")
464 + span_score = 0.8 # 使用合理的默认值
465 +
466 + if page_boxes_cache:
467 + # 如果有OCR结果,使用IoU加权平均(与方法中spans的处理逻辑一致)
468 + base_score = aggregate_ocr_scores_in_bbox(page_boxes_cache, temp_bbox, span_score)
469 + else:
470 + # 如果没有OCR结果,直接使用span_score(类似于spans的处理)
471 + base_score = span_score
472 +
473 + # -----------------------------------------------------
474 + # 步骤2: 计算content_factor(内容因子)
475 + # -----------------------------------------------------
476 + # 根据单元格是否有文本内容调整置信度
477 + # 有文本 -> 置信度更高,空单元格 -> 置信度较低
478 + # -----------------------------------------------------
479 + if cell_text:
480 + # 有文本:保持或稍微提升置信度
481 + # 文本越短,可能是标题或标签,置信度稍低
482 + # 文本较长,可能是内容单元格,置信度稍高
483 + text_length = len(cell_text)
484 + if text_length < 3:
485 + content_factor = 0.9 # 超短文本(可能是编号、符号等)
486 + elif text_length < 10:
487 + content_factor = 1.0 # 短文本(标题、标签等)
488 + else:
489 + content_factor = 1.05 # 长文本(内容单元格)
490 + # 限制content_factor在合理范围
491 + content_factor = min(1.1, content_factor)
492 + else:
493 + # 空单元格:显著降低置信度(但不为0,因为空单元格也可能是合理的)
494 + content_factor = 0.35
495 +
496 + # -----------------------------------------------------
497 + # 步骤3: 计算structure_factor(结构因子)
498 + # -----------------------------------------------------
499 + # 根据单元格的跨行跨列情况调整置信度
500 + # 跨行列的单元格通常结构更复杂,可能需要不同的置信度
501 + # -----------------------------------------------------
502 + if col['rowspan'] > 1 or col['colspan'] > 1:
503 + # 跨行列单元格:保持正常置信度
504 + structure_factor = 1.0
505 + else:
506 + # 普通单元格:保持正常置信度
507 + structure_factor = 1.0
508 +
509 + # -----------------------------------------------------
510 + # 步骤4: 计算quality_factor(质量因子)
511 + # -----------------------------------------------------
512 + # 根据单元格bbox大小和质量调整置信度
513 + # 太小的单元格可能是噪声,置信度降低
514 + # -----------------------------------------------------
515 + cell_width = cell_bbox[2] - cell_bbox[0]
516 + cell_height = cell_bbox[3] - cell_bbox[1]
517 + cell_area = cell_width * cell_height
518 +
519 + # 单元格bbox质量评估
520 + if cell_area < 100: # 面积小于100像素 -> 噪声可能性高
521 + quality_factor = 0.5
522 + elif cell_area < 400: # 面积在100-400像素 -> 可疑
523 + quality_factor = 0.75
524 + else: # 面积>=400像素 -> 正常
525 + quality_factor = 1.0
526 +
527 + # -----------------------------------------------------
528 + # 步骤5: 综合计算最终cell_score
529 + # -----------------------------------------------------
530 + # 应用公式:cell_score = base_score * content_factor * structure_factor * quality_factor
531 + # 然后限制在[0.0, 1.0]范围内
532 + # -----------------------------------------------------
533 + cell_score = base_score * content_factor * structure_factor * quality_factor
534 +
535 + # 确保score在合理范围内 [0.0, 1.0]
536 + cell_score = max(0.0, min(1.0, float(cell_score)))
537 +
538 + # 调试日志(第一个单元格)
539 + if row_idx == 0 and col_idx == 0:
540 + logger.debug(f"Cell score calculation: base={base_score:.4f}, "
541 + f"content={content_factor:.4f}, quality={quality_factor:.4f}, "
542 + f"final={cell_score:.4f}, text='{cell_text[:20]}'")
543 +
544 + # -----------------------------------------------------
545 + # 计算公式总结
546 + # -----------------------------------------------------
547 + # cell_score = base_score * content_factor * structure_factor * quality_factor
548 + #
549 + # 参数说明:
550 + # - base_score:
551 + # * 有OCR: IoU加权的OCR score(继承spans逻辑)
552 + # * 无OCR: span_score(直接继承)
553 + # - content_factor:
554 + # * 空单元格: 0.35
555 + # * 超短文本(<3): 0.9
556 + # * 短文本(3-10): 1.0
557 + # * 长文本(>=10): 1.05 (上限1.1)
558 + # - structure_factor: 1.0 (当前统一,可根据需要调整)
559 + # - quality_factor:
560 + # * area < 100: 0.5
561 + # * 100 <= area < 400: 0.75
562 + # * area >= 400: 1.0
563 + # -----------------------------------------------------
564 +
565 + cells.append({
566 + 'row_index': row_idx,
567 + 'col_index': col_idx,
568 + 'rowspan': col['rowspan'],
569 + 'colspan': col['colspan'],
570 + 'text': col['text'],
571 + 'bbox': cell_bbox, # 已经是整数列表
572 + 'score': round(cell_score, 4) # 保留4位小数
573 + })
574 +
575 + return cells
576 +