mirror of
https://github.com/PaddlePaddle/PaddleOCR.git
synced 2026-11-25 17:29:39 +08:00
add speed data (#18124)
* add speed data * fix link * update * update inference_engine doc * update * fix
This commit is contained in:
1 parent
77ddbafccd
commit
71c7fefbf5
28 files changed
+1463
-138
No files matched your search
@@ -21,11 +21,13 @@ In PaddleOCR, an inference engine refers to the underlying runtime used to execu
|
||||
| - | - | - |
|
||||
| PaddlePaddle framework | `paddle`, `paddle_static`, `paddle_dynamic` | Runs on the PaddlePaddle framework. |
|
||||
| Transformers | `transformers` | Runs on Hugging Face Transformers. |
|
||||
| ONNX Runtime | `onnxruntime` | Runs on ONNX Runtime. |
|
||||
|
||||
- `paddle`: The unified entry point for the PaddlePaddle framework. It selects `paddle_static` or `paddle_dynamic` according to the model type and files in the model directory. If both are available, `paddle_static` is preferred.
|
||||
- `paddle_static`: PaddlePaddle static-graph inference, suitable for scenarios that require better inference performance or more fine-grained performance tuning.
|
||||
- `paddle_dynamic`: PaddlePaddle dynamic-graph inference, which is more flexible and easier to debug compared to static graph.
|
||||
- `transformers`: Hugging Face Transformers inference, making it convenient to integrate with the Hugging Face ecosystem.
|
||||
- `onnxruntime`: ONNX Runtime inference, used to load and execute ONNX-format models.
|
||||
|
||||
## 3. Installation by Inference Engine
|
||||
|
||||
@@ -37,14 +39,22 @@ When using the PaddlePaddle framework for inference, install PaddlePaddle first.
|
||||
|
||||
### 3.2 Transformers
|
||||
|
||||
When using Transformers as the inference engine, you need to install Hugging Face Transformers (`>=5.8.0`). Example command:
|
||||
When using Transformers as the inference engine, you need to install Hugging Face Transformers (`>=5.10.0`). Example command:
|
||||
|
||||
```bash
|
||||
python -m pip install "transformers>=5.8.0"
|
||||
python -m pip install "transformers>=5.10.0"
|
||||
```
|
||||
|
||||
In many cases, you also need to install the underlying inference framework. For details, see the [Transformers official documentation](https://huggingface.co/docs/transformers/installation).
|
||||
|
||||
### 3.3 ONNX Runtime
|
||||
|
||||
When using ONNX Runtime as the inference engine, install the ONNX Runtime package. Example command:
|
||||
|
||||
```bash
|
||||
python -m pip install onnxruntime-gpu
|
||||
```
|
||||
|
||||
## 4. Configuration and Supported Values of `engine` and `engine_config`
|
||||
|
||||
### 4.1 `engine`
|
||||
@@ -58,6 +68,7 @@ In many cases, you also need to install the underlying inference framework. For
|
||||
| `paddle_static` | Static-graph inference | Uses Paddle static-graph inference. |
|
||||
| `paddle_dynamic` | Dynamic-graph inference | Uses Paddle dynamic-graph inference. |
|
||||
| `transformers` | Transformers inference | Uses Hugging Face Transformers inference. |
|
||||
| `onnxruntime` | ONNX Runtime inference | Uses ONNX Runtime inference. |
|
||||
|
||||
### 4.2 `engine_config`
|
||||
|
||||
@@ -102,12 +113,18 @@ Common fields include:
|
||||
- `processor_kwargs`: extra arguments passed to the processor / image processor loading API;
|
||||
- `tokenizer_kwargs`: a compatibility-preserved field that is merged with `processor_kwargs`.
|
||||
|
||||
#### `onnxruntime`
|
||||
|
||||
Common fields include:
|
||||
|
||||
- `device_type` / `device_id`: inference device type and device index.
|
||||
|
||||
#### 4.2.1 Flat vs. bucketed `engine_config`
|
||||
|
||||
At the same level `engine_config` may be:
|
||||
|
||||
- **Flat**: a dict whose keys are only those required by the **resolved** engine (for example, when using static graph only, top-level keys such as `run_mode` and `cpu_threads`).
|
||||
- **Bucketed**: top-level keys are **only** registered engine names (e.g. `paddle_static`, `paddle_dynamic`, `transformers`), each mapping to a nested dict. You **must not** mix bucket keys with flat keys at the same level (e.g. `{"paddle_static": {...}, "run_mode": "paddle"}` is invalid).
|
||||
- **Bucketed**: top-level keys are **only** registered engine names (e.g. `paddle_static`, `paddle_dynamic`, `transformers`, `onnxruntime`), each mapping to a nested dict. You **must not** mix bucket keys with flat keys at the same level (e.g. `{"paddle_static": {...}, "run_mode": "paddle"}` is invalid).
|
||||
|
||||
When an engine is resolved, only the corresponding config is used: flat configs are validated as a whole; bucketed configs take the entry for that engine.
|
||||
|
||||
@@ -128,6 +145,7 @@ When an engine is resolved, only the corresponding config is used: flat configs
|
||||
|
||||
```bash
|
||||
paddleocr text_detection -i general_ocr_001.png --engine transformers
|
||||
paddleocr text_detection -i general_ocr_001.png --engine onnxruntime
|
||||
```
|
||||
|
||||
### 5.2 Individual model (Python): explicitly specify `transformers`
|
||||
@@ -143,7 +161,20 @@ model = TextDetection(
|
||||
result = model.predict("general_ocr_001.png")
|
||||
```
|
||||
|
||||
### 5.3 Individual model (Python): specify `paddle_static` and `engine_config`
|
||||
### 5.3 Individual model (Python): explicitly specify `onnxruntime`
|
||||
|
||||
```python
|
||||
from paddleocr import TextDetection
|
||||
|
||||
model = TextDetection(
|
||||
model_name="PP-OCRv5_server_det",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
|
||||
result = model.predict("general_ocr_001.png")
|
||||
```
|
||||
|
||||
### 5.4 Individual model (Python): specify `paddle_static` and `engine_config`
|
||||
|
||||
```python
|
||||
from paddleocr import TextDetection
|
||||
@@ -161,13 +192,13 @@ model = TextDetection(
|
||||
result = model.predict("general_ocr_001.png")
|
||||
```
|
||||
|
||||
### 5.4 Pipeline (CLI): select the engine with `--engine`
|
||||
### 5.5 Pipeline (CLI): select the engine with `--engine`
|
||||
|
||||
```bash
|
||||
paddleocr ocr -i general_ocr_001.png --engine paddle_static
|
||||
```
|
||||
|
||||
### 5.5 Pipeline (Python API): configure the inference engine for a specific module
|
||||
### 5.6 Pipeline (Python API): configure the inference engine for a specific module
|
||||
|
||||
If you want to specify `engine` and `engine_config` for a specific module inside a pipeline, you can first export the configuration file, modify the corresponding module configuration, and then load it. For how to export, edit, and load the configuration file, see [Using PaddleX Pipeline Configuration Files](../../paddleocr_and_paddlex.en.md#3-using-paddlex-pipeline-configuration-files). Example:
|
||||
|
||||
|
||||
@@ -21,11 +21,13 @@ PaddleOCR 3.5 引入了统一的推理引擎配置方式:使用 `engine` 选
|
||||
| - | - | - |
|
||||
| 飞桨框架 | `paddle`、`paddle_static`、`paddle_dynamic` | 基于飞桨框架运行。 |
|
||||
| Transformers | `transformers` | 基于 Hugging Face Transformers 运行。 |
|
||||
| ONNX Runtime | `onnxruntime` | 基于 ONNX Runtime 运行。 |
|
||||
|
||||
- `paddle`:飞桨框架统一入口。根据模型类型和模型目录中的文件选择 `paddle_static` 或 `paddle_dynamic`,在二者都可用的情况下偏好 `paddle_static`。
|
||||
- `paddle_static`:飞桨静态图推理,适合对推理性能有一定要求或者需要进行精细化推理性能调优的场景。
|
||||
- `paddle_dynamic`:飞桨动态图推理,相比静态图更加灵活、易于调试。
|
||||
- `transformers`:Hugging Face Transformers 推理,便于与 Hugging Face 生态集成。
|
||||
- `onnxruntime`:ONNX Runtime 推理,用于加载并执行 ONNX 格式模型。
|
||||
|
||||
## 3. 各推理引擎安装方式
|
||||
|
||||
@@ -37,14 +39,22 @@ PaddleOCR 3.5 引入了统一的推理引擎配置方式:使用 `engine` 选
|
||||
|
||||
### 3.2 Transformers
|
||||
|
||||
当您使用 Transformers 作为推理引擎时,需要安装 Hugging Face Transformers(`>=5.8.0`)。示例命令如下:
|
||||
当您使用 Transformers 作为推理引擎时,需要安装 Hugging Face Transformers(`>=5.10.0`)。示例命令如下:
|
||||
|
||||
```bash
|
||||
python -m pip install "transformers>=5.8.0"
|
||||
python -m pip install "transformers>=5.10.0"
|
||||
```
|
||||
|
||||
通常,您还需要安装底层推理框架,详情可参考 [Transformers 官方文档](https://huggingface.co/docs/transformers/installation)。
|
||||
|
||||
### 3.3 ONNX Runtime
|
||||
|
||||
当您使用 ONNX Runtime 作为推理引擎时,需要安装 ONNX Runtime。示例命令如下:
|
||||
|
||||
```bash
|
||||
python -m pip install onnxruntime-gpu
|
||||
```
|
||||
|
||||
## 4. `engine` 和 `engine_config` 的设置与取值
|
||||
|
||||
### 4.1 `engine`
|
||||
@@ -58,6 +68,7 @@ python -m pip install "transformers>=5.8.0"
|
||||
| `paddle_static` | 静态图推理 | 使用飞桨静态图推理。 |
|
||||
| `paddle_dynamic` | 飞桨动态图推理 | 使用飞桨动态图推理。 |
|
||||
| `transformers` | Transformers 推理 | 使用 Hugging Face Transformers 推理。 |
|
||||
| `onnxruntime` | ONNX Runtime 推理 | 使用 ONNX Runtime 推理。 |
|
||||
|
||||
### 4.2 `engine_config`
|
||||
|
||||
@@ -102,12 +113,18 @@ python -m pip install "transformers>=5.8.0"
|
||||
- `processor_kwargs`:传给 processor / image processor 加载接口的额外参数;
|
||||
- `tokenizer_kwargs`:兼容保留字段,会与 `processor_kwargs` 合并使用。
|
||||
|
||||
#### `onnxruntime`
|
||||
|
||||
常见字段包括:
|
||||
|
||||
- `device_type` / `device_id`:推理设备类型和设备编号。
|
||||
|
||||
#### 4.2.1 扁平与分桶 `engine_config`
|
||||
|
||||
同一层级的 `engine_config` 可以是:
|
||||
|
||||
- **扁平**:只包含**当前解析得到的引擎**所需的字段(例如仅使用静态图时,顶层直接是 `run_mode`、`cpu_threads` 等)。
|
||||
- **分桶**:顶层键**仅**为 PaddleX 已注册的引擎名(如 `paddle_static`、`paddle_dynamic`、`transformers` 等),每个键对应一个嵌套字典。**不得**在同一层级混用「分桶键」与扁平字段(例如 `{"paddle_static": {...}, "run_mode": "paddle"}` 会报错)。
|
||||
- **分桶**:顶层键**仅**为 PaddleX 已注册的引擎名(如 `paddle_static`、`paddle_dynamic`、`transformers`、`onnxruntime` 等),每个键对应一个嵌套字典。**不得**在同一层级混用「分桶键」与扁平字段(例如 `{"paddle_static": {...}, "run_mode": "paddle"}` 会报错)。
|
||||
|
||||
解析为某一引擎时,只会使用与该引擎对应的一份配置:扁平形式直接参与校验;分桶形式则取出对应键下的字典。
|
||||
|
||||
@@ -128,6 +145,7 @@ python -m pip install "transformers>=5.8.0"
|
||||
|
||||
```bash
|
||||
paddleocr text_detection -i general_ocr_001.png --engine transformers
|
||||
paddleocr text_detection -i general_ocr_001.png --engine onnxruntime
|
||||
```
|
||||
|
||||
### 5.2 单模型(Python):显式指定 `transformers`
|
||||
@@ -143,7 +161,20 @@ model = TextDetection(
|
||||
result = model.predict("general_ocr_001.png")
|
||||
```
|
||||
|
||||
### 5.3 单模型(Python):指定 `paddle_static` 与 `engine_config`
|
||||
### 5.3 单模型(Python):显式指定 `onnxruntime`
|
||||
|
||||
```python
|
||||
from paddleocr import TextDetection
|
||||
|
||||
model = TextDetection(
|
||||
model_name="PP-OCRv5_server_det",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
|
||||
result = model.predict("general_ocr_001.png")
|
||||
```
|
||||
|
||||
### 5.4 单模型(Python):指定 `paddle_static` 与 `engine_config`
|
||||
|
||||
```python
|
||||
from paddleocr import TextDetection
|
||||
@@ -161,13 +192,13 @@ model = TextDetection(
|
||||
result = model.predict("general_ocr_001.png")
|
||||
```
|
||||
|
||||
### 5.4 产线(CLI):通过 `--engine` 选择引擎
|
||||
### 5.5 产线(CLI):通过 `--engine` 选择引擎
|
||||
|
||||
```bash
|
||||
paddleocr ocr -i general_ocr_001.png --engine paddle_static
|
||||
```
|
||||
|
||||
### 5.5 产线(Python API):为某个模块单独配置推理引擎
|
||||
### 5.6 产线(Python API):为某个模块单独配置推理引擎
|
||||
|
||||
如需为产线中的某一个模块单独指定 `engine`、`engine_config`,可先导出配置文件,修改对应模块配置后,再通过加载配置文件。配置文件的导出、编辑与加载方式可参见 [使用 PaddleX 产线配置文件](../../paddleocr_and_paddlex.md#3-paddlex)。示例如下:
|
||||
|
||||
|
||||
@@ -52,6 +52,14 @@ paddleocr chart_parsing -i "{'image': 'https://paddle-model-ecology.bj.bcebos.co
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr chart_parsing -i "{'image': 'https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/chart_parsing_02.png'}" \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_dynamic` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
**Note:** By default, PaddleOCR retrieves models from HuggingFace. If HuggingFace access is restricted in your environment, you can switch the model source to BOS by setting the environment variable: `PADDLE_PDX_MODEL_SOURCE="BOS"`. Support for more mainstream sources is planned.
|
||||
@@ -89,6 +97,23 @@ for res in results:
|
||||
res.save_to_json(f"./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import ChartParsing
|
||||
model = ChartParsing(
|
||||
model_name="PP-Chart2Table",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
results = model.predict(
|
||||
input={"image": "chart_parsing_02.png"},
|
||||
batch_size=1
|
||||
)
|
||||
for res in results:
|
||||
res.print()
|
||||
res.save_to_json(f"./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_dynamic` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
The output result will be:
|
||||
@@ -155,7 +180,7 @@ Defaults to GPU 0 if available; otherwise falls back to CPU.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_dynamic</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_dynamic</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -315,7 +340,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -325,7 +350,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -52,6 +52,14 @@ paddleocr chart_parsing -i "{'image': 'https://paddle-model-ecology.bj.bcebos.co
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr chart_parsing -i "{'image': 'https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/chart_parsing_02.png'}" \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_dynamic` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -89,6 +97,23 @@ for res in results:
|
||||
res.save_to_json(f"./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import ChartParsing
|
||||
model = ChartParsing(
|
||||
model_name="PP-Chart2Table",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
results = model.predict(
|
||||
input={"image": "chart_parsing_02.png"},
|
||||
batch_size=1
|
||||
)
|
||||
for res in results:
|
||||
res.print()
|
||||
res.save_to_json(f"./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_dynamic` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
运行后,得到的结果为:
|
||||
@@ -153,7 +178,7 @@ for res in results:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_dynamic</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_dynamic</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -311,7 +336,7 @@ for res in results:
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -321,7 +346,7 @@ for res in results:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -104,6 +104,14 @@ paddleocr doc_img_orientation_classification -i https://paddle-model-ecology.bj.
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr doc_img_orientation_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -139,6 +147,22 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import DocImgOrientationClassification
|
||||
|
||||
model = DocImgOrientationClassification(
|
||||
model_name="PP-LCNet_x1_0_doc_ori",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("img_rot180_demo.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_img("./output/demo.png")
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -201,7 +225,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -407,7 +431,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x1_0_doc_ori</td>
|
||||
<td rowspan="4">PP-LCNet_x1_0_doc_ori</td>
|
||||
<td>paddle_static</td>
|
||||
<td>2.21</td>
|
||||
<td>3.36</td>
|
||||
@@ -428,12 +452,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.14</td>
|
||||
<td>8.36</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>2.02</td>
|
||||
<td>0.87</td>
|
||||
<td>0.05</td>
|
||||
<td>3.03</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -443,13 +474,13 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Image Orientation Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/doc_img_orientation_classification.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Image Orientation Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/doc_img_orientation_classification.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
@@ -106,6 +106,14 @@ paddleocr doc_img_orientation_classification -i https://paddle-model-ecology.bj.
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr doc_img_orientation_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
如需了解推理引擎的介绍、速度数据及权重转换等详细信息,请参考后文 [推理引擎](#五推理引擎) 章节。
|
||||
@@ -134,6 +142,17 @@ model = DocImgOrientationClassification(
|
||||
)
|
||||
```
|
||||
|
||||
如果希望使用 `onnxruntime` 引擎进行推理,可以参考如下示例:
|
||||
|
||||
```python
|
||||
from paddleocr import DocImgOrientationClassification
|
||||
|
||||
model = DocImgOrientationClassification(
|
||||
model_name="PP-LCNet_x1_0_doc_ori",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
随后继续按上文方式调用 `predict()` 即可。
|
||||
@@ -197,7 +216,7 @@ model = DocImgOrientationClassification(
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -403,7 +422,7 @@ model = DocImgOrientationClassification(
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x1_0_doc_ori</td>
|
||||
<td rowspan="4">PP-LCNet_x1_0_doc_ori</td>
|
||||
<td>paddle_static</td>
|
||||
<td>2.21</td>
|
||||
<td>3.36</td>
|
||||
@@ -424,12 +443,19 @@ model = DocImgOrientationClassification(
|
||||
<td>0.14</td>
|
||||
<td>8.36</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>2.02</td>
|
||||
<td>0.87</td>
|
||||
<td>0.05</td>
|
||||
<td>3.03</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/img_rot180_demo.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -439,13 +465,13 @@ model = DocImgOrientationClassification(
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文本图像方向分类模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/doc_img_orientation_classification.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文本图像方向分类模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/doc_img_orientation_classification.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、FAQ
|
||||
@@ -109,6 +109,13 @@ paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg --model_name PP-DocLayoutV3 \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable <code>PADDLE_PDX_MODEL_SOURCE="BOS"</code> to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -144,6 +151,22 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import LayoutDetection
|
||||
|
||||
model = LayoutDetection(
|
||||
model_name="PP-DocLayoutV2",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("layout.jpg", batch_size=1, layout_nms=True)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#42-weight-conversion) section in the [Inference Engine](#4-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -209,7 +232,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -513,7 +536,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocLayoutV3</td>
|
||||
<td rowspan="4">PP-DocLayoutV3</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.95</td>
|
||||
<td>47.99</td>
|
||||
@@ -535,7 +558,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>78.97</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocLayoutV2</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.26</td>
|
||||
<td>39.11</td>
|
||||
<td>10.23</td>
|
||||
<td>58.80</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-DocLayoutV2</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.48</td>
|
||||
<td>30.94</td>
|
||||
@@ -556,12 +586,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>2.43</td>
|
||||
<td>69.30</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.25</td>
|
||||
<td>15.13</td>
|
||||
<td>1.25</td>
|
||||
<td>25.82</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -571,11 +608,11 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 4.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Layout Analysis Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/layout_analysis.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Layout Analysis Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/layout_analysis.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
@@ -68,6 +68,13 @@ paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg --model_name PP-DocLayoutV3 \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
您可以将版面区域检测模块中的模型推理集成到您的项目中。运行以下代码前,请您下载[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg)到本地。
|
||||
@@ -101,6 +108,22 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import LayoutDetection
|
||||
|
||||
model = LayoutDetection(
|
||||
model_name="PP-DocLayoutV3",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("layout.jpg", batch_size=1, layout_nms=True)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#四推理引擎) 中的 [权重转换](#42-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -165,7 +188,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -462,7 +485,7 @@ for res in output:
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocLayoutV3</td>
|
||||
<td rowspan="4">PP-DocLayoutV3</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.95</td>
|
||||
<td>47.99</td>
|
||||
@@ -484,7 +507,14 @@ for res in output:
|
||||
<td>78.97</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocLayoutV2</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.26</td>
|
||||
<td>39.11</td>
|
||||
<td>10.23</td>
|
||||
<td>58.80</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-DocLayoutV2</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.48</td>
|
||||
<td>30.94</td>
|
||||
@@ -505,12 +535,19 @@ for res in output:
|
||||
<td>2.43</td>
|
||||
<td>69.30</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.25</td>
|
||||
<td>15.13</td>
|
||||
<td>1.25</td>
|
||||
<td>25.82</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -520,11 +557,11 @@ for res in output:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 4.2 权重转换 {#42-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 版面分析模块权重转换](https://paddlepaddle.github.io/PaddleX/main/module_usage/tutorials/ocr_modules/layout_analysis.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 版面分析模块权重转换](https://paddlepaddle.github.io/PaddleX/main/module_usage/tutorials/ocr_modules/layout_analysis.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
@@ -328,6 +328,14 @@ paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable <code>PADDLE_PDX_MODEL_SOURCE="BOS"</code> to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -363,6 +371,22 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import LayoutDetection
|
||||
|
||||
model = LayoutDetection(
|
||||
model_name="PP-DocLayout_plus-L",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("layout.jpg", batch_size=1, layout_nms=True)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -432,7 +456,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -744,7 +768,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocLayout_plus-L</td>
|
||||
<td rowspan="4">PP-DocLayout_plus-L</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.92</td>
|
||||
<td>26.11</td>
|
||||
@@ -766,7 +790,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>52.24</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocBlockLayout</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.14</td>
|
||||
<td>12.35</td>
|
||||
<td>0.14</td>
|
||||
<td>21.81</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-DocBlockLayout</td>
|
||||
<td>paddle_static</td>
|
||||
<td>9.51</td>
|
||||
<td>27.59</td>
|
||||
@@ -787,12 +818,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.75</td>
|
||||
<td>50.96</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>7.53</td>
|
||||
<td>9.22</td>
|
||||
<td>0.06</td>
|
||||
<td>16.97</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -802,13 +840,13 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Layout Detection Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/layout_detection.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Layout Detection Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/layout_detection.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
@@ -328,6 +328,14 @@ paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -363,6 +371,22 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import LayoutDetection
|
||||
|
||||
model = LayoutDetection(
|
||||
model_name="PP-DocLayout_plus-L",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("layout.jpg", batch_size=1, layout_nms=True)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -433,7 +457,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -737,7 +761,7 @@ for res in output:
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocLayout_plus-L</td>
|
||||
<td rowspan="4">PP-DocLayout_plus-L</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.92</td>
|
||||
<td>26.11</td>
|
||||
@@ -759,7 +783,14 @@ for res in output:
|
||||
<td>52.24</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-DocBlockLayout</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.14</td>
|
||||
<td>12.35</td>
|
||||
<td>0.14</td>
|
||||
<td>21.81</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-DocBlockLayout</td>
|
||||
<td>paddle_static</td>
|
||||
<td>9.51</td>
|
||||
<td>27.59</td>
|
||||
@@ -780,12 +811,19 @@ for res in output:
|
||||
<td>0.75</td>
|
||||
<td>50.96</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>7.53</td>
|
||||
<td>9.22</td>
|
||||
<td>0.06</td>
|
||||
<td>16.97</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -795,13 +833,13 @@ for res in output:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 版面区域检测模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/layout_detection.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 版面区域检测模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/layout_detection.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、FAQ
|
||||
@@ -107,6 +107,14 @@ paddleocr table_cells_detection -i https://paddle-model-ecology.bj.bcebos.com/pa
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr table_cells_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -140,6 +148,21 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TableCellsDetection
|
||||
model = TableCellsDetection(
|
||||
model_name="RT-DETR-L_wired_table_cell_det",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("table_recognition.jpg", threshold=0.3, batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_img("./output/")
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -206,7 +229,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -430,7 +453,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">RT-DETR-L_wired_table_cell_det</td>
|
||||
<td rowspan="4">RT-DETR-L_wired_table_cell_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>3.59</td>
|
||||
<td>23.11</td>
|
||||
@@ -452,7 +475,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>42.10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">RT-DETR-L_wireless_table_cell_det</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>2.70</td>
|
||||
<td>9.10</td>
|
||||
<td>0.12</td>
|
||||
<td>12.07</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">RT-DETR-L_wireless_table_cell_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>3.77</td>
|
||||
<td>23.44</td>
|
||||
@@ -473,12 +503,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.71</td>
|
||||
<td>41.91</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>2.77</td>
|
||||
<td>9.11</td>
|
||||
<td>0.12</td>
|
||||
<td>12.14</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -488,13 +525,13 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Table Cell Detection Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/table_cells_detection.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Table Cell Detection Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/table_cells_detection.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
@@ -105,6 +105,14 @@ paddleocr table_cells_detection -i https://paddle-model-ecology.bj.bcebos.com/pa
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr table_cells_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -138,6 +146,21 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TableCellsDetection
|
||||
model = TableCellsDetection(
|
||||
model_name="RT-DETR-L_wired_table_cell_det",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("table_recognition.jpg", threshold=0.3, batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_img("./output/")
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -205,7 +228,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -441,7 +464,7 @@ for res in output:
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">RT-DETR-L_wired_table_cell_det</td>
|
||||
<td rowspan="4">RT-DETR-L_wired_table_cell_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>3.59</td>
|
||||
<td>23.11</td>
|
||||
@@ -463,7 +486,14 @@ for res in output:
|
||||
<td>42.10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">RT-DETR-L_wireless_table_cell_det</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>2.70</td>
|
||||
<td>9.10</td>
|
||||
<td>0.12</td>
|
||||
<td>12.07</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">RT-DETR-L_wireless_table_cell_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>3.77</td>
|
||||
<td>23.44</td>
|
||||
@@ -484,12 +514,19 @@ for res in output:
|
||||
<td>0.71</td>
|
||||
<td>41.91</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>2.77</td>
|
||||
<td>9.11</td>
|
||||
<td>0.12</td>
|
||||
<td>12.14</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -499,13 +536,13 @@ for res in output:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 表格单元格检测模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/table_cells_detection.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 表格单元格检测模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/table_cells_detection.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、FAQ
|
||||
@@ -100,6 +100,14 @@ paddleocr table_classification -i https://paddle-model-ecology.bj.bcebos.com/pad
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr table_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -131,6 +139,20 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TableClassification
|
||||
model = TableClassification(
|
||||
model_name="PP-LCNet_x1_0_table_cls",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("table_recognition.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -194,7 +216,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -386,7 +408,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x1_0_table_cls</td>
|
||||
<td rowspan="4">PP-LCNet_x1_0_table_cls</td>
|
||||
<td>paddle_static</td>
|
||||
<td>3.56</td>
|
||||
<td>3.38</td>
|
||||
@@ -407,12 +429,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.15</td>
|
||||
<td>14.05</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>3.23</td>
|
||||
<td>0.88</td>
|
||||
<td>0.05</td>
|
||||
<td>4.25</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_image_classification_001.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_image_classification_001.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -422,13 +451,13 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Table Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/table_classification.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Table Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/table_classification.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
@@ -98,6 +98,14 @@ paddleocr table_classification -i https://paddle-model-ecology.bj.bcebos.com/pad
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr table_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -129,6 +137,20 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TableClassification
|
||||
model = TableClassification(
|
||||
model_name="PP-LCNet_x1_0_table_cls",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("table_recognition.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -192,7 +214,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -387,7 +409,7 @@ for res in output:
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x1_0_table_cls</td>
|
||||
<td rowspan="4">PP-LCNet_x1_0_table_cls</td>
|
||||
<td>paddle_static</td>
|
||||
<td>3.56</td>
|
||||
<td>3.38</td>
|
||||
@@ -408,12 +430,19 @@ for res in output:
|
||||
<td>0.15</td>
|
||||
<td>14.05</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>3.23</td>
|
||||
<td>0.88</td>
|
||||
<td>0.05</td>
|
||||
<td>4.25</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_image_classification_001.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_image_classification_001.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -423,13 +452,13 @@ for res in output:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 表格分类模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/table_classification.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 表格分类模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/table_classification.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、FAQ
|
||||
@@ -124,6 +124,14 @@ paddleocr table_structure_recognition -i https://paddle-model-ecology.bj.bcebos.
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr table_structure_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -155,6 +163,20 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TableStructureRecognition
|
||||
model = TableStructureRecognition(
|
||||
model_name="SLANet",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict(input="table_recognition.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -213,7 +235,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -476,7 +498,23 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">SLANeXt_wired</td>
|
||||
<td rowspan="1">SLANet</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.42</td>
|
||||
<td>22.02</td>
|
||||
<td>0.22</td>
|
||||
<td>23.81</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="1">SLANet_plus</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.40</td>
|
||||
<td>21.64</td>
|
||||
<td>0.22</td>
|
||||
<td>23.42</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">SLANeXt_wired</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.50</td>
|
||||
<td>30.91</td>
|
||||
@@ -498,7 +536,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>51.12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">SLANeXt_wireless</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.60</td>
|
||||
<td>30.96</td>
|
||||
<td>0.25</td>
|
||||
<td>32.99</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">SLANeXt_wireless</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.67</td>
|
||||
<td>30.49</td>
|
||||
@@ -519,12 +564,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.75</td>
|
||||
<td>51.76</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.62</td>
|
||||
<td>31.01</td>
|
||||
<td>0.26</td>
|
||||
<td>33.06</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -534,13 +586,13 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Table Structure Recognition Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/table_structure_recognition.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Table Structure Recognition Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/table_structure_recognition.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
@@ -124,6 +124,14 @@ paddleocr table_structure_recognition -i https://paddle-model-ecology.bj.bcebos.
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr table_structure_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -155,6 +163,20 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TableStructureRecognition
|
||||
model = TableStructureRecognition(
|
||||
model_name="SLANet",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict(input="table_recognition.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -213,7 +235,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -480,7 +502,23 @@ python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py \
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">SLANeXt_wired</td>
|
||||
<td rowspan="1">SLANet</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.42</td>
|
||||
<td>22.02</td>
|
||||
<td>0.22</td>
|
||||
<td>23.81</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="1">SLANet_plus</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.40</td>
|
||||
<td>21.64</td>
|
||||
<td>0.22</td>
|
||||
<td>23.42</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">SLANeXt_wired</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.50</td>
|
||||
<td>30.91</td>
|
||||
@@ -502,7 +540,14 @@ python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py \
|
||||
<td>51.12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">SLANeXt_wireless</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.60</td>
|
||||
<td>30.96</td>
|
||||
<td>0.25</td>
|
||||
<td>32.99</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">SLANeXt_wireless</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.67</td>
|
||||
<td>30.49</td>
|
||||
@@ -523,12 +568,19 @@ python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py \
|
||||
<td>0.75</td>
|
||||
<td>51.76</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.62</td>
|
||||
<td>31.01</td>
|
||||
<td>0.26</td>
|
||||
<td>33.06</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -538,13 +590,13 @@ python3 -m paddle.distributed.launch --gpus '0,1,2,3' tools/train.py \
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 表格结构识别模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/table_structure_recognition.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 表格结构识别模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/table_structure_recognition.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、FAQ
|
||||
@@ -130,6 +130,14 @@ paddleocr text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/i
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -163,6 +171,21 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TextDetection
|
||||
model = TextDetection(
|
||||
model_name="PP-OCRv5_server_det",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("general_ocr_001.png", batch_size=1)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -233,7 +256,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -599,7 +622,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_mobile_det</td>
|
||||
<td rowspan="4">PP-OCRv5_mobile_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>11.43</td>
|
||||
<td>13.80</td>
|
||||
@@ -621,7 +644,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>37.54</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_server_det</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.98</td>
|
||||
<td>5.70</td>
|
||||
<td>2.04</td>
|
||||
<td>17.90</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv5_server_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>13.24</td>
|
||||
<td>26.91</td>
|
||||
@@ -642,12 +672,106 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>7.44</td>
|
||||
<td>36.76</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>10.01</td>
|
||||
<td>13.76</td>
|
||||
<td>1.92</td>
|
||||
<td>25.86</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_medium_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>13.89</td>
|
||||
<td>16.02</td>
|
||||
<td>2.49</td>
|
||||
<td>33.14</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>11.42</td>
|
||||
<td>26.23</td>
|
||||
<td>2.30</td>
|
||||
<td>40.10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>11.40</td>
|
||||
<td>8.57</td>
|
||||
<td>8.35</td>
|
||||
<td>29.57</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>10.80</td>
|
||||
<td>13.06</td>
|
||||
<td>2.19</td>
|
||||
<td>26.18</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_small_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.91</td>
|
||||
<td>10.97</td>
|
||||
<td>2.41</td>
|
||||
<td>24.45</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>11.56</td>
|
||||
<td>22.17</td>
|
||||
<td>2.66</td>
|
||||
<td>36.55</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>11.70</td>
|
||||
<td>7.34</td>
|
||||
<td>3.87</td>
|
||||
<td>23.89</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>11.32</td>
|
||||
<td>7.46</td>
|
||||
<td>2.54</td>
|
||||
<td>21.49</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_tiny_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>11.14</td>
|
||||
<td>10.71</td>
|
||||
<td>2.84</td>
|
||||
<td>24.85</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>11.52</td>
|
||||
<td>21.70</td>
|
||||
<td>2.94</td>
|
||||
<td>36.31</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>10.90</td>
|
||||
<td>6.99</td>
|
||||
<td>4.13</td>
|
||||
<td>23.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>11.19</td>
|
||||
<td>6.35</td>
|
||||
<td>2.79</td>
|
||||
<td>20.49</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -657,14 +781,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Detection Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/text_detection.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Detection Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/text_detection.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
|
||||
|
||||
@@ -165,6 +165,14 @@ paddleocr text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/i
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.png \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -200,6 +208,21 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TextDetection
|
||||
model = TextDetection(
|
||||
model_name="PP-OCRv5_server_det",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("general_ocr_001.png", batch_size=1)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -269,7 +292,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -642,7 +665,7 @@ python3 tools/export_model.py -c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml -o
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_mobile_det</td>
|
||||
<td rowspan="4">PP-OCRv5_mobile_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>11.43</td>
|
||||
<td>13.80</td>
|
||||
@@ -664,7 +687,14 @@ python3 tools/export_model.py -c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml -o
|
||||
<td>37.54</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_server_det</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>9.98</td>
|
||||
<td>5.70</td>
|
||||
<td>2.04</td>
|
||||
<td>17.90</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv5_server_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>13.24</td>
|
||||
<td>26.91</td>
|
||||
@@ -685,12 +715,106 @@ python3 tools/export_model.py -c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml -o
|
||||
<td>7.44</td>
|
||||
<td>36.76</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>10.01</td>
|
||||
<td>13.76</td>
|
||||
<td>1.92</td>
|
||||
<td>25.86</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_medium_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>13.89</td>
|
||||
<td>16.02</td>
|
||||
<td>2.49</td>
|
||||
<td>33.14</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>11.42</td>
|
||||
<td>26.23</td>
|
||||
<td>2.30</td>
|
||||
<td>40.10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>11.40</td>
|
||||
<td>8.57</td>
|
||||
<td>8.35</td>
|
||||
<td>29.57</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>10.80</td>
|
||||
<td>13.06</td>
|
||||
<td>2.19</td>
|
||||
<td>26.18</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_small_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>10.91</td>
|
||||
<td>10.97</td>
|
||||
<td>2.41</td>
|
||||
<td>24.45</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>11.56</td>
|
||||
<td>22.17</td>
|
||||
<td>2.66</td>
|
||||
<td>36.55</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>11.70</td>
|
||||
<td>7.34</td>
|
||||
<td>3.87</td>
|
||||
<td>23.89</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>11.32</td>
|
||||
<td>7.46</td>
|
||||
<td>2.54</td>
|
||||
<td>21.49</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_tiny_det</td>
|
||||
<td>paddle_static</td>
|
||||
<td>11.14</td>
|
||||
<td>10.71</td>
|
||||
<td>2.84</td>
|
||||
<td>24.85</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>11.52</td>
|
||||
<td>21.70</td>
|
||||
<td>2.94</td>
|
||||
<td>36.31</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>10.90</td>
|
||||
<td>6.99</td>
|
||||
<td>4.13</td>
|
||||
<td>23.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>11.19</td>
|
||||
<td>6.35</td>
|
||||
<td>2.79</td>
|
||||
<td>20.49</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_001.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -700,14 +824,14 @@ python3 tools/export_model.py -c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml -o
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文本检测模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/text_detection.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文本检测模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/text_detection.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、常见问题与解决方案
|
||||
|
||||
|
||||
@@ -106,6 +106,14 @@ paddleocr text_image_unwarping -i https://paddle-model-ecology.bj.bcebos.com/pad
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr text_image_unwarping -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"` to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -139,6 +147,21 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TextImageUnwarping
|
||||
model = TextImageUnwarping(
|
||||
model_name="UVDoc",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("doc_test.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
After running, the result obtained is:
|
||||
@@ -195,7 +218,7 @@ By default, GPU 0 will be used if available; otherwise, the CPU will be used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -404,7 +427,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">UVDoc</td>
|
||||
<td rowspan="4">UVDoc</td>
|
||||
<td>paddle_static</td>
|
||||
<td>14.96</td>
|
||||
<td>18.60</td>
|
||||
@@ -425,12 +448,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.91</td>
|
||||
<td>33.07</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>10.60</td>
|
||||
<td>8.44</td>
|
||||
<td>1.75</td>
|
||||
<td>21.30</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -440,7 +470,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -105,6 +105,14 @@ paddleocr text_image_unwarping -i https://paddle-model-ecology.bj.bcebos.com/pad
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr text_image_unwarping -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -138,6 +146,21 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TextImageUnwarping
|
||||
model = TextImageUnwarping(
|
||||
model_name="UVDoc",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("doc_test.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
运行后,得到的结果为:
|
||||
@@ -196,7 +219,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -399,7 +422,7 @@ for res in output:
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">UVDoc</td>
|
||||
<td rowspan="4">UVDoc</td>
|
||||
<td>paddle_static</td>
|
||||
<td>14.96</td>
|
||||
<td>18.60</td>
|
||||
@@ -420,12 +443,19 @@ for res in output:
|
||||
<td>0.91</td>
|
||||
<td>33.07</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>10.60</td>
|
||||
<td>8.44</td>
|
||||
<td>1.75</td>
|
||||
<td>21.30</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -435,7 +465,7 @@ for res in output:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -552,6 +552,14 @@ paddleocr text_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr text_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note:</b> The official PaddleOCR models are downloaded from HuggingFace by default. If you cannot access HuggingFace, you can change the model source to BOS by setting the environment variable `PADDLE_PDX_MODEL_SOURCE="BOS"`. More mainstream model sources will be supported in the future.
|
||||
@@ -585,6 +593,21 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TextRecognition
|
||||
model = TextRecognition(
|
||||
model_name="PP-OCRv5_server_rec",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict(input="general_ocr_rec_001.png", batch_size=1)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -643,7 +666,7 @@ By default, GPU 0 is used; if unavailable, CPU is used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -906,7 +929,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_mobile_rec</td>
|
||||
<td rowspan="4">PP-OCRv5_mobile_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.94</td>
|
||||
<td>6.69</td>
|
||||
@@ -928,7 +951,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>21.68</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_server_rec</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.82</td>
|
||||
<td>2.05</td>
|
||||
<td>0.91</td>
|
||||
<td>4.91</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv5_server_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.98</td>
|
||||
<td>11.37</td>
|
||||
@@ -949,12 +979,106 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.51</td>
|
||||
<td>16.36</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.80</td>
|
||||
<td>3.15</td>
|
||||
<td>0.90</td>
|
||||
<td>5.98</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_medium_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.74</td>
|
||||
<td>5.38</td>
|
||||
<td>0.84</td>
|
||||
<td>8.08</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>1.76</td>
|
||||
<td>13.38</td>
|
||||
<td>0.85</td>
|
||||
<td>16.10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>2.58</td>
|
||||
<td>7.04</td>
|
||||
<td>0.41</td>
|
||||
<td>10.19</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.74</td>
|
||||
<td>2.28</td>
|
||||
<td>0.84</td>
|
||||
<td>4.97</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_small_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.74</td>
|
||||
<td>4.73</td>
|
||||
<td>0.82</td>
|
||||
<td>7.41</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>1.76</td>
|
||||
<td>12.43</td>
|
||||
<td>0.87</td>
|
||||
<td>15.18</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>2.55</td>
|
||||
<td>6.70</td>
|
||||
<td>0.41</td>
|
||||
<td>9.82</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.73</td>
|
||||
<td>1.79</td>
|
||||
<td>0.83</td>
|
||||
<td>4.46</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_tiny_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.76</td>
|
||||
<td>2.77</td>
|
||||
<td>0.40</td>
|
||||
<td>5.04</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>1.75</td>
|
||||
<td>6.96</td>
|
||||
<td>0.36</td>
|
||||
<td>9.19</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>2.45</td>
|
||||
<td>3.12</td>
|
||||
<td>0.40</td>
|
||||
<td>6.12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.73</td>
|
||||
<td>0.92</td>
|
||||
<td>0.36</td>
|
||||
<td>3.12</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -964,13 +1088,13 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Image Orientation Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/text_recognition.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Image Orientation Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/text_recognition.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
|
||||
## 6. FAQ
|
||||
@@ -561,6 +561,14 @@ paddleocr text_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr text_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -594,6 +602,21 @@ for res in output:
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TextRecognition
|
||||
model = TextRecognition(
|
||||
model_name="PP-OCRv5_server_rec",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict(input="general_ocr_rec_001.png", batch_size=1)
|
||||
for res in output:
|
||||
res.print()
|
||||
res.save_to_img(save_path="./output/")
|
||||
res.save_to_json(save_path="./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -655,7 +678,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -929,7 +952,7 @@ Global.save_inference_dir="./PP-OCRv5_server_rec_infer/"
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_mobile_rec</td>
|
||||
<td rowspan="4">PP-OCRv5_mobile_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.94</td>
|
||||
<td>6.69</td>
|
||||
@@ -951,7 +974,14 @@ Global.save_inference_dir="./PP-OCRv5_server_rec_infer/"
|
||||
<td>21.68</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-OCRv5_server_rec</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.82</td>
|
||||
<td>2.05</td>
|
||||
<td>0.91</td>
|
||||
<td>4.91</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv5_server_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.98</td>
|
||||
<td>11.37</td>
|
||||
@@ -972,12 +1002,106 @@ Global.save_inference_dir="./PP-OCRv5_server_rec_infer/"
|
||||
<td>0.51</td>
|
||||
<td>16.36</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.80</td>
|
||||
<td>3.15</td>
|
||||
<td>0.90</td>
|
||||
<td>5.98</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_medium_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.74</td>
|
||||
<td>5.38</td>
|
||||
<td>0.84</td>
|
||||
<td>8.08</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>1.76</td>
|
||||
<td>13.38</td>
|
||||
<td>0.85</td>
|
||||
<td>16.10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>2.58</td>
|
||||
<td>7.04</td>
|
||||
<td>0.41</td>
|
||||
<td>10.19</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.74</td>
|
||||
<td>2.28</td>
|
||||
<td>0.84</td>
|
||||
<td>4.97</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_small_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.74</td>
|
||||
<td>4.73</td>
|
||||
<td>0.82</td>
|
||||
<td>7.41</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>1.76</td>
|
||||
<td>12.43</td>
|
||||
<td>0.87</td>
|
||||
<td>15.18</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>2.55</td>
|
||||
<td>6.70</td>
|
||||
<td>0.41</td>
|
||||
<td>9.82</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.73</td>
|
||||
<td>1.79</td>
|
||||
<td>0.83</td>
|
||||
<td>4.46</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-OCRv6_tiny_rec</td>
|
||||
<td>paddle_static</td>
|
||||
<td>1.76</td>
|
||||
<td>2.77</td>
|
||||
<td>0.40</td>
|
||||
<td>5.04</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>paddle_dynamic</td>
|
||||
<td>1.75</td>
|
||||
<td>6.96</td>
|
||||
<td>0.36</td>
|
||||
<td>9.19</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>transformers</td>
|
||||
<td>2.45</td>
|
||||
<td>3.12</td>
|
||||
<td>0.40</td>
|
||||
<td>6.12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>1.73</td>
|
||||
<td>0.92</td>
|
||||
<td>0.36</td>
|
||||
<td>3.12</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -987,13 +1111,13 @@ Global.save_inference_dir="./PP-OCRv5_server_rec_infer/"
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文字识别模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/text_recognition.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文字识别模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/text_recognition.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
|
||||
## 六、FAQ
|
||||
@@ -112,6 +112,14 @@ paddleocr textline_orientation_classification -i https://paddle-model-ecology.bj
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr textline_orientation_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/textline_rot180_demo.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<b>Note: </b>The official models would be download from HuggingFace by default. If can't access to HuggingFace, please set the environment variable <code>PADDLE_PDX_MODEL_SOURCE="BOS"</code> to change the model source to BOS. In the future, more model sources will be supported.
|
||||
@@ -143,6 +151,21 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured, and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import TextLineOrientationClassification
|
||||
model = TextLineOrientationClassification(
|
||||
model_name="PP-LCNet_x0_25_textline_ori",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("textline_rot180_demo.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_img("./output/demo.png")
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
If you want to use the trained model with the `paddle_dynamic` or `transformers` engine, refer to the [Weight Conversion](#52-weight-conversion) section in the [Inference Engine](#5-inference-engine) section below to convert the model from the `pdparams` format to the `safetensors` format using PaddleX.
|
||||
@@ -206,7 +229,7 @@ By default, GPU 0 is used if available; otherwise, CPU is used.
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, and <code>transformers</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><b>Meaning:</b> Inference engine.<br/><b>Description:</b> Supports <code>None</code> (the default), <code>paddle</code>, <code>paddle_static</code>, <code>paddle_dynamic</code>, <code>transformers</code>, and <code>onnxruntime</code>. When left as <code>None</code>, local inference uses the <code>paddle_static</code> engine by default. For detailed descriptions, supported values, compatibility rules, and examples, see <a href="../inference_deployment/local_inference/inference_engine.en.md">Inference Engine and Configuration</a>.</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -454,7 +477,7 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x0_25_textline_ori</td>
|
||||
<td rowspan="4">PP-LCNet_x0_25_textline_ori</td>
|
||||
<td>paddle_static</td>
|
||||
<td>0.30</td>
|
||||
<td>2.89</td>
|
||||
@@ -476,7 +499,14 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>5.36</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x1_0_textline_ori</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>0.27</td>
|
||||
<td>0.76</td>
|
||||
<td>0.05</td>
|
||||
<td>1.16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-LCNet_x1_0_textline_ori</td>
|
||||
<td>paddle_static</td>
|
||||
<td>0.33</td>
|
||||
<td>3.20</td>
|
||||
@@ -497,12 +527,19 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<td>0.14</td>
|
||||
<td>5.04</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>0.27</td>
|
||||
<td>0.77</td>
|
||||
<td>0.05</td>
|
||||
<td>1.16</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>Test Environment Description:</strong>
|
||||
<ul>
|
||||
<li><strong>Test Data:</strong> [Sample Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/textline_rot180_demo.jpg)</li>
|
||||
<li><strong>Test Data:</strong> <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/textline_rot180_demo.jpg">Sample Image</a></li>
|
||||
<li><strong>Hardware Configuration:</strong>
|
||||
<ul>
|
||||
<li>GPU: NVIDIA A100 40G</li>
|
||||
@@ -512,11 +549,11 @@ For detailed descriptions, values, compatibility rules, and examples of the infe
|
||||
<li><strong>Software Environment:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 Weight Conversion
|
||||
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Line Orientation Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/textline_orientation_classification.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference.
|
||||
When using the inference engine, the system will automatically download the official pre-trained model. If you need to use a self-trained model with the `paddle_dynamic` or `transformers` engine, please refer to the [PaddleX Text Line Orientation Classification Module Weight Conversion](https://paddlepaddle.github.io/PaddleX/latest/en/module_usage/tutorials/ocr_modules/textline_orientation_classification.html#442) section to convert the model from the `pdparams` format to the `safetensors` format using PaddleX. This allows seamless integration into the PaddleOCR API for inference. If you need to use a self-trained model with the `onnxruntime` engine, refer to [PaddleX Obtain ONNX Models](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html) to obtain the ONNX model, so it can be seamlessly integrated into the PaddleOCR API for inference.
|
||||
@@ -117,6 +117,14 @@ paddleocr textline_orientation_classification -i https://paddle-model-ecology.bj
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr textline_orientation_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/textline_rot180_demo.jpg \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<b>注:</b>PaddleOCR 官方模型默认从 HuggingFace 获取,如运行环境访问 HuggingFace 不便,可通过环境变量修改模型源为 BOS:`PADDLE_PDX_MODEL_SOURCE="BOS"`,未来将支持更多主流模型源;
|
||||
@@ -150,6 +158,21 @@ for res in output:
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请确保已配置 ONNX Runtime 环境,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import TextLineOrientationClassification
|
||||
model = TextLineOrientationClassification(
|
||||
model_name="PP-LCNet_x0_25_textline_ori",
|
||||
engine="onnxruntime",
|
||||
)
|
||||
output = model.predict("textline_rot180_demo.jpg", batch_size=1)
|
||||
for res in output:
|
||||
res.print(json_format=False)
|
||||
res.save_to_img("./output/demo.png")
|
||||
res.save_to_json("./output/res.json")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
训练后的模型如果想使用 `paddle_dynamic` 或 `transformers` 引擎,请参考后文 [推理引擎](#五推理引擎) 中的 [权重转换](#52-权重转换) 部分将模型由 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式。
|
||||
@@ -212,7 +235,7 @@ for res in output:
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>engine</code></td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><b>含义:</b>推理引擎。<br><b>说明:</b>支持 <code>None</code>(默认值)、<code>paddle</code>、<code>paddle_static</code>、<code>paddle_dynamic</code>、<code>transformers</code>、<code>onnxruntime</code>。保持为默认值 <code>None</code> 时,本地推理默认使用 <code>paddle_static</code> 引擎。详细说明、取值、兼容性规则与示例请参见 <a href="../inference_deployment/local_inference/inference_engine.md">推理引擎与配置说明</a>。</td>
|
||||
<td><code>str|None</code></td>
|
||||
<td><code>None</code></td>
|
||||
</tr>
|
||||
@@ -418,7 +441,7 @@ for res in output:
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x0_25_textline_ori</td>
|
||||
<td rowspan="4">PP-LCNet_x0_25_textline_ori</td>
|
||||
<td>paddle_static</td>
|
||||
<td>0.30</td>
|
||||
<td>2.89</td>
|
||||
@@ -440,7 +463,14 @@ for res in output:
|
||||
<td>5.36</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">PP-LCNet_x1_0_textline_ori</td>
|
||||
<td>onnxruntime</td>
|
||||
<td>0.27</td>
|
||||
<td>0.76</td>
|
||||
<td>0.05</td>
|
||||
<td>1.16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="4">PP-LCNet_x1_0_textline_ori</td>
|
||||
<td>paddle_static</td>
|
||||
<td>0.33</td>
|
||||
<td>3.20</td>
|
||||
@@ -461,12 +491,19 @@ for res in output:
|
||||
<td>0.14</td>
|
||||
<td>5.04</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>onnxruntime</td>
|
||||
<td>0.27</td>
|
||||
<td>0.77</td>
|
||||
<td>0.05</td>
|
||||
<td>1.16</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<strong>测试环境说明:</strong>
|
||||
<ul>
|
||||
<li><strong>测试数据:</strong>[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/textline_rot180_demo.jpg)</li>
|
||||
<li><strong>测试数据:</strong><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/textline_rot180_demo.jpg">示例图片</a></li>
|
||||
<li><strong>硬件配置:</strong>
|
||||
<ul>
|
||||
<li>GPU:NVIDIA A100 40G</li>
|
||||
@@ -476,11 +513,11 @@ for res in output:
|
||||
<li><strong>软件环境:</strong>
|
||||
<ul>
|
||||
<li>Ubuntu 22.04 / CUDA 12.6 / cuDNN 9.5</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10</li>
|
||||
<li>paddlepaddle-gpu 3.2.1 / paddleocr 3.5 / transformers 5.4.0 / torch 2.10 / onnxruntime-gpu 1.23.2</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
### 5.2 权重转换 {#52-权重转换}
|
||||
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文本行方向分类模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/textline_orientation_classification.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
使用推理引擎时,系统会自动下载官方预训练模型。若需使用自训练模型配合 `paddle_dynamic` 或 `transformers` 引擎,请参考 [PaddleX 文本行方向分类模块权重转换](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/textline_orientation_classification.html#442) 部分,将 `pdparams` 格式通过 PaddleX 转换为 `safetensors` 格式,即可无缝集成到 PaddleOCR 的 API 中进行推理。若需使用自训练模型配合`onnxruntime`引擎,请参考[PaddleX 获取 ONNX 模型](https://paddlepaddle.github.io/PaddleX/latest/pipeline_deploy/paddle2onnx.html)获取onnx模型,即可无缝集成到 PaddleOCR 的 API 中进行推理。
|
||||
@@ -705,6 +705,7 @@ Before using the general OCR pipeline locally, install the dependencies for your
|
||||
|
||||
- If you use the local `paddle_static` inference engine, install PaddlePaddle by following [PaddlePaddle Framework Installation](../paddlepaddle_installation.en.md).
|
||||
- If you use the `transformers` inference engine, install the required dependencies by following [Inference Engine and Configuration](../inference_deployment/local_inference/inference_engine.en.md).
|
||||
- If you use the `onnxruntime` inference engine, install the required dependencies by following [Inference Engine and Configuration](../inference_deployment/local_inference/inference_engine.en.md).
|
||||
|
||||
#### 2.0.2 Install paddleocr
|
||||
|
||||
@@ -770,6 +771,19 @@ paddleocr ocr -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_im
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured by following [Inference Engine and Configuration](../inference_deployment/local_inference/inference_engine.en.md), and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
paddleocr ocr -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png \
|
||||
--use_doc_orientation_classify False \
|
||||
--use_doc_unwarping False \
|
||||
--use_textline_orientation False \
|
||||
--save_path ./output \
|
||||
--device gpu:0 \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
<details><summary><b>Command line supports more parameter settings. Click to expand for detailed instructions on command line parameters.</b></summary>
|
||||
@@ -2577,6 +2591,35 @@ for res in result:
|
||||
res.save_to_json("output")
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured by following [Inference Engine and Configuration](../inference_deployment/local_inference/inference_engine.en.md), and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import PaddleOCR
|
||||
|
||||
ocr = PaddleOCR(
|
||||
use_doc_orientation_classify=False, # Disable document orientation classification
|
||||
use_doc_unwarping=False, # Disable document unwarping
|
||||
use_textline_orientation=False, # Disable textline orientation classification
|
||||
engine="onnxruntime",
|
||||
)
|
||||
# ocr = PaddleOCR(lang="en", engine="onnxruntime") # Use the English model
|
||||
# ocr = PaddleOCR(ocr_version="PP-OCRv4", engine="onnxruntime") # Use another PP-OCR version
|
||||
# ocr = PaddleOCR(device="gpu", engine="onnxruntime") # Use GPU for inference
|
||||
# ocr = PaddleOCR(
|
||||
# text_detection_model_name="PP-OCRv5_server_det",
|
||||
# text_recognition_model_name="PP-OCRv5_server_rec",
|
||||
# use_doc_orientation_classify=False,
|
||||
# use_doc_unwarping=False,
|
||||
# use_textline_orientation=False,
|
||||
# engine="onnxruntime",
|
||||
# ) # Switch to the PP-OCRv5_server models
|
||||
result = ocr.predict("./general_ocr_002.png")
|
||||
for res in result:
|
||||
res.print()
|
||||
res.save_to_img("output")
|
||||
res.save_to_json("output")
|
||||
```
|
||||
|
||||
In most scenarios, the default `paddle_static` inference engine delivers better inference performance and is the recommended first choice.
|
||||
|
||||
#### 4.2.2 Specify the local model path through the configuration file
|
||||
|
||||
@@ -713,6 +713,7 @@ devanagari_PP-OCRv3_mobile_rec_infer.tar">推理模型</a>/<a href="https://padd
|
||||
|
||||
- 如需使用本地推理引擎 `paddle_static`,请参考[飞桨框架安装说明](../paddlepaddle_installation.md)安装 PaddlePaddle。
|
||||
- 如需使用 `transformers` 推理引擎,请参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)安装相关依赖。
|
||||
- 如需使用 `onnxruntime` 推理引擎,请参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)安装相关依赖。
|
||||
|
||||
#### 2.0.2 安装 paddleocr
|
||||
|
||||
@@ -800,6 +801,19 @@ paddleocr ocr -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_im
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请先参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)完成 ONNX Runtime 环境配置,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
paddleocr ocr -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png \
|
||||
--use_doc_orientation_classify False \
|
||||
--use_doc_unwarping False \
|
||||
--use_textline_orientation False \
|
||||
--save_path ./output \
|
||||
--device gpu:0 \
|
||||
--engine onnxruntime
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
|
||||
<!-- Luxorion-12修改:表格参数描述 -->
|
||||
@@ -1257,6 +1271,35 @@ for res in result:
|
||||
res.save_to_json("output")
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请先参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)完成 ONNX Runtime 环境配置,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import PaddleOCR
|
||||
|
||||
ocr = PaddleOCR(
|
||||
use_doc_orientation_classify=False, # 通过 use_doc_orientation_classify 参数指定不使用文档方向分类模型
|
||||
use_doc_unwarping=False, # 通过 use_doc_unwarping 参数指定不使用文本图像矫正模型
|
||||
use_textline_orientation=False, # 通过 use_textline_orientation 参数指定不使用文本行方向分类模型
|
||||
engine="onnxruntime",
|
||||
)
|
||||
# ocr = PaddleOCR(lang="en", engine="onnxruntime") # 通过 lang 参数来使用英文模型
|
||||
# ocr = PaddleOCR(ocr_version="PP-OCRv4", engine="onnxruntime") # 通过 ocr_version 参数来使用 PP-OCR 其他版本
|
||||
# ocr = PaddleOCR(device="gpu", engine="onnxruntime") # 通过 device 参数使得在模型推理时使用 GPU
|
||||
# ocr = PaddleOCR(
|
||||
# text_detection_model_name="PP-OCRv5_server_det",
|
||||
# text_recognition_model_name="PP-OCRv5_server_rec",
|
||||
# use_doc_orientation_classify=False,
|
||||
# use_doc_unwarping=False,
|
||||
# use_textline_orientation=False,
|
||||
# engine="onnxruntime",
|
||||
# ) # 更换 PP-OCRv5_server 模型
|
||||
result = ocr.predict("./general_ocr_002.png")
|
||||
for res in result:
|
||||
res.print()
|
||||
res.save_to_img("output")
|
||||
res.save_to_json("output")
|
||||
```
|
||||
|
||||
在大多数场景下,默认的 `paddle_static` 推理引擎通常具备更好的推理性能,建议优先使用。
|
||||
<!-- Luxorion-12 修改:表格参数说明-->
|
||||
在上述 Python 脚本中,执行了如下几个步骤:
|
||||
|
||||
@@ -990,9 +990,17 @@ If you choose `transformers` as the inference engine, make sure the Transformers
|
||||
|
||||
```bash
|
||||
# Use the transformers engine for inference
|
||||
# Some models are still being supported. For inference, please disable formula recognition and replace the wireless table structure recognition model using the following command:
|
||||
paddleocr pp_structurev3 -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/pp_structure_v3_demo.png \
|
||||
--engine transformers --use_formula_recognition False --wireless_table_structure_recognition_model_name SLANeXt_wireless
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured by following [Inference Engine and Configuration](../inference_deployment/local_inference/inference_engine.en.md), and then run the following command:
|
||||
|
||||
```bash
|
||||
# Use the onnxruntime engine for inference
|
||||
# Some models are still being supported. For inference, please disable formula recognition using the following command:
|
||||
paddleocr pp_structurev3 -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/pp_structure_v3_demo.png \
|
||||
--engine onnxruntime --use_formula_recognition False
|
||||
```
|
||||
|
||||
<details><summary><b>Command line supports more parameters. Click to expand for detailed parameter descriptions</b></summary>
|
||||
@@ -1698,11 +1706,30 @@ If you choose `transformers` as the inference engine, make sure the Transformers
|
||||
```python
|
||||
from paddleocr import PPStructureV3
|
||||
|
||||
# Some models are still being supported. For inference, please disable formula recognition and replace the wireless table structure recognition model using the following code:
|
||||
pipeline = PPStructureV3(
|
||||
engine="transformers",
|
||||
)
|
||||
# pipeline = PPStructureV3(lang="en") # Set the lang parameter to use the English text recognition model. For other supported languages, see Section 5: Appendix. By default, both Chinese and English text recognition models are enabled.
|
||||
# pipeline = PPStructureV3(use_doc_orientation_classify=True) # Use use_doc_orientation_classify to enable/disable document orientation classification model
|
||||
# pipeline = PPStructureV3(use_doc_unwarping=True) # Use use_doc_unwarping to enable/disable document unwarping module
|
||||
# pipeline = PPStructureV3(use_textline_orientation=True) # Use use_textline_orientation to enable/disable textline orientation classification model
|
||||
# pipeline = PPStructureV3(device="gpu") # Use device to specify GPU for model inference
|
||||
output = pipeline.predict("./pp_structure_v3_demo.png")
|
||||
for res in output:
|
||||
res.print() ## Print the structured prediction output
|
||||
res.save_to_json(save_path="output") ## Save the current image's structured result in JSON format
|
||||
res.save_to_markdown(save_path="output") ## Save the current image's result in Markdown format
|
||||
```
|
||||
|
||||
If you choose `onnxruntime` as the inference engine, make sure the ONNX Runtime environment is configured by following [Inference Engine and Configuration](../inference_deployment/local_inference/inference_engine.en.md), and then run the following code:
|
||||
|
||||
```python
|
||||
from paddleocr import PPStructureV3
|
||||
|
||||
# Some models are still being supported. For inference, please disable formula recognition using the following code:
|
||||
pipeline = PPStructureV3(
|
||||
engine="onnxruntime",
|
||||
use_formula_recognition=False,
|
||||
wireless_table_structure_recognition_model_name="SLANeXt_wireless",
|
||||
)
|
||||
# pipeline = PPStructureV3(lang="en") # Set the lang parameter to use the English text recognition model. For other supported languages, see Section 5: Appendix. By default, both Chinese and English text recognition models are enabled.
|
||||
# pipeline = PPStructureV3(use_doc_orientation_classify=True) # Use use_doc_orientation_classify to enable/disable document orientation classification model
|
||||
|
||||
@@ -1069,10 +1069,18 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu
|
||||
如果选择 `transformers` 作为推理引擎,请先参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)完成 Transformers 环境配置,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 transformers 引擎进行推理
|
||||
# 部分模型尚在支持中,推理时需关闭公式识别功能并更换无线表格结构识别模型,请使用以下命令:
|
||||
paddleocr pp_structurev3 -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/pp_structure_v3_demo.png \
|
||||
--engine transformers --use_formula_recognition False --wireless_table_structure_recognition_model_name SLANeXt_wireless
|
||||
--engine transformers
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请先参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)完成 ONNX Runtime 环境配置,然后执行如下命令:
|
||||
|
||||
```bash
|
||||
# 使用 onnxruntime 引擎进行推理
|
||||
# 部分模型尚在支持中,推理时需关闭公式识别功能,请使用以下命令:
|
||||
paddleocr pp_structurev3 -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/pp_structure_v3_demo.png \
|
||||
--engine onnxruntime --use_formula_recognition False
|
||||
```
|
||||
|
||||
<details><summary><b>命令行支持更多参数设置,点击展开以查看命令行参数的详细说明</b></summary>
|
||||
@@ -1670,11 +1678,30 @@ for res in output:
|
||||
```python
|
||||
from paddleocr import PPStructureV3
|
||||
|
||||
# 部分模型尚在支持中,推理时需关闭公式识别功能并更换无线表格结构识别模型,请使用以下代码:
|
||||
pipeline = PPStructureV3(
|
||||
engine="transformers",
|
||||
)
|
||||
# pipeline = PPStructureV3(lang="en") # 将 lang 参数设置为使用英文文本识别模型。对于其他支持的语言,请参阅第5节:附录部分。默认配置为中英文模型。
|
||||
# pipeline = PPStructureV3(use_doc_orientation_classify=True) # 通过 use_doc_orientation_classify 指定是否使用文档方向分类模型
|
||||
# pipeline = PPStructureV3(use_doc_unwarping=True) # 通过 use_doc_unwarping 指定是否使用文本图像矫正模块
|
||||
# pipeline = PPStructureV3(use_textline_orientation=True) # 通过 use_textline_orientation 指定是否使用文本行方向分类模型
|
||||
# pipeline = PPStructureV3(device="gpu") # 通过 device 指定模型推理时使用 GPU
|
||||
output = pipeline.predict("./pp_structure_v3_demo.png")
|
||||
for res in output:
|
||||
res.print() ## 打印预测的结构化输出
|
||||
res.save_to_json(save_path="output") ## 保存当前图像的结构化json结果
|
||||
res.save_to_markdown(save_path="output") ## 保存当前图像的markdown格式的结果
|
||||
```
|
||||
|
||||
如果选择 `onnxruntime` 作为推理引擎,请先参考[推理引擎文档](../inference_deployment/local_inference/inference_engine.md)完成 ONNX Runtime 环境配置,然后执行如下代码:
|
||||
|
||||
```python
|
||||
from paddleocr import PPStructureV3
|
||||
|
||||
# 部分模型尚在支持中,推理时需关闭公式识别功能,请使用以下代码:
|
||||
pipeline = PPStructureV3(
|
||||
engine="onnxruntime",
|
||||
use_formula_recognition=False,
|
||||
wireless_table_structure_recognition_model_name="SLANeXt_wireless",
|
||||
)
|
||||
# pipeline = PPStructureV3(lang="en") # 将 lang 参数设置为使用英文文本识别模型。对于其他支持的语言,请参阅第5节:附录部分。默认配置为中英文模型。
|
||||
# pipeline = PPStructureV3(use_doc_orientation_classify=True) # 通过 use_doc_orientation_classify 指定是否使用文档方向分类模型
|
||||
|
||||
Reference in new issue
Block a user