Skip to content

Commit 4c294b2

Browse files
authored
Merge branch 'main' into docs_for_vl
2 parents f3a62d1 + 5f184ad commit 4c294b2

File tree

5 files changed

+37
-105
lines changed

5 files changed

+37
-105
lines changed

docs/version3.x/pipeline_usage/PaddleOCR-VL-Apple-Silicon.en.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ The inference performance under default configurations is not fully optimized an
4848
Install the MLX-VLM inference framework:
4949

5050
```shell
51-
git clone https://github.com/Blaizzy/mlx-vlm.git
52-
cd mlx-vlm
53-
pip install -e .
51+
python -m pip install -U mlx-vlm
52+
python -m pip install "transformers<5.0.0"
5453
```
5554

5655
Start the MLX-VLM inference service:

docs/version3.x/pipeline_usage/PaddleOCR-VL-Apple-Silicon.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ python -m pip install -U "paddleocr[doc-parser]"
4848
安装 MLX-VLM 推理框架:
4949

5050
```shell
51-
git clone https://github.com/Blaizzy/mlx-vlm.git
52-
cd mlx-vlm
53-
pip install -e .
51+
python -m pip install -U mlx-vlm
52+
python -m pip install "transformers<5.0.0"
5453
```
5554

5655
启动 MLX-VLM 推理服务:

docs/version3.x/pipeline_usage/PaddleOCR-VL.en.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ paddleocr doc_parser -i ./paddleocr_vl_demo.png --device dcu
238238
# MetaX GPU
239239
paddleocr doc_parser -i ./paddleocr_vl_demo.png --device metax_gpu
240240

241+
# Apple Silicon
242+
paddleocr doc_parser -i ./paddleocr_vl_demo.png --device cpu
243+
244+
# Huawei Ascend NPU
245+
# Huawei Ascend NPU please refer to Chapter 3 for inference using PaddlePaddle + vLLM
246+
241247
# Use --use_doc_orientation_classify to enable document orientation classification
242248
paddleocr doc_parser -i ./paddleocr_vl_demo.png --use_doc_orientation_classify True
243249

@@ -654,6 +660,10 @@ pipeline = PaddleOCRVL()
654660
# pipeline = PaddleOCRVL(device="dcu")
655661
# MetaX GPU
656662
# pipeline = PaddleOCRVL(device="metax_gpu")
663+
# Apple Silicon
664+
# pipeline = PaddleOCRVL(device="cpu")
665+
# Huawei Ascend NPU
666+
# Huawei Ascend NPU please refer to Chapter 3 for inference using PaddlePaddle + vLLM
657667

658668
# pipeline = PaddleOCRVL(use_doc_orientation_classify=True) # Use use_doc_orientation_classify to enable/disable document orientation classification model
659669
# pipeline = PaddleOCRVL(use_doc_unwarping=True) # Use use_doc_unwarping to enable/disable document unwarping module
@@ -666,21 +676,14 @@ for res in output:
666676
res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format
667677
```
668678

669-
For PDF files, each page will be processed individually, and a separate Markdown file will be generated for each page. If you wish to perform cross-page table merging, reconstruct multi-level labels, or merge multi-page results, you can achieve this using the following method:
679+
For PDF files, each page will be processed individually, and a separate Markdown file will be generated for each page. If you wish to perform cross-page table merging, reconstruct multi-level headings, or merge multi-page results, you can achieve this using the following method:
670680

671681
```python
672682
from paddleocr import PaddleOCRVL
673683

674684
input_file = "./your_pdf_file.pdf"
675685

676-
# NVIDIA GPU
677686
pipeline = PaddleOCRVL()
678-
# KUNLUNXIN XPU
679-
# pipeline = PaddleOCRVL(device="xpu")
680-
# HYGON DCU
681-
# pipeline = PaddleOCRVL(device="dcu")
682-
# MetaX GPU
683-
# pipeline = PaddleOCRVL(device="metax_gpu")
684687

685688
output = pipeline.predict(input=input_file)
686689

@@ -1443,7 +1446,8 @@ Setting it to <code>None</code> means using the instantiation parameter; otherwi
14431446
- Calling the `save_to_img()` method will save the visualization results to the specified `save_path`. If a directory is specified, visualized images for layout region detection, global OCR, layout reading order, etc., will be saved. If a file is specified, it will be saved directly to that file. (Pipelines typically contain many result images, so it is not recommended to directly specify a specific file path, as multiple images will be overwritten, retaining only the last one.)
14441447
- Calling the `save_to_markdown()` method will save the converted Markdown file to the specified `save_path`. The saved file path will be `save_path/{your_img_basename}.md`. If the input is a PDF file, it is recommended to directly specify a directory; otherwise, multiple markdown files will be overwritten.
14451448

1446-
Additionally, it also supports obtaining visualized images and prediction results with results through attributes, as follows:<table>
1449+
<li>Additionally, it also supports obtaining visualized images and prediction results with results through attributes, as follows:
1450+
<table>
14471451
<thead>
14481452
<tr>
14491453
<th>Attribute</th>
@@ -1477,7 +1481,7 @@ Additionally, it also supports obtaining visualized images and prediction result
14771481
<li>The prediction result returned by the <code>img</code> attribute is data of dict type. The keys are <code>layout_det_res</code>, <code>overall_ocr_res</code>, <code>text_paragraphs_ocr_res</code>, <code>formula_res_region1</code>, <code>table_cell_img</code>, and <code>seal_res_region1</code>, with corresponding values being <code>Image.Image</code> objects: used to display visualized images of layout region detection, OCR, OCR text paragraphs, formulas, tables, and seal results, respectively. If optional modules are not used, the dict only contains <code>layout_det_res</code>.</li>
14781482
<li>The prediction result returned by the <code>markdown</code> attribute is data of dict type. The keys are <code>markdown_texts</code>, <code>markdown_images</code>, and <code>page_continuation_flags</code>, with corresponding values being markdown text, images displayed in Markdown (<code>Image.Image</code> objects), and a bool tuple used to identify whether the first element on the current page is the start of a paragraph and whether the last element is the end of a paragraph, respectively.</li>
14791483
</ul>
1480-
1484+
</li>
14811485
</details>
14821486

14831487
## 3. Enhancing VLM Inference Performance Using Inference Acceleration Frameworks
@@ -1588,7 +1592,7 @@ The parameters supported by this command are as follows:
15881592

15891593
### 3.2 Client Usage Methods
15901594

1591-
After launching the VLM inference service, the client can call the service through PaddleOCR. **Please note that because the client needs to invoke the sequential model for layout detection, it is still recommended to run the client on GPU or other acceleration devices to achieve more stable and efficient performance. Please refer to Section 1 for the client-side environment configuration. The configuration described in Section 3.1 applies only to starting the service and is not applicable to the client.**
1595+
After launching the VLM inference service, the client can call the service through PaddleOCR. **Please note that because the client needs to call the layout detection model, it is still recommended to run the client on GPU or other acceleration devices to achieve more stable and efficient performance. Please refer to Section 1 for the client-side environment configuration. The configuration described in Section 3.1 applies only to starting the service and is not applicable to the client.**
15921596

15931597
#### 3.2.1 CLI Invocation
15941598

docs/version3.x/pipeline_usage/PaddleOCR-VL.md

Lines changed: 16 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ paddleocr doc_parser -i ./paddleocr_vl_demo.png --device dcu
240240
# 沐曦 GPU
241241
paddleocr doc_parser -i ./paddleocr_vl_demo.png --device metax_gpu
242242

243+
# Apple Silicon
244+
paddleocr doc_parser -i ./paddleocr_vl_demo.png --device cpu
245+
246+
# 华为昇腾 NPU
247+
# 华为昇腾 NPU 请参考第 3 章节使用 PaddlePaddle + vLLM 的方式进行推理
248+
243249
# 通过 --use_doc_orientation_classify 指定是否使用文档方向分类模型
244250
paddleocr doc_parser -i ./paddleocr_vl_demo.png --use_doc_orientation_classify True
245251

@@ -632,6 +638,10 @@ pipeline = PaddleOCRVL()
632638
# pipeline = PaddleOCRVL(device="dcu")
633639
# 沐曦 GPU
634640
# pipeline = PaddleOCRVL(device="metax_gpu")
641+
# Apple Silicon
642+
# pipeline = PaddleOCRVL(device="cpu")
643+
# 华为昇腾 NPU
644+
# 华为昇腾 NPU 请参考第 3 章节使用 PaddlePaddle + vLLM 的方式进行推理
635645

636646
# pipeline = PaddleOCRVL(use_doc_orientation_classify=True) # 通过 use_doc_orientation_classify 指定是否使用文档方向分类模型
637647
# pipeline = PaddleOCRVL(use_doc_unwarping=True) # 通过 use_doc_unwarping 指定是否使用文本图像矫正模块
@@ -644,22 +654,15 @@ for res in output:
644654
res.save_to_markdown(save_path="output") ## 保存当前图像的markdown格式的结果
645655
```
646656

647-
如果是 PDF 文件,会将 PDF 的每一页单独处理,每一页的 Markdown 文件也会对应单独的结果。如果您希望对多页的推理结果进行跨页表格合并、重建多级标和合并多页结果等需求,可以通过如下方式实现:
657+
如果是 PDF 文件,会将 PDF 的每一页单独处理,每一页的 Markdown 文件也会对应单独的结果。如果您希望对多页的推理结果进行跨页表格合并、重建多级标题和合并多页结果等需求,可以通过如下方式实现:
648658

649659
```python
650660
from paddleocr import PaddleOCRVL
651661

652662
input_file = "./your_pdf_file.pdf"
653663
output_path = Path("./output")
654664

655-
# 英伟达 GPU
656665
pipeline = PaddleOCRVL()
657-
# 昆仑芯 XPU
658-
# pipeline = PaddleOCRVL(device="xpu")
659-
# 海光 DCU
660-
# pipeline = PaddleOCRVL(device="dcu")
661-
# 沐曦 GPU
662-
# pipeline = PaddleOCRVL(device="metax_gpu")
663666

664667
output = pipeline.predict(input=input_file)
665668

@@ -671,7 +674,6 @@ output = pipeline.restructure_pages(pages_res)
671674
# output = pipeline.restructure_pages(pages_res, merge_table=True, relevel_titles=True) # 合并跨页表格,重建多级标题
672675
# output = pipeline.restructure_pages(pages_res, merge_table=True, relevel_titles=True, merge_pages=True) # 合并跨页表格,重建多级标题,合并多页结果为一页
673676

674-
675677
for res in output:
676678
res.print() ## 打印预测的结构化输出
677679
res.save_to_json(save_path="output") ## 保存当前图像的结构化json结果
@@ -691,19 +693,6 @@ output = pipeline.predict(["imgs/file1.png", "imgs/file2.png", "imgs/file3.png"]
691693
# output = pipeline.predict(file)
692694
```
693695

694-
如果您需要处理多个文件,**建议将包含文件的目录路径,或者文件路径列表传入 `predict` 方法**,以最大化处理效率。例如:
695-
696-
```python
697-
# `imgs` 目录中包含多张待处理图像:file1.png、file2.png、file3.png
698-
# 传入目录路径
699-
output = pipeline.predict("imgs")
700-
# 或者传入文件路径列表
701-
output = pipeline.predict(["imgs/file1.png", "imgs/file2.png", "imgs/file3.png"])
702-
# 以上两种方式的处理效率高于下列方式:
703-
# for file in ["imgs/file1.png", "imgs/file2.png", "imgs/file3.png"]:
704-
# output = pipeline.predict(file)
705-
```
706-
707696
**注:**
708697

709698
- 在示例代码中,`use_doc_orientation_classify``use_doc_unwarping` 参数默认均设置为 `False`,分别表示关闭文档方向分类、文本图像矫正功能,如果需要使用这些功能,可以手动设置为 `True`
@@ -1222,6 +1211,8 @@ output = pipeline.predict(["imgs/file1.png", "imgs/file2.png", "imgs/file3.png"]
12221211
<th>参数说明</th>
12231212
<th>参数类型</th>
12241213
<th>默认值</th>
1214+
</tr>
1215+
</thead>
12251216
<tr>
12261217
<td><code>res_list</code></td>
12271218
<td><b>含义:</b>多页 PDF 推理预测出的结果列表。</td>
@@ -1424,68 +1415,7 @@ output = pipeline.predict(["imgs/file1.png", "imgs/file2.png", "imgs/file3.png"]
14241415
</li>
14251416
<li>调用<code>save_to_img()</code> 方法会将可视化结果保存到指定的<code>save_path</code>中,如果指定为目录,则会将版面区域检测可视化图像、全局OCR可视化图像、版面阅读顺序可视化图像等内容保存,如果指定为文件,则直接保存到该文件中。</li>
14261417
<li>调用<code>save_to_markdown()</code> 方法会将转化后的 Markdown 文件保存到指定的<code>save_path</code>中,保存的文件路径为<code>save_path/{your_img_basename}.md</code>,如果输入是 PDF 文件,建议直接指定目录,否责多个 markdown 文件会被覆盖。</li>
1427-
1428-
- `page_index`: `(Union[int, None])` 如果输入是PDF文件,则表示当前是PDF的第几页,否则为 `None`
1429-
1430-
- `page_count`: `(Union[int, None])` 如果输入是PDF文件,表示当前是PDF的总页数,否则为 `None`
1431-
1432-
- `width`: `(int)` 原始输入图像的宽度。
1433-
1434-
- `height`: `(int)` 原始输入图像的高度。
1435-
1436-
- `model_settings`: `(Dict[str, bool])` 配置 PaddleOCR-VL 所需的模型参数
1437-
1438-
- `use_doc_preprocessor`: `(bool)` 控制是否启用文档预处理子产线
1439-
- `use_layout_detection`: `(bool)` 控制是否启用版面检测模块
1440-
- `use_chart_recognition`: `(bool)` 控制是否开启图表识别功能
1441-
- `format_block_content`: `(bool)` 控制是否在`JSON`中保存格式化后的markdown内容
1442-
- `markdown_ignore_labels`: `(List[str])` 需要在Markdown中忽略的版面标签
1443-
1444-
- `doc_preprocessor_res`: `(Dict[str, Union[List[float], str]])` 文档预处理结果dict,仅当`use_doc_preprocessor=True`时存在
1445-
- `input_path`: `(str)` 文档预处理子接受的图像路径,当输入为`numpy.ndarray`时,保存为`None`,此处为`None`
1446-
- `page_index`: `None`,此处的输入为`numpy.ndarray`,所以值为`None`
1447-
- `model_settings`: `(Dict[str, bool])` 文档预处理子的模型配置参数
1448-
- `use_doc_orientation_classify`: `(bool)` 控制是否启用文档图像方向分类子模块
1449-
- `use_doc_unwarping`: `(bool)` 控制是否启用文本图像扭曲矫正子模块
1450-
- `angle`: `(int)` 文档图像方向分类子模块的预测结果,启用时返回实际角度值
1451-
1452-
- `parsing_res_list`: `(List[Dict])` 解析结果的列表,每个元素为一个字典,列表顺序为解析后的阅读顺序。
1453-
- `block_bbox`: `(np.ndarray)` 版面区域的边界框。
1454-
- `block_label`: `(str)` 版面区域的标签,例如`text`, `table`等。
1455-
- `block_content`: `(str)` 内容为版面区域内的内容。
1456-
- `block_id`: `(int)` 版面区域的索引,用于显示版面排序结果。
1457-
- `block_order` `(int)` 版面区域的顺序,用于显示版面阅读顺序,对于非排序部分,默认值为 `None`。
1458-
1459-
- 调用`save_to_json()` 方法会将上述内容保存到指定的 `save_path` 中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}_res.json`,如果指定为文件,则直接保存到该文件中。由于 json 文件不支持保存numpy数组,因此会将其中的 `numpy.array` 类型转换为列表形式。json中的字段内容如下:
1460-
- `input_path`: `(str)` 待预测图像或者PDF的输入路径
1461-
1462-
- `page_index`: `(Union[int, None])` 如果输入是PDF文件,则表示当前是PDF的第几页,否则为 `None`
1463-
1464-
- `model_settings`: `(Dict[str, bool])` 配置 PaddleOCR-VL 所需的模型参数
1465-
1466-
- `use_doc_preprocessor`: `(bool)` 控制是否启用文档预处理子产线
1467-
- `use_layout_detection`: `(bool)` 控制是否启用版面检测模块
1468-
- `use_chart_recognition`: `(bool)` 控制是否开启图表识别功能
1469-
- `format_block_content`: `(bool)` 控制是否在`JSON`中保存格式化后的markdown内容
1470-
1471-
- `doc_preprocessor_res`: `(Dict[str, Union[List[float], str]])` 文档预处理结果dict,仅当`use_doc_preprocessor=True`时存在
1472-
- `input_path`: `(str)` 文档预处理子接受的图像路径,当输入为`numpy.ndarray`时,保存为`None`,此处为`None`
1473-
- `page_index`: `None`,此处的输入为`numpy.ndarray`,所以值为`None`
1474-
- `model_settings`: `(Dict[str, bool])` 文档预处理子的模型配置参数
1475-
- `use_doc_orientation_classify`: `(bool)` 控制是否启用文档图像方向分类子模块
1476-
- `use_doc_unwarping`: `(bool)` 控制是否启用文本图像扭曲矫正子模块
1477-
- `angle`: `(int)` 文档图像方向分类子模块的预测结果,启用时返回实际角度值
1478-
1479-
- `parsing_res_list`: `(List[Dict])` 解析结果的列表,每个元素为一个字典,列表顺序为解析后的阅读顺序。
1480-
- `block_bbox`: `(np.ndarray)` 版面区域的边界框。
1481-
- `block_label`: `(str)` 版面区域的标签,例如`text`, `table`等。
1482-
- `block_content`: `(str)` 内容为版面区域内的内容。
1483-
- `block_id`: `(int)` 版面区域的索引,用于显示版面排序结果。
1484-
- `block_order` `(int)` 版面区域的顺序,用于显示版面阅读顺序,对于非排序部分,默认值为 `None`
1485-
- 调用`save_to_img()` 方法会将可视化结果保存到指定的 `save_path` 中,如果指定为目录,则会将版面区域检测可视化图像、全局OCR可视化图像、版面阅读顺序可视化图像等内容保存,如果指定为文件,则直接保存到该文件中。
1486-
- 调用`save_to_markdown()` 方法会将转化后的 Markdown 文件保存到指定的 `save_path` 中,保存的文件路径为`save_path/{your_img_basename}.md`,如果输入是 PDF 文件,建议直接指定目录,否责多个 markdown 文件会被覆盖。
1487-
1488-
此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
1418+
<li>此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
14891419
<table>
14901420
<thead>
14911421
<tr>
@@ -1519,7 +1449,7 @@ output = pipeline.predict(["imgs/file1.png", "imgs/file2.png", "imgs/file3.png"]
15191449
<li><code>json</code> 属性获取的预测结果为dict类型的数据,相关内容与调用 <code>save_to_json()</code> 方法保存的内容一致。</li>
15201450
<li><code>img</code> 属性返回的预测结果是一个dict类型的数据。其中,键分别为 <code>ocr_res_img</code> 和 <code>preprocessed_img</code>,对应的值是两个 <code>Image.Image</code> 对象:一个用于显示 OCR 结果的可视化图像,另一个用于展示图像预处理的可视化图像。如果没有使用图像预处理子模块,则dict中只包含 <code>ocr_res_img</code>。</li>
15211451
</ul>
1522-
1452+
</li>
15231453
</details>
15241454

15251455

@@ -1641,7 +1571,7 @@ paddleocr genai_server --model_name PaddleOCR-VL-1.5-0.9B --backend vllm --port
16411571

16421572
### 3.2 客户端使用方法
16431573

1644-
启动 VLM 推理服务后,客户端即可通过 PaddleOCR 调用该服务。**请注意,由于客户端需要调用版面检测的顺序模型,仍建议在 GPU 等加速设备上运行客户端,以获得更稳定和高效的性能。客户端环境配置请参考第 1 节,3.1 节介绍的环境配置仅适用于启动服务,不适用于客户端。**
1574+
启动 VLM 推理服务后,客户端即可通过 PaddleOCR 调用该服务。**请注意,由于客户端需要调用版面检测模型,仍建议在 GPU 等加速设备上运行客户端,以获得更稳定和高效的性能。客户端环境配置请参考第 1 节,3.1 节介绍的环境配置仅适用于启动服务,不适用于客户端。**
16451575

16461576
#### 3.2.1 CLI 调用
16471577

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ nav:
308308
- PaddleOCR-VL-1.5简介: version3.x/algorithm/PaddleOCR-VL/PaddleOCR-VL-1.5.md
309309
- PaddleOCR-VL简介: version3.x/algorithm/PaddleOCR-VL/PaddleOCR-VL.md
310310
- PaddleOCR-VL NVIDIA Blackwell 架构 GPU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-NVIDIA-Blackwell.md
311-
- PaddleOCR-VL 昆仑芯 XPU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-Kunlunxin-XPU.md
312-
- PaddleOCR-VL 海光 DCU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-Hygon-DCU.md
311+
- PaddleOCR-VL 昆仑芯 XPU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-KUNLUNXIN-XPU.md
312+
- PaddleOCR-VL 海光 DCU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-HYGON-DCU.md
313313
- PaddleOCR-VL 沐曦 GPU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-MetaX-GPU.md
314314
- PaddleOCR-VL 天数 GPU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-Iluvatar-GPU.md
315315
- PaddleOCR-VL 华为昇腾 NPU 环境配置教程: version3.x/pipeline_usage/PaddleOCR-VL-Huawei-Ascend-NPU.md

0 commit comments

Comments
 (0)