README_zh-CN.md.bak 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <div align="center" xmlns="http://www.w3.org/1999/html">
  2. <!-- logo -->
  3. <p align="center">
  4. <img src="docs/images/MinerU-logo.png" width="300px" style="vertical-align:middle;">
  5. </p>
  6. <!-- icon -->
  7. [![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU)
  8. [![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU)
  9. [![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues)
  10. [![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues)
  11. [![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf)
  12. [![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf)
  13. [![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf)
  14. <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>
  15. <!-- language -->
  16. [English](README.md) | [简体中文](README_zh-CN.md)
  17. <!-- hot link -->
  18. <p align="center">
  19. <a href="https://github.com/opendatalab/PDF-Extract-Kit">PDF-Extract-Kit: 高质量PDF解析工具箱</a>🔥🔥🔥
  20. </p>
  21. <!-- join us -->
  22. <p align="center">
  23. 👋 join us on <a href="https://discord.gg/Tdedn9GTXq" target="_blank">Discord</a> and <a href="https://cdn.vansin.top/internlm/mineru.jpg" target="_blank">WeChat</a>
  24. </p>
  25. </div>
  26. # 更新记录
  27. - 2024/08/09 0.7.0b1发布,简化安装步骤提升易用性,加入表格识别功能
  28. - 2024/08/01 0.6.2b1发布,优化了依赖冲突问题和安装文档
  29. - 2024/07/05 首次开源
  30. <!-- TABLE OF CONTENT -->
  31. <details open="open">
  32. <summary><h2 style="display: inline-block">文档目录</h2></summary>
  33. <ol>
  34. <li>
  35. <a href="#mineru">MinerU</a>
  36. <ul>
  37. <li><a href="#项目简介">项目简介</a></li>
  38. <li><a href="#主要功能">主要功能</a></li>
  39. <li><a href="#快速开始">快速开始</a>
  40. <ul>
  41. <li><a href="#在线体验">在线体验</a></li>
  42. <li><a href="#使用CPU快速体验">使用CPU快速体验</a></li>
  43. <li><a href="#使用GPU">使用GPU</a></li>
  44. </ul>
  45. </li>
  46. <li><a href="#使用">使用方式</a>
  47. <ul>
  48. <li><a href="#命令行">命令行</a></li>
  49. <li><a href="#api">API</a></li>
  50. <li><a href="#二次开发">二次开发</a></li>
  51. </ul>
  52. </li>
  53. </ul>
  54. </li>
  55. <li><a href="#todo">TODO</a></li>
  56. <li><a href="#known-issues">Known Issues</a></li>
  57. <li><a href="#faq">FAQ</a></li>
  58. <li><a href="#all-thanks-to-our-contributors">Contributors</a></li>
  59. <li><a href="#license-information">License Information</a></li>
  60. <li><a href="#acknowledgments">Acknowledgements</a></li>
  61. <li><a href="#citation">Citation</a></li>
  62. <li><a href="#star-history">Star History</a></li>
  63. <li><a href="#magic-doc">magic-doc快速提取PPT/DOC/PDF</a></li>
  64. <li><a href="#magic-html">magic-html提取混合网页内容</a></li>
  65. <li><a href="#links">Links</a></li>
  66. </ol>
  67. </details>
  68. # MinerU
  69. ## 项目简介
  70. MinerU是一款将PDF转化为机器可读格式的工具(如markdown、json),可以很方便地抽取为任意格式。
  71. MinerU诞生于[书生-浦语](https://github.com/InternLM/InternLM)的预训练过程中,我们将会集中精力解决科技文献中的符号转化问题,希望在大模型时代为科技发展做出贡献。
  72. 相比国内外知名商用产品MinerU还很年轻,如果遇到问题或者结果不及预期请到[issue](https://github.com/opendatalab/MinerU/issues)提交问题,同时**附上相关PDF**。
  73. https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
  74. ## 主要功能
  75. - 删除页眉、页脚、脚注、页码等元素,保持语义连贯
  76. - 对多栏输出符合人类阅读顺序的文本
  77. - 保留原文档的结构,包括标题、段落、列表等
  78. - 提取图像、图片标题、表格、表格标题
  79. - 自动识别文档中的公式并将公式转换成latex
  80. - 自动识别文档中的表格并将表格转换成latex
  81. - 乱码PDF自动检测并启用OCR
  82. - 支持CPU和GPU环境
  83. - 支持windows/linux/mac平台
  84. ## 快速开始
  85. 如果遇到任何安装问题,请先查询 <a href="#faq">FAQ</a> </br>
  86. 如果遇到解析效果不及预期,参考 <a href="#known-issues">Known Issues</a></br>
  87. 有3种不同方式可以体验MinerU的效果:
  88. - [在线体验(无需任何安装)](#在线体验)
  89. - [使用CPU快速体验(Windows,Linux,Mac)](#使用cpu快速体验)
  90. - [Linux/Windows + CUDA](#使用gpu)
  91. **⚠️安装前必看——软硬件环境支持说明**
  92. 为了确保项目的稳定性和可靠性,我们在开发过程中仅对特定的软硬件环境进行优化和测试。这样当用户在推荐的系统配置上部署和运行项目时,能够获得最佳的性能表现和最少的兼容性问题。
  93. 通过集中资源和精力于主线环境,我们团队能够更高效地解决潜在的BUG,及时开发新功能。
  94. 在非主线环境中,由于硬件、软件配置的多样性,以及第三方依赖项的兼容性问题,我们无法100%保证项目的完全可用性。因此,对于希望在非推荐环境中使用本项目的用户,我们建议先仔细阅读文档以及FAQ,大多数问题已经在FAQ中有对应的解决方案,除此之外我们鼓励社区反馈问题,以便我们能够逐步扩大支持范围。
  95. <table>
  96. <tr>
  97. <td colspan="3" rowspan="2">操作系统</td>
  98. </tr>
  99. <tr>
  100. <td>Ubuntu 22.04 LTS</td>
  101. <td>Windows 10 / 11</td>
  102. <td>macOS 11+</td>
  103. </tr>
  104. <tr>
  105. <td colspan="3">CPU</td>
  106. <td>x86_64</td>
  107. <td>x86_64</td>
  108. <td>x86_64 / arm64</td>
  109. </tr>
  110. <tr>
  111. <td colspan="3">内存</td>
  112. <td colspan="3">大于等于16GB,推荐32G以上</td>
  113. </tr>
  114. <tr>
  115. <td colspan="3">python版本</td>
  116. <td colspan="3">3.10</td>
  117. </tr>
  118. <tr>
  119. <td colspan="3">Nvidia Driver 版本</td>
  120. <td>latest(专有驱动)</td>
  121. <td>latest</td>
  122. <td>None</td>
  123. </tr>
  124. <tr>
  125. <td colspan="3">CUDA环境</td>
  126. <td>自动安装[12.1(pytorch)+11.8(paddle)]</td>
  127. <td>11.8(手动安装)+cuDNN v8.7.0(手动安装)</td>
  128. <td>None</td>
  129. </tr>
  130. <tr>
  131. <td rowspan="2">GPU硬件支持列表</td>
  132. <td colspan="2">最低要求 8G+显存</td>
  133. <td colspan="2">3060ti/3070/3080/3080ti/4060/4070/4070ti<br>
  134. 8G显存仅可开启lavout和公式识别加速</td>
  135. <td rowspan="2">None</td>
  136. </tr>
  137. <tr>
  138. <td colspan="2">推荐配置 16G+显存</td>
  139. <td colspan="2">3090/3090ti/4070tisuper/4080/4090<br>
  140. 16G及以上可以同时开启layout,公式识别和ocr加速</td>
  141. </tr>
  142. </table>
  143. ### 在线体验
  144. [在线体验点击这里](https://opendatalab.com/OpenSourceTools/Extractor/PDF)
  145. ### 使用CPU快速体验
  146. #### 1. 安装magic-pdf
  147. 最新版本国内镜像源同步可能会有延迟,请耐心等待
  148. ```bash
  149. conda create -n MinerU python=3.10
  150. conda activate MinerU
  151. pip install magic-pdf[full]==0.7.0b1 --extra-index-url https://wheels.myhloli.com -i https://pypi.tuna.tsinghua.edu.cn/simple
  152. ```
  153. #### 2. 下载模型权重文件
  154. 详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md)
  155. > ❗️模型下载后请务必检查模型文件是否下载完整
  156. >
  157. > 请检查目录下的模型文件大小与网页上描述是否一致,如果可以的话,最好通过sha256校验模型是否下载完整
  158. #### 3. 拷贝配置文件并进行配置
  159. 在仓库根目录可以获得 [magic-pdf.template.json](magic-pdf.template.json) 配置模版文件
  160. > ❗️务必执行以下命令将配置文件拷贝到【用户目录】下,否则程序将无法运行
  161. >
  162. > windows的用户目录为 "C:\\Users\\用户名", linux用户目录为 "/home/用户名", macOS用户目录为 "/Users/用户名"
  163. ```bash
  164. cp magic-pdf.template.json ~/magic-pdf.json
  165. ```
  166. 在用户目录中找到magic-pdf.json文件并配置"models-dir"为[2. 下载模型权重文件](#2-下载模型权重文件)中下载的模型权重文件所在目录
  167. > ❗️务必正确配置模型权重文件所在目录的【绝对路径】,否则会因为找不到模型文件而导致程序无法运行
  168. >
  169. > windows系统中此路径应包含盘符,且需把路径中所有的`"\"`替换为`"/"`,否则会因为转义原因导致json文件语法错误。
  170. >
  171. > 例如:模型放在D盘根目录的models目录,则model-dir的值应为"D:/models"
  172. ```json
  173. {
  174. // other config
  175. "models-dir": "D:/models",
  176. "table-config": {
  177. "is_table_recog_enable": false, // 表格识别功能默认是关闭的,如果需要修改此处的值
  178. "max_time": 400
  179. }
  180. }
  181. ```
  182. ### 使用GPU
  183. 如果您的设备支持CUDA,且满足主线环境中的显卡要求,则可以使用GPU加速,请根据自己的系统选择适合的教程:
  184. - [Ubuntu22.04LTS + GPU](docs/README_Ubuntu_CUDA_Acceleration_zh_CN.md)
  185. - [Windows10/11 + GPU](docs/README_Windows_CUDA_Acceleration_zh_CN.md)
  186. - 使用Docker快速部署
  187. > Docker 需设备gpu显存大于等于16GB,默认开启所有加速功能
  188. ```bash
  189. wget https://github.com/opendatalab/MinerU/raw/master/Dockerfile
  190. docker build -t mineru:0.7.0b1 .
  191. docker run --rm -it --gpus=all mineru:0.7.0b1 /bin/bash
  192. magic-pdf --help
  193. ```
  194. ## 使用
  195. ### 命令行
  196. ```bash
  197. magic-pdf --help
  198. Usage: magic-pdf [OPTIONS]
  199. Options:
  200. -v, --version display the version and exit
  201. -p, --path PATH local pdf filepath or directory [required]
  202. -o, --output-dir TEXT output local directory
  203. -m, --method [ocr|txt|auto] the method for parsing pdf.
  204. ocr: using ocr technique to extract information from pdf,
  205. txt: suitable for the text-based pdf only and outperform ocr,
  206. auto: automatically choose the best method for parsing pdf
  207. from ocr and txt.
  208. without method specified, auto will be used by default.
  209. --help Show this message and exit.
  210. ## show version
  211. magic-pdf -v
  212. ## command line example
  213. magic-pdf -p {some_pdf} -o {some_output_dir} -m auto
  214. ```
  215. 其中 `{some_pdf}` 可以是单个pdf文件,也可以是一个包含多个pdf文件的目录。
  216. 运行完命令后输出的结果会保存在`{some_output_dir}`目录下, 输出的文件列表如下
  217. ```text
  218. ├── some_pdf.md # markdown 文件
  219. ├── images # 存放图片目录
  220. ├── some_pdf_layout.pdf # layout 绘图
  221. ├── some_pdf_middle.json # minerU 中间处理结果
  222. ├── some_pdf_model.json # 模型推理结果
  223. ├── some_pdf_origin.pdf # 原 pdf 文件
  224. └── some_pdf_spans.pdf # 最小粒度的bbox位置信息绘图
  225. ```
  226. 更多有关输出文件的信息,请参考[输出文件说明](docs/output_file_zh_cn.md)
  227. ### API
  228. 处理本地磁盘上的文件
  229. ```python
  230. image_writer = DiskReaderWriter(local_image_dir)
  231. image_dir = str(os.path.basename(local_image_dir))
  232. jso_useful_key = {"_pdf_type": "", "model_list": []}
  233. pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer)
  234. pipe.pipe_classify()
  235. pipe.pipe_analyze()
  236. pipe.pipe_parse()
  237. md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
  238. ```
  239. 处理对象存储上的文件
  240. ```python
  241. s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint)
  242. image_dir = "s3://img_bucket/"
  243. s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir)
  244. pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN)
  245. jso_useful_key = {"_pdf_type": "", "model_list": []}
  246. pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli)
  247. pipe.pipe_classify()
  248. pipe.pipe_analyze()
  249. pipe.pipe_parse()
  250. md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
  251. ```
  252. 详细实现可参考
  253. - [demo.py 最简单的处理方式](demo/demo.py)
  254. - [magic_pdf_parse_main.py 能够更清晰看到处理流程](demo/magic_pdf_parse_main.py)
  255. ### 二次开发
  256. TODO
  257. # TODO
  258. - [ ] 基于语义的阅读顺序
  259. - [ ] 正文中列表识别
  260. - [ ] 正文中代码块识别
  261. - [ ] 目录识别
  262. - [x] 表格识别
  263. - [ ] [化学式识别](docs/chemical_knowledge_introduction/introduction.pdf)
  264. - [ ] 几何图形识别
  265. # Known Issues
  266. - 阅读顺序基于规则的分割,在一些情况下会乱序
  267. - 不支持竖排文字
  268. - 列表、代码块、目录在layout模型里还没有支持
  269. - 漫画书、艺术图册、小学教材、习题尚不能很好解析
  270. - 在一些公式密集的PDF上强制启用OCR效果会更好
  271. - 如果您要处理包含大量公式的pdf,强烈建议开启OCR功能。使用pymuPDF提取文字的时候会出现文本行互相重叠的情况导致公式插入位置不准确。
  272. - **表格识别**目前处于测试阶段,识别速度较慢,识别准确度有待提升。以下是我们在Ubuntu 22.04 LTS + Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz + NVIDIA GeForce RTX 4090环境下的一些性能测试结果,可供参考。
  273. | 表格大小 | 解析耗时 |
  274. | ------------ | -------- |
  275. | 6\*5 55kb | 37s |
  276. | 16\*12 284kb | 3m18s |
  277. | 44\*7 559kb | 4m12s |
  278. # FAQ
  279. [常见问题](docs/FAQ_zh_cn.md)
  280. <<<<<<< HEAD
  281. =======
  282. [FAQ](docs/FAQ_en_us.md)
  283. >>>>>>> 7f0fe20004af7416db886f4b75c116bcc1c986b4
  284. [FAQ](docs/FAQ_en_us.md)
  285. # All Thanks To Our Contributors
  286. <a href="https://github.com/opendatalab/MinerU/graphs/contributors">
  287. <img src="https://contrib.rocks/image?repo=opendatalab/MinerU" />
  288. </a>
  289. # License Information
  290. [LICENSE.md](LICENSE.md)
  291. 本项目目前采用PyMuPDF以实现高级功能,但因其遵循AGPL协议,可能对某些使用场景构成限制。未来版本迭代中,我们计划探索并替换为许可条款更为宽松的PDF处理库,以提升用户友好度及灵活性。
  292. # Acknowledgments
  293. - [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit)
  294. - [StructEqTable](https://github.com/UniModal4Reasoning/StructEqTable-Deploy)
  295. - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
  296. - [PyMuPDF](https://github.com/pymupdf/PyMuPDF)
  297. - [fast-langdetect](https://github.com/LlmKira/fast-langdetect)
  298. - [pdfminer.six](https://github.com/pdfminer/pdfminer.six)
  299. # Citation
  300. ```bibtex
  301. @article{he2024opendatalab,
  302. title={Opendatalab: Empowering general artificial intelligence with open datasets},
  303. author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua},
  304. journal={arXiv preprint arXiv:2407.13773},
  305. year={2024}
  306. }
  307. @misc{2024mineru,
  308. title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool},
  309. author={MinerU Contributors},
  310. howpublished = {\url{https://github.com/opendatalab/MinerU}},
  311. year={2024}
  312. }
  313. ```
  314. # Star History
  315. <a>
  316. <picture>
  317. <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date&theme=dark" />
  318. <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
  319. <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
  320. </picture>
  321. </a>
  322. # Magic-doc
  323. [Magic-Doc](https://github.com/InternLM/magic-doc) Fast speed ppt/pptx/doc/docx/pdf extraction tool
  324. # Magic-html
  325. [Magic-HTML](https://github.com/opendatalab/magic-html) Mixed web page extraction tool
  326. # Links
  327. - [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU)
  328. - [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM)
  329. - [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit)