Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
5685b22b
Unverified
Commit
5685b22b
authored
Jul 15, 2025
by
Sidney233
Committed by
GitHub
Jul 15, 2025
Browse files
Merge branch 'opendatalab:dev' into dev
parents
77c6b669
7e34fe70
Changes
38
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
843 additions
and
712 deletions
+843
-712
docs/zh/index.md
docs/zh/index.md
+9
-6
docs/zh/known_issues.md
docs/zh/known_issues.md
+0
-10
docs/zh/output_file.md
docs/zh/output_file.md
+0
-434
docs/zh/quick_start/docker_deployment.md
docs/zh/quick_start/docker_deployment.md
+69
-0
docs/zh/quick_start/extension_modules.md
docs/zh/quick_start/extension_modules.md
+37
-0
docs/zh/quick_start/index.md
docs/zh/quick_start/index.md
+40
-11
docs/zh/quick_start/local_deployment.md
docs/zh/quick_start/local_deployment.md
+0
-72
docs/zh/quick_start/online_demo.md
docs/zh/quick_start/online_demo.md
+0
-5
docs/zh/todo.md
docs/zh/todo.md
+0
-9
docs/zh/usage/advanced_cli_parameters.md
docs/zh/usage/advanced_cli_parameters.md
+61
-0
docs/zh/usage/cli_tools.md
docs/zh/usage/cli_tools.md
+75
-0
docs/zh/usage/config.md
docs/zh/usage/config.md
+0
-11
docs/zh/usage/index.md
docs/zh/usage/index.md
+53
-103
docs/zh/usage/model_source.md
docs/zh/usage/model_source.md
+55
-0
docs/zh/usage/output_files.md
docs/zh/usage/output_files.md
+381
-0
mineru/backend/vlm/token_to_middle_json.py
mineru/backend/vlm/token_to_middle_json.py
+10
-8
mineru/utils/model_utils.py
mineru/utils/model_utils.py
+42
-30
mkdocs.yml
mkdocs.yml
+11
-13
No files found.
docs/zh/index.md
View file @
5685b22b
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
<img
src=
"../images/MinerU-logo.png"
width=
"300px"
style=
"vertical-align:middle;"
>
<img
src=
"../images/MinerU-logo.png"
width=
"300px"
style=
"vertical-align:middle;"
>
</p>
</p>
</div>
</div>
<!-- icon -->
<!-- icon -->
[

](https://github.com/opendatalab/MinerU)
[

](https://github.com/opendatalab/MinerU)
...
@@ -21,15 +22,11 @@
...
@@ -21,15 +22,11 @@
[

](https://arxiv.org/abs/2409.18839)
[

](https://arxiv.org/abs/2409.18839)
[

](https://deepwiki.com/opendatalab/MinerU)
[

](https://deepwiki.com/opendatalab/MinerU)
<div
align=
"center"
xmlns=
"http://www.w3.org/1999/html"
>
<div
align=
"center"
>
<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>
<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>
<!-- hot link -->
<!-- hot link -->
<p
align=
"center"
>
<p
align=
"center"
>
<a
href=
"https://github.com/opendatalab/PDF-Extract-Kit"
>
PDF-Extract-Kit: 高质量PDF解析工具箱
</a>
🔥🔥🔥
<br>
<br>
🚀
<a
href=
"https://mineru.net/?source=github"
>
MinerU 官网入口→✅ 免装在线版 ✅ 全功能客户端 ✅ 开发者API在线调用,省去部署麻烦,多种产品形态一键get,速冲!
</a>
🚀
<a
href=
"https://mineru.net/?source=github"
>
MinerU 官网入口→✅ 免装在线版 ✅ 全功能客户端 ✅ 开发者API在线调用,省去部署麻烦,多种产品形态一键get,速冲!
</a>
</p>
</p>
...
@@ -62,4 +59,10 @@ MinerU诞生于[书生-浦语](https://github.com/InternLM/InternLM)的预训练
...
@@ -62,4 +59,10 @@ MinerU诞生于[书生-浦语](https://github.com/InternLM/InternLM)的预训练
-
支持多种输出格式,如多模态与NLP的Markdown、按阅读顺序排序的JSON、含有丰富信息的中间格式等
-
支持多种输出格式,如多模态与NLP的Markdown、按阅读顺序排序的JSON、含有丰富信息的中间格式等
-
支持多种可视化结果,包括layout可视化、span可视化等,便于高效确认输出效果与质检
-
支持多种可视化结果,包括layout可视化、span可视化等,便于高效确认输出效果与质检
-
支持纯CPU环境运行,并支持 GPU(CUDA)/NPU(CANN)/MPS 加速
-
支持纯CPU环境运行,并支持 GPU(CUDA)/NPU(CANN)/MPS 加速
-
兼容Windows、Linux和Mac平台
-
兼容Windows、Linux和Mac平台
\ No newline at end of file
## 使用指南
-
[
快速上手指南
](
./quick_start/index.md
)
-
[
详细使用说明
](
./usage/index.md
)
\ No newline at end of file
docs/zh/known_issues.md
deleted
100644 → 0
View file @
77c6b669
# Known Issues
-
阅读顺序基于模型对可阅读内容在空间中的分布进行排序,在极端复杂的排版下可能会部分区域乱序
-
对竖排文字的支持较为有限
-
目录和列表通过规则进行识别,少部分不常见的列表形式可能无法识别
-
代码块在layout模型里还没有支持
-
漫画书、艺术图册、小学教材、习题尚不能很好解析
-
表格识别在复杂表格上可能会出现行/列识别错误
-
在小语种PDF上,OCR识别可能会出现字符不准确的情况(如拉丁文的重音符号、阿拉伯文易混淆字符等)
-
部分公式可能会无法在markdown中渲染
\ No newline at end of file
docs/zh/output_file.md
deleted
100644 → 0
View file @
77c6b669
This diff is collapsed.
Click to expand it.
docs/zh/quick_start/docker_deployment.md
0 → 100644
View file @
5685b22b
# 使用docker部署Mineru
MinerU提供了便捷的docker部署方式,这有助于快速搭建环境并解决一些棘手的环境兼容问题。
## 使用 Dockerfile 构建镜像:
```
bash
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/china/Dockerfile
docker build
-t
mineru-sglang:latest
-f
Dockerfile .
```
> [!TIP]
> [Dockerfile](https://github.com/opendatalab/MinerU/blob/master/docker/china/Dockerfile)默认使用`lmsysorg/sglang:v0.4.8.post1-cu126`作为基础镜像,支持Turing/Ampere/Ada Lovelace/Hopper平台,
> 如您使用较新的`Blackwell`平台,请将基础镜像修改为`lmsysorg/sglang:v0.4.8.post1-cu128-b200` 再执行build操作。
## Docker说明
Mineru的docker使用了
`lmsysorg/sglang`
作为基础镜像,因此在docker中默认集成了
`sglang`
推理加速框架和必需的依赖环境。因此在满足条件的设备上,您可以直接使用
`sglang`
加速VLM模型推理。
> [!NOTE]
> 使用`sglang`加速VLM模型推理需要满足的条件是:
>
> - 设备包含Turing及以后架构的显卡,且可用显存大于等于8G。
> - 物理机的显卡驱动应支持CUDA 12.6或更高版本,`Blackwell`平台应支持CUDA 12.8及更高版本,可通过`nvidia-smi`命令检查驱动版本。
> - docker中能够访问物理机的显卡设备。
>
> 如果您的设备不满足上述条件,您仍然可以使用MinerU的其他功能,但无法使用`sglang`加速VLM模型推理,即无法使用`vlm-sglang-engine`后端和启动`vlm-sglang-server`服务。
## 启动 Docker 容器:
```
bash
docker run
--gpus
all
\
--shm-size
32g
\
-p
30000:30000
-p
7860:7860
-p
8000:8000
\
--ipc
=
host
\
-it
mineru-sglang:latest
\
/bin/bash
```
执行该命令后,您将进入到Docker容器的交互式终端,并映射了一些端口用于可能会使用的服务,您可以直接在容器内运行MinerU相关命令来使用MinerU的功能。
您也可以直接通过替换
`/bin/bash`
为服务启动命令来启动MinerU服务,详细说明请参考
[
MinerU使用文档
](
../usage/index_back.md
)
。
## 通过 Docker Compose 直接启动服务
我们提供了
`compose.yml`
文件,您可以通过它来快速启动MinerU服务。
```
bash
# 下载 compose.yaml 文件
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/compose.yaml
```
-
启动
`sglang-server`
服务,并通过
`vlm-sglang-client`
后端连接
`sglang-server`
:
```
bash
docker compose
-f
compose.yaml
--profile
mineru-sglang-server up
-d
# 在另一个终端中通过sglang client连接sglang server(只需cpu与网络,不需要sglang环境)
mineru
-p
<input_path>
-o
<output_path>
-b
vlm-sglang-client
-u
http://<server_ip>:30000
```
-
启动 API 服务:
```
bash
docker compose
-f
compose.yaml
--profile
mineru-api up
-d
```
>[!TIP]
>在浏览器中访问 `http://<server_ip>:8000/docs` 查看API文档。
-
启动 Gradio WebUI 服务:
```
bash
docker compose
-f
compose.yaml
--profile
mineru-gradio up
-d
```
>[!TIP]
>在浏览器中访问 `http://<server_ip>:7860` 使用 Gradio WebUI 或访问 `http://<server_ip>:7860/?view=api` 使用 Gradio API。
\ No newline at end of file
docs/zh/quick_start/extension_modules.md
0 → 100644
View file @
5685b22b
# MinerU 扩展模块安装指南
MinerU 支持根据不同需求,按需安装扩展模块,以增强功能或支持特定的模型后端。
## 常见场景
### 核心功能安装
`core`
模块是 MinerU 的核心依赖,包含了除
`sglang`
外的所有功能模块。安装此模块可以确保 MinerU 的基本功能正常运行。
```
bash
uv pip
install
mineru[core]
```
---
### 使用`sglang`加速 VLM 模型推理
`sglang`
模块提供了对 VLM 模型推理的加速支持,适用于具有 Turing 及以后架构的显卡(8G 显存及以上)。安装此模块可以显著提升模型推理速度。
在配置中,
`all`
包含了
`core`
和
`sglang`
模块,因此
`mineru[all]`
和
`mineru[core,sglang]`
是等价的。
```
bash
uv pip
install
mineru[all]
```
> [!TIP]
> 如在安装包含sglang的完整包过程中发生异常,请参考 [sglang 官方文档](https://docs.sglang.ai/start/install.html) 尝试解决,或直接使用 [Docker](./docker_deployment.md) 方式部署镜像。
---
### 安装轻量版client连接sglang-server使用
如果您需要在边缘设备上安装轻量版的 client 端以连接
`sglang-server`
,可以安装mineru的基础包,非常轻量,适合在只有cpu和网络连接的设备上使用。
```
bash
uv pip
install
mineru
```
---
### 在过时的linux系统上使用pipeline后端
如果您的系统过于陈旧,无法满足
`mineru[core]`
的依赖要求,该选项可以最低限度的满足 MinerU 的运行需求,适用于老旧系统无法升级且仅需使用 pipeline 后端的场景。
```
bash
uv pip
install
mineru[pipeline_old_linux]
```
\ No newline at end of file
docs/zh/quick_start/index.md
View file @
5685b22b
...
@@ -2,15 +2,16 @@
...
@@ -2,15 +2,16 @@
如果遇到任何安装问题,请先查询
[
FAQ
](
../FAQ/index.md
)
如果遇到任何安装问题,请先查询
[
FAQ
](
../FAQ/index.md
)
## 在线体验
如果遇到解析效果不及预期,参考
[
Known Issues
](
../known_issues.md
)
-
官网在线demo:官网在线版功能与客户端一致,界面美观,功能丰富,需要登录使用
-
[

](https://mineru.net/OpenSourceTools/Extractor?source=github)
-
基于Gradio的在线demo:基于gradio开发的webui,界面简洁,仅包含核心解析功能,免登录
-
[

](https://www.modelscope.cn/studios/OpenDataLab/MinerU)
-
[

](https://huggingface.co/spaces/opendatalab/MinerU)
有2种不同方式可以体验MinerU的效果:
## 本地部署
-
[
在线体验
](
online_demo.md
)
-
[
本地部署
](
local_deployment.md
)
> [!WARNING]
> [!WARNING]
> **安装前必看——软硬件环境支持说明**
> **安装前必看——软硬件环境支持说明**
...
@@ -30,9 +31,9 @@
...
@@ -30,9 +31,9 @@
</tr>
</tr>
<tr>
<tr>
<td>
操作系统
</td>
<td>
操作系统
</td>
<td>
windows/linux/
mac
</td>
<td>
Linux / Windows /
mac
OS
</td>
<td>
windows/linux
</td>
<td>
Linux / Windows
</td>
<td>
windows(wsl2)/linux
</td>
<td>
Linux / Windows (via WSL2)
</td>
</tr>
</tr>
<tr>
<tr>
<td>
CPU推理支持
</td>
<td>
CPU推理支持
</td>
...
@@ -42,7 +43,7 @@
...
@@ -42,7 +43,7 @@
<tr>
<tr>
<td>
GPU要求
</td>
<td>
GPU要求
</td>
<td>
Turing及以后架构,6G显存以上或Apple Silicon
</td>
<td>
Turing及以后架构,6G显存以上或Apple Silicon
</td>
<td
colspan=
"2"
>
Ampere
及以后架构,8G显存以上
</td>
<td
colspan=
"2"
>
Turing
及以后架构,8G显存以上
</td>
</tr>
</tr>
<tr>
<tr>
<td>
内存要求
</td>
<td>
内存要求
</td>
...
@@ -56,4 +57,32 @@
...
@@ -56,4 +57,32 @@
<td>
python版本
</td>
<td>
python版本
</td>
<td
colspan=
"3"
>
3.10-3.13
</td>
<td
colspan=
"3"
>
3.10-3.13
</td>
</tr>
</tr>
</table>
</table>
\ No newline at end of file
### 安装 MinerU
#### 使用pip或uv安装MinerU
```
bash
pip
install
--upgrade
pip
-i
https://mirrors.aliyun.com/pypi/simple
pip
install
uv
-i
https://mirrors.aliyun.com/pypi/simple
uv pip
install
-U
"mineru[core]"
-i
https://mirrors.aliyun.com/pypi/simple
```
#### 通过源码安装MinerU
```
bash
git clone https://github.com/opendatalab/MinerU.git
cd
MinerU
uv pip
install
-e
.[core]
-i
https://mirrors.aliyun.com/pypi/simple
```
> [!TIP]
> `mineru[core]`包含除`sglang`加速外的所有核心功能,兼容Windows / Linux / macOS系统,适合绝大多数用户。
> 如果您有使用`sglang`加速VLM模型推理,或是在边缘设备安装轻量版client端等需求,可以参考文档[扩展模块安装指南](./extension_modules.md)。
---
#### 使用docker部署Mineru
MinerU提供了便捷的docker部署方式,这有助于快速搭建环境并解决一些棘手的环境兼容问题。
您可以在文档中获取
[
Docker部署说明
](
./docker_deployment.md
)
。
---
\ No newline at end of file
docs/zh/quick_start/local_deployment.md
deleted
100644 → 0
View file @
77c6b669
# 本地部署
## 安装 MinerU
### 使用 pip 或 uv 安装
```
bash
pip
install
--upgrade
pip
-i
https://mirrors.aliyun.com/pypi/simple
pip
install
uv
-i
https://mirrors.aliyun.com/pypi/simple
uv pip
install
-U
"mineru[core]"
-i
https://mirrors.aliyun.com/pypi/simple
```
### 源码安装
```
bash
git clone https://github.com/opendatalab/MinerU.git
cd
MinerU
uv pip
install
-e
.[core]
-i
https://mirrors.aliyun.com/pypi/simple
```
> [!NOTE]
> Linux和macOS系统安装后自动支持cuda/mps加速,Windows用户如需使用cuda加速,
> 请前往 [Pytorch官网](https://pytorch.org/get-started/locally/) 选择合适的cuda版本安装pytorch。
### 安装完整版(支持 sglang 加速)(需确保设备有Turing及以后架构,8G显存及以上显卡)
如需使用
**sglang 加速 VLM 模型推理**
,请选择合适的方式安装完整版本:
-
使用uv或pip安装
```
bash
uv pip
install
-U
"mineru[all]"
-i
https://mirrors.aliyun.com/pypi/simple
```
-
从源码安装:
```
bash
uv pip
install
-e
.[all]
-i
https://mirrors.aliyun.com/pypi/simple
```
> [!TIP]
> sglang安装过程中如发生异常,请参考[sglang官方文档](https://docs.sglang.ai/start/install.html)尝试解决或直接使用docker方式安装。
-
使用 Dockerfile 构建镜像:
```
bash
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/china/Dockerfile
docker build
-t
mineru-sglang:latest
-f
Dockerfile .
```
启动 Docker 容器:
```
bash
docker run
--gpus
all
\
--shm-size
32g
\
-p
30000:30000
\
--ipc
=
host
\
mineru-sglang:latest
\
mineru-sglang-server
--host
0.0.0.0
--port
30000
```
或使用 Docker Compose 启动:
```
bash
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/compose.yaml
docker compose
-f
compose.yaml up
-d
```
> [!TIP]
> Dockerfile默认使用`lmsysorg/sglang:v0.4.8.post1-cu126`作为基础镜像,支持Turing/Ampere/Ada Lovelace/Hopper平台,
> 如您使用较新的`Blackwell`平台,请将基础镜像修改为`lmsysorg/sglang:v0.4.8.post1-cu128-b200`。
### 安装client(用于在仅需 CPU 和网络连接的边缘设备上连接 sglang-server)
```
bash
uv pip
install
-U
mineru
-i
https://mirrors.aliyun.com/pypi/simple
mineru
-p
<input_path>
-o
<output_path>
-b
vlm-sglang-client
-u
http://<host_ip>:<port>
```
---
\ No newline at end of file
docs/zh/quick_start/online_demo.md
deleted
100644 → 0
View file @
77c6b669
# 在线体验
[

](https://mineru.net/OpenSourceTools/Extractor?source=github)
[

](https://www.modelscope.cn/studios/OpenDataLab/MinerU)
[

](https://huggingface.co/spaces/opendatalab/MinerU)
\ No newline at end of file
docs/zh/todo.md
deleted
100644 → 0
View file @
77c6b669
# TODO
-
[x] 基于模型的阅读顺序
-
[x] 正文中目录、列表识别
-
[x] 表格识别
-
[x] 标题分级
-
[ ] 正文中代码块识别
-
[
] [化学式识别
](
../chemical_knowledge_introduction/introduction.pdf
)
-
[ ] 几何图形识别
\ No newline at end of file
docs/zh/usage/a
pi
.md
→
docs/zh/usage/a
dvanced_cli_parameters
.md
View file @
5685b22b
# API 调用 或 可视化调用
# 命令行参数进阶技巧
1.
使用python api直接调用:
[
Python 调用示例
](
https://github.com/opendatalab/MinerU/blob/master/demo/demo.py
)
2.
使用fast api方式调用:
```
bash
mineru-api
--host
127.0.0.1
--port
8000
```
在浏览器中访问 http://127.0.0.1:8000/docs 查看API文档。
3.
使用gradio webui 或 gradio api调用
```
bash
# 使用 pipeline/vlm-transformers/vlm-sglang-client 后端
mineru-gradio
--server-name
127.0.0.1
--server-port
7860
# 或使用 vlm-sglang-engine/pipeline 后端
mineru-gradio
--server-name
127.0.0.1
--server-port
7860
--enable-sglang-engine
true
```
在浏览器中访问 http://127.0.0.1:7860 使用 Gradio WebUI 或访问 http://127.0.0.1:7860/?view=api 使用 Gradio API。
## SGLang 加速参数优化
### 显存优化参数
> [!TIP]
> sglang加速模式目前支持在最低8G显存的Turing架构显卡上运行,但在显存<24G的显卡上可能会遇到显存不足的问题, 可以通过使用以下参数来优化显存使用:
>
> - 如果您使用单张显卡遇到显存不足的情况时,可能需要调低KV缓存大小,`--mem-fraction-static 0.5`,如仍出现显存不足问题,可尝试进一步降低到`0.4`或更低
> - 如您有两张以上显卡,可尝试通过张量并行(TP)模式简单扩充可用显存:`--tp-size 2`
### 性能优化参数
> [!TIP]
> 如果您已经可以正常使用sglang对vlm模型进行加速推理,但仍然希望进一步提升推理速度,可以尝试以下参数:
>
> - 如果您有超过多张显卡,可以使用sglang的多卡并行模式来增加吞吐量:`--dp-size 2`
> - 同时您可以启用`torch.compile`来将推理速度加速约15%:`--enable-torch-compile`
### 参数传递说明
> [!TIP]
> [!TIP]
> - 以下是一些使用sglang加速模式的建议和注意事项:
> - sglang加速模式目前支持在最低8G显存的Turing架构显卡上运行,但在显存<24G的显卡上可能会遇到显存不足的问题, 可以通过使用以下参数来优化显存使用:
> - 如果您使用单张显卡遇到显存不足的情况时,可能需要调低KV缓存大小,`--mem-fraction-static 0.5`,如仍出现显存不足问题,可尝试进一步降低到`0.4`或更低。
> - 如您有两张以上显卡,可尝试通过张量并行(TP)模式简单扩充可用显存:`--tp-size 2`
> - 如果您已经可以正常使用sglang对vlm模型进行加速推理,但仍然希望进一步提升推理速度,可以尝试以下参数:
> - 如果您有超过多张显卡,可以使用sglang的多卡并行模式来增加吞吐量:`--dp-size 2`
> - 同时您可以启用`torch.compile`来将推理速度加速约15%:`--enable-torch-compile`
> - 如果您想了解更多有关`sglang`的参数使用方法,请参考 [sglang官方文档](https://docs.sglang.ai/backend/server_arguments.html#common-launch-commands)
> - 如果您想了解更多有关`sglang`的参数使用方法,请参考 [sglang官方文档](https://docs.sglang.ai/backend/server_arguments.html#common-launch-commands)
> - 所有sglang官方支持的参数都可用通过命令行参数传递给 MinerU,包括以下命令:`mineru`、`mineru-sglang-server`、`mineru-gradio`、`mineru-api`
> - 所有sglang官方支持的参数都可用通过命令行参数传递给 MinerU,包括以下命令:`mineru`、`mineru-sglang-server`、`mineru-gradio`、`mineru-api`
## GPU 设备选择与配置
### CUDA_VISIBLE_DEVICES 基本用法
> [!TIP]
> [!TIP]
> - 任何情况下,您都可以通过在命令行的开头添加`CUDA_VISIBLE_DEVICES` 环境变量来指定可见的 GPU 设备
。例如
:
> - 任何情况下,您都可以通过在命令行的开头添加`CUDA_VISIBLE_DEVICES` 环境变量来指定可见的 GPU 设备:
> ```bash
> ```bash
> CUDA_VISIBLE_DEVICES=1 mineru -p <input_path> -o <output_path>
> CUDA_VISIBLE_DEVICES=1 mineru -p <input_path> -o <output_path>
> ```
> ```
> - 这种指定方式对所有的命令行调用都有效,包括 `mineru`、`mineru-sglang-server`、`mineru-gradio` 和 `mineru-api`,且对`pipeline`、`vlm`后端均适用。
> - 这种指定方式对所有的命令行调用都有效,包括 `mineru`、`mineru-sglang-server`、`mineru-gradio` 和 `mineru-api`,且对`pipeline`、`vlm`后端均适用。
> - 以下是一些常见的 `CUDA_VISIBLE_DEVICES` 设置示例:
### 常见设备配置示例
> [!TIP]
> 以下是一些常见的 `CUDA_VISIBLE_DEVICES` 设置示例:
> ```bash
> ```bash
> CUDA_VISIBLE_DEVICES=1 Only device 1 will be seen
> CUDA_VISIBLE_DEVICES=1 Only device 1 will be seen
> CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible
> CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible
> CUDA_VISIBLE_DEVICES=
“
0,1
”
Same as above, quotation marks are optional
> CUDA_VISIBLE_DEVICES=
"
0,1
"
Same as above, quotation marks are optional
> CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked
> CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked
> CUDA_VISIBLE_DEVICES="" No GPU will be visible
> CUDA_VISIBLE_DEVICES="" No GPU will be visible
> ```
> ```
> - 以下是一些可能的使用场景:
> - 如果您有多张显卡,需要指定卡0和卡1,并使用多卡并行来启动'sglang-server',可以使用以下命令:
### 实际应用场景
> [!TIP]
> 以下是一些可能的使用场景:
>
> - 如果您有多张显卡,需要指定卡0和卡1,并使用多卡并行来启动'sglang-server',可以使用以下命令:
> ```bash
> ```bash
> CUDA_VISIBLE_DEVICES=0,1 mineru-sglang-server --port 30000 --dp-size 2
> CUDA_VISIBLE_DEVICES=0,1 mineru-sglang-server --port 30000 --dp-size 2
> ```
> ```
> - 如果您有多张显卡,需要在卡0和卡1上启动两个`fastapi`服务,并分别监听不同的端口,可以使用以下命令:
>
> - 如果您有多张显卡,需要在卡0和卡1上启动两个`fastapi`服务,并分别监听不同的端口,可以使用以下命令:
> ```bash
> ```bash
> # 在终端1中
> # 在终端1中
> CUDA_VISIBLE_DEVICES=0 mineru-api --host 127.0.0.1 --port 8000
> CUDA_VISIBLE_DEVICES=0 mineru-api --host 127.0.0.1 --port 8000
> # 在终端2中
> # 在终端2中
> CUDA_VISIBLE_DEVICES=1 mineru-api --host 127.0.0.1 --port 8001
> CUDA_VISIBLE_DEVICES=1 mineru-api --host 127.0.0.1 --port 8001
> ```
> ```
---
docs/zh/usage/cli_tools.md
0 → 100644
View file @
5685b22b
# 命令行工具使用说明
## 查看帮助信息
要查看 MinerU 命令行工具的帮助信息,可以使用
`--help`
参数。以下是各个命令行工具的帮助信息示例:
```
bash
mineru
--help
Usage: mineru
[
OPTIONS]
Options:
-v
,
--version
显示版本并退出
-p
,
--path
PATH 输入文件路径或目录(必填)
-o
,
--output
PATH 输出目录(必填)
-m
,
--method
[
auto|txt|ocr] 解析方法:auto(默认)、txt、ocr(仅用于 pipeline 后端)
-b
,
--backend
[
pipeline|vlm-transformers|vlm-sglang-engine|vlm-sglang-client]
解析后端(默认为 pipeline)
-l
,
--lang
[
ch|ch_server|ch_lite|en|korean|japan|chinese_cht|ta|te|ka|latin|arabic|east_slavic|cyrillic|devanagari]
指定文档语言(可提升 OCR 准确率,仅用于 pipeline 后端)
-u
,
--url
TEXT 当使用 sglang-client 时,需指定服务地址
-s
,
--start
INTEGER 开始解析的页码(从 0 开始)
-e
,
--end
INTEGER 结束解析的页码(从 0 开始)
-f
,
--formula
BOOLEAN 是否启用公式解析(默认开启)
-t
,
--table
BOOLEAN 是否启用表格解析(默认开启)
-d
,
--device
TEXT 推理设备(如 cpu/cuda/cuda:0/npu/mps,仅 pipeline 后端)
--vram
INTEGER 单进程最大 GPU 显存占用
(
GB
)
(仅 pipeline 后端)
--source
[
huggingface|modelscope|local]
模型来源,默认 huggingface
--help
显示帮助信息
```
```
bash
mineru-api
--help
Usage: mineru-api
[
OPTIONS]
Options:
--host
TEXT Server host
(
default: 127.0.0.1
)
--port
INTEGER Server port
(
default: 8000
)
--reload
Enable auto-reload
(
development mode
)
--help
Show this message and exit.
```
```
bash
mineru-gradio
--help
Usage: mineru-gradio
[
OPTIONS]
Options:
--enable-example
BOOLEAN Enable example files
for
input.The example
files to be input need to be placed
in
the
`
example
`
folder within the directory where
the
command
is currently executed.
--enable-sglang-engine
BOOLEAN Enable SgLang engine backend
for
faster
processing.
--enable-api
BOOLEAN Enable gradio API
for
serving the
application.
--max-convert-pages
INTEGER Set the maximum number of pages to convert
from PDF to Markdown.
--server-name
TEXT Set the server name
for
the Gradio app.
--server-port
INTEGER Set the server port
for
the Gradio app.
--latex-delimiters-type
[
a|b|all]
Set the
type
of LaTeX delimiters to use
in
Markdown rendering:
'a'
for
type
'$'
,
'b'
for
type
'()[]'
,
'all'
for
both types.
--help
Show this message and exit.
```
## 环境变量说明
MinerU命令行工具的某些参数存在相同功能的环境变量配置,通常环境变量配置的优先级高于命令行参数,且在所有命令行工具中都生效。
以下是常用的环境变量及其说明:
-
`MINERU_DEVICE_MODE`
:用于指定推理设备,支持
`cpu/cuda/cuda:0/npu/mps`
等设备类型,仅对
`pipeline`
后端生效。
-
`MINERU_VIRTUAL_VRAM_SIZE`
:用于指定单进程最大 GPU 显存占用(GB),仅对
`pipeline`
后端生效。
-
`MINERU_MODEL_SOURCE`
:用于指定模型来源,支持
`huggingface/modelscope/local`
,默认为
`huggingface`
,可通过环境变量切换为
`modelscope`
或使用本地模型。
-
`MINERU_TOOLS_CONFIG_JSON`
:用于指定配置文件路径,默认为用户目录下的
`mineru.json`
,可通过环境变量指定其他配置文件路径。
-
`MINERU_FORMULA_ENABLE`
:用于启用公式解析,默认为
`true`
,可通过环境变量设置为
`false`
来禁用公式解析。
-
`MINERU_TABLE_ENABLE`
:用于启用表格解析,默认为
`true`
,可通过环境变量设置为
`false`
来禁用表格解析。
docs/zh/usage/config.md
deleted
100644 → 0
View file @
77c6b669
# 基于配置文件扩展 MinerU 功能
-
MinerU 现已实现开箱即用,但也支持通过配置文件扩展功能。您可以在用户目录下创建
`mineru.json`
文件,添加自定义配置。
-
`mineru.json`
文件会在您使用内置模型下载命令
`mineru-models-download`
时自动生成,也可以通过将
[
配置模板文件
](
../../mineru.template.json
)
复制到用户目录下并重命名为
`mineru.json`
来创建。
-
以下是一些可用的配置选项:
-
`latex-delimiter-config`
:用于配置 LaTeX 公式的分隔符,默认为
`$`
符号,可根据需要修改为其他符号或字符串。
-
`llm-aided-config`
:用于配置 LLM 辅助标题分级的相关参数,兼容所有支持
`openai协议`
的 LLM 模型,默认使用
`阿里云百炼`
的
`qwen2.5-32b-instruct`
模型,您需要自行配置 API 密钥并将
`enable`
设置为
`true`
来启用此功能。
-
`models-dir`
:用于指定本地模型存储目录,请为
`pipeline`
和
`vlm`
后端分别指定模型目录,指定目录后您可通过配置环境变量
`export MINERU_MODEL_SOURCE=local`
来使用本地模型。
---
\ No newline at end of file
docs/zh/usage/index.md
View file @
5685b22b
# 使用 MinerU
# 使用 MinerU
## 命令行使用方式
## 快速配置模型源
MinerU默认使用
`huggingface`
作为模型源,若用户网络无法访问
`huggingface`
,可以通过环境变量便捷地切换模型源为
`modelscope`
:
### 基础用法
最简单的命令行调用方式如下:
```
bash
mineru
-p
<input_path>
-o
<output_path>
```
-
`<input_path>`
:本地 PDF/图片 文件或目录(支持 pdf/png/jpg/jpeg/webp/gif)
-
`<output_path>`
:输出目录
### 查看帮助信息
获取所有可用参数说明:
```
bash
```
bash
mineru
--help
export
MINERU_MODEL_SOURCE
=
modelscope
```
### 参数详解
```
text
Usage: mineru [OPTIONS]
Options:
-v, --version 显示版本并退出
-p, --path PATH 输入文件路径或目录(必填)
-o, --output PATH 输出目录(必填)
-m, --method [auto|txt|ocr] 解析方法:auto(默认)、txt、ocr(仅用于 pipeline 后端)
-b, --backend [pipeline|vlm-transformers|vlm-sglang-engine|vlm-sglang-client]
解析后端(默认为 pipeline)
-l, --lang [ch|ch_server|ch_lite|en|korean|japan|chinese_cht|ta|te|ka|latin|arabic|east_slavic|cyrillic|devanagari]
指定文档语言(可提升 OCR 准确率,仅用于 pipeline 后端)
-u, --url TEXT 当使用 sglang-client 时,需指定服务地址
-s, --start INTEGER 开始解析的页码(从 0 开始)
-e, --end INTEGER 结束解析的页码(从 0 开始)
-f, --formula BOOLEAN 是否启用公式解析(默认开启)
-t, --table BOOLEAN 是否启用表格解析(默认开启)
-d, --device TEXT 推理设备(如 cpu/cuda/cuda:0/npu/mps,仅 pipeline 后端)
--vram INTEGER 单进程最大 GPU 显存占用(GB)(仅 pipeline 后端)
--source [huggingface|modelscope|local]
模型来源,默认 huggingface
--help 显示帮助信息
```
```
有关模型源配置和自定义本地模型路径的更多信息,请参考文档中的
[
模型源说明
](
./model_source.md
)
。
---
---
## 模型源配置
## 通过命令行快速使用
MinerU内置了命令行工具,用户可以通过命令行快速使用MinerU进行PDF解析:
MinerU 默认在首次运行时自动从 HuggingFace 下载所需模型。若无法访问 HuggingFace,可通过以下方式切换模型源:
### 切换至 ModelScope 源
```
bash
```
bash
mineru
-p
<input_path>
-o
<output_path>
--source
modelscope
# 默认使用pipeline后端解析
```
或设置环境变量:
```
bash
export
MINERU_MODEL_SOURCE
=
modelscope
mineru
-p
<input_path>
-o
<output_path>
mineru
-p
<input_path>
-o
<output_path>
```
```
> [!TIP]
> - `<input_path>`:本地 PDF/图片 文件或目录
> - `<output_path>`:输出目录
>
> 更多关于输出文件的信息,请参考[输出文件说明](./output_file.md)。
### 使用本地模型
> [!NOTE]
> 命令行工具会在Linux和macOS系统自动尝试cuda/mps加速。Windows用户如需使用cuda加速,
#### 1. 下载模型到本地
> 请前往 [Pytorch官网](https://pytorch.org/get-started/locally/) 选择适合自己cuda版本的命令安装支持加速的`torch`和`torchvision`。
```
bash
mineru-models-download
--help
```
或使用交互式命令行工具选择模型下载:
```
bash
mineru-models-download
```
下载完成后,模型路径会在当前终端窗口输出,并自动写入用户目录下的
`mineru.json`
。
#### 2. 使用本地模型进行解析
```
bash
```
bash
mineru
-p
<input_path>
-o
<output_path>
--source
local
# 或指定vlm后端解析
mineru
-p
<input_path>
-o
<output_path>
-b
vlm-transformers
```
```
> [!TIP]
> vlm后端另外支持`sglang`加速,与`transformers`后端相比,`sglang`的加速比可达20~30倍,可以在[扩展模块安装指南](../quick_start/extension_modules.md)中查看支持`sglang`加速的完整包安装方法。
或通过环境变量启用:
如果需要通过自定义参数调整解析选项,您也可以在文档中查看更详细的
[
命令行工具使用说明
](
./cli_tools.md
)
。
```
bash
export
MINERU_MODEL_SOURCE
=
local
mineru
-p
<input_path>
-o
<output_path>
```
---
---
## 使用 sglang 加速 VLM 模型推理
## 通过api、webui、sglang-client/server进阶使用
### 通过 sglang-engine 模式
-
通过python api直接调用:
[
Python 调用示例
](
https://github.com/opendatalab/MinerU/blob/master/demo/demo.py
)
-
通过fast api方式调用:
```
bash
```
bash
mineru
-p
<input_path>
-o
<output_path>
-b
vlm-sglang-engine
mineru-api
--host
127.0.0.1
--port
8000
```
```
在浏览器中访问 http://127.0.0.1:8000/docs 查看API文档。
### 通过 sglang-server/client 模式
-
启动gradio webui 可视化前端:
```
bash
1.
启动 Server:
# 使用 pipeline/vlm-transformers/vlm-sglang-client 后端
mineru-gradio
--server-name
127.0.0.1
--server-port
7860
```
bash
# 或使用 vlm-sglang-engine/pipeline 后端(需安装sglang环境)
mineru-sglang-server
--port
30000
mineru-gradio
--server-name
127.0.0.1
--server-port
7860
--enable-sglang-engine
true
```
```
在浏览器中访问 http://127.0.0.1:7860 使用 Gradio WebUI 或访问 http://127.0.0.1:7860/?view=api 使用 Gradio API。
2.
在另一个终端中使用 Client 调用:
-
使用
`sglang-client/server`
方式调用:
```
bash
# 启动sglang server(需要安装sglang环境)
mineru-sglang-server
--port
30000
# 在另一个终端中通过sglang client连接sglang server(只需cpu与网络,不需要sglang环境)
mineru
-p
<input_path>
-o
<output_path>
-b
vlm-sglang-client
-u
http://127.0.0.1:30000
```
> [!TIP]
> 所有sglang官方支持的参数都可用通过命令行参数传递给 MinerU,包括以下命令:`mineru`、`mineru-sglang-server`、`mineru-gradio`、`mineru-api`,
> 我们整理了一些`sglang`使用中的常用参数和使用方法,可以在文档[命令行参数进阶技巧](./advanced_cli_parameters.md)中获取。
```
bash
mineru
-p
<input_path>
-o
<output_path>
-b
vlm-sglang-client
-u
http://127.0.0.1:30000
```
> [!TIP]
## 基于配置文件扩展 MinerU 功能
> 更多关于输出文件的信息,请参考 [输出文件说明](../output_file.md)
---
-
MinerU 现已实现开箱即用,但也支持通过配置文件扩展功能。您可以在用户目录下创建
`mineru.json`
文件,添加自定义配置。
-
`mineru.json`
文件会在您使用内置模型下载命令
`mineru-models-download`
时自动生成,也可以通过将
[
配置模板文件
](
https://github.com/opendatalab/MinerU/blob/master/mineru.template.json
)
复制到用户目录下并重命名为
`mineru.json`
来创建。
-
以下是一些可用的配置选项:
-
`latex-delimiter-config`
:用于配置 LaTeX 公式的分隔符,默认为
`$`
符号,可根据需要修改为其他符号或字符串。
-
`llm-aided-config`
:用于配置 LLM 辅助标题分级的相关参数,兼容所有支持
`openai协议`
的 LLM 模型,默认使用
`阿里云百炼`
的
`qwen2.5-32b-instruct`
模型,您需要自行配置 API 密钥并将
`enable`
设置为
`true`
来启用此功能。
-
`models-dir`
:用于指定本地模型存储目录,请为
`pipeline`
和
`vlm`
后端分别指定模型目录,指定目录后您可通过配置环境变量
`export MINERU_MODEL_SOURCE=local`
来使用本地模型。
docs/zh/usage/model_source.md
0 → 100644
View file @
5685b22b
# 模型源说明
MinerU使用
`HuggingFace`
和
`ModelScope`
作为模型仓库,用户可以根据需要切换模型源或使用本地模型。
-
`HuggingFace`
是默认的模型源,在全球范围内提供了优异的加载速度和极高稳定性。
-
`ModelScope`
是中国大陆地区用户的最佳选择,提供了无缝兼容的SDK模块,适用于无法访问
`HuggingFace`
的用户。
## 模型源的切换方法
### 通过命令行参数切换
目前仅
`mineru`
命令行工具支持通过命令行参数切换模型源,其他命令行工具如
`mineru-api`
、
`mineru-gradio`
等暂不支持。
```
bash
mineru
-p
<input_path>
-o
<output_path>
--source
modelscope
```
### 通过环境变量切换
在任何情况下可以通过设置环境变量来切换模型源,这适用于所有命令行工具和API调用。
```
bash
export
MINERU_MODEL_SOURCE
=
modelscope
```
或
```
python
import
os
os
.
environ
[
"MINERU_MODEL_SOURCE"
]
=
"modelscope"
```
>[!TIP]
> 通过环境变量设置的模型源会在当前终端会话中生效,直到终端关闭或环境变量被修改。且优先级高于命令行参数,如同时设置了命令行参数和环境变量,命令行参数将被忽略。
## 使用本地模型
### 1. 下载模型到本地
```
bash
mineru-models-download
--help
```
或使用交互式命令行工具选择模型下载:
```
bash
mineru-models-download
```
>[!TIP]
>- 下载完成后,模型路径会在当前终端窗口输出,并自动写入用户目录下的 `mineru.json`。
>- 模型下载到本地后,您可以自由移动模型文件夹到其他位置,同时需要在 `mineru.json` 中更新模型路径。
>- 如您将模型文件夹部署到其他服务器上,请确保将 `mineru.json`文件一同移动到新设备的用户目录中并正确配置模型路径。
>- 如您需要更新模型文件,可以再次运行 `mineru-models-download` 命令,模型更新暂不支持自定义路径,如您没有移动本地模型文件夹,模型文件会增量更新;如您移动了模型文件夹,模型文件会重新下载到默认位置并更新`mineru.json`。
### 2. 使用本地模型进行解析
```
bash
mineru
-p
<input_path>
-o
<output_path>
--source
local
```
或通过环境变量启用:
```
bash
export
MINERU_MODEL_SOURCE
=
local
mineru
-p
<input_path>
-o
<output_path>
```
\ No newline at end of file
docs/zh/usage/output_files.md
0 → 100644
View file @
5685b22b
# MinerU 输出文件说明
## 概览
`mineru`
命令执行后,除了输出主要的 markdown 文件外,还会生成多个辅助文件用于调试、质检和进一步处理。这些文件包括:
-
**可视化调试文件**
:帮助用户直观了解文档解析过程和结果
-
**结构化数据文件**
:包含详细的解析数据,可用于二次开发
下面将详细介绍每个文件的作用和格式。
## 可视化调试文件
### 布局分析文件 (layout.pdf)
**文件命名格式**
:
`{原文件名}_layout.pdf`
**功能说明**
:
-
可视化展示每一页的布局分析结果
-
每个检测框右上角的数字表示阅读顺序
-
使用不同背景色块区分不同类型的内容块
**使用场景**
:
-
检查布局分析是否正确
-
确认阅读顺序是否合理
-
调试布局相关问题

### 文本片段文件 (spans.pdf)
> [!NOTE]
> 仅适用于 pipeline 后端
**文件命名格式**
:
`{原文件名}_spans.pdf`
**功能说明**
:
-
根据 span 类型使用不同颜色线框标注页面内容
-
用于质量检查和问题排查
**使用场景**
:
-
快速排查文本丢失问题
-
检查行内公式识别情况
-
验证文本分割准确性

## 结构化数据文件
### 模型推理结果 (model.json)
> [!NOTE]
> 仅适用于 pipeline 后端
**文件命名格式**
:
`{原文件名}_model.json`
#### 数据结构定义
```
python
from
pydantic
import
BaseModel
,
Field
from
enum
import
IntEnum
class
CategoryType
(
IntEnum
):
"""内容类别枚举"""
title
=
0
# 标题
plain_text
=
1
# 文本
abandon
=
2
# 包括页眉页脚页码和页面注释
figure
=
3
# 图片
figure_caption
=
4
# 图片描述
table
=
5
# 表格
table_caption
=
6
# 表格描述
table_footnote
=
7
# 表格注释
isolate_formula
=
8
# 行间公式
formula_caption
=
9
# 行间公式的标号
embedding
=
13
# 行内公式
isolated
=
14
# 行间公式
text
=
15
# OCR 识别结果
class
PageInfo
(
BaseModel
):
"""页面信息"""
page_no
:
int
=
Field
(
description
=
"页码序号,第一页的序号是 0"
,
ge
=
0
)
height
:
int
=
Field
(
description
=
"页面高度"
,
gt
=
0
)
width
:
int
=
Field
(
description
=
"页面宽度"
,
ge
=
0
)
class
ObjectInferenceResult
(
BaseModel
):
"""对象识别结果"""
category_id
:
CategoryType
=
Field
(
description
=
"类别"
,
ge
=
0
)
poly
:
list
[
float
]
=
Field
(
description
=
"四边形坐标,格式为 [x0,y0,x1,y1,x2,y2,x3,y3]"
)
score
:
float
=
Field
(
description
=
"推理结果的置信度"
)
latex
:
str
|
None
=
Field
(
description
=
"LaTeX 解析结果"
,
default
=
None
)
html
:
str
|
None
=
Field
(
description
=
"HTML 解析结果"
,
default
=
None
)
class
PageInferenceResults
(
BaseModel
):
"""页面推理结果"""
layout_dets
:
list
[
ObjectInferenceResult
]
=
Field
(
description
=
"页面识别结果"
)
page_info
:
PageInfo
=
Field
(
description
=
"页面元信息"
)
# 完整的推理结果
inference_result
:
list
[
PageInferenceResults
]
=
[]
```
#### 坐标系统说明
`poly`
坐标格式:
`[x0, y0, x1, y1, x2, y2, x3, y3]`
-
分别表示左上、右上、右下、左下四点的坐标
-
坐标原点在页面左上角

#### 示例数据
```
json
[
{
"layout_dets"
:
[
{
"category_id"
:
2
,
"poly"
:
[
99.1906967163086
,
100.3119125366211
,
730.3707885742188
,
100.3119125366211
,
730.3707885742188
,
245.81326293945312
,
99.1906967163086
,
245.81326293945312
],
"score"
:
0.9999997615814209
}
],
"page_info"
:
{
"page_no"
:
0
,
"height"
:
2339
,
"width"
:
1654
}
}
]
```
### VLM 输出结果 (model_output.txt)
> [!NOTE]
> 仅适用于 VLM 后端
**文件命名格式**
:
`{原文件名}_model_output.txt`
#### 文件格式说明
-
使用
`----`
分割每一页的输出结果
-
每页包含多个以
`<|box_start|>`
开头、
`<|md_end|>`
结尾的文本块
#### 字段含义
| 标记 | 格式 | 说明 |
|------|---|------|
| 边界框 |
`<\|box_start\|>x0 y0 x1 y1<\|box_end\|>`
| 四边形坐标(左上、右下两点),页面缩放至 1000×1000 后的坐标值 |
| 类型标记 |
`<\|ref_start\|>type<\|ref_end\|>`
| 内容块类型标识 |
| 内容 |
`<\|md_start\|>markdown内容<\|md_end\|>`
| 该块的 Markdown 内容 |
#### 支持的内容类型
```
json
{
"text"
:
"文本"
,
"title"
:
"标题"
,
"image"
:
"图片"
,
"image_caption"
:
"图片描述"
,
"image_footnote"
:
"图片脚注"
,
"table"
:
"表格"
,
"table_caption"
:
"表格描述"
,
"table_footnote"
:
"表格脚注"
,
"equation"
:
"行间公式"
}
```
#### 特殊标记
-
`<|txt_contd|>`
:出现在文本末尾,表示该文本块可与后续文本块连接
-
表格内容采用
`otsl`
格式,需转换为 HTML 才能在 Markdown 中渲染
### 中间处理结果 (middle.json)
**文件命名格式**
:
`{原文件名}_middle.json`
#### 顶层结构
| 字段名 | 类型 | 说明 |
|--------|------|------|
|
`pdf_info`
|
`list[dict]`
| 每一页的解析结果数组 |
|
`_backend`
|
`string`
| 解析模式:
`pipeline`
或
`vlm`
|
|
`_version_name`
|
`string`
| MinerU 版本号 |
#### 页面信息结构 (pdf_info)
| 字段名 | 说明 |
|--------|------|
|
`preproc_blocks`
| PDF 预处理后的未分段中间结果 |
|
`layout_bboxes`
| 布局分割结果,包含布局方向和边界框,按阅读顺序排序 |
|
`page_idx`
| 页码,从 0 开始 |
|
`page_size`
| 页面的宽度和高度
`[width, height]`
|
|
`_layout_tree`
| 布局树状结构 |
|
`images`
| 图片块信息列表 |
|
`tables`
| 表格块信息列表 |
|
`interline_equations`
| 行间公式块信息列表 |
|
`discarded_blocks`
| 需要丢弃的块信息 |
|
`para_blocks`
| 分段后的内容块结果 |
#### 块结构层次
```
一级块 (table | image)
└── 二级块
└── 行 (line)
└── 片段 (span)
```
#### 一级块字段
| 字段名 | 说明 |
|--------|------|
|
`type`
| 块类型:
`table`
或
`image`
|
|
`bbox`
| 块的矩形框坐标
`[x0, y0, x1, y1]`
|
|
`blocks`
| 包含的二级块列表 |
#### 二级块字段
| 字段名 | 说明 |
|--------|------|
|
`type`
| 块类型(详见下表) |
|
`bbox`
| 块的矩形框坐标 |
|
`lines`
| 包含的行信息列表 |
#### 二级块类型
| 类型 | 说明 |
|------|------|
|
`image_body`
| 图像本体 |
|
`image_caption`
| 图像描述文本 |
|
`image_footnote`
| 图像脚注 |
|
`table_body`
| 表格本体 |
|
`table_caption`
| 表格描述文本 |
|
`table_footnote`
| 表格脚注 |
|
`text`
| 文本块 |
|
`title`
| 标题块 |
|
`index`
| 目录块 |
|
`list`
| 列表块 |
|
`interline_equation`
| 行间公式块 |
#### 行和片段结构
**行 (line) 字段**
:
-
`bbox`
:行的矩形框坐标
-
`spans`
:包含的片段列表
**片段 (span) 字段**
:
-
`bbox`
:片段的矩形框坐标
-
`type`
:片段类型(
`image`
、
`table`
、
`text`
、
`inline_equation`
、
`interline_equation`
)
-
`content`
|
`img_path`
:文本内容或图片路径
#### 示例数据
```
json
{
"pdf_info"
:
[
{
"preproc_blocks"
:
[
...
],
"layout_bboxes"
:
[
{
"layout_bbox"
:
[
52
,
61
,
294
,
731
],
"layout_label"
:
"V"
,
"sub_layout"
:
[]
}
],
"page_idx"
:
0
,
"page_size"
:
[
612.0
,
792.0
],
"para_blocks"
:
[
{
"type"
:
"text"
,
"bbox"
:
[
52
,
61.956024169921875
,
294
,
82.99800872802734
],
"lines"
:
[
{
"bbox"
:
[
52
,
61.956024169921875
,
294
,
72.0000228881836
],
"spans"
:
[
{
"bbox"
:
[
54.0
,
61.956024169921875
,
296.2261657714844
,
72.0000228881836
],
"content"
:
"dependent on the service headway..."
,
"type"
:
"text"
,
"score"
:
1.0
}
]
}
]
}
]
}
],
"_backend"
:
"pipeline"
,
"_version_name"
:
"0.6.1"
}
```
### 内容列表 (content_list.json)
**文件命名格式**
:
`{原文件名}_content_list.json`
#### 功能说明
这是一个简化版的
`middle.json`
,按阅读顺序平铺存储所有可读内容块,去除了复杂的布局信息,便于后续处理。
#### 内容类型
| 类型 | 说明 |
|------|------|
|
`image`
| 图片 |
|
`table`
| 表格 |
|
`text`
| 文本/标题 |
|
`equation`
| 行间公式 |
#### 文本层级标识
通过
`text_level`
字段区分文本层级:
-
无
`text_level`
或
`text_level: 0`
:正文文本
-
`text_level: 1`
:一级标题
-
`text_level: 2`
:二级标题
-
以此类推...
#### 通用字段
所有内容块都包含
`page_idx`
字段,表示所在页码(从 0 开始)。
#### 示例数据
```
json
[
{
"type"
:
"text"
,
"text"
:
"The response of flow duration curves to afforestation"
,
"text_level"
:
1
,
"page_idx"
:
0
},
{
"type"
:
"text"
,
"text"
:
"Abstract"
,
"text_level"
:
2
,
"page_idx"
:
0
},
{
"type"
:
"image"
,
"img_path"
:
"images/a8ecda1c69b27e4f79fce1589175a9d721cbdc1cf78b4cc06a015f3746f6b9d8.jpg"
,
"img_caption"
:
[
"Fig. 1. Annual flow duration curves..."
],
"img_footnote"
:
[],
"page_idx"
:
1
},
{
"type"
:
"equation"
,
"img_path"
:
"images/181ea56ef185060d04bf4e274685f3e072e922e7b839f093d482c29bf89b71e8.jpg"
,
"text"
:
"$$Q_{
\\
%} = f(P) + g(T)$$"
,
"text_format"
:
"latex"
,
"page_idx"
:
2
},
{
"type"
:
"table"
,
"img_path"
:
"images/e3cb413394a475e555807ffdad913435940ec637873d673ee1b039e3bc3496d0.jpg"
,
"table_caption"
:
[
"Table 2 Significance of the rainfall and time terms"
],
"table_footnote"
:
[
"indicates that the rainfall term was significant..."
],
"table_body"
:
"<html><body><table>...</table></body></html>"
,
"page_idx"
:
5
}
]
```
## 总结
以上文件为 MinerU 的完整输出结果,用户可根据需要选择合适的文件进行后续处理:
-
**模型输出**
:使用原始输出(model.json、model_output.txt)
-
**调试和验证**
:使用可视化文件(layout.pdf、spans.pdf)
-
**内容提取**
:使用简化文件(
*
.md、content_list.json)
-
**二次开发**
:使用结构化文件(middle.json)
mineru/backend/vlm/token_to_middle_json.py
View file @
5685b22b
...
@@ -12,14 +12,16 @@ from mineru.version import __version__
...
@@ -12,14 +12,16 @@ from mineru.version import __version__
heading_level_import_success
=
False
heading_level_import_success
=
False
llm_aided_config
=
get_llm_aided_config
()
llm_aided_config
=
get_llm_aided_config
()
if
llm_aided_config
and
llm_aided_config
.
get
(
'title_aided'
,
{}).
get
(
'enable'
,
False
):
if
llm_aided_config
:
try
:
title_aided_config
=
llm_aided_config
.
get
(
'title_aided'
,
{})
from
mineru.utils.llm_aided
import
llm_aided_title
if
title_aided_config
.
get
(
'enable'
,
False
):
from
mineru.backend.pipeline.model_init
import
AtomModelSingleton
try
:
heading_level_import_success
=
True
from
mineru.utils.llm_aided
import
llm_aided_title
except
Exception
as
e
:
from
mineru.backend.pipeline.model_init
import
AtomModelSingleton
logger
.
warning
(
"The heading level feature cannot be used. If you need to use the heading level feature, "
heading_level_import_success
=
True
"please execute `pip install mineru[core]` to install the required packages."
)
except
Exception
as
e
:
logger
.
warning
(
"The heading level feature cannot be used. If you need to use the heading level feature, "
"please execute `pip install mineru[core]` to install the required packages."
)
def
token_to_page_info
(
token
,
image_dict
,
page
,
image_writer
,
page_index
)
->
dict
:
def
token_to_page_info
(
token
,
image_dict
,
page
,
image_writer
,
page_index
)
->
dict
:
...
...
mineru/utils/model_utils.py
View file @
5685b22b
...
@@ -206,37 +206,49 @@ def filter_nested_tables(table_res_list, overlap_threshold=0.8, area_threshold=0
...
@@ -206,37 +206,49 @@ def filter_nested_tables(table_res_list, overlap_threshold=0.8, area_threshold=0
def
remove_overlaps_min_blocks
(
res_list
):
def
remove_overlaps_min_blocks
(
res_list
):
#
重叠block,小的不能直接删除,需要和大的那个合并成一个更大的。
# 重叠block,小的不能直接删除,需要和大的那个合并成一个更大的。
#
删除重叠blocks中较小的那些
# 删除重叠blocks中较小的那些
need_remove
=
[]
need_remove
=
[]
for
res1
in
res_list
:
for
i
in
range
(
len
(
res_list
)):
for
res2
in
res_list
:
# 如果当前元素已在需要移除列表中,则跳过
if
res1
!=
res2
:
if
res_list
[
i
]
in
need_remove
:
overlap_box
=
get_minbox_if_overlap_by_ratio
(
continue
res1
[
'bbox'
],
res2
[
'bbox'
],
0.8
)
for
j
in
range
(
i
+
1
,
len
(
res_list
)):
if
overlap_box
is
not
None
:
# 如果比较对象已在需要移除列表中,则跳过
res_to_remove
=
next
(
if
res_list
[
j
]
in
need_remove
:
(
res
for
res
in
res_list
if
res
[
'bbox'
]
==
overlap_box
),
continue
None
,
)
overlap_box
=
get_minbox_if_overlap_by_ratio
(
if
(
res_list
[
i
][
'bbox'
],
res_list
[
j
][
'bbox'
],
0.8
res_to_remove
is
not
None
)
and
res_to_remove
not
in
need_remove
):
if
overlap_box
is
not
None
:
large_res
=
res1
if
res1
!=
res_to_remove
else
res2
res_to_remove
=
None
x1
,
y1
,
x2
,
y2
=
large_res
[
'bbox'
]
large_res
=
None
sx1
,
sy1
,
sx2
,
sy2
=
res_to_remove
[
'bbox'
]
x1
=
min
(
x1
,
sx1
)
# 确定哪个是小块(要移除的)
y1
=
min
(
y1
,
sy1
)
if
overlap_box
==
res_list
[
i
][
'bbox'
]:
x2
=
max
(
x2
,
sx2
)
res_to_remove
=
res_list
[
i
]
y2
=
max
(
y2
,
sy2
)
large_res
=
res_list
[
j
]
large_res
[
'bbox'
]
=
[
x1
,
y1
,
x2
,
y2
]
elif
overlap_box
==
res_list
[
j
][
'bbox'
]:
need_remove
.
append
(
res_to_remove
)
res_to_remove
=
res_list
[
j
]
large_res
=
res_list
[
i
]
if
len
(
need_remove
)
>
0
:
for
res
in
need_remove
:
if
res_to_remove
is
not
None
and
res_to_remove
not
in
need_remove
:
res_list
.
remove
(
res
)
# 更新大块的边界为两者的并集
x1
,
y1
,
x2
,
y2
=
large_res
[
'bbox'
]
sx1
,
sy1
,
sx2
,
sy2
=
res_to_remove
[
'bbox'
]
x1
=
min
(
x1
,
sx1
)
y1
=
min
(
y1
,
sy1
)
x2
=
max
(
x2
,
sx2
)
y2
=
max
(
y2
,
sy2
)
large_res
[
'bbox'
]
=
[
x1
,
y1
,
x2
,
y2
]
need_remove
.
append
(
res_to_remove
)
# 从列表中移除标记的元素
for
res
in
need_remove
:
res_list
.
remove
(
res
)
return
res_list
,
need_remove
return
res_list
,
need_remove
...
...
mkdocs.yml
View file @
5685b22b
...
@@ -49,17 +49,16 @@ nav:
...
@@ -49,17 +49,16 @@ nav:
-
"
MinerU"
:
index.md
-
"
MinerU"
:
index.md
-
Quick Start
:
-
Quick Start
:
-
quick_start/index.md
-
quick_start/index.md
-
Online Demo
:
quick_start/online_demo
.md
-
Extension Modules
:
quick_start/extension_modules
.md
-
L
oc
al
Deployment
:
quick_start/
l
oc
al
_deployment.md
-
D
oc
ker
Deployment
:
quick_start/
d
oc
ker
_deployment.md
-
Usage
:
-
Usage
:
-
usage/index.md
-
usage/index.md
-
API Calls or Visual Invocation
:
usage/api.md
-
CLI Tools
:
usage/cli_tools.md
-
Extending MinerU Functionality Through Configuration Files
:
usage/config.md
-
Model Source
:
usage/model_source.md
-
Advanced CLI Parameters
:
usage/advanced_cli_parameters.md
-
Output File Format
:
usage/output_files.md
-
FAQ
:
-
FAQ
:
-
FAQ
:
FAQ/index.md
-
FAQ
:
FAQ/index.md
-
Output File Format
:
output_file.md
-
Known Issues
:
known_issues.md
-
TODO
:
todo.md
plugins
:
plugins
:
-
search
-
search
...
@@ -76,15 +75,14 @@ plugins:
...
@@ -76,15 +75,14 @@ plugins:
nav_translations
:
nav_translations
:
Home
:
主页
Home
:
主页
Quick Start
:
快速开始
Quick Start
:
快速开始
Online Demo
:
在线体验
Extension Modules
:
扩展模块
L
oc
al
Deployment
:
本地
部署
D
oc
ker
Deployment
:
Docker
部署
Usage
:
使用方法
Usage
:
使用方法
API Calls or Visual Invocation
:
API 调用 或 可视化调用
CLI Tools
:
命令行工具
Extending MinerU Functionality Through Configuration Files
:
基于配置文件扩展 MinerU 功能
Model Source
:
模型源
Advanced CLI Parameters
:
命令行参数进阶技巧
FAQ
:
FAQ
FAQ
:
FAQ
Output File Format
:
输出文件格式
Output File Format
:
输出文件格式
Known Issues
:
Known Issues
TODO
:
TODO
-
mkdocs-video
-
mkdocs-video
markdown_extensions
:
markdown_extensions
:
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment