Browse Source

add text det doc (#2905)

* add text det doc

* add text det doc

* add text det doc

* add seal text det doc

* add uvdoc docs

* add stfpm docs

* update ocr_det_params
Sunflower7788 10 months ago
parent
commit
0992491c65

+ 175 - 7
docs/module_usage/tutorials/cv_modules/anomaly_detection.md

@@ -14,7 +14,7 @@ comments: true
 <thead>
 <tr>
 <th>模型</th><th>模型下载链接</th>
-<th>ROCAUC(Avg)</th>
+<th>mIoU</th>
 <th>模型存储大小(M)</th>
 <th>介绍</th>
 </tr>
@@ -22,13 +22,13 @@ comments: true
 <tbody>
 <tr>
 <td>STFPM</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/STFPM_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/STFPM_pretrained.pdparams">训练模型</a></td>
-<td>0.962</td>
+<td>0.9901</td>
 <td>22.5</td>
 <td>一种基于表示的图像异常检测算法,由预训练的教师网络和结构相同的学生网络组成。学生网络通过将自身特征与教师网络中的对应特征相匹配来检测异常。</td>
 </tr>
 </tbody>
 </table>
-<b>以上模型精度指标测量自 MVTec_AD 数据集。</b>
+<b>以上模型精度指标测量自 MVTec_AD 数据集中的grid类别。</b>
 
 
 ## 三、快速集成
@@ -41,14 +41,182 @@ from paddlex import create_model
 
 model_name = "STFPM"
 
-model = create_model(model_name)
+model = create_model(model_name=model_name)
 output = model.predict("uad_grid.png", batch_size=1)
 
 for res in output:
-    res.print(json_format=False)
-    res.save_to_img("./output/")
-    res.save_to_json("./output/res.json")
+    res.print()
+    res.save_to_img(save_path="./output/")
+    res.save_to_json(save_path="./output/res.json")
 ```
+
+运行后,得到的结果为:
+```bash
+{'res': "{'input_path': 'uad_grid.png', 'pred': '...'}"}
+```
+
+运行结果参数含义如下:
+- `input_path`:表示输入待检测异常的图像路径
+- `doctr_img`:表示异常检测后的图像可视化结果,由于数据过多不便于直接print,所以此处用`...`替换,可以通过`res.save_to_img()`将预测结果保存为图片,通过`res.save_to_json()`将预测结果保存为json文件。
+
+
+可视化图片如下:
+
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/refs/heads/main/images/modules/image_ad/uad_grid_res.png">
+
+相关方法、参数等说明如下:
+
+* `create_model`实例化图像异常检测模型(此处以`STFPM`为例),具体说明如下:
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>model_name</code></td>
+<td>模型名称</td>
+<td><code>str</code></td>
+<td>所有PaddleX支持的模型名称</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>model_dir</code></td>
+<td>模型存储路径</td>
+<td><code>str</code></td>
+<td>无</td>
+<td>无</td>
+</tr>
+</table>
+
+* 其中,`model_name` 必须指定,指定 `model_name` 后,默认使用 PaddleX 内置的模型参数,在此基础上,指定 `model_dir` 时,使用用户自定义的模型。
+
+* 调用图像异常检测模型的 `predict()` 方法进行推理预测,`predict()` 方法参数有 `input` 和 `batch_size`,具体说明如下:
+
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>input</code></td>
+<td>待预测数据,支持多种输入类型</td>
+<td><code>Python Var</code>/<code>str</code>/<code>dict</code>/<code>list</code></td>
+<td>
+<ul>
+  <li><b>Python变量</b>,如<code>numpy.ndarray</code>表示的图像数据</li>
+  <li><b>文件路径</b>,如图像文件的本地路径:<code>/root/data/img.jpg</code></li>
+  <li><b>URL链接</b>,如图像文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png">示例</a></li>
+  <li><b>本地目录</b>,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code></li>
+  <li><b>字典</b>,字典的<code>key</code>需与具体任务对应,如图像分类任务对应<code>\"img\"</code>,字典的<code>val</code>支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code></li>
+  <li><b>列表</b>,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code>,<code>[{\"img\": \"/root/data1\"}, {\"img\": \"/root/data2/img.jpg\"}]</code></li>
+</ul>
+</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>batch_size</code></td>
+<td>批大小</td>
+<td><code>int</code></td>
+<td>任意整数</td>
+<td>1</td>
+</tr>
+</table>
+
+* 对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`json`文件的操作:
+
+<table>
+<thead>
+<tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
+<th>参数类型</th>
+<th>参数说明</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "3"><code>print()</code></td>
+<td rowspan = "3">打印结果到终端</td>
+<td><code>format_json</code></td>
+<td><code>bool</code></td>
+<td>是否对输出内容进行使用 <code>JSON</code> 缩进格式化</td>
+<td><code>True</code></td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td rowspan = "3"><code>save_to_json()</code></td>
+<td rowspan = "3">将结果保存为json格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td><code>save_to_img()</code></td>
+<td>将结果保存为图像格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+</table>
+
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
+
+<table>
+<thead>
+<tr>
+<th>属性</th>
+<th>属性说明</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的<code>json</code>格式的结果</td>
+</tr>
+<tr>
+<td rowspan = "1"><code>img</code></td>
+<td rowspan = "1">获取格式为<code>dict</code>的可视化图像</td>
+</tr>
+
+</table>
+
+关于更多 PaddleX 的单模型推理的 API 的使用方法,可以参考[PaddleX单模型Python脚本使用说明](../../instructions/model_python_API.md)。
+
 关于更多 PaddleX 的单模型推理的 API 的使用方法,可以参考[PaddleX单模型Python脚本使用说明](../../instructions/model_python_API.md)。
 
 ## 四、二次开发

+ 322 - 6
docs/module_usage/tutorials/ocr_modules/seal_text_detection.md

@@ -24,7 +24,7 @@ comments: true
 <tbody>
 <tr>
 <td>PP-OCRv4_server_seal_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-OCRv4_server_seal_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_server_seal_det_pretrained.pdparams">训练模型</a></td>
-<td>98.21</td>
+<td>98.40</td>
 <td>84.341</td>
 <td>2425.06</td>
 <td>109</td>
@@ -32,7 +32,7 @@ comments: true
 </tr>
 <tr>
 <td>PP-OCRv4_mobile_seal_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-OCRv4_mobile_seal_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_mobile_seal_det_pretrained.pdparams">训练模型</a></td>
-<td>96.47</td>
+<td>96.36</td>
 <td>10.5878</td>
 <td>131.813</td>
 <td>4.6</td>
@@ -50,13 +50,329 @@ comments: true
 
 ```bash
 from paddlex import create_model
-model = create_model("PP-OCRv4_server_seal_det")
+model = create_model(model_name="PP-OCRv4_server_seal_det")
 output = model.predict("seal_text_det.png", batch_size=1)
 for res in output:
-    res.print(json_format=False)
-    res.save_to_img("./output/")
-    res.save_to_json("./output/res.json")
+    res.print()
+    res.save_to_img(save_path="./output/")
+    res.save_to_json(save_path="./output/res.json")
 ```
+
+运行后,得到的结果为:
+
+```bash
+{'res': {'input_path': 'seal_text_det.png', 'dt_polys': [[[165, 469], [202, 500], [251, 523], [309, 535], [374, 527], [425, 506], [465, 475], [469, 473], [473, 473], [478, 476], [508, 506], [510, 510], [510, 514], [507, 521], [455, 561], [452, 562], [391, 586], [389, 587], [310, 597], [308, 597], [235, 583], [232, 583], [171, 554], [170, 552], [121, 510], [118, 506], [117, 503], [118, 498], [121, 496], [153, 469], [157, 466], [161, 466]], [[444, 444], [448, 447], [450, 450], [450, 453], [450, 497], [449, 501], [446, 503], [443, 505], [440, 506], [197, 506], [194, 505], [190, 503], [189, 499], [187, 493], [186, 490], [187, 453], [188, 449], [190, 446], [194, 444], [197, 443], [441, 443]], [[466, 346], [471, 350], [473, 351], [476, 356], [477, 361], [477, 425], [477, 430], [474, 434], [470, 437], [463, 439], [175, 440], [170, 439], [166, 437], [163, 432], [161, 426], [160, 361], [161, 357], [163, 352], [168, 349], [171, 347], [177, 345], [462, 345]], [[324, 38], [484, 92], [490, 95], [492, 97], [586, 227], [588, 231], [589, 236], [590, 384], [590, 390], [587, 394], [583, 397], [579, 399], [571, 398], [508, 379], [503, 377], [500, 374], [497, 369], [497, 366], [494, 260], [429, 170], [324, 136], [207, 173], [143, 261], [139, 366], [138, 370], [136, 375], [131, 378], [129, 379], [66, 397], [61, 397], [56, 397], [51, 393], [49, 390], [47, 383], [49, 236], [50, 230], [51, 227], [148, 96], [151, 92], [156, 90], [316, 38], [320, 37]]], 'dt_scores': [0.9929380286534535, 0.9980056201238314, 0.9936831226022099, 0.9884004535508197]}}
+```
+
+运行结果参数含义如下:
+- `input_path`:表示输入待预测图像的路径
+- `dt_polys`:表示预测的文本检测框,其中每个文本检测框包含一个多边形的多个顶点。其中每个顶点都是一个二元组,分别表示该顶点的x坐标和y坐标
+- `dt_scores`:表示预测的文本检测框的置信度
+
+
+可视化图片如下:
+
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/refs/heads/main/images/modules/seal_text_det/seal_text_det_res.png">
+
+相关方法、参数等说明如下:
+
+* `create_model`实例化文本检测模型(此处以`PP-OCRv4_server_seal_det`为例),具体说明如下:
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>model_name</code></td>
+<td>模型名称</td>
+<td><code>str</code></td>
+<td>所有PaddleX支持的印章文本检测模型名称</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>model_dir</code></td>
+<td>模型存储路径</td>
+<td><code>str</code></td>
+<td>无</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>limit_side_len</code></td>
+<td>检测的图像边长限制</td>
+<td><code>int/None</code></td>
+<td>
+<ul>
+<li><b>int</b>: 大于0的任意整数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>limit_type</code></td>
+<td>检测的图像边长限制,检测的边长限制类型 </td>
+<td><code>str/None</code></td>
+<td>
+<ul>
+<li><b>str</b>: 支持min和max. min表示保证图像最短边不小于det_limit_side_len, max: 表示保证图像最长边不大于limit_side_len
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+</td>
+<td>None</td>
+</tr>
+<tr>
+<td><code>thresh</code></td>
+<td>输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>box_thresh</code></td>
+<td>检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>max_candidates</code></td>
+<td>输出的最大文本框数量 </td>
+<td><code>int/None</code></td>
+<td>
+<ul>
+<li><b>int</b>: 大于0的任意整数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>unclip_ratio</code></td>
+<td>Vatti clipping算法的扩张系数,使用该方法对文字区域进行扩张 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>use_dilation</code></td>
+<td>是否对分割结果进行膨胀 </td>
+<td><code>bool/None</code></td>
+<td>True/False/None</td>
+<td>None</td>
+</tr>
+</table>
+
+* 其中,`model_name` 必须指定,指定 `model_name` 后,默认使用 PaddleX 内置的模型参数,在此基础上,指定 `model_dir` 时,使用用户自定义的模型。
+
+* 调用印章文本检测模型的 `predict()` 方法进行推理预测,`predict()` 方法参数有 `input`、 `batch_size`、 `limit_side_len`、 `limit_type`、 `thresh`、 `box_thresh`、 `max_candidates`、`unclip_ratio`和`use_dilation`,具体说明如下:
+
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>input</code></td>
+<td>待预测数据,支持多种输入类型</td>
+<td><code>Python Var</code>/<code>str</code>/<code>dict</code>/<code>list</code></td>
+<td>
+<ul>
+  <li><b>Python变量</b>,如<code>numpy.ndarray</code>表示的图像数据</li>
+  <li><b>文件路径</b>,如图像文件的本地路径:<code>/root/data/img.jpg</code></li>
+  <li><b>URL链接</b>,如图像文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png">示例</a></li>
+  <li><b>本地目录</b>,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code></li>
+  <li><b>字典</b>,字典的<code>key</code>需与具体任务对应,如图像分类任务对应<code>\"img\"</code>,字典的<code>val</code>支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code></li>
+  <li><b>列表</b>,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code>,<code>[{\"img\": \"/root/data1\"}, {\"img\": \"/root/data2/img.jpg\"}]</code></li>
+</ul>
+</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>batch_size</code></td>
+<td>批大小</td>
+<td><code>int</code></td>
+<td>大于0的任意整数</td>
+<td>1</td>
+</tr>
+<tr>
+<td><code>limit_side_len</code></td>
+<td>检测的图像边长限制</td>
+<td><code>int/None</code></td>
+<td>
+<ul>
+<li><b>int</b>: 大于0的任意整数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>limit_type</code></td>
+<td>检测的图像边长限制,检测的边长限制类型 </td>
+<td><code>str/None</code></td>
+<td>
+<ul>
+<li><b>str</b>: 支持min和max. min表示保证图像最短边不小于det_limit_side_len, max: 表示保证图像最长边不大于limit_side_len
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+</td>
+<td>None</td>
+</tr>
+<tr>
+<td><code>thresh</code></td>
+<td>输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>box_thresh</code></td>
+<td>检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>max_candidates</code></td>
+<td>输出的最大文本框数量 </td>
+<td><code>int/None</code></td>
+<td>
+<ul>
+<li><b>int</b>: 大于0的任意整数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>unclip_ratio</code></td>
+<td>Vatti clipping算法的扩张系数,使用该方法对文字区域进行扩张 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>use_dilation</code></td>
+<td>是否对分割结果进行膨胀 </td>
+<td><code>bool/None</code></td>
+<td>True/False/None</td>
+<td>None</td>
+</tr>
+</table>
+
+* 对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`json`文件的操作:
+
+<table>
+<thead>
+<tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
+<th>参数类型</th>
+<th>参数说明</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "3"><code>print()</code></td>
+<td rowspan = "3">打印结果到终端</td>
+<td><code>format_json</code></td>
+<td><code>bool</code></td>
+<td>是否对输出内容进行使用 <code>JSON</code> 缩进格式化</td>
+<td><code>True</code></td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td rowspan = "3"><code>save_to_json()</code></td>
+<td rowspan = "3">将结果保存为json格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td><code>save_to_img()</code></td>
+<td>将结果保存为图像格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+</table>
+
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
+
+<table>
+<thead>
+<tr>
+<th>属性</th>
+<th>属性说明</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的<code>json</code>格式的结果</td>
+</tr>
+<tr>
+<td rowspan = "1"><code>img</code></td>
+<td rowspan = "1">获取格式为<code>dict</code>的可视化图像</td>
+</tr>
+
+</table>
+
 关于更多 PaddleX 的单模型推理的 API 的使用方法,可以参考[PaddleX单模型Python脚本使用说明](../../instructions/model_python_API.md)。
 
 ## 四、二次开发

+ 305 - 6
docs/module_usage/tutorials/ocr_modules/text_detection.md

@@ -24,7 +24,7 @@ comments: true
 <tbody>
 <tr>
 <td>PP-OCRv4_server_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-OCRv4_server_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_server_det_pretrained.pdparams">训练模型</a></td>
-<td>82.69</td>
+<td>82.56</td>
 <td>83.3501</td>
 <td>2434.01</td>
 <td>109</td>
@@ -32,14 +32,33 @@ comments: true
 </tr>
 <tr>
 <td>PP-OCRv4_mobile_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-OCRv4_mobile_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv4_mobile_det_pretrained.pdparams">训练模型</a></td>
-<td>77.79</td>
+<td>77.35</td>
 <td>10.6923</td>
 <td>120.177</td>
 <td>4.7</td>
 <td>PP-OCRv4 的移动端文本检测模型,效率更高,适合在端侧设备部署</td>
 </tr>
+<tr>
+<td>PP-OCRv3_mobile_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-OCRv3_mobile_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv3_mobile_det_pretrained.pdparams">训练模型</a></td>
+<td>78.68</td>
+<td></td>
+<td></td>
+<td>2.1</td>
+<td>PP-OCRv3 的移动端文本检测模型,效率更高,适合在端侧设备部署</td>
+</tr>
+<tr>
+<td>PP-OCRv3_server_det</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-OCRv3_server_det_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv3_server_det_pretrained.pdparams">训练模型</a></td>
+<td>80.11</td>
+<td></td>
+<td></td>
+<td>102.1</td>
+<td>PP-OCRv3 的服务端文本检测模型,精度更高,适合在性能较好的服务器上部署</td>
+</tr>
 </tbody>
 </table>
+
+<b>注:以上精度指标的评估集是 PaddleOCR 自建的中英文数据集,覆盖街景、网图、文档、手写多个场景,其中文本识别包含 593 张图片。所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b>
+
 ## 三、快速集成
 > ❗ 在快速集成前,请先安装 PaddleX 的 wheel 包,详细请参考 [PaddleX本地安装教程](../../../installation/installation.md)。
 >
@@ -47,13 +66,293 @@ comments: true
 
 ```python
 from paddlex import create_model
-model = create_model("PP-OCRv4_mobile_det")
+model = create_model(model_name="PP-OCRv4_mobile_det")
 output = model.predict("general_ocr_001.png", batch_size=1)
 for res in output:
-    res.print(json_format=False)
-    res.save_to_img("./output/")
-    res.save_to_json("./output/res.json")
+    res.print()
+    res.save_to_img(save_path="./output/")
+    res.save_to_json(save_path="./output/res.json")
 ```
+
+运行后,得到的结果为:
+
+```bash
+{'res': {'input_path': 'general_ocr_001.png', 'dt_polys': [[[73, 553], [443, 541], [444, 574], [74, 585]], [[17, 507], [515, 489], [517, 534], [19, 552]], [[191, 458], [398, 449], [400, 481], [193, 490]], [[41, 413], [483, 390], [485, 431], [43, 453]]], 'dt_scores': [0.7555687038101032, 0.701620896397861, 0.8839516283528792, 0.8123399529333318]}}
+```
+
+运行结果参数含义如下:
+- `input_path`:表示输入待预测图像的路径
+- `dt_polys`:表示预测的文本检测框,其中每个文本检测框包含一个四边形的四个顶点。其中每个顶点都是一个二元组,分别表示该顶点的x坐标和y坐标
+- `dt_scores`:表示预测的文本检测框的置信度
+
+可视化图片如下:
+
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/refs/heads/main/images/modules/text_det/general_ocr_001_res.png">
+
+相关方法、参数等说明如下:
+
+* `create_model`实例化文本检测模型(此处以`PP-OCRv4_mobile_det`为例),具体说明如下:
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>model_name</code></td>
+<td>模型名称</td>
+<td><code>str</code></td>
+<td>所有PaddleX支持的文本检测模型名称</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>model_dir</code></td>
+<td>模型存储路径</td>
+<td><code>str</code></td>
+<td>无</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>limit_side_len</code></td>
+<td>检测的图像边长限制</td>
+<td><code>int/None</code></td>
+<td>
+<ul>
+<li><b>int</b>: 大于0的任意整数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>limit_type</code></td>
+<td>检测的图像边长限制,检测的边长限制类型 </td>
+<td><code>str/None</code></td>
+<td>
+<ul>
+<li><b>str</b>: 支持min和max. min表示保证图像最短边不小于det_limit_side_len, max: 表示保证图像最长边不大于limit_side_len
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+</td>
+<td>None</td>
+</tr>
+<tr>
+<td><code>thresh</code></td>
+<td>输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>box_thresh</code></td>
+<td>检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>unclip_ratio</code></td>
+<td>Vatti clipping算法的扩张系数,使用该方法对文字区域进行扩张 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用PaddleX官方模型配置中的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+</table>
+
+* 其中,`model_name` 必须指定,指定 `model_name` 后,默认使用 PaddleX 内置的模型参数,在此基础上,指定 `model_dir` 时,使用用户自定义的模型。
+
+* 调用文本检测模型的 `predict()` 方法进行推理预测,`predict()` 方法参数有 `input`、 `batch_size`、 `limit_side_len`、 `limit_type`、 `thresh`、 `box_thresh`、 `max_candidates`、`unclip_ratio`和`use_dilation`,具体说明如下:
+
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>input</code></td>
+<td>待预测数据,支持多种输入类型</td>
+<td><code>Python Var</code>/<code>str</code>/<code>dict</code>/<code>list</code></td>
+<td>
+<ul>
+  <li><b>Python变量</b>,如<code>numpy.ndarray</code>表示的图像数据</li>
+  <li><b>文件路径</b>,如图像文件的本地路径:<code>/root/data/img.jpg</code></li>
+  <li><b>URL链接</b>,如图像文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png">示例</a></li>
+  <li><b>本地目录</b>,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code></li>
+  <li><b>字典</b>,字典的<code>key</code>需与具体任务对应,如图像分类任务对应<code>\"img\"</code>,字典的<code>val</code>支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code></li>
+  <li><b>列表</b>,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code>,<code>[{\"img\": \"/root/data1\"}, {\"img\": \"/root/data2/img.jpg\"}]</code></li>
+</ul>
+</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>batch_size</code></td>
+<td>批大小</td>
+<td><code>int</code></td>
+<td>大于0的任意整数</td>
+<td>1</td>
+</tr>
+<tr>
+<td><code>limit_side_len</code></td>
+<td>检测的图像边长限制</td>
+<td><code>int/None</code></td>
+<td>
+<ul>
+<li><b>int</b>: 大于0的任意整数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>limit_type</code></td>
+<td>检测的图像边长限制,检测的边长限制类型 </td>
+<td><code>str/None</code></td>
+<td>
+<ul>
+<li><b>str</b>: 支持min和max. min表示保证图像最短边不小于det_limit_side_len, max: 表示保证图像最长边不大于limit_side_len
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+</td>
+<td>None</td>
+</tr>
+<tr>
+<td><code>thresh</code></td>
+<td>输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>box_thresh</code></td>
+<td>检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+<tr>
+<td><code>unclip_ratio</code></td>
+<td>Vatti clipping算法的扩张系数,使用该方法对文字区域进行扩张 </td>
+<td><code>float/None</code></td>
+<td>
+<ul>
+<li><b>float</b>: 大于0的任意浮点数
+<li><b>None</b>: 如果设置为None, 将默认使用模型初始化的该参数值</td>
+</ul>
+<td>None</td>
+</tr>
+</table>
+
+* 对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`json`文件的操作:
+
+<table>
+<thead>
+<tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
+<th>参数类型</th>
+<th>参数说明</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "3"><code>print()</code></td>
+<td rowspan = "3">打印结果到终端</td>
+<td><code>format_json</code></td>
+<td><code>bool</code></td>
+<td>是否对输出内容进行使用 <code>JSON</code> 缩进格式化</td>
+<td><code>True</code></td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td rowspan = "3"><code>save_to_json()</code></td>
+<td rowspan = "3">将结果保存为json格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td><code>save_to_img()</code></td>
+<td>将结果保存为图像格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+</table>
+
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
+
+<table>
+<thead>
+<tr>
+<th>属性</th>
+<th>属性说明</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的<code>json</code>格式的结果</td>
+</tr>
+<tr>
+<td rowspan = "1"><code>img</code></td>
+<td rowspan = "1">获取格式为<code>dict</code>的可视化图像</td>
+</tr>
+
+</table>
+
+
 关于更多 PaddleX 的单模型推理的 API 的使用方法,可以参考 [PaddleX单模型Python脚本使用说明](../../../module_usage/instructions/model_python_API.md)。
 
 ## 四、二次开发

+ 174 - 8
docs/module_usage/tutorials/ocr_modules/text_image_unwarping.md

@@ -5,7 +5,7 @@ comments: true
 # 文本图像矫正模块使用教程
 
 ## 一、概述
-文本图像矫正的主要目的是针对图像进行几何变换,以纠正图像中的文档扭曲、倾斜、透视变形等问题,以供后续的文本识别模块进行更准确的识别
+文本图像矫正的主要目的是针对图像进行几何变换,以纠正图像中的文档扭曲、倾斜、透视变形等问题,以供后续的文本识别进行更准确。
 
 ## 二、支持模型列表
 
@@ -15,7 +15,7 @@ comments: true
 <thead>
 <tr>
 <th>模型</th><th>模型下载链接</th>
-<th>MS-SSIM (%)</th>
+<th>CER </th>
 <th>模型存储大小(M)</th>
 <th>介绍</th>
 </tr>
@@ -23,7 +23,7 @@ comments: true
 <tbody>
 <tr>
 <td>UVDoc</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/UVDoc_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/UVDoc_pretrained.pdparams">训练模型</a></td>
-<td>54.40</td>
+<td>0.179</td>
 <td>30.3 M</td>
 <td>高精度文本图像矫正模型</td>
 </tr>
@@ -33,17 +33,183 @@ comments: true
 
 
 ## 三、快速集成
-在快速集成前,首先需要安装PaddleX的wheel包,wheel的安装方式请参考 [PaddleX本地安装教程](../../../installation/installation.md)。完成wheel包的安装后,几行代码即可完成文本检测模块的推理,可以任意切换该模块下的模型,您也可以将文本检测的模块中的模型推理集成到您的项目中。运行以下代码前,请您下载[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg)到本地。
+在快速集成前,首先需要安装PaddleX的wheel包,wheel的安装方式请参考 [PaddleX本地安装教程](../../../installation/installation.md)。完成wheel包的安装后,几行代码即可完成图像矫正模块的推理,可以任意切换该模块下的模型,您也可以将图像矫正的模块中的模型推理集成到您的项目中。运行以下代码前,请您下载[示例图片](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/doc_test.jpg)到本地。
 
 ```
 from paddlex import create_model
-model = create_model("UVDoc")
+model = create_model(model_name="UVDoc")
 output = model.predict("doc_test.jpg", batch_size=1)
 for res in output:
-    res.print(json_format=False)
-    res.save_to_img("./output/")
-    res.save_to_json("./output/res.json")
+    res.print()
+    res.save_to_img(save_path="./output/")
+    res.save_to_json(save_path="./output/res.json")
 ```
+
+运行后,得到的结果为:
+```bash
+{'res': "{'input_path': 'doc_test.jpg', 'doctr_img': '...'}"}
+```
+
+运行结果参数含义如下:
+- `input_path`:表示输入待矫正图像的路径
+- `doctr_img`:表示矫正后的图像结果,由于数据过多不便于直接print,所以此处用`...`替换,可以通过`res.save_to_img()`将预测结果保存为图片,通过`res.save_to_json()`将预测结果保存为json文件。
+
+
+可视化图片如下:
+
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/refs/heads/main/images/modules/image_unwarp/doc_test_res.jpg">
+
+相关方法、参数等说明如下:
+
+* `create_model`实例化图像矫正模型(此处以`UVDoc`为例),具体说明如下:
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>model_name</code></td>
+<td>模型名称</td>
+<td><code>str</code></td>
+<td>所有PaddleX支持的模型名称</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>model_dir</code></td>
+<td>模型存储路径</td>
+<td><code>str</code></td>
+<td>无</td>
+<td>无</td>
+</tr>
+</table>
+
+* 其中,`model_name` 必须指定,指定 `model_name` 后,默认使用 PaddleX 内置的模型参数,在此基础上,指定 `model_dir` 时,使用用户自定义的模型。
+
+* 调用图像矫正模型的 `predict()` 方法进行推理预测,`predict()` 方法参数有 `input` 和 `batch_size`,具体说明如下:
+
+<table>
+<thead>
+<tr>
+<th>参数</th>
+<th>参数说明</th>
+<th>参数类型</th>
+<th>可选项</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td><code>input</code></td>
+<td>待预测数据,支持多种输入类型</td>
+<td><code>Python Var</code>/<code>str</code>/<code>dict</code>/<code>list</code></td>
+<td>
+<ul>
+  <li><b>Python变量</b>,如<code>numpy.ndarray</code>表示的图像数据</li>
+  <li><b>文件路径</b>,如图像文件的本地路径:<code>/root/data/img.jpg</code></li>
+  <li><b>URL链接</b>,如图像文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_rec_001.png">示例</a></li>
+  <li><b>本地目录</b>,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code></li>
+  <li><b>字典</b>,字典的<code>key</code>需与具体任务对应,如图像分类任务对应<code>\"img\"</code>,字典的<code>val</code>支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code></li>
+  <li><b>列表</b>,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code>,<code>[{\"img\": \"/root/data1\"}, {\"img\": \"/root/data2/img.jpg\"}]</code></li>
+</ul>
+</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>batch_size</code></td>
+<td>批大小</td>
+<td><code>int</code></td>
+<td>任意整数</td>
+<td>1</td>
+</tr>
+</table>
+
+* 对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`json`文件的操作:
+
+<table>
+<thead>
+<tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
+<th>参数类型</th>
+<th>参数说明</th>
+<th>默认值</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "3"><code>print()</code></td>
+<td rowspan = "3">打印结果到终端</td>
+<td><code>format_json</code></td>
+<td><code>bool</code></td>
+<td>是否对输出内容进行使用 <code>JSON</code> 缩进格式化</td>
+<td><code>True</code></td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td rowspan = "3"><code>save_to_json()</code></td>
+<td rowspan = "3">将结果保存为json格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>指定缩进级别,以美化输出的 <code>JSON</code> 数据,使其更具可读性,仅当 <code>format_json</code> 为 <code>True</code> 时有效</td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>控制是否将非 <code>ASCII</code> 字符转义为 <code>Unicode</code>。设置为 <code>True</code> 时,所有非 <code>ASCII</code> 字符将被转义;<code>False</code> 则保留原始字符,仅当<code>format_json</code>为<code>True</code>时有效</td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td><code>save_to_img()</code></td>
+<td>将结果保存为图像格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致</td>
+<td>无</td>
+</tr>
+</table>
+
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
+
+<table>
+<thead>
+<tr>
+<th>属性</th>
+<th>属性说明</th>
+</tr>
+</thead>
+<tr>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的<code>json</code>格式的结果</td>
+</tr>
+<tr>
+<td rowspan = "1"><code>img</code></td>
+<td rowspan = "1">获取格式为<code>dict</code>的可视化图像</td>
+</tr>
+
+</table>
+
 关于更多 PaddleX 的单模型推理的 API 的使用方法,可以参考[PaddleX单模型Python脚本使用说明](../../instructions/model_python_API.md)。
 
 ## 四、二次开发

+ 2 - 11
paddlex/inference/models_new/text_detection/predictor.py

@@ -45,9 +45,7 @@ class TextDetPredictor(BasicPredictor):
         limit_type: Union[str, None] = None,
         thresh: Union[float, None] = None,
         box_thresh: Union[float, None] = None,
-        max_candidates: Union[int, None] = None,
         unclip_ratio: Union[float, None] = None,
-        use_dilation: Union[bool, None] = None,
         *args,
         **kwargs
     ):
@@ -57,9 +55,7 @@ class TextDetPredictor(BasicPredictor):
         self.limit_type = limit_type
         self.thresh = thresh
         self.box_thresh = box_thresh
-        self.max_candidates = max_candidates
         self.unclip_ratio = unclip_ratio
-        self.use_dilation = use_dilation
         self.pre_tfs, self.infer, self.post_op = self._build()
 
     def _build_batch_sampler(self):
@@ -96,9 +92,7 @@ class TextDetPredictor(BasicPredictor):
         limit_type: Union[str, None] = None,
         thresh: Union[float, None] = None,
         box_thresh: Union[float, None] = None,
-        max_candidates: Union[int, None] = None,
         unclip_ratio: Union[float, None] = None,
-        use_dilation: Union[bool, None] = None,
     ):
 
         batch_raw_imgs = self.pre_tfs["Read"](imgs=batch_data)
@@ -116,9 +110,7 @@ class TextDetPredictor(BasicPredictor):
             batch_shapes,
             thresh=thresh or self.thresh,
             box_thresh=box_thresh or self.box_thresh,
-            max_candidates=max_candidates or self.max_candidates,
             unclip_ratio=unclip_ratio or self.unclip_ratio,
-            use_dilation=use_dilation or self.use_dilation,
         )
         return {
             "input_path": batch_data,
@@ -179,10 +171,9 @@ class TextDetPredictor(BasicPredictor):
             return DBPostProcess(
                 thresh=self.thresh or kwargs.get("thresh", 0.3),
                 box_thresh=self.box_thresh or kwargs.get("box_thresh", 0.6),
-                max_candidates=self.max_candidates
-                or kwargs.get("max_candidates", 1000),
                 unclip_ratio=self.unclip_ratio or kwargs.get("unclip_ratio", 2.0),
-                use_dilation=self.use_dilation or kwargs.get("use_dilation", False),
+                max_candidates=kwargs.get("max_candidates", 1000),
+                use_dilation=kwargs.get("use_dilation", False),
                 score_mode=kwargs.get("score_mode", "fast"),
                 box_type=kwargs.get("box_type", "quad"),
             )

+ 5 - 13
paddlex/inference/models_new/text_detection/processors.py

@@ -242,7 +242,6 @@ class DBPostProcess:
         dest_width,
         dest_height,
         box_thresh,
-        max_candidates,
         unclip_ratio,
     ):
         """_bitmap: single map with shape (1, H, W), whose values are binarized as {0, 1}"""
@@ -257,7 +256,7 @@ class DBPostProcess:
             (bitmap * 255).astype(np.uint8), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE
         )
 
-        for contour in contours[:max_candidates]:
+        for contour in contours[:self.max_candidates]:
             epsilon = 0.002 * cv2.arcLength(contour, True)
             approx = cv2.approxPolyDP(contour, epsilon, True)
             points = approx.reshape((-1, 2))
@@ -299,7 +298,6 @@ class DBPostProcess:
         dest_width,
         dest_height,
         box_thresh,
-        max_candidates,
         unclip_ratio,
     ):
         """_bitmap: single map with shape (1, H, W), whose values are binarized as {0, 1}"""
@@ -315,7 +313,7 @@ class DBPostProcess:
         elif len(outs) == 2:
             contours, _ = outs[0], outs[1]
 
-        num_contours = min(len(contours), max_candidates)
+        num_contours = min(len(contours), self.max_candidates)
 
         boxes = []
         scores = []
@@ -420,9 +418,7 @@ class DBPostProcess:
         img_shapes,
         thresh: Union[float, None] = None,
         box_thresh: Union[float, None] = None,
-        max_candidates: Union[int, None] = None,
         unclip_ratio: Union[float, None] = None,
-        use_dilation: Union[bool, None] = None,
     ):
         """apply"""
         boxes, scores = [], []
@@ -432,9 +428,7 @@ class DBPostProcess:
                 img_shape,
                 thresh or self.thresh,
                 box_thresh or self.box_thresh,
-                max_candidates or self.max_candidates,
                 unclip_ratio or self.unclip_ratio,
-                use_dilation or self.use_dilation,
             )
             boxes.append(box)
             scores.append(score)
@@ -446,13 +440,11 @@ class DBPostProcess:
         img_shape,
         thresh,
         box_thresh,
-        max_candidates,
         unclip_ratio,
-        use_dilation,
     ):
         pred = pred[0, :, :]
         segmentation = pred > thresh
-        dilation_kernel = None if not use_dilation else np.array([[1, 1], [1, 1]])
+        dilation_kernel = None if not self.use_dilation else np.array([[1, 1], [1, 1]])
         src_h, src_w, ratio_h, ratio_w = img_shape
         if dilation_kernel is not None:
             mask = cv2.dilate(
@@ -463,11 +455,11 @@ class DBPostProcess:
             mask = segmentation
         if self.box_type == "poly":
             boxes, scores = self.polygons_from_bitmap(
-                pred, mask, src_w, src_h, box_thresh, max_candidates, unclip_ratio
+                pred, mask, src_w, src_h, box_thresh, unclip_ratio
             )
         elif self.box_type == "quad":
             boxes, scores = self.boxes_from_bitmap(
-                pred, mask, src_w, src_h, box_thresh, max_candidates, unclip_ratio
+                pred, mask, src_w, src_h, box_thresh, unclip_ratio
             )
         else:
             raise ValueError("box_type can only be one of ['quad', 'poly']")