فهرست منبع

add_doc_preprocess_cli_args (#2936)

* add_doc_preprocess_cli_args

* add_doc_preprocess

* add_video_det_doc

* add_video_det_doc

* add_video_det_doc

* add_docs

* add_docs
Sunflower7788 10 ماه پیش
والد
کامیت
137af2a379

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 8 - 5
docs/module_usage/tutorials/video_modules/video_detection.md


+ 149 - 87
docs/pipeline_usage/tutorials/cv_pipelines/image_anomaly_detection.md

@@ -5,33 +5,32 @@ comments: true
 # 图像异常检测产线使用教程
 
 ## 1. 图像异常检测产线介绍
-图像异常检测是一种通过分析图像中的内容,来识别与众不同或不符合正常模式的图像处理技术。它广泛应用于工业质量检测、医疗影像分析和安全监控等领域。通过使用机器学习和深度学习算法,图像异常检测能够自动识别出图像中潜在的缺陷、异常或异常行为,从而帮助我们及时发现问题并采取相应措施。图像异常检测系统被设计用于自动检测和标记图像中的异常情况,以提高工作效率和准确性。
+图像异常检测是一种通过分析图像中的内容,来识别与众不同或不符合正常模式的图像处理技术。它广泛应用于工业质量检测、医疗影像分析和安全监控等领域。通过使用机器学习和深度学习算法,图像异常检测能够自动识别出图像中潜在的缺陷、异常或异常行为,从而帮助我们及时发现问题并采取相应措施。图像异常检测系统被设计用于自动检测和标记图像中的异常情况,以提高工作效率和准确性。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/image_anomaly_detection/01.png">
 
-
-<b>图像异常检测产线中包含了无监督异常检测模块,模型的benchmark如下</b>:
+<b>图像异常检测</b><b>产线中包含图像异常检测模块</b>,包含的模型如下。
 
 <table>
 <thead>
 <tr>
 <th>模型</th><th>模型下载链接</th>
-<th>Avg(%)</th>
+<th>mIoU(%)</th>
 <th>模型存储大小(M)</th>
 </tr>
 </thead>
 <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>96.2</td>
+<td>99.01</td>
 <td>21.5 M</td>
 </tr>
 </tbody>
 </table>
-<b>注:以上精度指标为 </b>[MVTec AD](https://www.mvtec.com/company/research/datasets/mvtec-ad)<b> 验证集 平均异常分数。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b>
+<b>注:以上精度指标为 </b><a href="https://www.mvtec.com/company/research/datasets/mvtec-ad">MVTec AD</a><b> 验证集 grid 数据的mIoU结果。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b>
 
 ## 2. 快速开始
-PaddleX 所提供的预训练的模型产线均可以快速体验效果,您可以在本地使用命令行或 Python 体验图像异常检测产线的效果。
+PaddleX 所提供的模型产线均可以快速体验效果,您可以在本地使用命令行或 Python 体验图像异常检测产线的效果。
 
 在本地使用图像异常检测产线前,请确保您已经按照[PaddleX本地安装教程](../../../installation/installation.md)完成了PaddleX的wheel包安装。
 
@@ -39,58 +38,42 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,您可
 一行命令即可快速体验图像异常检测产线效果,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/uad_grid.png),并将 `--input` 替换为本地路径,进行预测
 
 ```bash
-paddlex --pipeline anomaly_detection --input uad_grid.png --device gpu:0
+paddlex --pipeline anomaly_detection --input uad_grid.png --device gpu:0  --save_path ./output
 ```
-参数说明:
 
-```
---pipeline:产线名称,此处为图像异常检测产线
---input:待处理的输入图片的本地路径或URL
---device 使用的GPU序号(例如gpu:0表示使用第0块GPU,gpu:1,2表示使用第1、2块GPU),也可选择使用CPU(--device cpu)
-```
+相关的参数说明可以参考[2.1.2 Python脚本方式集成](#212-python脚本方式集成)中的参数说明。
 
-在执行上述 Python 脚本时,加载的是默认的图像异常检测产线配置文件,若您需要自定义配置文件,可执行如下命令获取
+运行后,会将结果打印到终端上,结果如下:
 
-<details><summary> 👉点击展开</summary>
 
-<pre><code>paddlex --get_pipeline_config anomaly_detection
-</code></pre>
-<p>执行后,图像异常检测产线配置文件将被保存在当前路径。若您希望自定义保存位置,可执行如下命令(假设自定义保存位置为 <code>./my_path</code> ):</p>
-<pre><code>paddlex --get_pipeline_config anomaly_detection --save_path ./my_path
-</code></pre>
-<p>获取产线配置文件后,可将 --pipeline 替换为配置文件保存路径,即可使配置文件生效。例如,若配置文件保存路径为 <code>./anomaly_detection.yaml</code>,只需执行:</p>
-<pre><code class="language-bash">paddlex --pipeline ./anomaly_detection.yaml --input uad_grid.png --device gpu:0
-</code></pre>
-<p>其中,<code>--model</code>、<code>--device</code> 等参数无需指定,将使用配置文件中的参数。若依然指定了参数,将以指定的参数为准。</p></details>
+<pre><code>{'input_path': 'uad_grid.png', 'pred': '...'}</code></pre>
 
-运行后,得到的结果为:
 
-```bash
-{'input_path': 'uad_grid.png', 'pred': '...'}
-```
+运行结果参数说明可以参考[2.1.2 Python脚本方式集成](#212-python脚本方式集成)中的结果解释。
+
+可视化结果保存在`save_path`下,可视化结果如下:
+
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/image_anomaly_detection/02.png">
 
-可视化图片默认不进行保存,您可以通过 `--save_path` 自定义保存路径,随后所有结果将被保存在指定路径下。
 
 ### 2.2 Python脚本方式集成
-几行代码即可完成产线的快速推理,以图像异常检测产线为例:
+
+上述命令行是为了快速体验查看效果,一般来说,在项目中,往往需要通过代码集成,您可以通过几行代码即可完成产线的快速推理,推理代码如下:
 
 ```python
 from paddlex import create_pipeline
 
 pipeline = create_pipeline(pipeline="anomaly_detection")
-
-output = pipeline.predict("uad_grid.png")
+output = pipeline.predict(input="uad_grid.png")
 for res in output:
     res.print() ## 打印预测的结构化输出
-    res.save_to_img("./output/") ## 保存结果可视化图像
-    res.save_to_json("./output/") ## 保存预测的结构化输出
+    res.save_to_img(save_path="./output/") ## 保存结果可视化图像
+    res.save_to_json(save_path="./output/") ## 保存预测的结构化输出
 ```
-得到的结果与命令行方式相同。
 
 在上述 Python 脚本中,执行了如下几个步骤:
 
-(1)实例化 `create_pipeline` 实例化产线对象:具体参数说明如下:
+(1)通过 `create_pipeline()` 实例化产线对象:具体参数说明如下:
 
 <table>
 <thead>
@@ -110,9 +93,9 @@ for res in output:
 </tr>
 <tr>
 <td><code>device</code></td>
-<td>产线模型推理设备。支持:“gpu”,“cpu”。</td>
+<td>产线推理设备。支持指定GPU具体卡号,如“gpu:0”,其他硬件具体卡号,如“npu:0”,CPU如“cpu”。</td>
 <td><code>str</code></td>
-<td><code>gpu</code></td>
+<td><code>gpu:0</code></td>
 </tr>
 <tr>
 <td><code>use_hpip</code></td>
@@ -122,72 +105,152 @@ for res in output:
 </tr>
 </tbody>
 </table>
-(2)调用产线对象的 `predict` 方法进行推理预测:`predict` 方法参数为`x`,用于输入待预测数据,支持多种输入方式,具体示例如下:
+
+(2)调用 anomaly_detection 产线对象的 `predict()` 方法进行推理预测。该方法将返回一个 `generator`。以下是 `predict()` 方法的参数及其说明:
+
+<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|str|list</code></td>
+<td>
+<ul>
+  <li><b>Python Var</b>:如 <code>numpy.ndarray</code> 表示的图像数据</li>
+  <li><b>str</b>:如图像文件的本地路径:<code>/root/data/img.jpg</code>;<b>如URL链接</b>,如图像文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/uad_grid.png">示例</a>;<b>如本地目录</b>,该目录下需包含待预测图像,如本地路径:<code>/root/data/</code></li>
+  <li><b>List</b>:列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray]</code>,<code>[\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code></li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>device</code></td>
+<td>产线推理设备</td>
+<td><code>str|None</code></td>
+<td>
+<ul>
+  <li><b>CPU</b>:如 <code>cpu</code> 表示使用 CPU 进行推理;</li>
+  <li><b>GPU</b>:如 <code>gpu:0</code> 表示使用第 1 块 GPU 进行推理;</li>
+  <li><b>NPU</b>:如 <code>npu:0</code> 表示使用第 1 块 NPU 进行推理;</li>
+  <li><b>XPU</b>:如 <code>xpu:0</code> 表示使用第 1 块 XPU 进行推理;</li>
+  <li><b>MLU</b>:如 <code>mlu:0</code> 表示使用第 1 块 MLU 进行推理;</li>
+  <li><b>DCU</b>:如 <code>dcu:0</code> 表示使用第 1 块 DCU 进行推理;</li>
+  <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+</table>
+
+(3)对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为图片、保存为`json`文件的操作:
 
 <table>
 <thead>
 <tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
 <th>参数类型</th>
 <th>参数说明</th>
+<th>默认值</th>
 </tr>
 </thead>
-<tbody>
 <tr>
-<td>Python Var</td>
-<td>支持直接传入Python变量,如numpy.ndarray表示的图像数据。</td>
+<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>str</td>
-<td>支持传入待预测数据文件路径,如图像文件的本地路径:<code>/root/data/img.jpg</code>。</td>
+<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>str</td>
-<td>支持传入待预测数据文件URL,如图像文件的网络URL:<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/uad_grid.png">示例</a>。</td>
+<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>str</td>
-<td>支持传入本地目录,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code>。</td>
+<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>dict</td>
-<td>支持传入字典类型,字典的key需与具体任务对应,如图像分类任务对应\"img\",字典的val支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code>。</td>
+<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>list</td>
-<td>支持传入列表,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray],[\"/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>。</td>
+<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>
-</tbody>
 </table>
-(3)调用`predict`方法获取预测结果:`predict` 方法为`generator`,因此需要通过调用获得预测结果,`predict`方法以batch为单位对数据进行预测,因此预测结果为list形式表示的一组预测结果
 
-(4)对预测结果进行处理:每个样本的预测结果均为`dict`类型,且支持打印,或保存为文件,支持保存的类型与具体产线相关,如:
+- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下:
+
+    - `input_path`: `(str)` 待预测图像的输入路径
+
+    - `pred`: `(str)` 预测结果,由于像素值较多,此处用`...`代替,不进行打印。
+
+- 调用`save_to_json()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}_res.json`,如果指定为文件,则直接保存到该文件中。由于json文件不支持保存numpy数组,因此会将其中的`numpy.array`类型转换为列表形式。
+- 调用`save_to_img()` 方法会将可视化结果保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}_res.{your_img_extension}`,如果指定为文件,则直接保存到该文件中。(产线通常包含较多结果图片,不建议直接指定为具体的文件路径,否则多张图会被覆盖,仅保留最后一张图)
+
+* 此外,也支持通过属性获取带结果的可视化图像和预测结果,具体如下:
 
 <table>
 <thead>
 <tr>
-<th>方法</th>
-<th>说明</th>
-<th>方法参数</th>
+<th>属性</th>
+<th>属性说明</th>
 </tr>
 </thead>
-<tbody>
 <tr>
-<td>print</td>
-<td>打印结果到终端</td>
-<td><code>- format_json</code>:bool类型,是否对输出内容进行使用json缩进格式化,默认为True;<br/><code>- indent</code>:int类型,json格式化设置,仅当format_json为True时有效,默认为4;<br/><code>- ensure_ascii</code>:bool类型,json格式化设置,仅当format_json为True时有效,默认为False;</td>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的 <code>json</code> 格式的结果</td>
 </tr>
 <tr>
-<td>save_to_json</td>
-<td>将结果保存为json格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;<br/><code>- indent</code>:int类型,json格式化设置,默认为4;<br/><code>- ensure_ascii</code>:bool类型,json格式化设置,默认为False;</td>
+<td rowspan = "2"><code>img</code></td>
+<td rowspan = "2">获取格式为 <code>dict</code> 的可视化图像</td>
 </tr>
-<tr>
-<td>save_to_img</td>
-<td>将结果保存为图像格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
-</tr>
-</tbody>
 </table>
+
+
+- `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
+- `img` 属性返回的预测结果是一个字典类型的数据。其中,键为 `res`,对应的值是 `Image.Image` 对象:用于显示 anomaly_detection 结果的可视化图像。
+
+此外,您可以获取 anomaly_detection 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+
+```
+paddlex --get_pipeline_config anomaly_detection --save_path ./my_path
+```
+
 若您获取了配置文件,即可对图像异常检测产线各项配置进行自定义,只需要修改 `create_pipeline` 方法中的 `pipeline` 参数值为产线配置文件路径即可。
 
 例如,若您的配置文件保存在 `./my_path/*anomaly_detection.yaml` ,则只需执行:
@@ -717,29 +780,28 @@ echo &quot;Output image saved at &quot; . $output_image_path . &quot;\n&quot;;
 ### 4.2 模型应用
 当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
 
-若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
+若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径填写至产线配置文件中的 `model_dir` 即可:
 
 ```python
-......
-Pipeline:
-  model: STFPM   #可修改为微调后模型的本地路径
-  batch_size: 1
-  device: "gpu:0"
-......
+pipeline_name: anomaly_detection
+
+SubModules:
+  AnomalyDetection:
+    module_name: anomaly_detection
+    model_name: STFPM
+    model_dir: null  # 替换为微调后的文档图像方向分类模型权重路径
+    batch_size: 1   
 ```
-随后, 参考本地体验中的命令行方式或 Python 脚本方式,加载修改后的产线配置文件即可。
+
+随后, 参考[2. 快速开始](#2-快速开始)中的命令行方式或Python脚本方式,加载修改后的产线配置文件即可。
+
 
 ##  5. 多硬件支持
 PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU和寒武纪 MLU 等多种主流硬件设备,<b>仅需修改 `--device`</b> 参数即可完成不同硬件之间的无缝切换。
 
-例如,您使用英伟达 GPU 进行图像异常检测产线的推理,使用的 Python 命令为:
+例如,您使用昇腾 NPU 进行图像异常检测产线的推理,使用的 Python 命令为:
 
-```
-paddlex --pipeline anomaly_detection --input uad_grid.png --device gpu:0
-```
-此时,若您想将硬件切换为昇腾 NPU,仅需对 Python 命令中的 `--device` 修改为 npu:0 即可:
-
-```
+```bash
 paddlex --pipeline anomaly_detection --input uad_grid.png --device npu:0
 ```
 若您想在更多种类的硬件上使用图像异常检测产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。

+ 432 - 0
docs/pipeline_usage/tutorials/ocr_pipelines/doc_preprocessor.en.md

@@ -0,0 +1,432 @@
+---
+comments: true
+---
+
+# Document Image Preprocessing Pipeline Tutorial
+
+## 1. Introduction to the Do Pipeline
+
+The document image preprocessing pipeline integrates two major functions: document orientation classification and geometric distortion correction. The document orientation classification can automatically identify the four orientations of a document (0°, 90°, 180°, 270°) to ensure that the document is processed in the correct direction for subsequent tasks. The geometric distortion correction model is used to correct geometric distortions that occur during the document's photographing or scanning process, restoring the document to its original shape and proportions. This is suitable for digital document management, preprocessing for doc_preprocessor recognition, and any scenario where improving document image quality is necessary. Through automated orientation correction and distortion correction, this module significantly enhances the accuracy and efficiency of document processing, providing users with a more reliable foundation for image analysis. The pipeline also offers flexible service deployment options, supporting invocation using various programming languages on multiple hardware platforms. Moreover, it provides the capability for further development, allowing you to train and fine-tune on your own dataset based on this pipeline, with the trained models being seamlessly integrable.
+
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/doc_preprocessor/02.jpg">
+
+**The general document image preprocessing pipeline includes optional document image orientation classification module and document image correction module** with the following models included.
+
+<p><b>Document Image Orientation Classification Module (Optional):</b></p>
+
+<table>
+<thead>
+<tr>
+<th>Model</th><th>Model download link</th>
+<th>Top-1 Acc(%)</th>
+<th>GPU inference time(ms)</th>
+<th>CPU inference time (ms)</th>
+<th>Model storage size(M)</th>
+<th>Introduction</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>PP-LCNet_x1_0_doc_ori</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PP-LCNet_x1_0_doc_ori_infer.tar">                Inference Model</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-LCNet_x1_0_doc_ori_pretrained.pdparams">Train Model</a></td>
+<td>99.06</td>
+<td>3.84845</td>
+<td>9.23735</td>
+<td>7</td>
+<td>A document image classification model based on PP-LCNet_x1_0, containing four categories: 0 degrees, 90 degrees, 180 degrees, and 270 degrees.</td>
+</tr>
+</tbody>
+</table>
+<b>Note: The accuracy metrics mentioned above are evaluated on a self-constructed dataset, which covers various scenarios such as IDs and documents, including 1000 images. The GPU inference time is based on an NVIDIA Tesla T4 machine with a precision type of FP32. The CPU inference speed is based on an Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz with 8 threads and a precision type of FP32.</b>
+
+<p><b>Text Image Unwarping Module (Optional):</b></p>
+
+<table>
+<thead>
+<tr>
+<th>Model</th><th>Model download link</th>
+<th>CER </th>
+<th>Model storage size(M)</th>
+<th>Introduction</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>UVDoc</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/UVDoc_infer.tar">Inference Model</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/UVDoc_pretrained.pdparams">Train Model</a></td>
+<td>0.179</td>
+<td>30.3 M</td>
+<td>High-Precision Text Image Correction Model</td>
+</tr>
+</tbody>
+</table>
+<b>The accuracy metrics of the model are measured from <a href="https://www3.cs.stonybrook.edu/~cvl/docunet.html">DocUNet benchmark</a> </b>
+
+
+
+## 2. Quick Start
+
+PaddleX supports experiencing the effects of the document image preprocessing pipeline locally via command line or Python.
+
+Before using the document image preprocessing pipeline locally, please ensure you have completed the installation of the PaddleX wheel package according to the [PaddleX Local Installation Guide](../../../installation/installation.md).
+
+### 2.1 Local Experience
+
+#### 2.1.1 Command Line Experience
+You can quickly experience the effects of the document image preprocessing pipeline with a single command. Use the [test file](https://paddle-model-ecology.bj.bcebos.com/paddlex/demo_image/doc_test_rotated.jpg) and replace `--input` with the local path to perform predictions.
+
+```bash
+paddlex --pipeline doc_preprocessor \
+        --input doc_test_rotated.jpg \
+        --use_doc_orientation_classify True \
+        --use_doc_unwarping True \
+        --save_path ./output \
+        --device gpu:0
+```
+You can refer to the parameter descriptions in [2.1.2 Python Script Integration](#212-python-script-integration) for related parameter details.
+
+After running, the results will be printed to the terminal as follows:
+
+<pre><code>{'res': {'input_path': 'doc_test_rotated.jpg', 'model_settings': {'use_doc_orientation_classify': True, 'use_doc_unwarping': True}, 'angle': 180}}
+</code></pre>
+
+You can refer to the results explanation in [2.1.2 Python Script Integration](#212-python-script-integration) for a description of the output parameters.
+
+The visualized results are saved under `save_path`. The visualized results are as follows:
+
+<img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/doc_preprocessor/02.jpg">
+
+
+#### 2.1.2 Python Script Integration
+
+The above command line is for quickly experiencing and viewing the effect. Generally, in a project, it is often necessary to integrate through code. You can complete quick inference in a production line with just a few lines of code. The inference code is as follows:
+
+```python
+from paddlex import create_pipeline
+
+pipeline = create_pipeline(pipeline="doc_preprocessor")
+output = pipeline.predict(
+    input="doc_test_rotated.jpg",
+    use_doc_orientation_classify=True,
+    use_doc_unwarping=True,
+)
+for res in output:
+    res.print()
+    res.save_to_img(save_path="./output/")
+    res.save_to_json(save_path="./output/")
+```
+
+In the above Python script, the following steps were executed:
+
+
+(1) Instantiate the `doc_preprocessor` pipeline object using `create_pipeline()`. The specific parameter descriptions are as follows:
+
+
+<table>
+<thead>
+<tr>
+<th>Parameter</th>
+<th>Description</th>
+<th>Type</th>
+<th>Default</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td><code>pipeline</code></td>
+<td>The pipeline name or the path to the pipeline configuration file. If it is a pipeline name, it must be a pipeline supported by PaddleX.</td>
+<td><code>str</code></td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>device</code></td>
+<td>Inference device for the pipeline. Supports specifying the GPU card number, such as "gpu:0", other hardware card numbers, such as "npu:0", and CPU as "cpu".</td>
+<td><code>str</code></td>
+<td><code>gpu:0</code></td>
+</tr>
+<tr>
+<td><code>use_hpip</code></td>
+<td>Whether to enable high-performance inference, available only when the pipeline supports high-performance inference.</td>
+<td><code>bool</code></td>
+<td><code>False</code></td>
+</tr>
+</tbody>
+</table>
+
+
+(2) Call the `predict()` method of the doc_preprocessor pipeline object for inference prediction. This method will return a `generator`. Below are the parameters of the `predict()` method and their descriptions:
+
+
+<table>
+<thead>
+<tr>
+<th>Parameter</th>
+<th>Description</th>
+<th>Type</th>
+<th>Options</th>
+<th>Default</th>
+</tr>
+</thead>
+<tr>
+<td><code>input</code></td>
+<td>Data to be predicted, supporting various input types, required</td>
+<td><code>Python Var|str|list</code></td>
+<td>
+<ul>
+  <li><b>Python Var</b>: Such as image data represented by <code>numpy.ndarray</code></li>
+  <li><b>str</b>: Such as the local path of an image file or PDF file: <code>/root/data/img.jpg</code>; <b>As URL link</b>, such as the network URL of an image file or PDF file: <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_doc_preprocessor_002.png">example</a>; <b>As a local directory</b>, which should contain images to be predicted, such as a local path: <code>/root/data/</code> (currently does not support directory prediction for PDFs, PDF files need to be specified to the specific file path)</li>
+  <li><b>List</b>: List elements must be of the above types, such as <code>[numpy.ndarray, numpy.ndarray]</code>, <code>["/root/data/img1.jpg", "/root/data/img2.jpg"]</code>, <code>["/root/data1", "/root/data2"]</code></li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>device</code></td>
+<td>Inference device for the pipeline</td>
+<td><code>str|None</code></td>
+<td>
+<ul>
+  <li><b>CPU</b>: Like <code>cpu</code>, indicating inference using CPU;</li>
+  <li><b>GPU</b>: Like <code>gpu:0</code>, indicating inference using the first GPU;</li>
+  <li><b>NPU</b>: Like <code>npu:0</code>, indicating inference using the first NPU;</li>
+  <li><b>XPU</b>: Like <code>xpu:0</code>, indicating inference using the first XPU;</li>
+  <li><b>MLU</b>: Like <code>mlu:0</code>, indicating inference using the first MLU;</li>
+  <li><b>DCU</b>: Like <code>dcu:0</code>, indicating inference using the first DCU;</li>
+  <li><b>None</b>: If set to <code>None</code>, the default value initialized by the pipeline will be used. During initialization, it will preferentially use the local GPU device 0, if none, then the CPU device;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>use_doc_orientation_classify</code></td>
+<td>Whether to use the document orientation classification module</td>
+<td><code>bool|None</code></td>
+<td>
+<ul>
+  <li><b>bool</b>: <code>True</code> or <code>False</code>;</li>
+  <li><b>None</b>: If set to <code>None</code>, the default value initialized by the pipeline will be used, initialized to <code>True</code>;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>use_doc_unwarping</code></td>
+<td>Whether to use the document unwarping correction module</td>
+<td><code>bool|None</code></td>
+<td>
+<ul>
+  <li><b>bool</b>: <code>True</code> or <code>False</code>;</li>
+  <li><b>None</b>: If set to <code>None</code>, the default value initialized by the pipeline will be used, initialized to <code>True</code>;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+</tbody>
+</table>
+
+
+(3) Process the prediction results, where the prediction result for each sample is of `dict` type. Additionally, these results support operations such as printing, saving as an image, and saving as a `json` file.
+
+<table>
+<thead>
+<tr>
+<th>Method</th>
+<th>Description</th>
+<th>Parameter</th>
+<th>Type</th>
+<th>Description</th>
+<th>Default</th>
+</tr>
+</thead>
+<tr>
+<td rowspan="3"><code>print()</code></td>
+<td rowspan="3">Prints the results to the terminal</td>
+<td><code>format_json</code></td>
+<td><code>bool</code></td>
+<td>Whether to format the output using <code>JSON</code> indentation</td>
+<td><code>True</code></td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>Specifies the indentation level to beautify the output <code>JSON</code> data for better readability, effective only when <code>format_json</code> is <code>True</code></td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>Controls whether to escape non-<code>ASCII</code> characters as <code>Unicode</code>. When set to <code>True</code>, all non-<code>ASCII</code> characters will be escaped; <code>False</code> retains the original characters, effective only when <code>format_json</code> is <code>True</code></td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td rowspan="3"><code>save_to_json()</code></td>
+<td rowspan="3">Saves the results as a JSON format file</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>The file path to save, naming consistent with the input file type when it is a directory</td>
+<td>None</td>
+</tr>
+<tr>
+<td><code>indent</code></td>
+<td><code>int</code></td>
+<td>Specifies the indentation level to beautify the output <code>JSON</code> data for better readability, effective only when <code>format_json</code> is <code>True</code></td>
+<td>4</td>
+</tr>
+<tr>
+<td><code>ensure_ascii</code></td>
+<td><code>bool</code></td>
+<td>Controls whether to escape non-<code>ASCII</code> characters as <code>Unicode</code>. When set to <code>True</code>, all non-<code>ASCII</code> characters will be escaped; <code>False</code> retains the original characters, effective only when <code>format_json</code> is <code>True</code></td>
+<td><code>False</code></td>
+</tr>
+<tr>
+<td><code>save_to_img()</code></td>
+<td>Saves the results as an image format file</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>The file path to save, supporting both directory or file path</td>
+<td>None</td>
+</tr>
+</table>
+
+
+- Calling the `print()` method will output the results to the terminal. The content printed to the terminal is explained as follows:
+
+    - `input_path`: `(str)` The input path of the image to be predicted.
+
+    - `model_settings`: `(Dict[str, bool])` Model parameters required for configuring the pipeline.
+
+        - `use_doc_orientation_classify`: `(bool)` Controls whether to enable the document orientation classification module.
+        - `use_doc_unwarping`: `(bool)` Controls whether to enable the document unwarping module.
+
+    - `angle`: `(int)` The prediction result of the document orientation classification. When enabled, the values are [0, 90, 180, 270]; when not enabled, it is -1.
+
+- Calling the `save_to_json()` method will save the above content to the specified `save_path`. If a directory is specified, the path will be `save_path/{your_img_basename}.json`; if a file is specified, it will be saved directly to that file. Since JSON files do not support saving NumPy arrays, any `numpy.array` types will be converted to lists.
+
+- Calling the `save_to_img()` method will save the visualized results to the specified `save_path`. If a directory is specified, the path will be `save_path/{your_img_basename}_doc_preprocessor_res_img.{your_img_extension}`; if a file is specified, it will be saved directly to that file. (Since the pipeline typically includes multiple result images, it is not recommended to specify a specific file path directly, as multiple images may be overwritten, leaving only the last image.)
+
+* Additionally, it is also possible to obtain visualized images with results and prediction outcomes through attributes, as detailed below:
+
+<table>
+<thead>
+<tr>
+<th>Attribute</th>
+<th>Description</th>
+</tr>
+</thead>
+<tr>
+<td rowspan="1"><code>json</code></td>
+<td rowspan="1">Retrieves the prediction results in <code>json</code> format</td>
+</tr>
+<tr>
+<td rowspan="2"><code>img</code></td>
+<td rowspan="2">Retrieves visualized images in <code>dict</code> format</td>
+</tr>
+</table>
+
+
+- The `json` attribute retrieves prediction results as a dictionary type of data, consistent with the content saved by calling the `save_to_json()` method.
+- The `img` attribute returns prediction results as a dictionary type of data. Here, the key is `preprocessed_img`, and the corresponding value is an `Image.Image` object, which is a visualized image used to display the results of the `doc_preprocessor`.
+
+Additionally, you can obtain the `doc_preprocessor` pipeline configuration file and load it for prediction. You can execute the following command to save the results in `my_path`:
+
+```
+paddlex --get_pipeline_config doc_preprocessor --save_path ./my_path
+```
+
+Once you have the configuration file, you can customize the various configurations of the `doc_preprocessor` pipeline by simply changing the `pipeline` parameter value in the `create_pipeline` method to the path of the pipeline configuration file. An example is as follows:
+
+例如,若您的配置文件保存在 `./my_path/doc_preprocessor.yaml` ,则只需执行:
+
+```python
+from paddlex import create_pipeline
+pipeline = create_pipeline(pipeline="./my_path/doc_preprocessor.yaml")
+output = pipeline.predict(
+    input="doc_test_rotated.jpg"
+    use_doc_orientation_classify=True,
+    use_doc_unwarping=True,
+)
+for res in output:
+    res.print()
+    res.save_to_img("./output/")
+    res.save_to_json("./output/")
+```
+
+<b>Note:</b> The parameters in the configuration file are for pipeline initialization. If you wish to modify the initialization parameters for the `doc_preprocessor` pipeline, you can directly edit the parameters in the configuration file and load the file for prediction. Additionally, CLI prediction also supports passing in a configuration file; simply specify the path to the configuration file using `--pipeline`.
+
+## 3. Development Integration/Deployment
+
+If the document image preprocessing pipeline meets your requirements for inference speed and accuracy, you can proceed directly with development integration/deployment.
+
+If you need to apply the document image preprocessing pipeline directly to your Python project, you can refer to the sample code in [2.2 Python Script Method](#22-python-script-method-integration).
+
+Additionally, PaddleX offers three other deployment methods, detailed as follows:
+
+🚀 <b>High-Performance Inference</b>: In real production environments, many applications have stringent performance standards for deployment strategies, especially regarding response speed, to ensure efficient system operation and a smooth user experience. To address this, PaddleX provides a high-performance inference plugin designed to deeply optimize model inference and pre/post-processing, resulting in significant end-to-end process acceleration. For detailed high-performance inference procedures, please refer to the [PaddleX High-Performance Inference Guide](../../../pipeline_deploy/high_performance_inference.en.md).
+
+☁️ <b>Service Deployment</b>: Service deployment is a common form of deployment in real production environments. By encapsulating inference functions as services, clients can access these services through network requests to obtain inference results. PaddleX supports multiple pipeline service deployment solutions. For detailed pipeline service deployment procedures, please refer to the [PaddleX Service Deployment Guide](../../../pipeline_deploy/serving.en.md).
+
+
+
+
+## 4. Custom Development
+
+If the default model weights provided by the document image preprocessing pipeline do not meet your accuracy or speed requirements in your specific scenario, you can try to further fine-tune the existing model using data from your specific domain or application scenario to enhance the recognition performance of the document image preprocessing pipeline in your context.
+
+### 4.1 Model Fine-Tuning
+
+Since the document image preprocessing pipeline consists of several modules, if the pipeline's performance does not meet expectations, it may be due to any one of these modules. You can analyze the images with poor recognition results to identify which module has issues, and then refer to the corresponding fine-tuning tutorial link in the table below to fine-tune the model.
+
+
+<table>
+  <thead>
+    <tr>
+      <th>situation</th>
+      <th>Fine-tuning model </th>
+      <th>Fine-tuning reference link</th>
+    </tr>
+  </thead>
+  <tbody>
+    <tr>
+      <td>The overall image rotation correction is inaccurate.</td>
+      <td>Image orientation classification module</td>
+      <td><a href="../../../module_usage/tutorials/ocr_modules/doc_img_orientation_classification.en.md">链接</a></td>
+    </tr>
+    <tr>
+      <td>The image distortion correction is inaccurate.</td>
+      <td>Image Unwarping</td>
+      <td>Fine-tuning is not supported at the moment.</td>
+    </tr>
+  </tbody>
+</table>
+
+### 4.2 Model Application
+
+After completing fine-tuning training with a private dataset, you can obtain a local model weights file.
+
+If you need to use the fine-tuned model weights, simply modify the pipeline configuration file by entering the local path of the fine-tuned model weights into the `model_dir` field in the pipeline configuration file.
+
+```yaml
+......
+  DocOrientationClassify:
+    module_name: doc_text_orientation
+    model_name: PP-LCNet_x1_0_doc_ori
+    model_dir: ./output/best_model/inference  # Replace it with the path of the fine-tuned document image orientation classification model weights.
+......
+```
+
+Then, refer to the command line method or Python script method in [2. Quick Start](#2-quick-start) to load the modified pipeline configuration file.
+
+## 5. Multi-Hardware Support
+
+PaddleX supports a variety of mainstream hardware devices such as NVIDIA GPU, Kunlunxin XPU, Ascend NPU, and Cambricon MLU. You can achieve seamless switching between different hardware by simply modifying the `--device` parameter.
+
+For example, if you are using an Ascend NPU for inference in a document image preprocessing pipeline, the Python command you would use is:
+
+```bash
+paddlex --pipeline doc_preprocessor \
+        --input doc_test_rotated.jpg \
+        --use_doc_orientation_classify True \
+        --use_doc_unwarping True \
+        --save_path ./output \
+        --device npu:0
+```
+
+If you want to use the document image preprocessing pipeline on more types of hardware, please refer to the [PaddleX Multi-Hardware Usage Guide](../../../other_devices_support/multi_devices_use_guide.en.md).

+ 8 - 5
docs/pipeline_usage/tutorials/ocr_pipelines/doc_preprocessor.md

@@ -12,6 +12,8 @@ comments: true
 
 <b>通用文档图像预处理</b><b>产线中包含可选用的文档图像方向分类模块和文档图像矫正模块</b>包含的模型如下。
 
+<p><b>文档图像方向分类模块(可选):</b></p>
+
 <table>
 <thead>
 <tr>
@@ -36,6 +38,7 @@ comments: true
 </table>
 <b>注:以上精度指标的评估集是自建的数据集,覆盖证件和文档等多个场景,包含 1000 张图片。GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为 8,精度类型为 FP32。</b>
 
+<p><b>文本图像矫正模块(可选):</b></p>
 
 <table>
 <thead>
@@ -282,8 +285,8 @@ for res in output:
 
     - `model_settings`: `(Dict[str, bool])` 配置产线所需的模型参数
 
-        - `use_doc_preprocessor`: `(bool)` 控制是否启用文档预处理子产线
-        - `use_textline_orientation`: `(bool)` 控制是否启用文本行方向分类功能
+        - `use_doc_orientation_classify`: `(bool)` 控制是否启用文档方向分类模块
+        - `use_doc_unwarping`: `(bool)` 控制是否启用文档扭曲矫正模块
 
     - `angle`: `(int)` 文档方向分类的预测结果。启用时取值为[0,90,180,270];未启用时为-1
 
@@ -311,9 +314,9 @@ for res in output:
 
 
 - `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
-- `img` 属性返回的预测结果是一个字典类型的数据。其中,键分别为 `doc_preprocessor_res_img` 和 `preprocessed_img`,对应的值是两个 `Image.Image` 对象:一个用于显示 doc_preprocessor 结果的可视化图像,另一个用于展示图像预处理的可视化图像。如果没有使用图像预处理子模块,则字典中只包含 `doc_preprocessor_res_img`
+- `img` 属性返回的预测结果是一个字典类型的数据。其中,键为 `preprocessed_img`,对应的值是 `Image.Image` 对象:用于显示 doc_preprocessor 结果的可视化图像。
 
-此外,您可以获取doc_preprocessor产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+此外,您可以获取 doc_preprocessor 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
 
 ```
 paddlex --get_pipeline_config doc_preprocessor --save_path ./my_path
@@ -614,7 +617,7 @@ for i, res in enumerate(result[&quot;docPreprocessorResult&quot;]):
   DocOrientationClassify:
     module_name: doc_text_orientation
     model_name: PP-LCNet_x1_0_doc_ori
-    model_dir: ./output/best_model/inference # # 替换为微调后的文档图像方向分类模型权重路径
+    model_dir: ./output/best_model/inference  # 替换为微调后的文档图像方向分类模型权重路径
 ......
 ```
 随后, 参考[2. 快速开始](#2-快速开始)中的命令行方式或Python脚本方式,加载修改后的产线配置文件即可。

+ 146 - 85
docs/pipeline_usage/tutorials/time_series_pipelines/time_series_anomaly_detection.md

@@ -5,7 +5,7 @@ comments: true
 # 时序异常检测产线使用教程
 
 ## 1. 通用时序异常检测产线介绍
-时序异常检测是一种识别时间序列数据中异常模式或行为的技术,广泛应用于网络安全、设备监控和金融欺诈检测等领域。它通过分析历史数据中的正常趋势和规律,来发现与预期行为显著不同的事件,例如突然增加的网络流量或异常的交易活动。时序异常检测能够自动识别数据中的异常点,为企业和组织提供实时警报,帮助及时应对潜在风险和问题。这项技术在保障系统稳定性和安全性方面发挥着重要作用。
+时序异常检测是一种识别时间序列数据中异常模式或行为的技术,广泛应用于网络安全、设备监控和金融欺诈检测等领域。它通过分析历史数据中的正常趋势和规律,来发现与预期行为显著不同的事件,例如突然增加的网络流量或异常的交易活动。时序异常检测能够自动识别数据中的异常点,为企业和组织提供实时警报,帮助及时应对潜在风险和问题。这项技术在保障系统稳定性和安全性方面发挥着重要作用。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/time_series/05.png">
 
@@ -52,27 +52,20 @@ comments: true
 <td>94.57</td>
 <td>320K</td>
 </tr>
-<tr>
-<td>TimesNet_ad</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/TimesNet_ad_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/TimesNet_ad_pretrained.pdparams">训练模型</a></td>
-<td>98.37</td>
-<td>94.80</td>
-<td>96.56</td>
-<td>1.3M</td>
-</tr>
 </tbody>
 </table>
 <p><b>注:以上精度指标测量自 </b><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ts_anomaly_examples.tar">PSM</a><b> 数据集。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
 
 
 ## 2. 快速开始
-PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在线体验通用时序异常检测产线的效果,也可以在本地使用命令行或 Python 体验通用时序异常检测产线的效果。
+PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在星河社区体验通用时序异常检测产线的效果,也可以在本地使用命令行或 Python 体验时序异常检测产线的效果。
 
 ### 2.1 在线体验
 您可以[在线体验](https://aistudio.baidu.com/community/app/105706/webUI?source=appCenter)通用时序异常检测产线的效果,用官方提供的 demo 进行识别,例如:
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/time_series/06.png">
 
-如果您对产线运行的效果满意,可以直接对产线进行集成部署,如果不满意,您可以利用私有数据<b>对产线中的模型进行在线微调</b>。
+如果您对产线运行的效果满意,可以直接进行集成部署。您可以选择从云端下载部署包也可以参考[2.2节本地体验](#22-本地体验)中的方法进行本地部署。果对效果不满意,您可以利用私有数据<b>对产线中的模型进行微调训练</b>。如果您具备本地训练的硬件资源,可以直接在本地开展训练;如果没有,星河零代码平台提供了一键式训练服务,无需编写代码,只需上传数据后,即可一键启动训练任务。
 
 <b>注</b>:由于时序数据和场景紧密相关,时序任务的在线体验官方内置模型仅是在一个特定场景下的模型方案,并非通用方案,不适用其他场景,因此体验方式不支持使用任意的文件来体验官方模型方案效果。但是,在完成自己场景数据下的模型训练之后,可以选择自己训练的模型方案,并使用对应场景的数据进行在线体验。
 
@@ -83,31 +76,12 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
 一行命令即可快速体验时序异常检测产线效果,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_ad.csv),并将 `--input` 替换为本地路径,进行预测
 
 ```bash
-paddlex --pipeline ts_ad --input ts_ad.csv --device gpu:0
-```
-参数说明:
-
-```
---pipeline:产线名称,此处为时序异常检测产线
---input:待处理的输入序列的本地路径或URL
---device 使用的GPU序号(例如gpu:0表示使用第0块GPU,gpu:1,2表示使用第1、2块GPU),也可选择使用CPU(--device cpu)
+paddlex --pipeline ts_anomaly_detection --input ts_ad.csv --device gpu:0 --save_path ./output
 ```
 
-在执行上述 Python 脚本时,加载的是默认的时序异常检测产线配置文件,若您需要自定义配置文件,可执行如下命令获取:
+相关的参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的参数说明。
 
-<details><summary> 👉点击展开</summary>
-
-<pre><code>paddlex --get_pipeline_config ts_ad
-</code></pre>
-<p>执行后,时序异常检测产线配置文件将被保存在当前路径。若您希望自定义保存位置,可执行如下命令(假设自定义保存位置为 <code>./my_path</code> ):</p>
-<pre><code>paddlex --get_pipeline_config ts_ad --save_path ./my_path
-</code></pre>
-<p>获取产线配置文件后,可将<code>--pipeline</code> 替换为配置文件保存路径,即可使配置文件生效。例如,若配置文件保存路径为 <code>./ts_ad.yaml</code>,只需执行:</p>
-<pre><code class="language-bash">paddlex --pipeline ./ts_ad.yaml --input ts_ad.csv --device gpu:0
-</code></pre>
-<p>其中,<code>--model</code>、<code>--device</code> 等参数无需指定,将使用配置文件中的参数。若依然指定了参数,将以指定的参数为准。</p></details>
-
-运行后,得到的结果为:
+运行后,会将结果打印到终端上,结果如下:
 
 ```
 {'input_path': 'ts_ad.csv', 'anomaly':            label
@@ -127,24 +101,27 @@ timestamp
 [96 rows x 1 columns]}
 ```
 
+运行结果参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的结果解释。
+
+时序文件结果保存在`save_path`下。
+
 #### 2.2.2 Python脚本方式集成
-几行代码即可完成产线的快速推理,以通用时序异常检测产线为例:
+上述命令行是为了快速体验查看效果,一般来说,在项目中,往往需要通过代码集成,您可以通过几行代码即可完成产线的快速推理,推理代码如下
 
 ```python
 from paddlex import create_pipeline
 
-pipeline = create_pipeline(pipeline="ts_ad")
-
+pipeline = create_pipeline(pipeline="ts_anomaly_detection")
 output = pipeline.predict("ts_ad.csv")
 for res in output:
     res.print() ## 打印预测的结构化输出
-    res.save_to_csv("./output/") ## 保存csv格式结果
+    res.save_to_csv(save_path="./output/") ## 保存csv格式结果
+    res.save_to_json(save_path="./output/") ## 保存json格式结果
 ```
-得到的结果与命令行方式相同。
 
 在上述 Python 脚本中,执行了如下几个步骤:
 
-(1)实例化 `create_pipeline` 实例化产线对象:具体参数说明如下:
+(1)通过 `create_pipeline()` 实例化产线对象:具体参数说明如下:
 
 <table>
 <thead>
@@ -160,13 +137,13 @@ for res in output:
 <td><code>pipeline</code></td>
 <td>产线名称或是产线配置文件路径。如为产线名称,则必须为 PaddleX 所支持的产线。</td>
 <td><code>str</code></td>
-<td></td>
+<td><code>None</code></td>
 </tr>
 <tr>
 <td><code>device</code></td>
-<td>产线模型推理设备。支持:“gpu”,“cpu”。</td>
+<td>产线推理设备。支持指定GPU具体卡号,如“gpu:0”,其他硬件具体卡号,如“npu:0”,CPU如“cpu”。</td>
 <td><code>str</code></td>
-<td><code>gpu</code></td>
+<td><code>gpu:0</code></td>
 </tr>
 <tr>
 <td><code>use_hpip</code></td>
@@ -176,78 +153,164 @@ for res in output:
 </tr>
 </tbody>
 </table>
-(2)调用产线对象的 `predict` 方法进行推理预测:`predict` 方法参数为`x`,用于输入待预测数据,支持多种输入方式,具体示例如下:
+
+(2)调用 ts_anomaly_detection 产线对象的 `predict()` 方法进行推理预测。该方法将返回一个 `generator`。以下是 `predict()` 方法的参数及其说明:
+
+<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|str|list</code></td>
+<td>
+<ul>
+  <li><b>Python Var</b>:如 <code>pandas.DataFrame</code> 表示的时序数据</li>
+  <li><b>str</b>:如时序文件的本地路径:<code>/root/data/ts.csv</code>;<b>如URL链接</b>,如时序文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_ad.csv">示例</a>;<b>如本地目录</b>,该目录下需包含待预测时序,如本地路径:<code>/root/data/</code></li>
+  <li><b>List</b>:列表元素需为上述类型数据,如<code>[pandas.DataFrame, pandas.DataFrame]</code>,<code>[\"/root/data/ts1.csv\", \"/root/data/ts2.csv\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code></li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>device</code></td>
+<td>产线推理设备</td>
+<td><code>str|None</code></td>
+<td>
+<ul>
+  <li><b>CPU</b>:如 <code>cpu</code> 表示使用 CPU 进行推理;</li>
+  <li><b>GPU</b>:如 <code>gpu:0</code> 表示使用第 1 块 GPU 进行推理;</li>
+  <li><b>NPU</b>:如 <code>npu:0</code> 表示使用第 1 块 NPU 进行推理;</li>
+  <li><b>XPU</b>:如 <code>xpu:0</code> 表示使用第 1 块 XPU 进行推理;</li>
+  <li><b>MLU</b>:如 <code>mlu:0</code> 表示使用第 1 块 MLU 进行推理;</li>
+  <li><b>DCU</b>:如 <code>dcu:0</code> 表示使用第 1 块 DCU 进行推理;</li>
+  <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+</tbody>
+</table>
+
+(3)对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为`csv`文件、保存为`json`文件的操作:
+
 
 <table>
 <thead>
 <tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
 <th>参数类型</th>
 <th>参数说明</th>
+<th>默认值</th>
 </tr>
 </thead>
-<tbody>
 <tr>
-<td>Python Var</td>
-<td>支持直接传入Python变量,如numpy.ndarray表示的图像数据。</td>
+<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>str</td>
-<td>支持传入待预测数据文件路径,如图像文件的本地路径:<code>/root/data/img.jpg</code>。</td>
+<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>str</td>
-<td>支持传入待预测数据文件URL,如图像文件的网络URL:<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_ad.csv">示例</a>。</td>
+<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>str</td>
-<td>支持传入本地目录,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code>。</td>
+<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>dict</td>
-<td>支持传入字典类型,字典的key需与具体任务对应,如图像分类任务对应\"img\",字典的val支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code>。</td>
+<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>list</td>
-<td>支持传入列表,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray],[\"/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>。</td>
+<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_csv()</code></td>
+<td>将结果保存为时序文件格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,支持目录或文件路径</td>
+<td>无</td>
 </tr>
-</tbody>
 </table>
-(3)调用`predict`方法获取预测结果:`predict` 方法为`generator`,因此需要通过调用获得预测结果,`predict`方法以batch为单位对数据进行预测,因此预测结果为list形式表示的一组预测结果。
 
-(4)对预测结果进行处理:每个样本的预测结果均为`dict`类型,且支持打印,或保存为文件,支持保存的类型与具体产线相关,如:
+- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下:
+    - `input_path`: `(str)` 待预测时序文件的输入路径
+    - `anomaly`: `(Pandas.DataFrame)` 时序异常检测结果,包含样本id和对应的异常检测类别。1为异常,0为正常。
+
+- 调用`save_to_json()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_ts_basename}_res.json`,如果指定为文件,则直接保存到该文件中。由于json文件不支持保存numpy数组,因此会将其中的`numpy.array`类型转换为列表形式。
+- 调用`save_to_csv()` 方法会将可视化结果保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_ts_basename}_res.csv`,如果指定为文件,则直接保存到该文件中。
+
+* 此外,也支持通过属性获取不同格式的预测结果,具体如下:
 
 <table>
 <thead>
 <tr>
-<th>方法</th>
-<th>说明</th>
-<th>方法参数</th>
+<th>属性</th>
+<th>属性说明</th>
 </tr>
 </thead>
-<tbody>
 <tr>
-<td>save_to_csv</td>
-<td>将结果保存为csv格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的 <code>json</code> 格式的结果</td>
 </tr>
 <tr>
-<td>save_to_xlsx</td>
-<td>将结果保存为表格格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
+<td rowspan = "2"><code>csv</code></td>
+<td rowspan = "2">获取格式为 <code>csv</code> 格式的结果</td>
 </tr>
-</tbody>
 </table>
+
+
+- `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
+- `csv` 属性返回的是一个`Pandas.DataFrame`类型数据,保存了时序异常检测结果。
+
+此外,您可以获取 ts_anomaly_detection 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+
+```
+paddlex --get_pipeline_config ts_anomaly_detection --save_path ./my_path
+```
+
 若您获取了配置文件,即可对时序异常检测产线各项配置进行自定义,只需要修改 `create_pipeline` 方法中的 `pipeline` 参数值为产线配置文件路径即可。
 
-例如,若您的配置文件保存在 `./my_path/ts_ad.yaml` ,则只需执行:
+例如,若您的配置文件保存在 `./my_path/ts_anomaly_detection.yaml` ,则只需执行:
 
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="./my_path/ts_ad.yaml")
+pipeline = create_pipeline(pipeline="./my_path/ts_anomaly_detection.yaml")
 output = pipeline.predict("ts_ad.csv")
 for res in output:
     res.print() ## 打印预测的结构化输出
     res.save_to_csv("./output/") ## 保存csv格式结果
+    res.save_to_json("./output/") ## 保存json格式结果
 ```
 
 ## 3. 开发集成/部署
@@ -743,15 +806,17 @@ echo &quot;Output time-series data saved at &quot; . $output_csv_path . &quot;\n
 ### 4.2 模型应用
 当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
 
-若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
+若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径填写至产线配置文件中的 `model_dir` 即可:
 
-```python
-......
-Pipeline:
-  model: DLinear_ad  #可修改为微调后模型的本地路径
-  batch_size: 1
-  device: "gpu:0"
-......
+```yaml
+pipeline_name: ts_anomaly_detection
+
+SubModules:
+  TSAnomalyDetection:
+    module_name: ts_anomaly_detection
+    model_name: DLinear_ad
+    model_dir: null  # 此处替换为您训练后得到的模型权重本地路径
+    batch_size: 1  
 ```
 
 随后, 参考本地体验中的命令行方式或 Python 脚本方式,加载修改后的产线配置文件即可。
@@ -759,14 +824,10 @@ Pipeline:
 ##  5. 多硬件支持
 PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU和寒武纪 MLU 等多种主流硬件设备,<b>仅需修改 `--device` 参数</b>即可完成不同硬件之间的无缝切换。
 
-例如,您使用英伟达 GPU 进行时序异常检测产线的推理,使用的 Python 命令为:
+例如,您使用昇腾 NPU 进行时序异常检测产线的推理,使用的 Python 命令为:
 
 ```bash
-paddlex --pipeline ts_ad --input ts_ad.csv --device gpu:0
+paddlex --pipeline ts_anomaly_detection --input ts_ad.csv --device npu:0
 ```
-此时,若您想将硬件切换为昇腾 NPU,仅需对 Python 命令中的` --device` 修改为 npu:0 即可:
 
-```bash
-paddlex --pipeline ts_ad --input ts_ad.csv --device npu:0
-```
 若您想在更多种类的硬件上使用通用时序异常检测产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。

+ 148 - 83
docs/pipeline_usage/tutorials/time_series_pipelines/time_series_classification.md

@@ -5,7 +5,7 @@ comments: true
 # 时序分类产线使用教程
 
 ## 1. 通用时序分类产线介绍
-时序分类是一种将时间序列数据归类到预定义类别的技术,广泛应用于行为识别、金融趋势分析等领域。它通过分析随时间变化的特征,识别出不同的模式或事件,例如将一段语音信号分类为“问候”或“请求”,或将股票价格走势划分为“上涨”或“下跌”。时序分类通常使用机器学习和深度学习模型,能够有效捕捉时间依赖性和变化规律,以便为数据提供准确的分类标签。这项技术在智能监控、市场预测等应用中起着关键作用。
+时序分类是一种将时间序列数据归类到预定义类别的技术,广泛应用于行为识别、金融趋势分析等领域。它通过分析随时间变化的特征,识别出不同的模式或事件,例如将一段语音信号分类为“问候”或“请求”,或将股票价格走势划分为“上涨”或“下跌”。时序分类通常使用机器学习和深度学习模型,能够有效捕捉时间依赖性和变化规律,以便为数据提供准确的分类标签。这项技术在智能监控、市场预测等应用中起着关键作用。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/time_series/01.png">
 
@@ -31,14 +31,14 @@ comments: true
 <p><b>注:以上精度指标测量自 <a href="https://paddlets.bj.bcebos.com/classification/UWaveGestureLibrary_TEST.csv">UWaveGestureLibrary</a> 数据集。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
 
 ## 2. 快速开始
-PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在线体验通用时序分类产线的效果,也可以在本地使用命令行或 Python 体验通用时序分类产线的效果。
+PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在星河社区体验通用时序分类产线的效果,也可以在本地使用命令行或 Python 体验时序分类产线的效果。
 
 ### 2.1 在线体验
 您可以[在线体验](https://aistudio.baidu.com/community/app/105707/webUI?source=appCenter)通用时序分类产线的效果,用官方提供的 demo 进行识别,例如:
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/time_series/02.png">
 
-如果您对产线运行的效果满意,可以直接对产线进行集成部署,如果不满意,您可以利用私有数据<b>对产线中的模型进行在线微调</b>。
+如果您对产线运行的效果满意,可以直接进行集成部署。您可以选择从云端下载部署包也可以参考[2.2节本地体验](#22-本地体验)中的方法进行本地部署。果对效果不满意,您可以利用私有数据<b>对产线中的模型进行微调训练</b>。如果您具备本地训练的硬件资源,可以直接在本地开展训练;如果没有,星河零代码平台提供了一键式训练服务,无需编写代码,只需上传数据后,即可一键启动训练任务。
 
 注:由于时序数据和场景紧密相关,时序任务的在线体验官方内置模型仅是在一个特定场景下的模型方案,并非通用方案,不适用其他场景,因此体验方式不支持使用任意的文件来体验官方模型方案效果。但是,在完成自己场景数据下的模型训练之后,可以选择自己训练的模型方案,并使用对应场景的数据进行在线体验。
 
@@ -49,31 +49,12 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
 一行命令即可快速体验时序分类产线效果,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_cls.csv),并将 `--input` 替换为本地路径,进行预测
 
 ```bash
-paddlex --pipeline ts_cls --input ts_cls.csv --device gpu:0
+paddlex --pipeline ts_classification --input ts_cls.csv --device gpu:0 --save_path ./output
 ```
-参数说明:
 
-```
---pipeline:产线名称,此处为时序分类产线
---input:待处理的输入序列的本地路径或URL
---device 使用的GPU序号(例如gpu:0表示使用第0块GPU,gpu:1,2表示使用第1、2块GPU),也可选择使用CPU(--device cpu)
-```
-
-在执行上述 Python 脚本时,加载的是默认的时序分类产线配置文件,若您需要自定义配置文件,可执行如下命令获取:
-
-<details><summary> 👉点击展开</summary>
-
-<pre><code>paddlex --get_pipeline_yaml ts_cls
-</code></pre>
-<p>执行后,时序分类产线配置文件将被保存在当前路径。若您希望自定义保存位置,可执行如下命令(假设自定义保存位置为<em> ./my_path</em>):</p>
-<pre><code>paddlex --get_pipeline_config ts_cls --save_path ./my_path
-</code></pre>
-<p>获取产线配置文件后,可将 <code>--pipeline</code> 替换为配置文件保存路径,即可使配置文件生效。例如,若配置文件保存路径为 <code>./ts_cls.yaml</code>,只需执行:</p>
-<pre><code class="language-bash">paddlex --pipeline ./ts_cls.yaml --input ts_cls.csv --device gpu:0
-</code></pre>
-<p>其中,<code>--model</code>、<code>--device</code> 等参数无需指定,将使用配置文件中的参数。若依然指定了参数,将以指定的参数为准。</p></details>
+相关的参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的参数说明。
 
-运行后,得到的结果为
+运行后,会将结果打印到终端上,结果如下:
 
 ```
 {'input_path': 'ts_cls.csv', 'classification':         classid     score
@@ -81,24 +62,27 @@ sample
 0             0  0.617688}
 ```
 
+运行结果参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的结果解释。
+
+时序文件结果保存在`save_path`下。
+
 #### 2.2.2 Python脚本方式集成
-几行代码即可完成产线的快速推理,以通用时序分类产线为例:
+上述命令行是为了快速体验查看效果,一般来说,在项目中,往往需要通过代码集成,您可以通过几行代码即可完成产线的快速推理,推理代码如下
 
 ```python
 from paddlex import create_pipeline
 
 pipeline = create_pipeline(pipeline="ts_cls")
-
 output = pipeline.predict("ts_cls.csv")
 for res in output:
     res.print() ## 打印预测的结构化输出
-    res.save_to_csv("./output/") ## 保存csv格式结果
+    res.save_to_csv(save_path="./output/") ## 保存csv格式结果
+    res.save_to_json(save_path="./output/") ## 保存json格式结果
 ```
-得到的结果与命令行方式相同。
 
 在上述 Python 脚本中,执行了如下几个步骤:
 
-(1)实例化 `create_pipeline` 实例化产线对象:具体参数说明如下:
+(1)通过 `create_pipeline()` 实例化产线对象:具体参数说明如下:
 
 <table>
 <thead>
@@ -114,13 +98,13 @@ for res in output:
 <td><code>pipeline</code></td>
 <td>产线名称或是产线配置文件路径。如为产线名称,则必须为 PaddleX 所支持的产线。</td>
 <td><code>str</code></td>
-<td></td>
+<td><code>None</code></td>
 </tr>
 <tr>
 <td><code>device</code></td>
-<td>产线模型推理设备。支持:“gpu”,“cpu”。</td>
+<td>产线推理设备。支持指定GPU具体卡号,如“gpu:0”,其他硬件具体卡号,如“npu:0”,CPU如“cpu”。</td>
 <td><code>str</code></td>
-<td><code>gpu</code></td>
+<td><code>gpu:0</code></td>
 </tr>
 <tr>
 <td><code>use_hpip</code></td>
@@ -130,83 +114,164 @@ for res in output:
 </tr>
 </tbody>
 </table>
-(2)调用产线对象的 `predict` 方法进行推理预测:`predict` 方法参数为`x`,用于输入待预测数据,支持多种输入方式,具体示例如下:
+
+(2)调用 ts_classification 产线对象的 `predict()` 方法进行推理预测。该方法将返回一个 `generator`。以下是 `predict()` 方法的参数及其说明:
 
 <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|str|list</code></td>
+<td>
+<ul>
+  <li><b>Python Var</b>:如 <code>pandas.DataFrame</code> 表示的时序数据</li>
+  <li><b>str</b>:如时序文件的本地路径:<code>/root/data/ts.csv</code>;<b>如URL链接</b>,如时序文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_cls.csv">示例</a>;<b>如本地目录</b>,该目录下需包含待预测时序,如本地路径:<code>/root/data/</code></li>
+  <li><b>List</b>:列表元素需为上述类型数据,如<code>[pandas.DataFrame, pandas.DataFrame]</code>,<code>[\"/root/data/ts1.csv\", \"/root/data/ts2.csv\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code></li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>device</code></td>
+<td>产线推理设备</td>
+<td><code>str|None</code></td>
+<td>
+<ul>
+  <li><b>CPU</b>:如 <code>cpu</code> 表示使用 CPU 进行推理;</li>
+  <li><b>GPU</b>:如 <code>gpu:0</code> 表示使用第 1 块 GPU 进行推理;</li>
+  <li><b>NPU</b>:如 <code>npu:0</code> 表示使用第 1 块 NPU 进行推理;</li>
+  <li><b>XPU</b>:如 <code>xpu:0</code> 表示使用第 1 块 XPU 进行推理;</li>
+  <li><b>MLU</b>:如 <code>mlu:0</code> 表示使用第 1 块 MLU 进行推理;</li>
+  <li><b>DCU</b>:如 <code>dcu:0</code> 表示使用第 1 块 DCU 进行推理;</li>
+  <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+</tbody>
+</table>
+
+(3)对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为`csv`文件、保存为`json`文件的操作:
+
+
+<table>
+<thead>
+<tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
 <th>参数类型</th>
 <th>参数说明</th>
+<th>默认值</th>
 </tr>
 </thead>
-<tbody>
 <tr>
-<td>Python Var</td>
-<td>支持直接传入Python变量,如numpy.ndarray表示的图像数据。</td>
+<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>str</td>
-<td>支持传入待预测数据文件路径,如图像文件的本地路径:<code>/root/data/img.jpg</code>。</td>
+<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>str</td>
-<td>支持传入待预测数据文件URL,如图像文件的网络URL:<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_cls.csv">示例</a>。</td>
+<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>str</td>
-<td>支持传入本地目录,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code>。</td>
+<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>dict</td>
-<td>支持传入字典类型,字典的key需与具体任务对应,如图像分类任务对应\"img\",字典的val支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code>。</td>
+<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>list</td>
-<td>支持传入列表,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray],[\"/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>。</td>
+<td><code>save_to_csv()</code></td>
+<td>将结果保存为时序文件格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,支持目录或文件路径</td>
+<td>无</td>
 </tr>
-</tbody>
 </table>
-(3)调用`predict`方法获取预测结果:`predict` 方法为`generator`,因此需要通过调用获得预测结果,`predict`方法以batch为单位对数据进行预测,因此预测结果为list形式表示的一组预测结果。
 
-(4)对预测结果进行处理:每个样本的预测结果均为`dict`类型,且支持打印,或保存为文件,支持保存的类型与具体产线相关,如:
+- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下:
+    - `input_path`: `(str)` 待预测时序文件的输入路径
+    - `classification`: `(Pandas.DataFrame)` 时序分类结果,包含样本id和对应的分类类别以及置信度得分。
+
+- 调用`save_to_json()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_ts_basename}_res.json`,如果指定为文件,则直接保存到该文件中。由于json文件不支持保存numpy数组,因此会将其中的`numpy.array`类型转换为列表形式。
+- 调用`save_to_csv()` 方法会将可视化结果保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_ts_basename}_res.csv`,如果指定为文件,则直接保存到该文件中。
+
+* 此外,也支持通过属性获取不同格式的预测结果,具体如下:
 
 <table>
 <thead>
 <tr>
-<th>方法</th>
-<th>说明</th>
-<th>方法参数</th>
+<th>属性</th>
+<th>属性说明</th>
 </tr>
 </thead>
-<tbody>
-<tr>
-<td>save_to_csv</td>
-<td>将结果保存为csv格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
-</tr>
 <tr>
-<td>save_to_html</td>
-<td>将结果保存为html格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的 <code>json</code> 格式的结果</td>
 </tr>
 <tr>
-<td>save_to_xlsx</td>
-<td>将结果保存为表格格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
+<td rowspan = "2"><code>csv</code></td>
+<td rowspan = "2">获取格式为 <code>csv</code> 格式的结果</td>
 </tr>
-</tbody>
 </table>
+
+
+- `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
+- `csv` 属性返回的是一个`Pandas.DataFrame`类型数据,保存了时序分类结果。
+
+此外,您可以获取 ts_classification 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+
+```
+paddlex --get_pipeline_config ts_classification --save_path ./my_path
+```
+
 若您获取了配置文件,即可对时序分类产线各项配置进行自定义,只需要修改 `create_pipeline` 方法中的 `pipeline` 参数值为产线配置文件路径即可。
 
 例如,若您的配置文件保存在 `./my_path/ts_cls.yaml` ,则只需执行:
 
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="./my_path/ts_forecast.yaml")
+pipeline = create_pipeline(pipeline="./my_path/ts_classification.yaml")
 output = pipeline.predict("ts_cls.csv")
 for res in output:
     res.print() ## 打印预测的结构化输出
     res.save_to_csv("./output/") ## 保存csv格式结果
+    res.save_to_json("./output/") ## 保存json格式结果
 ```
 
 ## 3. 开发集成/部署
@@ -653,37 +718,37 @@ echo &quot;label: &quot; . $result[&quot;label&quot;] . &quot;, score: &quot; .
 
 
 ## 4. 二次开发
-如果通用时序分类产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升通用时序分类产线的在您的场景中的识别效果。
+如果时序分类产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升时序分类产线的在您的场景中的识别效果。
+
 
 ### 4.1 模型微调
-由于通用时序分类产线包含时序分类模块,如果模型产线的效果不及预期,那么您需要参考[时序分类模块开发教程](../../../module_usage/tutorials/time_series_modules/time_series_classification.md)中的[二次开发](../../../module_usage/tutorials/time_series_modules/time_series_classification.md#四二次开发)章节,使用您的私有数据集对时序分类模型进行微调。
+由于时序分类产线包含时序分类模块,如果模型产线的效果不及预期,那么您需要参考[时序分类模块开发教程](../../../module_usage/tutorials/time_series_modules/time_series_classification.md)中的[二次开发](../../../module_usage/tutorials/time_series_modules/time_series_classification.md#四二次开发)章节,使用您的私有数据集对时序分类模型进行微调。
 
 ### 4.2 模型应用
 当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
 
-若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
+若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径填写至产线配置文件中的 `model_dir` 即可:
 
-```python
-......
-Pipeline:
-  model: TimesNet_cls  #可修改为微调后模型的本地路径
-  device: "gpu"
-  batch_size: 1
-......
+```yaml
+pipeline_name: ts_classification
+
+SubModules:
+  TSClassification:
+    module_name: ts_classification
+    model_name: TimesNet_cls
+    model_dir: null  # 此处替换为您训练后得到的模型权重本地路径
+    batch_size: 1   
 ```
+
 随后, 参考本地体验中的命令行方式或 Python 脚本方式,加载修改后的产线配置文件即可。
 
 ##  5. 多硬件支持
 PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU和寒武纪 MLU 等多种主流硬件设备,<b>仅需修改 `--device` 参数</b>即可完成不同硬件之间的无缝切换。
 
-例如,您使用英伟达 GPU 进行时序分类产线的推理,使用的 Python 命令为:
+例如,您使用昇腾 NPU 进行时序分类产线的推理,使用的 Python 命令为:
 
 ```bash
-paddlex --pipeline ts_cls --input ts_cls.csv --device gpu:0
+paddlex --pipeline ts_classification --input ts_cls.csv --device npu:0
 ```
-此时,若您想将硬件切换为昇腾 NPU,仅需对 Python 命令中的 `--device` 进行修改即可:
 
-```bash
-paddlex --pipeline ts_cls --input ts_cls.csv --device npu:0
-```
 若您想在更多种类的硬件上使用通用时序分类产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。

+ 186 - 100
docs/pipeline_usage/tutorials/time_series_pipelines/time_series_forecasting.md

@@ -5,7 +5,7 @@ comments: true
 # 时序预测产线使用教程
 
 ## 1. 通用时序预测产线介绍
-时序预测是一种利用历史数据来预测未来趋势的技术,通过分析时间序列数据的变化模式。广泛应用于金融市场、天气预报和销售预测等领域。时序预测通常使用统计方法或深度学习模型(如LSTM、ARIMA等),能够处理数据中的时间依赖性,以提供准确的预判,帮助决策者做出更好的规划和响应。此技术在许多行业中发挥着重要作用,如能源管理、供应链优化和市场分析等。
+时序预测是一种利用历史数据来预测未来趋势的技术,通过分析时间序列数据的变化模式。广泛应用于金融市场、天气预报和销售预测等领域。时序预测通常使用统计方法或深度学习模型(如LSTM、ARIMA等),能够处理数据中的时间依赖性,以提供准确的预判,帮助决策者做出更好的规划和响应。此技术在许多行业中发挥着重要作用,如能源管理、供应链优化和市场分析等。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/time_series/03.png">
 
@@ -15,10 +15,11 @@ comments: true
 <table>
 <thead>
 <tr>
-<th>模型</th><th>模型下载链接</th>
+<th>模型名称</th><th>模型下载链接</th>
 <th>mse</th>
 <th>mae</th>
 <th>模型存储大小(M)</th>
+<th>介绍</th>
 </tr>
 </thead>
 <tbody>
@@ -26,57 +27,66 @@ comments: true
 <td>DLinear</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/DLinear_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/DLinear_pretrained.pdparams">训练模型</a></td>
 <td>0.382</td>
 <td>0.394</td>
-<td>72K</td>
+<td>72k</td>
+<td>DLinear结构简单,效率高且易用的时序预测模型</td>
 </tr>
 <tr>
 <td>NLinear</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/NLinear_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/NLinear_pretrained.pdparams">训练模型</a></td>
 <td>0.386</td>
 <td>0.392</td>
-<td>40K</td>
+<td>40k</td>
+<td>NLinear结构简单,效率高且易用的时序预测模型</td>
+</tr>
+<tr>
+<td>RLinear</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/RLinear_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/RLinear_pretrained.pdparams">训练模型</a></td>
+<td>0.385</td>
+<td>0.392</td>
+<td>40k</td>
+<td>RLinear结构简单,效率高且易用的时序预测模型</td>
 </tr>
 <tr>
 <td>Nonstationary</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/Nonstationary_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/Nonstationary_pretrained.pdparams">训练模型</a></td>
 <td>0.600</td>
 <td>0.515</td>
-<td>55.5 M</td>
+<td>60.3M</td>
+<td>基于transformer结构,针对性优化非平稳时间序列的长时序预测模型</td>
 </tr>
 <tr>
 <td>PatchTST</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/PatchTST_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PatchTST_pretrained.pdparams">训练模型</a></td>
-<td>0.385</td>
-<td>0.397</td>
+<td>0.379</td>
+<td>0.391</td>
 <td>2.0M</td>
-</tr>
-<tr>
-<td>RLinear</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/RLinear_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/RLinear_pretrained.pdparams">训练模型</a></td>
-<td>0.384</td>
-<td>0.392</td>
-<td>40K</td>
+<td>PatchTST是兼顾局部模式和全局依赖关系的高精度长时序预测模型</td>
 </tr>
 <tr>
 <td>TiDE</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/TiDE_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/TiDE_pretrained.pdparams">训练模型</a></td>
-<td>0.405</td>
-<td>0.412</td>
+<td>0.407</td>
+<td>0.414</td>
 <td>31.7M</td>
+<td>TiDE是适用于处理多变量、长期的时间序列预测问题的高精度模型</td>
 </tr>
 <tr>
 <td>TimesNet</td><td><a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b2/TimesNet_infer.tar">推理模型</a>/<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/TimesNet_pretrained.pdparams">训练模型</a></td>
-<td>0.417</td>
-<td>0.431</td>
+<td>0.416</td>
+<td>0.429</td>
 <td>4.9M</td>
+<td>通过多周期分析,TimesNet是适应性强的高精度时间序列分析模型</td>
 </tr>
 </tbody>
 </table>
-<p><b>注:以上精度指标测量自 <a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/data/Etth1.tar">ETTH1</a>。以上所有模型 GPU 推理耗时基于 NVIDIA Tesla T4 机器,精度类型为 FP32, CPU 推理速度基于 Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz,线程数为8,精度类型为 FP32。</b></p>
+
+<p><b>注:以上精度指标测量自</b>[ETTH1](https://paddle-model-ecology.bj.bcebos.com/paddlex/data/Etth1.tar)<b>测试数据集,输入序列长度为96,预测序列长度除 TiDE 外为96,TiDE为720 。</b></p>
 
 ## 2. 快速开始
-PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可以在线体验通用时序预测产线的效果,也可以在本地使用命令行或 Python 体验通用时序预测产线的效果。
+
+PaddleX 所提供的模型产线均可以快速体验效果,你可以在星河社区体验体验通用时序预测产线的效果,也可以在本地使用命令行或 Python 体验时序预测产线的效果。
 
 ### 2.1 在线体验
-您可以[在线体验](https://aistudio.baidu.com/community/app/105706/webUI?source=appCenter)通用时序预测产线的效果,用官方提供的 demo 进行识别,例如:
+您可以[在线体验](https://aistudio.baidu.com/community/app/105706/webUI?source=appCenter)时序预测产线的效果,用官方提供的 demo 进行识别,例如:
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/pipelines/time_series/04.png">
 
-如果您对产线运行的效果满意,可以直接对产线进行集成部署,如果不满意,您可以利用私有数据<b>对产线中的模型进行在线微调</b>。
+如果您对产线运行的效果满意,可以直接进行集成部署。您可以选择从云端下载部署包也可以参考[2.2节本地体验](#22-本地体验)中的方法进行本地部署。果对效果不满意,您可以利用私有数据<b>对产线中的模型进行微调训练</b>。如果您具备本地训练的硬件资源,可以直接在本地开展训练;如果没有,星河零代码平台提供了一键式训练服务,无需编写代码,只需上传数据后,即可一键启动训练任务。
 
 注:由于时序数据和场景紧密相关,时序任务的在线体验官方内置模型仅是在一个特定场景下的模型方案,并非通用方案,不适用其他场景,因此体验方式不支持使用任意的文件来体验官方模型方案效果。但是,在完成自己场景数据下的模型训练之后,可以选择自己训练的模型方案,并使用对应场景的数据进行在线体验。
 
@@ -87,31 +97,15 @@ PaddleX 所提供的预训练的模型产线均可以快速体验效果,你可
 一行命令即可快速体验时序预测产线效果,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_fc.csv),并将 `--input` 替换为本地路径,进行预测
 
 ```bash
-paddlex --pipeline ts_fc --input ts_fc.csv --device gpu:0
-```
-参数说明:
-
-```
---pipeline:产线名称,此处为时序预测产线
---input:待处理的输入序列的本地路径或URL
---device 使用的GPU序号(例如gpu:0表示使用第0块GPU,gpu:1,2表示使用第1、2块GPU),也可选择使用CPU(--device cpu)
+paddlex --pipeline ts_forecast --input ts_fc.csv --device gpu:0 --save_path ./output
 ```
 
-在执行上述 Python 脚本时,加载的是默认的时序预测产线配置文件,若您需要自定义配置文件,可执行如下命令获取:
+相关的参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的参数说明。
 
-<details><summary> 👉点击展开</summary>
 
-<pre><code>paddlex --get_pipeline_config ts_fc
-</code></pre>
-<p>执行后,时序预测产线配置文件将被保存在当前路径。若您希望自定义保存位置,可执行如下命令(假设自定义保存位置为 <code>./my_path</code> ):</p>
-<pre><code>paddlex --get_pipeline_config ts_fc --save_path ./my_path
-</code></pre>
-<p>获取产线配置文件后,可将 <code>--pipeline</code> 替换为配置文件保存路径,即可使配置文件生效。例如,若配置文件保存路径为 <code>./ts_fc.yaml</code>,只需执行:</p>
-<pre><code class="language-bash">paddlex --pipeline ./ts_fc.yaml --input ts_fc.csv --device gpu:0
-</code></pre>
-<p>其中,<code>--model</code>、<code>--device</code> 等参数无需指定,将使用配置文件中的参数。若依然指定了参数,将以指定的参数为准。</p></details>
+运行后,会将结果打印到终端上,结果如下:
 
-运行后,得到的结果为:
+<details><summary> 👉点击展开</summary>
 
 ```
 {'input_path': 'ts_fc.csv', 'forecast':                            OT
@@ -130,25 +124,31 @@ date
 
 [96 rows x 1 columns]}
 ```
+</details>
+
+运行结果参数说明可以参考[2.2.2 Python脚本方式集成](#222-python脚本方式集成)中的结果解释。
+
+时序文件结果保存在`save_path`下。
+
 
 #### 2.2.2 Python脚本方式集成
-几行代码即可完成产线的快速推理,以通用时序预测产线为例:
+上述命令行是为了快速体验查看效果,一般来说,在项目中,往往需要通过代码集成,您可以通过几行代码即可完成产线的快速推理,推理代码如下
 
 ```python
 from paddlex import create_pipeline
 
-pipeline = create_pipeline(pipeline="ts_fc")
+pipeline = create_pipeline(pipeline="ts_forecast")
 
-output = pipeline.predict("ts_fc.csv")
+output = pipeline.predict(input="ts_fc.csv")
 for res in output:
     res.print() ## 打印预测的结构化输出
-    res.save_to_csv("./output/") ## 保存csv格式结果
+    res.save_to_csv(save_path="./output/") ## 保存csv格式结果
+    res.save_to_json(save_path="./output/") ## 保存json格式结果
 ```
-得到的结果与命令行方式相同。
 
 在上述 Python 脚本中,执行了如下几个步骤:
 
-(1)实例化 `create_pipeline` 实例化产线对象:具体参数说明如下:
+(1)通过 `create_pipeline()` 实例化产线对象:具体参数说明如下:
 
 <table>
 <thead>
@@ -164,13 +164,13 @@ for res in output:
 <td><code>pipeline</code></td>
 <td>产线名称或是产线配置文件路径。如为产线名称,则必须为 PaddleX 所支持的产线。</td>
 <td><code>str</code></td>
-<td></td>
+<td><code>None</code></td>
 </tr>
 <tr>
 <td><code>device</code></td>
-<td>产线模型推理设备。支持:“gpu”,“cpu”。</td>
+<td>产线推理设备。支持指定GPU具体卡号,如“gpu:0”,其他硬件具体卡号,如“npu:0”,CPU如“cpu”。</td>
 <td><code>str</code></td>
-<td><code>gpu</code></td>
+<td><code>gpu:0</code></td>
 </tr>
 <tr>
 <td><code>use_hpip</code></td>
@@ -180,84 +180,172 @@ for res in output:
 </tr>
 </tbody>
 </table>
-(2)调用产线对象的 `predict` 方法进行推理预测:`predict` 方法参数为`x`,用于输入待预测数据,支持多种输入方式,具体示例如下:
+
+(2)调用 ts_forecast 产线对象的 `predict()` 方法进行推理预测。该方法将返回一个 `generator`。以下是 `predict()` 方法的参数及其说明:
+
+<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|str|list</code></td>
+<td>
+<ul>
+  <li><b>Python Var</b>:如 <code>pandas.DataFrame</code> 表示的时序数据</li>
+  <li><b>str</b>:如时序文件的本地路径:<code>/root/data/ts.csv</code>;<b>如URL链接</b>,如时序文件的网络URL:<a href = "https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_fc.csv">示例</a>;<b>如本地目录</b>,该目录下需包含待预测时序,如本地路径:<code>/root/data/</code></li>
+  <li><b>List</b>:列表元素需为上述类型数据,如<code>[pandas.DataFrame, pandas.DataFrame]</code>,<code>[\"/root/data/ts1.csv\", \"/root/data/ts2.csv\"]</code>,<code>[\"/root/data1\", \"/root/data2\"]</code></li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+<tr>
+<td><code>device</code></td>
+<td>产线推理设备</td>
+<td><code>str|None</code></td>
+<td>
+<ul>
+  <li><b>CPU</b>:如 <code>cpu</code> 表示使用 CPU 进行推理;</li>
+  <li><b>GPU</b>:如 <code>gpu:0</code> 表示使用第 1 块 GPU 进行推理;</li>
+  <li><b>NPU</b>:如 <code>npu:0</code> 表示使用第 1 块 NPU 进行推理;</li>
+  <li><b>XPU</b>:如 <code>xpu:0</code> 表示使用第 1 块 XPU 进行推理;</li>
+  <li><b>MLU</b>:如 <code>mlu:0</code> 表示使用第 1 块 MLU 进行推理;</li>
+  <li><b>DCU</b>:如 <code>dcu:0</code> 表示使用第 1 块 DCU 进行推理;</li>
+  <li><b>None</b>:如果设置为 <code>None</code>, 将默认使用产线初始化的该参数值,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备;</li>
+</ul>
+</td>
+<td><code>None</code></td>
+</tr>
+</tbody>
+</table>
+
+(3)对预测结果进行处理,每个样本的预测结果均为`dict`类型,且支持打印、保存为`csv`文件、保存为`json`文件的操作:
+
 
 <table>
 <thead>
 <tr>
+<th>方法</th>
+<th>方法说明</th>
+<th>参数</th>
 <th>参数类型</th>
 <th>参数说明</th>
+<th>默认值</th>
 </tr>
 </thead>
-<tbody>
 <tr>
-<td>Python Var</td>
-<td>支持直接传入Python变量,如numpy.ndarray表示的图像数据。</td>
+<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>str</td>
-<td>支持传入待预测数据文件路径,如图像文件的本地路径:<code>/root/data/img.jpg</code>。</td>
+<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>str</td>
-<td>支持传入待预测数据文件URL,如图像文件的网络URL:<a href="https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_fc.csv">示例</a>。</td>
+<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>str</td>
-<td>支持传入本地目录,该目录下需包含待预测数据文件,如本地路径:<code>/root/data/</code>。</td>
+<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>dict</td>
-<td>支持传入字典类型,字典的key需与具体任务对应,如图像分类任务对应\"img\",字典的val支持上述类型数据,例如:<code>{\"img\": \"/root/data1\"}</code>。</td>
+<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>list</td>
-<td>支持传入列表,列表元素需为上述类型数据,如<code>[numpy.ndarray, numpy.ndarray],[\"/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>。</td>
+<td><code>save_to_csv()</code></td>
+<td>将结果保存为时序文件格式的文件</td>
+<td><code>save_path</code></td>
+<td><code>str</code></td>
+<td>保存的文件路径,支持目录或文件路径</td>
+<td>无</td>
 </tr>
-</tbody>
 </table>
-(3)调用`predict`方法获取预测结果:`predict` 方法为`generator`,因此需要通过调用获得预测结果,`predict`方法以batch为单位对数据进行预测,因此预测结果为list形式表示的一组预测结果。
 
-(4)对预测结果进行处理:每个样本的预测结果均为`dict`类型,且支持打印,或保存为文件,支持保存的类型与具体产线相关,如:
+- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下:
+
+    - `input_path`: `(str)` 待预测时序文件的输入路径
+
+    - `forecast`: `(Pandas.DataFrame)` 时序预测结果,包含预测的未来时间点和对应的预测值。
+
+- 调用`save_to_json()` 方法会将上述内容保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_ts_basename}_res.json`,如果指定为文件,则直接保存到该文件中。由于json文件不支持保存numpy数组,因此会将其中的`numpy.array`类型转换为列表形式。
+- 调用`save_to_csv()` 方法会将可视化结果保存到指定的`save_path`中,如果指定为目录,则保存的路径为`save_path/{your_ts_basename}_res.csv`,如果指定为文件,则直接保存到该文件中。
+
+* 此外,也支持通过属性获取不同格式的预测结果,具体如下:
 
 <table>
 <thead>
 <tr>
-<th>方法</th>
-<th>说明</th>
-<th>方法参数</th>
+<th>属性</th>
+<th>属性说明</th>
 </tr>
 </thead>
-<tbody>
-<tr>
-<td>save_to_csv</td>
-<td>将结果保存为csv格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
-</tr>
 <tr>
-<td>save_to_html</td>
-<td>将结果保存为html格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
+<td rowspan = "1"><code>json</code></td>
+<td rowspan = "1">获取预测的 <code>json</code> 格式的结果</td>
 </tr>
 <tr>
-<td>save_to_xlsx</td>
-<td>将结果保存为表格格式的文件</td>
-<td><code>- save_path</code>:str类型,保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致;</td>
+<td rowspan = "2"><code>csv</code></td>
+<td rowspan = "2">获取格式为 <code>csv</code> 格式的结果</td>
 </tr>
-</tbody>
 </table>
+
+
+- `json` 属性获取的预测结果为dict类型的数据,相关内容与调用 `save_to_json()` 方法保存的内容一致。
+- `csv` 属性返回的是一个`Pandas.DataFrame`类型数据,保存了时序预测结果。
+
+
+此外,您可以获取 ts_forecast 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+
+```
+paddlex --get_pipeline_config ts_forecast --save_path ./my_path
+```
+
 若您获取了配置文件,即可对时序预测产线各项配置进行自定义,只需要修改 `create_pipeline` 方法中的 `pipeline` 参数值为产线配置文件路径即可。
 
-例如,若您的配置文件保存在 `./my_path/ts_fc.yaml` ,则只需执行:
+例如,若您的配置文件保存在 `./my_path/ts_forecast.yaml` ,则只需执行:
 
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="./my_path/ts_fc.yaml")
+pipeline = create_pipeline(pipeline="./my_path/ts_forecast.yaml")
 output = pipeline.predict("ts_fc.csv")
 for res in output:
     res.print() ## 打印预测的结构化输出
     res.save_to_csv("./output/") ## 保存csv格式结果
+    res.save_to_json("./output/") ## 保存json格式结果
 ```
+
+<b>注:</b> 配置文件中的参数为产线初始化参数,如果希望更改 ts_forecasts 产线初始化参数,可以直接修改配置文件中的参数,并加载配置文件进行预测。同时,CLI 预测也支持传入配置文件,`--pipeline` 指定配置文件的路径即可。
+
+
 ## 3. 开发集成/部署
 如果产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。
 
@@ -743,7 +831,7 @@ echo &quot;Output time-series data saved at &quot; . $output_csv_path . &quot;\n
 您可以根据需要选择合适的方式部署模型产线,进而进行后续的 AI 应用集成。
 
 ## 4. 二次开发
-如果通用时序预测产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升通用时序预测产线的在您的场景中的识别效果。
+如果时序预测产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用<b>您自己拥有的特定领域或应用场景的数据</b>对现有模型进行进一步的<b>微调</b>,以提升时序预测产线的在您的场景中的识别效果。
 
 #### 4.1 模型微调
 由于通用时序预测产线包含时序预测模块,如果模型产线的效果不及预期,那么您需要参考[时序异常检测模块开发教程](../../../module_usage/tutorials/time_series_modules/time_series_forecasting.md)中的[二次开发](../../../module_usage/tutorials/time_series_modules/time_series_forecasting.md#四二次开发)章节,使用您的私有数据集对时序预测模型进行微调。
@@ -751,29 +839,27 @@ echo &quot;Output time-series data saved at &quot; . $output_csv_path . &quot;\n
 #### 4.2 模型应用
 当您使用私有数据集完成微调训练后,可获得本地模型权重文件。
 
-若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可:
+若您需要使用微调后的模型权重,只需对产线配置文件做修改,将微调后模型权重的本地路径填写至产线配置文件中的 `model_dir` 即可:
 
-```python
-......
-Pipeline:
-  model: DLinear  #可修改为微调后模型的本地路径
-  device: "gpu"
-  batch_size: 0
-......
+```yaml
+pipeline_name: ts_forecast
+
+SubModules:
+  TSForecast:
+    module_name: ts_forecast
+    model_name: DLinear
+    model_dir: null # 此处替换为您训练后得到的模型权重本地路径
+    batch_size: 1   
 ```
 随后, 参考本地体验中的命令行方式或 Python 脚本方式,加载修改后的产线配置文件即可。
 
 ##  5. 多硬件支持
 PaddleX 支持英伟达 GPU、昆仑芯 XPU、昇腾 NPU和寒武纪 MLU 等多种主流硬件设备,<b>仅需修改 `--device` 参数</b>即可完成不同硬件之间的无缝切换。
 
-例如,您使用英伟达 GPU 进行时序预测产线的推理,使用的 Python 命令为:
+例如,您使用昇腾 NPU 进行时序预测产线的推理,使用的 Python 命令为:
 
 ```bash
-paddlex --pipeline ts_fc --input ts_fc.csv --device gpu:0
+paddlex --pipeline ts_forecast --input ts_fc.csv --device npu:0
 ```
-此时,若您想将硬件切换为昇腾 NPU,仅需对 Python 命令中的 `--device` 修改为 npu:0 即可:
 
-```bash
-paddlex --pipeline ts_fc --input ts_fc.csv --device npu:0
-```
 若您想在更多种类的硬件上使用通用时序预测产线,请参考[PaddleX多硬件使用指南](../../../other_devices_support/multi_devices_use_guide.md)。

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 13 - 25
docs/pipeline_usage/tutorials/video_pipelines/video_detection.md


+ 6 - 1
paddlex/inference/pipelines_new/video_detection/pipeline.py

@@ -45,7 +45,12 @@ class VideoDetectionPipeline(BasePipeline):
         super().__init__(device=device, pp_option=pp_option, use_hpip=use_hpip)
 
         video_detection_model_config = config["SubModules"]["VideoDetection"]
-        self.video_detection_model = self.create_model(video_detection_model_config)
+        model_kwargs = {}
+        if "nms_thresh" in video_detection_model_config:
+            model_kwargs["nms_thresh"] = video_detection_model_config["nms_thresh"]
+        if "score_thresh" in video_detection_model_config:
+            model_kwargs["score_thresh"] = video_detection_model_config["score_thresh"]
+        self.video_detection_model = self.create_model(video_detection_model_config, **model_kwargs)
 
     def predict(
         self,

+ 27 - 3
paddlex/utils/pipeline_arguments.py

@@ -108,9 +108,9 @@ PIPELINE_ARGUMENTS = {
     "table_recognition": None,
     "layout_parsing": None,
     "seal_recognition": None,
-    "ts_cls": None,
-    "ts_fc": None,
-    "ts_ad": None,
+    "ts_forecast": None,
+    "ts_anomaly_detection": None,
+    "ts_classification": None,
     "formula_recognition": None,
     "instance_segmentation": None,
     "semantic_segmentation": None,
@@ -123,5 +123,29 @@ PIPELINE_ARGUMENTS = {
             "help": "Sets the Top-K value for video classification.",
         },
     ],
+    "video_detection": [
+        {
+            "name": "--nms_thresh",
+            "type": float,
+            "help": "Sets the NMS threshold for video detection.",
+        },
+        {
+            "name": "--score_thresh",
+            "type": float,
+            "help": "Sets the confidence threshold for video detection.",
+        },
+    ],
+    "doc_preprocessor":[
+        {
+            "name": "--use_doc_orientation_classify",
+            "type": bool,
+            "help": "Determines whether to use document orientation classification.",
+        },  
+        {
+            "name": "--use_doc_unwarping",
+            "type": bool,
+            "help": "Determines whether to use document unwarping.",
+        },
+    ]
 
 }

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است