Ver Fonte

update rec practical docs (#3283)

zhangyubo0722 há 9 meses atrás
pai
commit
cbe81185c2

+ 33 - 9
docs/practical_tutorials/image_classification_garbage_tutorial.en.md

@@ -17,7 +17,9 @@ PaddleX offers two ways to experience the pipelines: one is through the PaddleX
 - Local Experience:
     ```bash
     paddlex --pipeline image_classification \
-        --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png
+        --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png \
+        --device gpu:0 \
+        --save_path ./output/
     ```
 
 - AIStudio Community Experience: Go to [Baidu AIStudio Community](https://aistudio.baidu.com/pipeline/mine), click "Create Pipeline", and create a <b>General Image Classification</b> pipeline for a quick trial.
@@ -133,7 +135,7 @@ tar -xf ./dataset/trash40.tar -C ./dataset/
 To verify the dataset, simply run the following command:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=check_dataset \
     -o Global.dataset_dir=./dataset/trash40/
 ```
@@ -161,7 +163,7 @@ After executing the above command, PaddleX will verify the dataset and count the
   "analysis": {
     "histogram": "check_dataset/histogram.png"
   },
-  "dataset_path": "./dataset/trash40/",
+  "dataset_path": "trash40",
   "show_type": "image",
   "dataset_type": "ClsDataset"
 }
@@ -206,7 +208,7 @@ When splitting data, the original annotation files will be renamed as `xxx.bak`
 Before training, please ensure that you have validated the dataset. To complete PaddleX model training, simply use the following command:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=train \
     -o Global.dataset_dir=./dataset/trash40 \
     -o Train.num_classes=40
@@ -244,7 +246,7 @@ After completing model training, all outputs are saved in the specified output d
 After completing model training, you can evaluate the specified model weight file on the validation set to verify the model accuracy. To evaluate a model using PaddleX, simply use the following command:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=evaluate \
     -o Global.dataset_dir=./dataset/trash40
 ```
@@ -364,7 +366,7 @@ Changing Epochs Experiment Results:
 Replace the model in the production line with the fine-tuned model for testing. Use the [test file](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png) to perform predictions:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=predict \
     -o Predict.model_dir="output/best_model/inference" \
     -o Predict.input="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png"
@@ -379,16 +381,38 @@ The prediction results will be generated under `./output`, and the prediction re
 
 ## 7. Development Integration/Deployment
 If the General Image Classification Pipeline meets your requirements for inference speed and accuracy in the production line, you can proceed directly with development integration/deployment.
-1. Directly apply the trained model in your Python project by referring to the following sample code, and modify the `Pipeline.model` in the `paddlex/pipelines/image_classification.yaml` configuration file to your own model path:
+
+1. If you need to use the fine-tuned model weights, you can obtain the configuration file for the image_classification pipeline and load it for prediction. You can execute the following command to save the results in my_path:
+
+```
+paddlex --get_pipeline_config image_classification --save_path ./my_path
+```
+
+Fill in the local path of the fine-tuned model weights into the `model_dir` field in the configuration file. If you need to directly apply the general image classification pipeline to your Python project, you can refer to the following example:
+
+```yaml
+pipeline_name: image_classification
+
+SubModules:
+  ImageClassification:
+    module_name: image_classification
+    model_name: PP-LCNet_x0_5
+    model_dir: null # Replace this with the local path to your trained model weights
+    batch_size: 4
+    topk: 5
+```
+Subsequently, in your Python code, you can utilize the pipeline as follows:
+
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="paddlex/pipelines/image_classification.yaml")
+pipeline = create_pipeline(pipeline="my_path/image_classification.yaml")
 output = pipeline.predict("./dataset/trash40/images/test/0/img_154.jpg")
 for res in output:
     res.print() # Print the structured output of the prediction
-    res.save_to_img("./output/") # Save the visualized result image
+    res.save_to_img("./output/") # Save the visualized image of the result
     res.save_to_json("./output/") # Save the structured output of the prediction
 ```
+
 For more parameters, please refer to the [General Image Classification Pipeline Usage Tutorial](../pipeline_usage/tutorials/cv_pipelines/image_classification.en.md).
 
 2. Additionally, PaddleX offers three other deployment methods, detailed as follows:

+ 33 - 8
docs/practical_tutorials/image_classification_garbage_tutorial.md

@@ -18,7 +18,9 @@ PaddleX 提供了两种体验的方式,一种是可以直接通过 PaddleX whe
   - 本地体验方式:
     ```bash
     paddlex --pipeline image_classification \
-        --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png
+        --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png \
+        --device gpu:0 \
+        --save_path ./output/
     ```
 
   - 星河社区体验方式:前往[AI Studio 星河社区](https://aistudio.baidu.com/pipeline/mine),点击【创建产线】,创建【<b>通用图像分类</b>】产线进行快速体验;
@@ -133,7 +135,7 @@ tar -xf ./dataset/trash40.tar -C ./dataset/
 在对数据集校验时,只需一行命令:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=check_dataset \
     -o Global.dataset_dir=./dataset/trash40/
 ```
@@ -160,7 +162,7 @@ python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
   "analysis": {
     "histogram": "check_dataset/histogram.png"
   },
-  "dataset_path": "./dataset/trash40/",
+  "dataset_path": "trash40",
   "show_type": "image",
   "dataset_type": "ClsDataset"
 }
@@ -203,7 +205,7 @@ python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
 在训练之前,请确保您已经对数据集进行了校验。完成 PaddleX 模型的训练,只需如下一条命令:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=train \
     -o Global.dataset_dir=./dataset/trash40 \
     -o Train.num_classes=40
@@ -241,7 +243,7 @@ PaddleX 中每个模型都提供了模型开发的配置文件,用于设置相
 在完成模型训练后,可以对指定的模型权重文件在验证集上进行评估,验证模型精度。使用 PaddleX 进行模型评估,只需一行命令:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=evaluate \
     -o Global.dataset_dir=./dataset/trash40
 ```
@@ -361,7 +363,7 @@ python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
 将产线中的模型替换为微调后的模型进行测试,使用 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png),进行预测:
 
 ```bash
-python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
+python main.py -c paddlex/configs/modules/image_classification/PP-LCNet_x1_0.yaml \
     -o Global.mode=predict \
     -o Predict.model_dir="output/best_model/inference" \
     -o Predict.input="https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/garbage_demo.png"
@@ -376,16 +378,39 @@ python main.py -c paddlex/configs/image_classification/PP-LCNet_x1_0.yaml \
 
 ## 7. 开发集成/部署
 如果通用图像分类产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。
-1. 直接将训练好的模型应用在您的 Python 项目中,可以参考如下示例代码,并将`paddlex/pipelines/image_classification.yaml`配置文件中的`Pipeline.model`修改为自己的模型路径:
+
+1. 若您需要使用微调后的模型权重,可以获取 image_classification 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+
+```
+paddlex --get_pipeline_config image_classification --save_path ./my_path
+```
+
+将微调后模型权重的本地路径填写至产线配置文件中的 `model_dir` 即可, 若您需要将通用图像分类产线直接应用在您的 Python 项目中,可以参考 如下示例:
+
+```yaml
+pipeline_name: image_classification
+
+SubModules:
+  ImageClassification:
+    module_name: image_classification
+    model_name: PP-LCNet_x0_5
+    model_dir: null # 此处替换为您训练后得到的模型权重本地路径
+    batch_size: 4
+    topk: 5
+```
+
+随后,在您的 Python 代码中,您可以这样使用产线:
+
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="paddlex/pipelines/image_classification.yaml")
+pipeline = create_pipeline(pipeline="my_path/image_classification.yaml")
 output = pipeline.predict("./dataset/trash40/images/test/0/img_154.jpg")
 for res in output:
     res.print() # 打印预测的结构化输出
     res.save_to_img("./output/") # 保存结果可视化图像
     res.save_to_json("./output/") # 保存预测的结构化输出
 ```
+
 更多参数请参考 [图像分类产线使用教程](../pipeline_usage/tutorials/cv_pipelines/image_classification.md)。
 
 2. 此外,PaddleX 也提供了其他三种部署方式,详细说明如下:

+ 51 - 10
docs/practical_tutorials/ocr_rec_chinese_tutorial.en.md

@@ -18,6 +18,11 @@ PaddleX offers two ways to experience the pipeline: one is through the PaddleX w
     ```bash
     paddlex --pipeline OCR \
         --input https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png
+        --use_doc_orientation_classify False \
+        --use_doc_unwarping False \
+        --use_textline_orientation False \
+        --device gpu:0 \
+        --save_path ./output/
     ```
 
 - AIStudio Community Experience: Go to [Baidu AIStudio Community](https://aistudio.baidu.com/pipeline/mine), click "Create Pipeline", and create a <b>Universal OCR</b> pipeline for a quick trial.
@@ -87,7 +92,7 @@ tar -xf ./dataset/handwrite_chinese_text_rec.tar -C ./dataset/
 To verify the dataset, simply use the following command:
 
 ```bash
-python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
     -o Global.mode=check_dataset \
     -o Global.dataset_dir=./dataset/handwrite_chinese_text_rec
 ```
@@ -128,7 +133,7 @@ After executing the above command, PaddleX will verify the dataset and collect b
   "analysis": {
     "histogram": "check_dataset\/histogram.png"
   },
-  "dataset_path": "\/mnt\/liujiaxuan01\/new\/new2\/handwrite_chinese_text_rec",
+  "dataset_path": "handwrite_chinese_text_rec",
   "show_type": "image",
   "dataset_type": "MSTextRecDataset"
 }
@@ -172,7 +177,7 @@ During data splitting, the original annotation files will be renamed to `xxx.bak
 Before training, ensure that you have validated your dataset. To complete PaddleX model training, simply use the following command:
 
 ```bash
-python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
     -o Global.mode=train \
     -o Global.dataset_dir=./dataset/handwrite_chinese_text_rec
 ```
@@ -209,7 +214,7 @@ After completing model training, all outputs are saved in the specified output d
 After completing model training, you can evaluate the specified model weight file on the validation set to verify the model accuracy. To evaluate a model using PaddleX, simply use the following command:
 
 ```bash
-python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
     -o Global.mode=evaluate \
     -o Global.dataset_dir=./dataset/handwrite_chinese_text_rec
 ```
@@ -307,10 +312,10 @@ Next, based on a learning rate of 0.0002, we can increase the number of training
 Replace the model in the production line with the fine-tuned model for testing, for example:
 
 ```bash
-paddlex --pipeline OCR \
-        --model PP-OCRv4_server_det PP-OCRv4_server_rec \
-        --model_dir None output/best_accuracy/inference \
-        --input https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
+    -o Global.mode=predict \
+    -o Predict.model_dir="output/best_model/inference" \
+    -o Predict.input=https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png
 ```
 
 The prediction results will be generated under `./output`, and the prediction result for `case.jpg` is shown below:
@@ -322,16 +327,52 @@ The prediction results will be generated under `./output`, and the prediction re
 
 ## 7. Development Integration/Deployment
 If the general OCR pipeline meets your requirements for inference speed and accuracy in the production line, you can proceed directly with development integration/deployment.
-1. Directly apply the trained model in your Python project by referring to the following sample code, and modify the `Pipeline.model` in the `paddlex/pipelines/OCR.yaml` configuration file to your own model path:
+
+1. If you need to use the fine-tuned model weights, you can obtain the configuration file for the OCR pipeline and load it for prediction. You can execute the following command to save the results in my_path:
+
+```
+paddlex --get_pipeline_config OCR --save_path ./my_path
+```
+
+Fill in the local path of the fine-tuned model weights into the `model_dir` field in the configuration file. If you need to directly apply the OCR pipeline to your Python project, you can refer to the following example:
+
+```yaml
+pipeline_name: OCR
+
+text_type: general
+
+use_doc_preprocessor: True
+use_textline_orientation: True
+
+SubPipelines:
+  DocPreprocessor:
+    ...
+
+SubModules:
+  TextDetection:
+    ...
+  TextLineOrientation:
+    ...
+  TextRecognition:
+    module_name: text_recognition
+    model_name: PP-OCRv4_mobile_rec
+    model_dir: null # 此处替换为您训练后得到的模型权重本地路径
+    batch_size: 1
+    score_thresh: 0.0
+```
+
+Subsequently, in your Python code, you can utilize the pipeline as follows:
+
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="paddlex/pipelines/OCR.yaml")
+pipeline = create_pipeline(pipeline="my_path/OCR.yaml")
 output = pipeline.predict("https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png")
 for res in output:
     res.print() # Print the structured output of the prediction
     res.save_to_img("./output/") # Save the visualized image of the result
     res.save_to_json("./output/") # Save the structured output of the prediction
 ```
+
 For more parameters, please refer to the [General OCR Pipeline Usage Tutorial](../pipeline_usage/tutorials/ocr_pipelines/OCR.en.md).
 
 2. Additionally, PaddleX offers three other deployment methods, detailed as follows:

+ 52 - 10
docs/practical_tutorials/ocr_rec_chinese_tutorial.md

@@ -19,6 +19,11 @@ PaddleX 提供了两种体验的方式,一种是可以直接通过 PaddleX whe
     ```bash
     paddlex --pipeline OCR \
         --input https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png
+        --use_doc_orientation_classify False \
+        --use_doc_unwarping False \
+        --use_textline_orientation False \
+        --device gpu:0 \
+        --save_path ./output/
     ```
 
   - 星河社区体验方式:前往[AI Studio 星河社区](https://aistudio.baidu.com/pipeline/mine),点击【创建产线】,创建【<b>通用OCR</b>】产线进行快速体验;
@@ -86,7 +91,7 @@ tar -xf ./dataset/handwrite_chinese_text_rec.tar -C ./dataset/
 在对数据集校验时,只需一行命令:
 
 ```bash
-python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
     -o Global.mode=check_dataset \
     -o Global.dataset_dir=./dataset/handwrite_chinese_text_rec
 ```
@@ -127,7 +132,7 @@ python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
   "analysis": {
     "histogram": "check_dataset\/histogram.png"
   },
-  "dataset_path": "\/mnt\/liujiaxuan01\/new\/new2\/handwrite_chinese_text_rec",
+  "dataset_path": "handwrite_chinese_text_rec",
   "show_type": "image",
   "dataset_type": "MSTextRecDataset"
 }
@@ -169,7 +174,7 @@ python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
 在训练之前,请确保您已经对数据集进行了校验。完成 PaddleX 模型的训练,只需如下一条命令:
 
 ```bash
-python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
     -o Global.mode=train \
     -o Global.dataset_dir=./dataset/handwrite_chinese_text_rec
 ```
@@ -206,7 +211,7 @@ PaddleX 中每个模型都提供了模型开发的配置文件,用于设置相
 在完成模型训练后,可以对指定的模型权重文件在验证集上进行评估,验证模型精度。使用 PaddleX 进行模型评估,只需一行命令:
 
 ```bash
-python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
     -o Global.mode=evaluate \
     -o Global.dataset_dir=./dataset/handwrite_chinese_text_rec
 ```
@@ -304,13 +309,14 @@ python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml \
 将产线中的模型替换为微调后的模型进行测试,如:
 
 ```bash
-paddlex --pipeline OCR \
-        --model PP-OCRv4_server_det PP-OCRv4_server_rec \
-        --model_dir None output/best_accuracy/inference \
-        --input https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png
+python main.py -c paddlex/configs/modules/text_recognition/PP-OCRv4_server_rec.yaml \
+    -o Global.mode=predict \
+    -o Predict.model_dir="output/best_model/inference" \
+    -o Predict.input=https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png
 ```
 
 通过上述可在`./output`下生成预测结果,其中`case.jpg`的预测结果如下:
+
 <center>
 
 <img src="https://raw.githubusercontent.com/cuicheng01/PaddleX_doc_images/main/images/practical_tutorials/ocr/06.png" width="600"/>
@@ -319,16 +325,52 @@ paddlex --pipeline OCR \
 
 ## 7. 开发集成/部署
 如果通用 OCR 产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。
-1. 直接将训练好的模型应用在您的 Python 项目中,可以参考如下示例代码,并将`paddlex/pipelines/OCR.yaml`配置文件中的`Pipeline.model`修改为自己的模型路径:
+
+1. 若您需要使用微调后的模型权重,可以获取 OCR 产线配置文件,并加载配置文件进行预测。可执行如下命令将结果保存在 `my_path` 中:
+
+```
+paddlex --get_pipeline_config OCR --save_path ./my_path
+```
+
+将微调后模型权重的本地路径填写至产线配置文件中的 `model_dir` 即可, 若您需要将通用 OCR 产线直接应用在您的 Python 项目中,可以参考 如下示例:
+
+```yaml
+pipeline_name: OCR
+
+text_type: general
+
+use_doc_preprocessor: True
+use_textline_orientation: True
+
+SubPipelines:
+  DocPreprocessor:
+    ...
+
+SubModules:
+  TextDetection:
+    ...
+  TextLineOrientation:
+    ...
+  TextRecognition:
+    module_name: text_recognition
+    model_name: PP-OCRv4_mobile_rec
+    model_dir: null # 此处替换为您训练后得到的模型权重本地路径
+    batch_size: 1
+    score_thresh: 0.0
+```
+
+随后,在您的 Python 代码中,您可以这样使用产线:
+
 ```python
 from paddlex import create_pipeline
-pipeline = create_pipeline(pipeline="paddlex/pipelines/OCR.yaml")
+pipeline = create_pipeline(pipeline="my_path/OCR.yaml")
 output = pipeline.predict("https://paddle-model-ecology.bj.bcebos.com/paddlex/PaddleX3.0/doc_images/practical_tutorial/OCR_rec/case.png")
 for res in output:
     res.print() # 打印预测的结构化输出
     res.save_to_img("./output/") # 保存结果可视化图像
     res.save_to_json("./output/") # 保存预测的结构化输出
 ```
+
 更多参数请参考 [OCR 产线使用教程](../pipeline_usage/tutorials/ocr_pipelines/OCR.md)。
 
 2. 此外,PaddleX 也提供了其他三种部署方式,详细说明如下: