From 07833b7d79ae1a08921ff0d1bd5d26aad8899641 Mon Sep 17 00:00:00 2001 From: yunyaoXYY <109218879+yunyaoXYY@users.noreply.github.com> Date: Wed, 7 Dec 2022 21:17:53 +0800 Subject: [PATCH 1/4] [Bug Fix] Fix SortBoxes function for PPOCR det model (#814) * Imporve OCR Readme * Improve OCR Readme * Improve OCR Readme * Improve OCR Readme * Improve OCR Readme * Add Initialize function to PP-OCR * Add Initialize function to PP-OCR * Add Initialize function to PP-OCR * Make all the model links come from PaddleOCR * Improve OCR readme * Improve OCR readme * Improve OCR readme * Improve OCR readme * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add Readme for vision results * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add check for label file in postprocess of Rec model * Add comments to create API docs * Improve OCR comments * Rename OCR and add comments * Make sure previous python example works * Make sure previous python example works * Fix Rec model bug * Fix Rec model bug * Fix rec model bug * Add SetTrtMaxBatchSize function for TensorRT * Add SetTrtMaxBatchSize Pybind * Add set_trt_max_batch_size python function * Set TRT dynamic shape in PPOCR examples * Set TRT dynamic shape in PPOCR examples * Set TRT dynamic shape in PPOCR examples * Fix PPOCRv2 python example * Fix PPOCR dynamic input shape bug * Remove useless code * Fix PPOCR bug * Remove useless comments in PaddleSeg example * Fix quantize docs readme * Fix PP-OCRv2 readme * Modify dynamic shape in PP-OCRv2 example * Modify TRT dynamic shape for PP-OCRv2 * Fix sort box for det model Co-authored-by: Jason --- fastdeploy/vision/ocr/ppocr/utils/sorted_boxes.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fastdeploy/vision/ocr/ppocr/utils/sorted_boxes.cc b/fastdeploy/vision/ocr/ppocr/utils/sorted_boxes.cc index b0a909f9a..053215e4a 100755 --- a/fastdeploy/vision/ocr/ppocr/utils/sorted_boxes.cc +++ b/fastdeploy/vision/ocr/ppocr/utils/sorted_boxes.cc @@ -35,13 +35,16 @@ void SortBoxes(std::vector>* boxes) { if (boxes->size() == 0) { return; } - + for (int i = 0; i < boxes->size() - 1; i++) { - if (std::abs((*boxes)[i + 1][1] - (*boxes)[i][1]) < 10 && - ((*boxes)[i + 1][0] < (*boxes)[i][0])) { - std::swap((*boxes)[i], (*boxes)[i + 1]); + for (int j = i; j >=0 ; j--){ + if (std::abs((*boxes)[j + 1][1] - (*boxes)[j][1]) < 10 && + ((*boxes)[j + 1][0] < (*boxes)[j][0])) { + std::swap((*boxes)[i], (*boxes)[i + 1]); + } } } + } std::vector ArgSort(const std::vector &array) { From 647d6117f5c9094e4bb44c6a1418677c040045bb Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Wed, 7 Dec 2022 21:18:20 +0800 Subject: [PATCH 2/4] [Backend] Return paddle inference back to dev3 version (#824) back_to_dev3 --- cmake/paddle_inference.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/paddle_inference.cmake b/cmake/paddle_inference.cmake index a9bfc11c1..f1b5ee6c7 100644 --- a/cmake/paddle_inference.cmake +++ b/cmake/paddle_inference.cmake @@ -48,7 +48,7 @@ endif(WIN32) set(PADDLEINFERENCE_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/") -set(PADDLEINFERENCE_VERSION "2.4-dev4") +set(PADDLEINFERENCE_VERSION "2.4-dev3") if(WIN32) if (WITH_GPU) set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.zip") From 7112b08dc44a04535da67d1a81eca1ce7105a86d Mon Sep 17 00:00:00 2001 From: Winter <1558270516@qq.com> Date: Thu, 8 Dec 2022 10:48:38 +0800 Subject: [PATCH 3/4] [Doc] Update OCR README & some dead links (#829) [Android] 1.change OCR README message. 2.modify README links. --- .../paddleclas/android/README.md | 2 +- .../vision/ocr/PP-OCRv2/android/README.md | 128 +++++++++++++++++- .../vision/ocr/PP-OCRv3/android/README.md | 128 +++++++++++++++++- .../segmentation/paddleseg/android/README.md | 2 +- 4 files changed, 246 insertions(+), 14 deletions(-) diff --git a/examples/vision/classification/paddleclas/android/README.md b/examples/vision/classification/paddleclas/android/README.md index eba5ceceb..a9262d946 100644 --- a/examples/vision/classification/paddleclas/android/README.md +++ b/examples/vision/classification/paddleclas/android/README.md @@ -125,7 +125,7 @@ option.enableLiteFp16(); model.init(modelFile, paramFile, configFile, option); // Bitmap读取、模型预测、资源释放 同上 ... ``` -更详细的用法请参考 [MainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/examples/MainActivity.java#L207) 中的用法 +更详细的用法请参考 [MainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/classification/ClassificationMainActivity.java) 中的用法 ## 替换 FastDeploy 预测库和模型 替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-xxx-shared`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/MobileNetV1_x0_25_infer`。 diff --git a/examples/vision/ocr/PP-OCRv2/android/README.md b/examples/vision/ocr/PP-OCRv2/android/README.md index 51163d8a6..4181a93e1 100644 --- a/examples/vision/ocr/PP-OCRv2/android/README.md +++ b/examples/vision/ocr/PP-OCRv2/android/README.md @@ -27,14 +27,14 @@ | --- | --- | --- | | ![app_pic](https://user-images.githubusercontent.com/14995488/203484427-83de2316-fd60-4baf-93b6-3755f9b5559d.jpg) | ![app_res](https://user-images.githubusercontent.com/14995488/203495616-af42a5b7-d3bc-4fce-8d5e-2ed88454f618.jpg) | ![app_setup](https://user-images.githubusercontent.com/14995488/203484436-57fdd041-7dcc-4e0e-b6cb-43e5ac1e729b.jpg) | -### PP-OCRv2 & PP-OCRv3 Java API 说明 +### PP-OCRv2 Java API 说明 - 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。 PP-OCR初始化参数说明如下: - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams - labelFile: String, 可选参数,表示label标签文件所在路径,用于可视化,如 ppocr_keys_v1.txt,每一行包含一个label - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 - 与其他模型不同的是,PP-OCRv2 和 PP-OCRv3 包含 DBDetector、Classifier和Recognizer等基础模型,以及PPOCRv2和PPOCRv3等pipeline类型。 + 与其他模型不同的是,PP-OCRv2 包含 DBDetector、Classifier和Recognizer等基础模型,以及pipeline类型。 ```java // 构造函数: constructor w/o label file public DBDetector(String modelFile, String paramsFile); @@ -47,10 +47,6 @@ public PPOCRv2(); // 空构造函数,之后可以调用init初始化 // Constructor w/o classifier public PPOCRv2(DBDetector detModel, Recognizer recModel); public PPOCRv2(DBDetector detModel, Classifier clsModel, Recognizer recModel); -public PPOCRv3(); // 空构造函数,之后可以调用init初始化 -// Constructor w/o classifier -public PPOCRv3(DBDetector detModel, Recognizer recModel); -public PPOCRv3(DBDetector detModel, Classifier clsModel, Recognizer recModel); ``` - 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 ```java @@ -66,6 +62,126 @@ public boolean release(); // 释放native资源 public boolean initialized(); // 检查是否初始化成功 ``` +- RuntimeOption设置说明 + +```java +public void enableLiteFp16(); // 开启fp16精度推理 +public void disableLiteFP16(); // 关闭fp16精度推理 +public void enableLiteInt8(); // 开启int8精度推理,针对量化模型 +public void disableLiteInt8(); // 关闭int8精度推理 +public void setCpuThreadNum(int threadNum); // 设置线程数 +public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 +public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +``` + +- 模型结果OCRResult说明 +```java +public class OCRResult { + public int[][] mBoxes; // 表示单张图片检测出来的所有目标框坐标,每个框以8个int数值依次表示框的4个坐标点,顺序为左下,右下,右上,左上 + public String[] mText; // 表示多个文本框内被识别出来的文本内容 + public float[] mRecScores; // 表示文本框内识别出来的文本的置信度 + public float[] mClsScores; // 表示文本框的分类结果的置信度 + public int[] mClsLabels; // 表示文本框的方向分类类别 + public boolean mInitialized = false; // 检测结果是否有效 +} +``` +其他参考:C++/Python对应的OCRResult说明: [api/vision_results/ocr_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/ocr_result.md) + + +- 模型调用示例1:使用构造函数 +```java +import java.nio.ByteBuffer; +import android.graphics.Bitmap; +import android.opengl.GLES20; + +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.OCRResult; +import com.baidu.paddle.fastdeploy.vision.ocr.Classifier; +import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector; +import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer; + +// 模型路径 +String detModelFile = "ch_PP-OCRv2_det_infer/inference.pdmodel"; +String detParamsFile = "ch_PP-OCRv2_det_infer/inference.pdiparams"; +String clsModelFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdmodel"; +String clsParamsFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdiparams"; +String recModelFile = "ch_PP-OCRv2_rec_infer/inference.pdmodel"; +String recParamsFile = "ch_PP-OCRv2_rec_infer/inference.pdiparams"; +String recLabelFilePath = "labels/ppocr_keys_v1.txt"; +// 设置RuntimeOption +RuntimeOption detOption = new RuntimeOption(); +RuntimeOption clsOption = new RuntimeOption(); +RuntimeOption recOption = new RuntimeOption(); +detOption.setCpuThreadNum(2); +clsOption.setCpuThreadNum(2); +recOption.setCpuThreadNum(2); +detOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +clsOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +detOption.enableLiteFp16(); +clsOption.enableLiteFp16(); +recOption.enableLiteFp16(); +// 初始化模型 +DBDetector detModel = new DBDetector(detModelFile, detParamsFile, detOption); +Classifier clsModel = new Classifier(clsModelFile, clsParamsFile, clsOption); +Recognizer recModel = new Recognizer(recModelFile, recParamsFile, recLabelFilePath, recOption); +PPOCRv2 model = new PPOCRv2(detModel, clsModel, recModel); + +// 读取图片: 以下仅为读取Bitmap的伪代码 +ByteBuffer pixelBuffer = ByteBuffer.allocate(width * height * 4); +GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer); +Bitmap ARGB8888ImageBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); +ARGB8888ImageBitmap.copyPixelsFromBuffer(pixelBuffer); + +// 模型推理 +OCRResult result = model.predict(ARGB8888ImageBitmap); + +// 释放模型资源 +model.release(); +``` + +- 模型调用示例2: 在合适的程序节点,手动调用init +```java +// import 同上 ... +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.OCRResult; +import com.baidu.paddle.fastdeploy.vision.ocr.Classifier; +import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector; +import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer; +// 新建空模型 +PPOCRv2 model = new PPOCRv2(); +// 模型路径 +String detModelFile = "ch_PP-OCRv2_det_infer/inference.pdmodel"; +String detParamsFile = "ch_PP-OCRv2_det_infer/inference.pdiparams"; +String clsModelFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdmodel"; +String clsParamsFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdiparams"; +String recModelFile = "ch_PP-OCRv2_rec_infer/inference.pdmodel"; +String recParamsFile = "ch_PP-OCRv2_rec_infer/inference.pdiparams"; +String recLabelFilePath = "labels/ppocr_keys_v1.txt"; +// 设置RuntimeOption +RuntimeOption detOption = new RuntimeOption(); +RuntimeOption clsOption = new RuntimeOption(); +RuntimeOption recOption = new RuntimeOption(); +detOption.setCpuThreadNum(2); +clsOption.setCpuThreadNum(2); +recOption.setCpuThreadNum(2); +detOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +clsOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +detOption.enableLiteFp16(); +clsOption.enableLiteFp16(); +recOption.enableLiteFp16(); +// 使用init函数初始化 +DBDetector detModel = new DBDetector(detModelFile, detParamsFile, detOption); +Classifier clsModel = new Classifier(clsModelFile, clsParamsFile, clsOption); +Recognizer recModel = new Recognizer(recModelFile, recParamsFile, recLabelFilePath, recOption); +model.init(detModel, clsModel, recModel); +// Bitmap读取、模型预测、资源释放 同上 ... +``` +更详细的用法请参考 [OcrMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java)中的用法 + ## 替换 FastDeploy SDK和模型 替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models`。 - 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: diff --git a/examples/vision/ocr/PP-OCRv3/android/README.md b/examples/vision/ocr/PP-OCRv3/android/README.md index 0028547a5..f4e23ab99 100644 --- a/examples/vision/ocr/PP-OCRv3/android/README.md +++ b/examples/vision/ocr/PP-OCRv3/android/README.md @@ -27,14 +27,14 @@ | --- | --- | --- | | ![app_pic](https://user-images.githubusercontent.com/14995488/203484427-83de2316-fd60-4baf-93b6-3755f9b5559d.jpg) | ![app_res](https://user-images.githubusercontent.com/14995488/203495616-af42a5b7-d3bc-4fce-8d5e-2ed88454f618.jpg) | ![app_setup](https://user-images.githubusercontent.com/14995488/203484436-57fdd041-7dcc-4e0e-b6cb-43e5ac1e729b.jpg) | -### PP-OCRv2 & PP-OCRv3 Java API 说明 +### PP-OCRv3 Java API 说明 - 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。 PP-OCR初始化参数说明如下: - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams - labelFile: String, 可选参数,表示label标签文件所在路径,用于可视化,如 ppocr_keys_v1.txt,每一行包含一个label - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 - 与其他模型不同的是,PP-OCRv2 和 PP-OCRv3 包含 DBDetector、Classifier和Recognizer等基础模型,以及PPOCRv2和PPOCRv3等pipeline类型。 + 与其他模型不同的是,PP-OCRv3 包含 DBDetector、Classifier和Recognizer等基础模型,以及pipeline类型。 ```java // 构造函数: constructor w/o label file public DBDetector(String modelFile, String paramsFile); @@ -43,10 +43,6 @@ public Classifier(String modelFile, String paramsFile); public Classifier(String modelFile, String paramsFile, RuntimeOption option); public Recognizer(String modelFile, String paramsFile, String labelPath); public Recognizer(String modelFile, String paramsFile, String labelPath, RuntimeOption option); -public PPOCRv2(); // 空构造函数,之后可以调用init初始化 -// Constructor w/o classifier -public PPOCRv2(DBDetector detModel, Recognizer recModel); -public PPOCRv2(DBDetector detModel, Classifier clsModel, Recognizer recModel); public PPOCRv3(); // 空构造函数,之后可以调用init初始化 // Constructor w/o classifier public PPOCRv3(DBDetector detModel, Recognizer recModel); @@ -66,6 +62,126 @@ public boolean release(); // 释放native资源 public boolean initialized(); // 检查是否初始化成功 ``` +- RuntimeOption设置说明 + +```java +public void enableLiteFp16(); // 开启fp16精度推理 +public void disableLiteFP16(); // 关闭fp16精度推理 +public void enableLiteInt8(); // 开启int8精度推理,针对量化模型 +public void disableLiteInt8(); // 关闭int8精度推理 +public void setCpuThreadNum(int threadNum); // 设置线程数 +public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 +public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +``` + +- 模型结果OCRResult说明 +```java +public class OCRResult { + public int[][] mBoxes; // 表示单张图片检测出来的所有目标框坐标,每个框以8个int数值依次表示框的4个坐标点,顺序为左下,右下,右上,左上 + public String[] mText; // 表示多个文本框内被识别出来的文本内容 + public float[] mRecScores; // 表示文本框内识别出来的文本的置信度 + public float[] mClsScores; // 表示文本框的分类结果的置信度 + public int[] mClsLabels; // 表示文本框的方向分类类别 + public boolean mInitialized = false; // 检测结果是否有效 +} +``` +其他参考:C++/Python对应的OCRResult说明: [api/vision_results/ocr_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/ocr_result.md) + + +- 模型调用示例1:使用构造函数 +```java +import java.nio.ByteBuffer; +import android.graphics.Bitmap; +import android.opengl.GLES20; + +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.OCRResult; +import com.baidu.paddle.fastdeploy.vision.ocr.Classifier; +import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector; +import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer; + +// 模型路径 +String detModelFile = "ch_PP-OCRv3_det_infer/inference.pdmodel"; +String detParamsFile = "ch_PP-OCRv3_det_infer/inference.pdiparams"; +String clsModelFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdmodel"; +String clsParamsFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdiparams"; +String recModelFile = "ch_PP-OCRv3_rec_infer/inference.pdmodel"; +String recParamsFile = "ch_PP-OCRv3_rec_infer/inference.pdiparams"; +String recLabelFilePath = "labels/ppocr_keys_v1.txt"; +// 设置RuntimeOption +RuntimeOption detOption = new RuntimeOption(); +RuntimeOption clsOption = new RuntimeOption(); +RuntimeOption recOption = new RuntimeOption(); +detOption.setCpuThreadNum(2); +clsOption.setCpuThreadNum(2); +recOption.setCpuThreadNum(2); +detOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +clsOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +detOption.enableLiteFp16(); +clsOption.enableLiteFp16(); +recOption.enableLiteFp16(); +// 初始化模型 +DBDetector detModel = new DBDetector(detModelFile, detParamsFile, detOption); +Classifier clsModel = new Classifier(clsModelFile, clsParamsFile, clsOption); +Recognizer recModel = new Recognizer(recModelFile, recParamsFile, recLabelFilePath, recOption); +PPOCRv3 model = new PPOCRv3(detModel,clsModel,recModel); + +// 读取图片: 以下仅为读取Bitmap的伪代码 +ByteBuffer pixelBuffer = ByteBuffer.allocate(width * height * 4); +GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer); +Bitmap ARGB8888ImageBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); +ARGB8888ImageBitmap.copyPixelsFromBuffer(pixelBuffer); + +// 模型推理 +OCRResult result = model.predict(ARGB8888ImageBitmap); + +// 释放模型资源 +model.release(); +``` + +- 模型调用示例2: 在合适的程序节点,手动调用init +```java +// import 同上 ... +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.OCRResult; +import com.baidu.paddle.fastdeploy.vision.ocr.Classifier; +import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector; +import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer; +// 新建空模型 +PPOCRv3 model = new PPOCRv3(); +// 模型路径 +String detModelFile = "ch_PP-OCRv3_det_infer/inference.pdmodel"; +String detParamsFile = "ch_PP-OCRv3_det_infer/inference.pdiparams"; +String clsModelFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdmodel"; +String clsParamsFile = "ch_ppocr_mobile_v2.0_cls_infer/inference.pdiparams"; +String recModelFile = "ch_PP-OCRv3_rec_infer/inference.pdmodel"; +String recParamsFile = "ch_PP-OCRv3_rec_infer/inference.pdiparams"; +String recLabelFilePath = "labels/ppocr_keys_v1.txt"; +// 设置RuntimeOption +RuntimeOption detOption = new RuntimeOption(); +RuntimeOption clsOption = new RuntimeOption(); +RuntimeOption recOption = new RuntimeOption(); +detOption.setCpuThreadNum(2); +clsOption.setCpuThreadNum(2); +recOption.setCpuThreadNum(2); +detOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +clsOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +detOption.enableLiteFp16(); +clsOption.enableLiteFp16(); +recOption.enableLiteFp16(); +// 使用init函数初始化 +DBDetector detModel = new DBDetector(detModelFile, detParamsFile, detOption); +Classifier clsModel = new Classifier(clsModelFile, clsParamsFile, clsOption); +Recognizer recModel = new Recognizer(recModelFile, recParamsFile, recLabelFilePath, recOption); +model.init(detModel, clsModel, recModel); +// Bitmap读取、模型预测、资源释放 同上 ... +``` +更详细的用法请参考 [OcrMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java)中的用法 + ## 替换 FastDeploy SDK和模型 替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models`。 - 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: diff --git a/examples/vision/segmentation/paddleseg/android/README.md b/examples/vision/segmentation/paddleseg/android/README.md index 9b3fe5062..f5fc5cfa7 100644 --- a/examples/vision/segmentation/paddleseg/android/README.md +++ b/examples/vision/segmentation/paddleseg/android/README.md @@ -155,7 +155,7 @@ model.setVerticalScreenFlag(true); model.init(modelFile, paramFile, configFile, option); // Bitmap读取、模型预测、资源释放 同上 ... ``` -更详细的用法请参考 [SegmentationMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/SegmentationMainActivity.java) 中的用法 +更详细的用法请参考 [SegmentationMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationMainActivity.java) 中的用法 ## 替换 FastDeploy SDK和模型 替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`。 From b3bc76e53692c6771258d372b4292cbca81ec043 Mon Sep 17 00:00:00 2001 From: yunyaoXYY <109218879+yunyaoXYY@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:38:28 +0800 Subject: [PATCH 4/4] [Doc] Fix links in quantization readme. (#831) * Fix links in readme * Fix links in readme --- tools/common_tools/auto_compression/README.md | 12 ++++++------ tools/common_tools/auto_compression/README_EN.md | 12 ++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/common_tools/auto_compression/README.md b/tools/common_tools/auto_compression/README.md index d4b2c2546..a990eeaa3 100644 --- a/tools/common_tools/auto_compression/README.md +++ b/tools/common_tools/auto_compression/README.md @@ -112,14 +112,14 @@ FastDeploy目前为用户提供了多个模型的压缩[config](./configs/)文 ## 4. FastDeploy 部署量化模型 用户在获得量化模型之后,即可以使用FastDeploy进行部署, 部署文档请参考: 具体请用户参考示例文档: -- [YOLOv5 量化模型部署](../../examples/vision/detection/yolov5/quantize/) +- [YOLOv5 量化模型部署](../../../examples/vision/detection/yolov5/quantize/) -- [YOLOv6 量化模型部署](../../examples/vision/detection/yolov6/quantize/) +- [YOLOv6 量化模型部署](../../../examples/vision/detection/yolov6/quantize/) -- [YOLOv7 量化模型部署](../../examples/vision/detection/yolov7/quantize/) +- [YOLOv7 量化模型部署](../../../examples/vision/detection/yolov7/quantize/) -- [PadddleClas 量化模型部署](../../examples/vision/classification/paddleclas/quantize/) +- [PadddleClas 量化模型部署](../../../examples/vision/classification/paddleclas/quantize/) -- [PadddleDetection 量化模型部署](../../examples/vision/detection/paddledetection/quantize/) +- [PadddleDetection 量化模型部署](../../../examples/vision/detection/paddledetection/quantize/) -- [PadddleSegmentation 量化模型部署](../../examples/vision/segmentation/paddleseg/quantize/) +- [PadddleSegmentation 量化模型部署](../../../examples/vision/segmentation/paddleseg/quantize/) diff --git a/tools/common_tools/auto_compression/README_EN.md b/tools/common_tools/auto_compression/README_EN.md index f68022c13..9c591208d 100644 --- a/tools/common_tools/auto_compression/README_EN.md +++ b/tools/common_tools/auto_compression/README_EN.md @@ -121,10 +121,14 @@ FastDeploy currently provides users with compression [config](./configs/) files Once obtained the quantized model, developers can deploy it on FastDeploy. Please refer to the following docs for more details -- [YOLOv5 Quantized Model Deployment](../../examples/vision/detection/yolov5/quantize/) +- [YOLOv5 Quantized Model Deployment](../../../examples/vision/detection/yolov5/quantize/) -- [YOLOv6 Quantized Model Deployment](../../examples/vision/detection/yolov6/quantize/) +- [YOLOv6 Quantized Model Deployment](../../../examples/vision/detection/yolov6/quantize/) -- [YOLOv7 Quantized Model Deployment](../../examples/vision/detection/yolov7/quantize/) +- [YOLOv7 Quantized Model Deployment](../../../examples/vision/detection/yolov7/quantize/) -- [PadddleClas Quantized Model Deployment](../../examples/vision/classification/paddleclas/quantize/) +- [PadddleClas Quantized Model Deployment](../../../examples/vision/classification/paddleclas/quantize/) + +- [PadddleDetection Quantized Model Deployment](../../../examples/vision/detection/paddledetection/quantize/) + +- [PadddleSegmentation Quantized Model Deployment](../../../examples/vision/segmentation/paddleseg/quantize/)