MinerU https://github.com/opendatalab/MinerU/
官网有详细的说明,需要 gpu cuda 支持。
实测笔记本 cpu 模式也能使用,如下。
1. pip 安装 mineru (CPU模式)
1 2 3 4 5 6
| python -m venv .venv_mnu .venv_mnu\Scripts\activate
pip install -U "mineru[core]" -i https://mirrors.aliyun.com/pypi/simple
|
2. 预训练模型下载
1 2 3 4 5 6 7
| mineru-models-download
mineru-models-download -s modelscope -m pipeline
|
模型默认会被下载到 ~\.cache\modelscope\hub\models
同时创建一个配置文件 ~\mineru.json
默认下载到当前用户目录下。
运行
帮助:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| 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|... ] 指定文档语言(可提升 OCR 准确率,仅用于 pipeline 后端) -u, --url TEXT 当使用 sglang-client 时,需指定服务地址 -s, --start INTEGER 开始解析的页码(从 0 开始) -e, --end INTEGER 结束解析的页码(从 0 开始) -f, --formula BOOLEAN 是否启用公式解析(默认开启,仅 pipeline 后端) -t, --table BOOLEAN 是否启用表格解析(默认开启,仅 pipeline 后端) -d, --device TEXT 推理设备(如 cpu/cuda/cuda:0/npu/mps,仅 pipeline 后端) --vram INTEGER 单进程最大 GPU 显存占用(仅 pipeline 后端) --source [huggingface|modelscope|local] 模型来源,默认 huggingface --help 显示帮助信息
|
例:
1 2 3
| mineru -d cpu --source local -o . -p 123.pdf
mineru -d cpu --source local -o . -l ch_lite -p 123.pdf
|
耗时
使用 cpu (笔记本 intel ultra 7 155h), 检测一个 10 页的pdf,内容主要是中文文字。
步骤 |
说明 |
数量 |
耗时 |
Layout Predict |
pdf 页面解析 |
10/10 |
00:18<00:00, 1.82s/it |
MFD Predict |
数学公式检测 |
10/10 |
00:52<00:00, 5.27s/it |
MFR Predict |
数学公式识别 |
1/1 |
00:01<00:00, 1.40s/it |
OCR-det ch |
OCR检测中文 |
51/51 |
00:23<00:00, 2.14it/s |
Table Predict |
表格识别 |
1/1 |
00:04<00:00, 4.47s/it |
OCR-rec Predict |
OCR识别 |
319/319 |
00:52<00:00, 6.12it/s |
Processing pages |
处理页面 |
10/10 |
00:02<00:00, 3.49it/s |