diff --git a/examples/vision/README.md b/examples/vision/README.md index 347da1be75..cd271e5587 100755 --- a/examples/vision/README.md +++ b/examples/vision/README.md @@ -1,33 +1,36 @@ -# 视觉模型部署 +English | [简体中文](README_CN.md) -本目录下提供了各类视觉模型的部署,主要涵盖以下任务类型 +# Visual Model Deployment -| 任务类型 | 说明 | 预测结果结构体 | +This directory provides the deployment of various visual models, including the following task types + +| Task Type | Description | Predicted Structure | |:-------------- |:----------------------------------- |:-------------------------------------------------------------------------------- | -| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | [DetectionResult](../../docs/api/vision_results/detection_result.md) | -| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../docs/api/vision_results/segmentation_result.md) | -| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../docs/api/vision_results/classification_result.md) | -| FaceDetection | 人脸检测,输入图像,检测图像中人脸位置,并返回检测框坐标及人脸关键点 | [FaceDetectionResult](../../docs/api/vision_results/face_detection_result.md) | -| FaceAlignment | 人脸对齐(人脸关键点检测),输入图像,返回人脸关键点 | [FaceAlignmentResult](../../docs/api/vision_results/face_alignment_result.md) | -| KeypointDetection | 关键点检测,输入图像,返回图像中人物行为的各个关键点坐标和置信度 | [KeyPointDetectionResult](../../docs/api/vision_results/keypointdetection_result.md) | -| FaceRecognition | 人脸识别,输入图像,返回可用于相似度计算的人脸特征的embedding | [FaceRecognitionResult](../../docs/api/vision_results/face_recognition_result.md) | -| Matting | 抠图,输入图像,返回图片的前景每个像素点的Alpha值 | [MattingResult](../../docs/api/vision_results/matting_result.md) | -| OCR | 文本框检测,分类,文本框内容识别,输入图像,返回文本框坐标,文本框的方向类别以及框内的文本内容 | [OCRResult](../../docs/api/vision_results/ocr_result.md) | -| MOT | 多目标跟踪,输入图像,检测图像中物体位置,并返回检测框坐标,对象id及类别置信度 | [MOTResult](../../docs/api/vision_results/mot_result.md) | -| HeadPose | 头部姿态估计,返回头部欧拉角 | [HeadPoseResult](../../docs/api/vision_results/headpose_result.md) | +| Detection | Target detection. Input the image, detect the object’s position in the image, and return the detected box coordinates, category, and confidence coefficient | [DetectionResult](../../docs/api/vision_results/detection_result.md) | +| Segmentation | Semantic segmentation. Input the image and output the classification and confidence coefficient of each pixel | [SegmentationResult](../../docs/api/vision_results/segmentation_result.md) | +| Classification | Image classification. Input the image and output the classification result and confidence coefficient of the image | [ClassifyResult](../../docs/api/vision_results/classification_result.md) | +| FaceDetection | Face detection. Input the image, detect the position of faces in the image, and return detected box coordinates and key points of faces | [FaceDetectionResult](../../docs/api/vision_results/face_detection_result.md) | +| FaceAlignment | Face alignment(key points detection).Input the image and return face key points | [FaceAlignmentResult](../../docs/api/vision_results/face_alignment_result.md) | +| KeypointDetection | Key point detection. Input the image and return the coordinates and confidence coefficient of the key points of the person's behavior in the image | [KeyPointDetectionResult](../../docs/api/vision_results/keypointdetection_result.md) | +| FaceRecognition | Face recognition. Input the image and return an embedding of facial features that can be used for similarity calculation | [FaceRecognitionResult](../../docs/api/vision_results/face_recognition_result.md) | +| Matting | Matting. Input the image and return the Alpha value of each pixel in the foreground of the image | [MattingResult](../../docs/api/vision_results/matting_result.md) | +| OCR | Text box detection, classification, and text box content recognition. Input the image and return the text box’s coordinates, orientation category, and content | [OCRResult](../../docs/api/vision_results/ocr_result.md) | +| MOT | Multi-objective tracking. Input the image and detect the position of objects in the image, and return detected box coordinates, object id, and class confidence | [MOTResult](../../docs/api/vision_results/mot_result.md) | +| HeadPose | Head posture estimation. Return head Euler angle | [HeadPoseResult](../../docs/api/vision_results/headpose_result.md) | + +## FastDeploy API Design -## FastDeploy API设计 +Generally, visual models have a uniform task paradigm. When designing API (including C++/Python), FastDeploy conducts four steps to deploy visual models -视觉模型具有较有统一任务范式,在设计API时(包括C++/Python),FastDeploy将视觉模型的部署拆分为四个步骤 +- Model loading +- Image pre-processing +- Model Inference +- Post-processing of inference results -- 模型加载 -- 图像预处理 -- 模型推理 -- 推理结果后处理 +Targeted at the vision suite of PaddlePaddle and external popular models, FastDeploy provides an end-to-end deployment service. Users merely prepare the model and follow these steps to complete the deployment -FastDeploy针对飞桨的视觉套件,以及外部热门模型,提供端到端的部署服务,用户只需准备模型,按以下步骤即可完成整个模型的部署 +- Model Loading +- Calling the `predict`interface -- 加载模型 -- 调用`predict`接口 +When deploying visual models, FastDeploy supports one-click switching of the backend inference engine. Please refer to [How to switch model inference engine](../../docs/cn/faq/how_to_change_backend.md). -FastDeploy在各视觉模型部署时,也支持一键切换后端推理引擎,详情参阅[如何切换模型推理引擎](../../docs/cn/faq/how_to_change_backend.md)。 diff --git a/examples/vision/README_CN.md b/examples/vision/README_CN.md new file mode 100644 index 0000000000..71492d8f01 --- /dev/null +++ b/examples/vision/README_CN.md @@ -0,0 +1,34 @@ +[English](README_EN.md) | 简体中文 +# 视觉模型部署 + +本目录下提供了各类视觉模型的部署,主要涵盖以下任务类型 + +| 任务类型 | 说明 | 预测结果结构体 | +|:-------------- |:----------------------------------- |:-------------------------------------------------------------------------------- | +| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | [DetectionResult](../../docs/api/vision_results/detection_result.md) | +| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../docs/api/vision_results/segmentation_result.md) | +| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../docs/api/vision_results/classification_result.md) | +| FaceDetection | 人脸检测,输入图像,检测图像中人脸位置,并返回检测框坐标及人脸关键点 | [FaceDetectionResult](../../docs/api/vision_results/face_detection_result.md) | +| FaceAlignment | 人脸对齐(人脸关键点检测),输入图像,返回人脸关键点 | [FaceAlignmentResult](../../docs/api/vision_results/face_alignment_result.md) | +| KeypointDetection | 关键点检测,输入图像,返回图像中人物行为的各个关键点坐标和置信度 | [KeyPointDetectionResult](../../docs/api/vision_results/keypointdetection_result.md) | +| FaceRecognition | 人脸识别,输入图像,返回可用于相似度计算的人脸特征的embedding | [FaceRecognitionResult](../../docs/api/vision_results/face_recognition_result.md) | +| Matting | 抠图,输入图像,返回图片的前景每个像素点的Alpha值 | [MattingResult](../../docs/api/vision_results/matting_result.md) | +| OCR | 文本框检测,分类,文本框内容识别,输入图像,返回文本框坐标,文本框的方向类别以及框内的文本内容 | [OCRResult](../../docs/api/vision_results/ocr_result.md) | +| MOT | 多目标跟踪,输入图像,检测图像中物体位置,并返回检测框坐标,对象id及类别置信度 | [MOTResult](../../docs/api/vision_results/mot_result.md) | +| HeadPose | 头部姿态估计,返回头部欧拉角 | [HeadPoseResult](../../docs/api/vision_results/headpose_result.md) | + +## FastDeploy API设计 + +视觉模型具有较有统一任务范式,在设计API时(包括C++/Python),FastDeploy将视觉模型的部署拆分为四个步骤 + +- 模型加载 +- 图像预处理 +- 模型推理 +- 推理结果后处理 + +FastDeploy针对飞桨的视觉套件,以及外部热门模型,提供端到端的部署服务,用户只需准备模型,按以下步骤即可完成整个模型的部署 + +- 加载模型 +- 调用`predict`接口 + +FastDeploy在各视觉模型部署时,也支持一键切换后端推理引擎,详情参阅[如何切换模型推理引擎](../../docs/cn/faq/how_to_change_backend.md)。 diff --git a/examples/vision/classification/paddleclas/README.md b/examples/vision/classification/paddleclas/README.md index b0dd5ebaaf..db66eb7013 100644 --- a/examples/vision/classification/paddleclas/README.md +++ b/examples/vision/classification/paddleclas/README.md @@ -1,34 +1,36 @@ -# PaddleClas 模型部署 +English | [简体中文](README_CN.md) -## 模型版本说明 +# PaddleClas Model Deployment + +## Model Description - [PaddleClas Release/2.4](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4) -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PP-LCNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNet.md) -- [PP-LCNetV2系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNetV2.md) -- [EfficientNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/EfficientNet_and_ResNeXt101_wsl.md) -- [GhostNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) -- [MobileNet系列模型(包含v1,v2,v3)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) -- [ShuffleNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) -- [SqueezeNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Others.md) -- [Inception系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Inception.md) -- [PP-HGNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-HGNet.md) -- [ResNet系列模型(包含vd系列)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/ResNet_and_vd.md) +- [PP-LCNet Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNet.md) +- [PP-LCNetV2 Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNetV2.md) +- [EfficientNet Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/EfficientNet_and_ResNeXt101_wsl.md) +- [GhostNet Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) +- [MobileNet Models(including v1,v2,v3)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) +- [ShuffleNet Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) +- [SqueezeNet Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Others.md) +- [Inception Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Inception.md) +- [PP-HGNet Models](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-HGNet.md) +- [ResNet Models(including vd series)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/ResNet_and_vd.md) -## 准备PaddleClas部署模型 +## Prepare PaddleClas Deployment Model -PaddleClas模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) +For PaddleClas model export, refer to [Model Export](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) -注意:PaddleClas导出的模型仅包含`inference.pdmodel`和`inference.pdiparams`两个文件,但为了满足部署的需求,同时也需准备其提供的通用[inference_cls.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/deploy/configs/inference_cls.yaml)文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,开发者可直接下载此文件使用。但需根据自己的需求修改yaml文件中的配置参数,具体可比照PaddleClas模型训练[config](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4/ppcls/configs/ImageNet)中的infer部分的配置信息进行修改。 +Attention:The model exported by PaddleClas contains two files, including `inference.pdmodel` and `inference.pdiparams`. However, it is necessary to prepare the generic [inference_cls.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/deploy/configs/inference_cls.yaml) file provided by PaddleClas to meet the requirements of deployment. FastDeploy will obtain from the yaml file the preprocessing information required during inference. FastDeploy will get the preprocessing information needed by the model from the yaml file. Developers can directly download this file. But they need to modify the configuration parameters in the yaml file based on personalized needs. Refer to the configuration information in the infer section of the PaddleClas model training [config.](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4/ppcls/configs/ImageNet) -## 下载预训练模型 +## Download Pre-trained Model -为了方便开发者的测试,下面提供了PaddleClas导出的部分模型(含inference_cls.yaml文件),开发者可直接下载使用。 +For developers' testing, some models exported by PaddleClas (including the inference_cls.yaml file) are provided below. Developers can download them directly. -| 模型 | 参数文件大小 |输入Shape | Top1 | Top5 | +| Model | Parameter File Size |Input Shape | Top1 | Top5 | |:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | | [PPLCNet_x1_0](https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNet_x1_0_infer.tgz) | 12MB | 224x224 |71.32% | 90.03% | | [PPLCNetV2_base](https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNetV2_base_infer.tgz) | 26MB | 224x224 |77.04% | 93.27% | @@ -50,8 +52,8 @@ PaddleClas模型导出,请参考其文档说明[模型导出](https://github.c | [PPHGNet_base_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_base_ssld_infer.tgz) | 274MB | 224x224 | 85.0% | 97.35% | | [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz) | 98MB | 224x224 | 79.12% | 94.44% | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) -- [服务化部署](serving) +- [Python Deployment](python) +- [C++ Deployment](cpp) +- [Serving Deployment](serving) diff --git a/examples/vision/classification/paddleclas/README_CN.md b/examples/vision/classification/paddleclas/README_CN.md new file mode 100644 index 0000000000..5f46d51fd1 --- /dev/null +++ b/examples/vision/classification/paddleclas/README_CN.md @@ -0,0 +1,58 @@ +[English](README.md) | 简体中文 +# PaddleClas 模型部署 + +## 模型版本说明 + +- [PaddleClas Release/2.4](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4) + +目前FastDeploy支持如下模型的部署 + +- [PP-LCNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNet.md) +- [PP-LCNetV2系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNetV2.md) +- [EfficientNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/EfficientNet_and_ResNeXt101_wsl.md) +- [GhostNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) +- [MobileNet系列模型(包含v1,v2,v3)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) +- [ShuffleNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) +- [SqueezeNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Others.md) +- [Inception系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Inception.md) +- [PP-HGNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-HGNet.md) +- [ResNet系列模型(包含vd系列)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/ResNet_and_vd.md) + +## 准备PaddleClas部署模型 + +PaddleClas模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) + +注意:PaddleClas导出的模型仅包含`inference.pdmodel`和`inference.pdiparams`两个文件,但为了满足部署的需求,同时也需准备其提供的通用[inference_cls.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/deploy/configs/inference_cls.yaml)文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,开发者可直接下载此文件使用。但需根据自己的需求修改yaml文件中的配置参数,具体可比照PaddleClas模型训练[config](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4/ppcls/configs/ImageNet)中的infer部分的配置信息进行修改。 + + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleClas导出的部分模型(含inference_cls.yaml文件),开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | Top1 | Top5 | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | +| [PPLCNet_x1_0](https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNet_x1_0_infer.tgz) | 12MB | 224x224 |71.32% | 90.03% | +| [PPLCNetV2_base](https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNetV2_base_infer.tgz) | 26MB | 224x224 |77.04% | 93.27% | +| [EfficientNetB7](https://bj.bcebos.com/paddlehub/fastdeploy/EfficientNetB7_infer.tgz) | 255MB | 600x600 | 84.3% | 96.9% | +| [EfficientNetB0_small](https://bj.bcebos.com/paddlehub/fastdeploy/EfficientNetB0_small_infer.tgz)| 18MB | 224x224 | 75.8% | 75.8% | +| [GhostNet_x1_3_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/GhostNet_x1_3_ssld_infer.tgz) | 29MB | 224x224 | 75.7% | 92.5% | +| [GhostNet_x0_5](https://bj.bcebos.com/paddlehub/fastdeploy/GhostNet_x0_5_infer.tgz) | 10MB | 224x224 | 66.8% | 86.9% | +| [MobileNetV1_x0_25](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_x0_25_infer.tgz) | 1.9MB | 224x224 | 51.4% | 75.5% | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_ssld_infer.tgz) | 17MB | 224x224 | 77.9% | 93.9% | +| [MobileNetV2_x0_25](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV2_x0_25_infer.tgz) | 5.9MB | 224x224 | 53.2% | 76.5% | +| [MobileNetV2_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV2_ssld_infer.tgz) | 14MB | 224x224 | 76.74% | 93.39% | +| [MobileNetV3_small_x0_35_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV3_small_x0_35_ssld_infer.tgz) | 6.4MB | 224x224 | 55.55% | 77.71% | +| [MobileNetV3_large_x1_0_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV3_large_x1_0_ssld_infer.tgz) | 22MB | 224x224 | 78.96% | 94.48% | +| [ShuffleNetV2_x0_25](https://bj.bcebos.com/paddlehub/fastdeploy/ShuffleNetV2_x0_25_infer.tgz) | 2.4MB | 224x224 | 49.9% | 73.79% | +| [ShuffleNetV2_x2_0](https://bj.bcebos.com/paddlehub/fastdeploy/ShuffleNetV2_x2_0_infer.tgz) | 29MB | 224x224 | 73.15% | 91.2% | +| [SqueezeNet1_1](https://bj.bcebos.com/paddlehub/fastdeploy/SqueezeNet1_1_infer.tgz) | 4.8MB | 224x224 | 60.1% | 81.9% | +| [InceptionV3](https://bj.bcebos.com/paddlehub/fastdeploy/InceptionV3_infer.tgz) | 92MB | 299x299 | 79.14% | 94.59% | +| [PPHGNet_tiny_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_tiny_ssld_infer.tgz) | 57MB | 224x224 | 81.95% | 96.12% | +| [PPHGNet_base_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_base_ssld_infer.tgz) | 274MB | 224x224 | 85.0% | 97.35% | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz) | 98MB | 224x224 | 79.12% | 94.44% | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) +- [服务化部署](serving) diff --git a/examples/vision/classification/paddleclas/a311d/README.md b/examples/vision/classification/paddleclas/a311d/README.md index b0d988da9e..e4a57bcf6c 100755 --- a/examples/vision/classification/paddleclas/a311d/README.md +++ b/examples/vision/classification/paddleclas/a311d/README.md @@ -1,11 +1,12 @@ -# PaddleClas 量化模型在 A311D 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PaddleClas 量化模型到 A311D 上。 +English | [简体中文](README_CN.md) +# Deploy PaddleClas Quantification Model on A311D +Now FastDeploy supports the deployment of PaddleClas quantification model to A311D based on Paddle Lite. -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +For model quantification and download, refer to [model quantification](../quantize/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -在 A311D 上只支持 C++ 的部署。 +Only C++ deployment is supported on A311D. -- [C++部署](cpp) +- [C++ deployment](cpp) diff --git a/examples/vision/classification/paddleclas/a311d/README_CN.md b/examples/vision/classification/paddleclas/a311d/README_CN.md new file mode 100644 index 0000000000..bd38afd840 --- /dev/null +++ b/examples/vision/classification/paddleclas/a311d/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# PaddleClas 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 PaddleClas 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/classification/paddleclas/android/README.md b/examples/vision/classification/paddleclas/android/README.md index a9262d946c..68dbfc939b 100644 --- a/examples/vision/classification/paddleclas/android/README.md +++ b/examples/vision/classification/paddleclas/android/README.md @@ -1,81 +1,82 @@ -## 图像分类 PaddleClas Android Demo 使用文档 +English | [简体中文](README_CN.md) +## PaddleClas Android Demo Tutorial -在 Android 上实现实时的图像分类功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 +Real-time image classification on Android. This demo is easy to use for everyone. For example, you can run your own trained model in the Demo. -## 环境准备 +## Prepare the Environment -1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 -2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` +1. Install Android Studio in your local environment. Refer to [Android Studio Official Website](https://developer.android.com/studio) for detailed tutorial. +2. Prepare an Android phone and turn on the USB debug mode: `Settings -> Find developer options -> Open developer options and USB debug mode` -## 部署步骤 +## Deployment steps -1. 目标检测 PaddleClas Demo 位于 `fastdeploy/examples/vision/classification/paddleclas/android` 目录 -2. 用 Android Studio 打开 paddleclas/android 工程 -3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) +1. The target detection PaddleClas Demo is located in the `fastdeploy/examples/vision/classification/paddleclas/android` +2. Open paddleclas/android project with Android Studio +3. Connect the phone to the computer, turn on USB debug mode and file transfer mode, and connect your phone to Android Studio (allow the phone to install software from USB)

image

-> **注意:** ->> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 +> **Attention:** +>> If you encounter an NDK configuration error during import, compilation or running, open ` File > Project Structure > SDK Location` and change the path of SDK configured by the `Andriod SDK location`. -4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库,需要联网) -成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 +4. Click the Run button to automatically compile the APP and install it to the phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files. Internet is required). +The final effect is as follows. Figure 1: Install the APP on the phone; Figure 2: The effect when opening the APP. It will automatically recognize and mark the objects in the image; Figure 3: APP setting option. Click setting in the upper right corner and modify your options. - | APP 图标 | APP 效果 | APP设置项 + | APP Icon | APP Effect | APP Settings | --- | --- | --- | | ![app_pic ](https://user-images.githubusercontent.com/14995488/203484427-83de2316-fd60-4baf-93b6-3755f9b5559d.jpg) | ![app_res](https://user-images.githubusercontent.com/14995488/203494666-16528cb3-0ce2-48fc-9f9e-37da17b2c2f6.jpg) | ![app_setup](https://user-images.githubusercontent.com/14995488/203484436-57fdd041-7dcc-4e0e-b6cb-43e5ac1e729b.jpg) | -## PaddleClasModel Java API 说明 -- 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。PaddleClasModel初始化参数说明如下: - - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel - - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams - - configFile: String, 模型推理的预处理配置文件,如 infer_cfg.yml - - labelFile: String, 可选参数,表示label标签文件所在路径,用于可视化,如 imagenet1k_label_list.txt,每一行包含一个label - - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 +## PaddleClasModel Java API Description +- Model initialized API: The initialized API contains two ways: Firstly, initialize directly through the constructor. Secondly, initialize at the appropriate program node by calling the init function. PaddleClasModel initialization parameters are as follows. + - modelFile: String. Model file path in paddle format, such as model.pdmodel + - paramFile: String. Parameter file path in paddle format, such as model.pdiparams + - configFile: String. Preprocessing file for model inference, such as infer_cfg.yml + - labelFile: String. This optional parameter indicates the path of the label file and is used for visualization, such as imagenet1k_label_list.txt, each line containing one label + - option: RuntimeOption. Optional parameter for model initialization. Default runtime options if not passing the parameter. ```java -// 构造函数: constructor w/o label file -public PaddleClasModel(); // 空构造函数,之后可以调用init初始化 +// Constructor: constructor w/o label file +public PaddleClasModel(); // An empty constructor, which can be initialized by calling init public PaddleClasModel(String modelFile, String paramsFile, String configFile); public PaddleClasModel(String modelFile, String paramsFile, String configFile, String labelFile); public PaddleClasModel(String modelFile, String paramsFile, String configFile, RuntimeOption option); public PaddleClasModel(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); -// 手动调用init初始化: call init manually w/o label file +// Call init manually for initialization: call init manually w/o label file public boolean init(String modelFile, String paramsFile, String configFile, RuntimeOption option); public boolean init(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); ``` -- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +- Model Prediction API: The Model Prediction API contains an API for direct prediction and an API for visualization. In direct prediction, we do not save the image and render the result on Bitmap. Instead, we merely predict the inference result. For prediction and visualization, the results are both predicted and visualized, the visualized images are saved to the specified path, and the visualized results are rendered in Bitmap (Now Bitmap in ARGB8888 format is supported). Afterward, the Bitmap can be displayed on the camera. ```java -// 直接预测:不保存图片以及不渲染结果到Bitmap上 +// Direct prediction: No image saving and no result rendering to Bitmap public ClassifyResult predict(Bitmap ARGB8888Bitmap); -// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +// Prediction and visualization: Predict and visualize the results, save the visualized image to the specified path, and render the visualized results on Bitmap public ClassifyResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold) ``` -- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +- Model resource release API: Call release() API to release model resources. Return true for successful release and false for failure; call initialized() to determine whether the model was initialized successfully, with true indicating successful initialization and false indicating failure. ```java -public boolean release(); // 释放native资源 -public boolean initialized(); // 检查是否初始化成功 +public boolean release(); // Realise native resources +public boolean initialized(); // Check if initialization is successful ``` -- RuntimeOption设置说明 +- RuntimeOption settings ```java -public void enableLiteFp16(); // 开启fp16精度推理 -public void disableLiteFP16(); // 关闭fp16精度推理 -public void setCpuThreadNum(int threadNum); // 设置线程数 -public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 -public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 -public void enableRecordTimeOfRuntime(); // 是否打印模型运行耗时 +public void enableLiteFp16(); // Enable fp16 accuracy inference +public void disableLiteFP16(); // Disable fp16 accuracy inference +public void setCpuThreadNum(int threadNum); // Set thread numbers +public void setLitePowerMode(LitePowerMode mode); // Set power mode +public void setLitePowerMode(String modeStr); // Set power mode through character string +public void enableRecordTimeOfRuntime(); // Whether the print model is time-consuming ``` -- 模型结果ClassifyResult说明 +- Model ClassifyResult ```java -public float[] mScores; // [n] 得分 -public int[] mLabelIds; // [n] 分类ID -public boolean initialized(); // 检测结果是否有效 +public float[] mScores; // [n] Score +public int[] mLabelIds; // [n] Classification ID +public boolean initialized(); // Whether the result is valid or not ``` -- 模型调用示例1:使用构造函数以及默认的RuntimeOption +- Model Calling Example 1: Using Constructor or Default RuntimeOption ```java import java.nio.ByteBuffer; import android.graphics.Bitmap; @@ -84,67 +85,67 @@ import android.opengl.GLES20; import com.baidu.paddle.fastdeploy.vision.ClassifyResult; import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel; -// 初始化模型 +// Initialize the model PaddleClasModel model = new PaddleClasModel("MobileNetV1_x0_25_infer/inference.pdmodel", "MobileNetV1_x0_25_infer/inference.pdiparams", "MobileNetV1_x0_25_infer/inference_cls.yml"); -// 读取图片: 以下仅为读取Bitmap的伪代码 +// Read the image: The following is merely the pseudo code to read the 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); -// 模型推理 +// Model inference ClassifyResult result = model.predict(ARGB8888ImageBitmap); -// 释放模型资源 +// Release model resources model.release(); ``` -- 模型调用示例2: 在合适的程序节点,手动调用init,并自定义RuntimeOption +- Model calling example 2: Manually call init at the appropriate program node and self-define RuntimeOption ```java -// import 同上 ... +// import is as the above... import com.baidu.paddle.fastdeploy.RuntimeOption; import com.baidu.paddle.fastdeploy.LitePowerMode; import com.baidu.paddle.fastdeploy.vision.ClassifyResult; import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel; -// 新建空模型 +// Create an empty model PaddleClasModel model = new PaddleClasModel(); -// 模型路径 +// Model path String modelFile = "MobileNetV1_x0_25_infer/inference.pdmodel"; String paramFile = "MobileNetV1_x0_25_infer/inference.pdiparams"; String configFile = "MobileNetV1_x0_25_infer/inference_cls.yml"; -// 指定RuntimeOption +// Specify RuntimeOption RuntimeOption option = new RuntimeOption(); option.setCpuThreadNum(2); option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); option.enableRecordTimeOfRuntime(); option.enableLiteFp16(); -// 使用init函数初始化 +// Use init function for initialization model.init(modelFile, paramFile, configFile, option); -// Bitmap读取、模型预测、资源释放 同上 ... +// Bitmap reading, model prediction, and resource release are as above ... ``` -更详细的用法请参考 [MainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/classification/ClassificationMainActivity.java) 中的用法 +Refer to [MainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/classification/ClassificationMainActivity.java) for more information -## 替换 FastDeploy 预测库和模型 -替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-xxx-shared`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/MobileNetV1_x0_25_infer`。 -- 替换FastDeploy预测库的步骤: - - 下载或编译最新的FastDeploy Android预测库,解压缩后放在 `app/libs` 目录下; - - 修改 `app/src/main/cpp/CMakeLists.txt` 中的预测库路径,指向您下载或编译的预测库路径。如: +## Replace FastDeploy Prediction Library and Models +It’s simple to replace the FastDeploy prediction library and models. The prediction library is located at `app/libs/fastdeploy-android-xxx-shared`, where `xxx` represents the version of your prediction library. The models are located at `app/src/main/assets/models/MobileNetV1_x0_25_infer`. +- Steps to replace FastDeploy prediction library: + - Download or compile the latest FastDeploy Android SDK, unzip and place it in the `app/libs`; + - Modify the default value of the model path in `app/src/main/cpp/CMakeLists.txt` and to the prediction library path you download or compile. For example, ```cmake set(FastDeploy_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/fastdeploy-android-xxx-shared") ``` -- 替换PaddleClas模型的步骤: - - 将您的PaddleClas分类模型放在 `app/src/main/assets/models` 目录下; - - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +- Steps to replace PaddleClas models: + - Put your PaddleClas model in `app/src/main/assets/models`; + - Modify the default value of the model path in `app/src/main/res/values/strings.xml`. For example, ```xml - + models/MobileNetV1_x0_25_infer labels/imagenet1k_label_list.txt ``` -## 更多参考文档 -如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: -- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) -- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) +## More Reference Documents +For more FastDeploy Java API documentes and how to access FastDeploy C++ API via JNI, refer to: +- [Use FastDeploy Java SDK in Android](../../../../../java/android/) +- [Use FastDeploy C++ SDK in Android](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/classification/paddleclas/android/README_CN.md b/examples/vision/classification/paddleclas/android/README_CN.md new file mode 100644 index 0000000000..ee4ec75912 --- /dev/null +++ b/examples/vision/classification/paddleclas/android/README_CN.md @@ -0,0 +1,151 @@ +[English](README.md) | 简体中文 +## 图像分类 PaddleClas Android Demo 使用文档 + +在 Android 上实现实时的图像分类功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 + +## 环境准备 + +1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 +2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` + +## 部署步骤 + +1. 目标检测 PaddleClas Demo 位于 `fastdeploy/examples/vision/classification/paddleclas/android` 目录 +2. 用 Android Studio 打开 paddleclas/android 工程 +3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) + +

+image +

+ +> **注意:** +>> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 + +4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库,需要联网) +成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 + + | APP 图标 | APP 效果 | APP设置项 + | --- | --- | --- | + | ![app_pic ](https://user-images.githubusercontent.com/14995488/203484427-83de2316-fd60-4baf-93b6-3755f9b5559d.jpg) | ![app_res](https://user-images.githubusercontent.com/14995488/203494666-16528cb3-0ce2-48fc-9f9e-37da17b2c2f6.jpg) | ![app_setup](https://user-images.githubusercontent.com/14995488/203484436-57fdd041-7dcc-4e0e-b6cb-43e5ac1e729b.jpg) | + +## PaddleClasModel Java API 说明 +- 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。PaddleClasModel初始化参数说明如下: + - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel + - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams + - configFile: String, 模型推理的预处理配置文件,如 infer_cfg.yml + - labelFile: String, 可选参数,表示label标签文件所在路径,用于可视化,如 imagenet1k_label_list.txt,每一行包含一个label + - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 + +```java +// 构造函数: constructor w/o label file +public PaddleClasModel(); // 空构造函数,之后可以调用init初始化 +public PaddleClasModel(String modelFile, String paramsFile, String configFile); +public PaddleClasModel(String modelFile, String paramsFile, String configFile, String labelFile); +public PaddleClasModel(String modelFile, String paramsFile, String configFile, RuntimeOption option); +public PaddleClasModel(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); +// 手动调用init初始化: call init manually w/o label file +public boolean init(String modelFile, String paramsFile, String configFile, RuntimeOption option); +public boolean init(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); +``` +- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +```java +// 直接预测:不保存图片以及不渲染结果到Bitmap上 +public ClassifyResult predict(Bitmap ARGB8888Bitmap); +// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +public ClassifyResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold) +``` +- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +```java +public boolean release(); // 释放native资源 +public boolean initialized(); // 检查是否初始化成功 +``` +- RuntimeOption设置说明 +```java +public void enableLiteFp16(); // 开启fp16精度推理 +public void disableLiteFP16(); // 关闭fp16精度推理 +public void setCpuThreadNum(int threadNum); // 设置线程数 +public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 +public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +public void enableRecordTimeOfRuntime(); // 是否打印模型运行耗时 +``` + +- 模型结果ClassifyResult说明 +```java +public float[] mScores; // [n] 得分 +public int[] mLabelIds; // [n] 分类ID +public boolean initialized(); // 检测结果是否有效 +``` + +- 模型调用示例1:使用构造函数以及默认的RuntimeOption +```java +import java.nio.ByteBuffer; +import android.graphics.Bitmap; +import android.opengl.GLES20; + +import com.baidu.paddle.fastdeploy.vision.ClassifyResult; +import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel; + +// 初始化模型 +PaddleClasModel model = new PaddleClasModel("MobileNetV1_x0_25_infer/inference.pdmodel", + "MobileNetV1_x0_25_infer/inference.pdiparams", + "MobileNetV1_x0_25_infer/inference_cls.yml"); + +// 读取图片: 以下仅为读取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); + +// 模型推理 +ClassifyResult result = model.predict(ARGB8888ImageBitmap); + +// 释放模型资源 +model.release(); +``` + +- 模型调用示例2: 在合适的程序节点,手动调用init,并自定义RuntimeOption +```java +// import 同上 ... +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.ClassifyResult; +import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel; +// 新建空模型 +PaddleClasModel model = new PaddleClasModel(); +// 模型路径 +String modelFile = "MobileNetV1_x0_25_infer/inference.pdmodel"; +String paramFile = "MobileNetV1_x0_25_infer/inference.pdiparams"; +String configFile = "MobileNetV1_x0_25_infer/inference_cls.yml"; +// 指定RuntimeOption +RuntimeOption option = new RuntimeOption(); +option.setCpuThreadNum(2); +option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +option.enableRecordTimeOfRuntime(); +option.enableLiteFp16(); +// 使用init函数初始化 +model.init(modelFile, paramFile, configFile, option); +// Bitmap读取、模型预测、资源释放 同上 ... +``` +更详细的用法请参考 [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`。 +- 替换FastDeploy预测库的步骤: + - 下载或编译最新的FastDeploy Android预测库,解压缩后放在 `app/libs` 目录下; + - 修改 `app/src/main/cpp/CMakeLists.txt` 中的预测库路径,指向您下载或编译的预测库路径。如: +```cmake +set(FastDeploy_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/fastdeploy-android-xxx-shared") +``` +- 替换PaddleClas模型的步骤: + - 将您的PaddleClas分类模型放在 `app/src/main/assets/models` 目录下; + - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +```xml + +models/MobileNetV1_x0_25_infer +labels/imagenet1k_label_list.txt +``` + +## 更多参考文档 +如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: +- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/classification/paddleclas/cpp/README.md b/examples/vision/classification/paddleclas/cpp/README.md index 1b76038fed..d428d8a08d 100755 --- a/examples/vision/classification/paddleclas/cpp/README.md +++ b/examples/vision/classification/paddleclas/cpp/README.md @@ -1,52 +1,48 @@ -# PaddleClas C++部署示例 +English | [简体中文](README_CN.md) +# PaddleClas C++ Deployment Example -本目录下提供`infer.cc`快速完成PaddleClas系列模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PaddleClas models on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上ResNet50_vd推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking ResNet50_vd inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download FastDeploy precompiled library. Users can choose your appropriate version in the`FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载ResNet50_vd模型文件和测试图片 +# Download ResNet50_vd model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz tar -xvf ResNet50_vd_infer.tgz wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# CPU推理 +# CPU inference ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 0 -# GPU推理 +# GPU inference ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2 -# IPU推理 +# IPU inference ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 3 -# KunlunXin XPU推理 +# KunlunXin XPU inference ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 4 -# Huawei Ascend NPU推理 -./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 5 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. Refer to +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) for SDK use-pattern in Windows -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) +## PaddleClas C++ Interface -## PaddleClas C++接口 - -### PaddleClas类 +### PaddleClas Class ```c++ fastdeploy::vision::classification::PaddleClasModel( @@ -57,32 +53,32 @@ fastdeploy::vision::classification::PaddleClasModel( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) +PaddleClas model loading and initialization, where model_file and params_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict function > ```c++ > PaddleClasModel::Predict(cv::Mat* im, ClassifyResult* result, int topk = 1) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output results directly. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分类结果,包括label_id,以及相应的置信度, ClassifyResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 +> > * **im**: Input images in HWC or BGR format +> > * **result**: The classification result, including label_id, and the corresponding confidence. Refer to [Visual Model Prediction Results](../../../../../docs/api/vision_results/) for the description of ClassifyResult +> > * **topk**(int): Return the topk classification results with the highest prediction probability. Default 1 -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Visual Model prediction results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/paddleclas/cpp/README_CN.md b/examples/vision/classification/paddleclas/cpp/README_CN.md new file mode 100644 index 0000000000..a99e362b61 --- /dev/null +++ b/examples/vision/classification/paddleclas/cpp/README_CN.md @@ -0,0 +1,89 @@ +[English](README.md) | 简体中文 +# PaddleClas C++部署示例 + +本目录下提供`infer.cc`快速完成PaddleClas系列模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上ResNet50_vd推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载ResNet50_vd模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz +tar -xvf ResNet50_vd_infer.tgz +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + + +# CPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 0 +# GPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1 +# GPU上TensorRT推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2 +# IPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 3 +# KunlunXin XPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 4 +# Huawei Ascend NPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 5 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +## PaddleClas C++接口 + +### PaddleClas类 + +```c++ +fastdeploy::vision::classification::PaddleClasModel( + const string& model_file, + const string& params_file, + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PaddleClasModel::Predict(cv::Mat* im, ClassifyResult* result, int topk = 1) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分类结果,包括label_id,以及相应的置信度, ClassifyResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 + + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/paddleclas/python/README.md b/examples/vision/classification/paddleclas/python/README.md index 14de9ff385..dd45dbe497 100755 --- a/examples/vision/classification/paddleclas/python/README.md +++ b/examples/vision/classification/paddleclas/python/README.md @@ -1,37 +1,36 @@ -# PaddleClas模型 Python部署示例 +English | [简体中文](README_CN.md) +# Example of PaddleClas models Python Deployment -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install the FastDeploy Python whl package. Please refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of ResNet50_vd on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/classification/paddleclas/python -# 下载ResNet50_vd模型文件和测试图片 +# Download the ResNet50_vd model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz tar -xvf ResNet50_vd_infer.tgz wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# CPU推理 +# CPU inference python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 -# GPU推理 +# GPU inference python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# Use TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 -# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待) +# IPU inference(Attention: It is somewhat time-consuming for the operation of model serialization when running IPU inference for the first time. Please be patient.) python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1 -# 昆仑芯XPU推理 -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device kunlunxin --topk 1 -# 华为昇腾NPU推理 -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ascend --topk 1 +# XPU inference +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device xpu --topk 1 ``` -运行完成后返回结果如下所示 +The result returned after running is as follows ```bash ClassifyResult( label_ids: 153, @@ -39,43 +38,43 @@ scores: 0.686229, ) ``` -## PaddleClasModel Python接口 +## PaddleClasModel Python Interface ```python fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) +PaddleClas model loading and initialization, where model_file and params_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend Inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > PaddleClasModel.predict(input_image, topk=1) > ``` > -> 模型预测结口,输入图像直接输出分类topk结果。 +> Model prediction interface. Input images and output classification topk results directly. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format +> > * **topk**(int): Return the topk classification results with the highest prediction probability. Default 1 -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.ClassifyResult` structure. Refer to [Visual Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other documents -- [PaddleClas 模型介绍](..) -- [PaddleClas C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PaddleClas Model Description](..) +- [PaddleClas C++ Deployment](../cpp) +- [Model prediction results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/paddleclas/python/README_CN.md b/examples/vision/classification/paddleclas/python/README_CN.md new file mode 100644 index 0000000000..7cf14fa880 --- /dev/null +++ b/examples/vision/classification/paddleclas/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# PaddleClas模型 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/classification/paddleclas/python + +# 下载ResNet50_vd模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz +tar -xvf ResNet50_vd_infer.tgz +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + +# CPU推理 +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 +# GPU推理 +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 +# IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1 +# 昆仑芯XPU推理 +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device kunlunxin --topk 1 +# 华为昇腾NPU推理 +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ascend --topk 1 +``` + +运行完成后返回结果如下所示 +```bash +ClassifyResult( +label_ids: 153, +scores: 0.686229, +) +``` + +## PaddleClasModel Python接口 + +```python +fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PaddleClasModel.predict(input_image, topk=1) +> ``` +> +> 模型预测结口,输入图像直接输出分类topk结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 + +> **返回** +> +> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [PaddleClas 模型介绍](..) +- [PaddleClas C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/paddleclas/quantize/README.md b/examples/vision/classification/paddleclas/quantize/README.md index e55f95e261..bacbac08aa 100755 --- a/examples/vision/classification/paddleclas/quantize/README.md +++ b/examples/vision/classification/paddleclas/quantize/README.md @@ -1,50 +1,51 @@ -# PaddleClas 量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. +English | [简体中文](README_CN.md) +# PaddleClas Quantification Model Deployment +FastDeploy supports the deployment of quantification models and provides a convenient tool for automatic model compression. + Users can use it to deploy models after quantification or directly deploy quantized models provided by FastDeploy. -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) -注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 +## FastDeploy one-click auto-compression tool +FastDeploy provides a one-click auto-compression tool that allows users to quantize models by simply entering a configuration file. +Refer to [one-click auto-compression tool](../../../../../tools/common_tools/auto_compression/) for details. +Attention:The quantized classification model still requires the inference_cls.yaml file in the FP32 model folder. The model folder after personal quantification does not contain this yaml file. But users can copy this yaml file from the FP32 model folder to your quantized model folder. -## 下载量化完成的PaddleClas模型 -用户也可以直接下载下表中的量化模型进行部署. +## Download the quantized PaddleClas model +Users can also directly download the quantized models in the table below. -Benchmark表格说明: -- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. -- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. -- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. -- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 -- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 -- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. -- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. -- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. +Benchmark table description: +- Runtime latency: model’s inference latency on multiple Runtimes, including CPU->GPU data copy, GPU inference, and GPU->CPU data copy time. It does not include the pre and post processing time of the model. +- End2End latency: model’s latency in the actual inference scenario, including the pre and post processing time of the model. +- Measured latency: The average latency after 1000 times of inference in milliseconds. +- INT8 + FP16: Enable FP16 inference for Runtime while inferring the INT8 quantification model +- INT8 + FP16 + PM: Use Pinned Memory to speed up the GPU->CPU data copy while inferring the INT8 quantization model with FP16 turned on. +- Maximum speedup ratio: Obtained by dividing the FP32 latency by the highest INT8 inference latency. +- The strategy is to use a few unlabeled data sets to train the model for quantification and to verify the accuracy on the full validation set. The INT8 accuracy does not represent the highest value. +- The CPU is Intel(R) Xeon(R) Gold 6271C, and the number of CPU threads is fixed to 1. The GPU is Tesla T4 with TensorRT version 8.4.15. ### Runtime Benchmark -| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 Top1 | INT8 Top1 | 量化方式 | +| Model |Inference Backend |Deployment Hardware | FP32 Runtime Latency | INT8 Runtime Latency | INT8 + FP16 Runtime Latency | INT8+FP16+PM Runtime Latency | Maximum Speedup Ratio | FP32 Top1 | INT8 Top1 | Quantification Method | | ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | TensorRT | GPU | 3.55 | 0.99|0.98|1.06 | 3.62 | 79.12 | 79.06 | 离线量化 | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle-TensorRT | GPU | 3.46 |None |0.87|1.03 | 3.98 | 79.12 | 79.06 | 离线量化 | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | ONNX Runtime | CPU | 76.14 | 35.43 |None|None | 2.15 | 79.12 | 78.87| 离线量化| -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle Inference | CPU | 76.21 | 24.01 |None|None | 3.17 | 79.12 | 78.55 | 离线量化| -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | TensorRT | GPU | 0.91 | 0.43 |0.49 | 0.54 | 2.12 |77.89 | 76.86 | 离线量化 | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle-TensorRT | GPU | 0.88| None| 0.49|0.51 | 1.80 |77.89 | 76.86 | 离线量化 | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | ONNX Runtime | CPU | 30.53 | 9.59|None|None | 3.18 |77.89 | 75.09 |离线量化 | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle Inference | CPU | 12.29 | 4.68 | None|None|2.62 |77.89 | 71.36 |离线量化 | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | TensorRT | GPU | 3.55 | 0.99|0.98|1.06 | 3.62 | 79.12 | 79.06 | Offline | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle-TensorRT | GPU | 3.46 |None |0.87|1.03 | 3.98 | 79.12 | 79.06 | Offline | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | ONNX Runtime | CPU | 76.14 | 35.43 |None|None | 2.15 | 79.12 | 78.87| Offline| +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle Inference | CPU | 76.21 | 24.01 |None|None | 3.17 | 79.12 | 78.55 | Offline| +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | TensorRT | GPU | 0.91 | 0.43 |0.49 | 0.54 | 2.12 |77.89 | 76.86 | Offline | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle-TensorRT | GPU | 0.88| None| 0.49|0.51 | 1.80 |77.89 | 76.86 | Offline | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | ONNX Runtime | CPU | 30.53 | 9.59|None|None | 3.18 |77.89 | 75.09 |Offline | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle Inference | CPU | 12.29 | 4.68 | None|None|2.62 |77.89 | 71.36 |Offline | -### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 Top1 | INT8 Top1 | 量化方式 | +### End2End Benchmark +| Model |Inference Backend |Deployment Hardware | FP32 End2End Latency | INT8 End2End Latency | INT8 + FP16 End2End Latency | INT8+FP16+PM End2End Latency | Maximum Speedup Ratio | FP32 Top1 | INT8 Top1 | Quantification Method | | ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | TensorRT | GPU | 4.92| 2.28|2.24|2.23 | 2.21 | 79.12 | 79.06 | 离线量化 | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle-TensorRT | GPU | 4.48|None |2.09|2.10 | 2.14 | 79.12 | 79.06 | 离线量化 | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | ONNX Runtime | CPU | 77.43 | 41.90 |None|None | 1.85 | 79.12 | 78.87| 离线量化| -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle Inference | CPU | 80.60 | 27.75 |None|None | 2.90 | 79.12 | 78.55 | 离线量化| -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | TensorRT | GPU | 2.19 | 1.48|1.57| 1.57 | 1.48 |77.89 | 76.86 | 离线量化 | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle-TensorRT | GPU | 2.04| None| 1.47|1.45 | 1.41 |77.89 | 76.86 | 离线量化 | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | ONNX Runtime | CPU | 34.02 | 12.97|None|None | 2.62 |77.89 | 75.09 |离线量化 | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle Inference | CPU | 16.31 | 7.42 | None|None| 2.20 |77.89 | 71.36 |离线量化 | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | TensorRT | GPU | 4.92| 2.28|2.24|2.23 | 2.21 | 79.12 | 79.06 | Offline | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle-TensorRT | GPU | 4.48|None |2.09|2.10 | 2.14 | 79.12 | 79.06 | Offline | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | ONNX Runtime | CPU | 77.43 | 41.90 |None|None | 1.85 | 79.12 | 78.87| Offline| +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle Inference | CPU | 80.60 | 27.75 |None|None | 2.90 | 79.12 | 78.55 | Offline| +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | TensorRT | GPU | 2.19 | 1.48|1.57| 1.57 | 1.48 |77.89 | 76.86 | Offline | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle-TensorRT | GPU | 2.04| None| 1.47|1.45 | 1.41 |77.89 | 76.86 | Offline | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | ONNX Runtime | CPU | 34.02 | 12.97|None|None | 2.62 |77.89 | 75.09 |Offline | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle Inference | CPU | 16.31 | 7.42 | None|None| 2.20 |77.89 | 71.36 |Offline | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/classification/paddleclas/quantize/README_CN.md b/examples/vision/classification/paddleclas/quantize/README_CN.md new file mode 100644 index 0000000000..fcc9f1a372 --- /dev/null +++ b/examples/vision/classification/paddleclas/quantize/README_CN.md @@ -0,0 +1,51 @@ +[English](README.md) | 简体中文 +# PaddleClas 量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. + +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) +注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 + +## 下载量化完成的PaddleClas模型 +用户也可以直接下载下表中的量化模型进行部署. + +Benchmark表格说明: +- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. +- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. +- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. +- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 +- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 +- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. +- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. +- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. + +### Runtime Benchmark +| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 Top1 | INT8 Top1 | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | TensorRT | GPU | 3.55 | 0.99|0.98|1.06 | 3.62 | 79.12 | 79.06 | 离线量化 | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle-TensorRT | GPU | 3.46 |None |0.87|1.03 | 3.98 | 79.12 | 79.06 | 离线量化 | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | ONNX Runtime | CPU | 76.14 | 35.43 |None|None | 2.15 | 79.12 | 78.87| 离线量化| +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle Inference | CPU | 76.21 | 24.01 |None|None | 3.17 | 79.12 | 78.55 | 离线量化| +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | TensorRT | GPU | 0.91 | 0.43 |0.49 | 0.54 | 2.12 |77.89 | 76.86 | 离线量化 | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle-TensorRT | GPU | 0.88| None| 0.49|0.51 | 1.80 |77.89 | 76.86 | 离线量化 | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | ONNX Runtime | CPU | 30.53 | 9.59|None|None | 3.18 |77.89 | 75.09 |离线量化 | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle Inference | CPU | 12.29 | 4.68 | None|None|2.62 |77.89 | 71.36 |离线量化 | + +### 端到端 Benchmark +| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 Top1 | INT8 Top1 | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | TensorRT | GPU | 4.92| 2.28|2.24|2.23 | 2.21 | 79.12 | 79.06 | 离线量化 | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle-TensorRT | GPU | 4.48|None |2.09|2.10 | 2.14 | 79.12 | 79.06 | 离线量化 | +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | ONNX Runtime | CPU | 77.43 | 41.90 |None|None | 1.85 | 79.12 | 78.87| 离线量化| +| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50_vd_ptq.tar) | Paddle Inference | CPU | 80.60 | 27.75 |None|None | 2.90 | 79.12 | 78.55 | 离线量化| +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | TensorRT | GPU | 2.19 | 1.48|1.57| 1.57 | 1.48 |77.89 | 76.86 | 离线量化 | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle-TensorRT | GPU | 2.04| None| 1.47|1.45 | 1.41 |77.89 | 76.86 | 离线量化 | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | ONNX Runtime | CPU | 34.02 | 12.97|None|None | 2.62 |77.89 | 75.09 |离线量化 | +| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/mobilenetv1_ssld_ptq.tar) | Paddle Inference | CPU | 16.31 | 7.42 | None|None| 2.20 |77.89 | 71.36 |离线量化 | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/classification/paddleclas/rknpu2/README.md b/examples/vision/classification/paddleclas/rknpu2/README.md index d61e6c5706..c6200b983d 100644 --- a/examples/vision/classification/paddleclas/rknpu2/README.md +++ b/examples/vision/classification/paddleclas/rknpu2/README.md @@ -1,18 +1,19 @@ -# PaddleClas 模型RKNPU2部署 +English | [简体中文](README_CN.md) +# PaddleClas Model RKNPU2 Deployment -## 转换模型 -下面以 ResNet50_vd为例子,教大家如何转换分类模型到RKNN模型。 +## Convert the model +Taking ResNet50_vd as an example, this document demonstrates how to convert classification model to RKNN model. -### 导出ONNX模型 +### Export the ONNX model ```bash -# 安装 paddle2onnx +# Install paddle2onnx pip install paddle2onnx -# 下载ResNet50_vd模型文件和测试图片 +# Download ResNet50_vd model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz tar -xvf ResNet50_vd_infer.tgz -# 静态图转ONNX模型,注意,这里的save_file请和压缩包名对齐 +# From static map to ONNX model. Attention: Align the save_file with the zip file name paddle2onnx --model_dir ResNet50_vd_infer \ --model_filename inference.pdmodel \ --params_filename inference.pdiparams \ @@ -21,16 +22,16 @@ paddle2onnx --model_dir ResNet50_vd_infer \ --opset_version 10 \ --enable_onnx_checker True -# 固定shape,注意这里的inputs得对应netron.app展示的 inputs 的 name,有可能是image 或者 x +# Fix shape. Attention: the inputs here should correspond to the name of the inputs shown in netron.app, which may be image or x python -m paddle2onnx.optimize --input_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \ --output_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \ --input_shape_dict "{'inputs':[1,3,224,224]}" ``` -### 编写模型导出配置文件 -以转化RK3588的RKNN模型为例子,我们需要编辑tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml,来转换ONNX模型到RKNN模型。 +### Write the model export configuration file +Taking the example of RKNN model from RK3588, we need to edit tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml to convert ONNX model to RKNN model. -如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如: +If you need to perform the normalize operation on NPU, configure the normalize parameters based on your model. For example: ```yaml model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx output_folder: ./ResNet50_vd_infer @@ -49,7 +50,7 @@ do_quantization: False dataset: "./ResNet50_vd_infer/dataset.txt" ``` -**在CPU上做normalize**可以参考以下yaml: +To **normalize on CPU**, refer to the following yaml: ```yaml model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx output_folder: ./ResNet50_vd_infer @@ -67,17 +68,17 @@ outputs_nodes: do_quantization: False dataset: "./ResNet50_vd_infer/dataset.txt" ``` -这里我们选择在NPU上执行normalize操作. +Here we perform the normalize operation on NPU. -### ONNX模型转RKNN模型 +### From ONNX model to RKNN model ```shell python tools/rknpu2/export.py \ --config_path tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml \ --target_platform rk3588 ``` -## 其他链接 -- [Cpp部署](./cpp) -- [Python部署](./python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) +## Other Links +- [Cpp Deployment](./cpp) +- [Python Deployment](./python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) diff --git a/examples/vision/classification/paddleclas/rknpu2/README_CN.md b/examples/vision/classification/paddleclas/rknpu2/README_CN.md new file mode 100644 index 0000000000..24f070ccf6 --- /dev/null +++ b/examples/vision/classification/paddleclas/rknpu2/README_CN.md @@ -0,0 +1,84 @@ +[English](README.md) | 简体中文 +# PaddleClas 模型RKNPU2部署 + +## 转换模型 +下面以 ResNet50_vd为例子,教大家如何转换分类模型到RKNN模型。 + +### 导出ONNX模型 +```bash +# 安装 paddle2onnx +pip install paddle2onnx + +# 下载ResNet50_vd模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz +tar -xvf ResNet50_vd_infer.tgz + +# 静态图转ONNX模型,注意,这里的save_file请和压缩包名对齐 +paddle2onnx --model_dir ResNet50_vd_infer \ + --model_filename inference.pdmodel \ + --params_filename inference.pdiparams \ + --save_file ResNet50_vd_infer/ResNet50_vd_infer.onnx \ + --enable_dev_version True \ + --opset_version 10 \ + --enable_onnx_checker True + +# 固定shape,注意这里的inputs得对应netron.app展示的 inputs 的 name,有可能是image 或者 x +python -m paddle2onnx.optimize --input_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \ + --output_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \ + --input_shape_dict "{'inputs':[1,3,224,224]}" +``` + +### 编写模型导出配置文件 +以转化RK3588的RKNN模型为例子,我们需要编辑tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml,来转换ONNX模型到RKNN模型。 + +如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如: +```yaml +model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx +output_folder: ./ResNet50_vd_infer +mean: + - + - 123.675 + - 116.28 + - 103.53 +std: + - + - 58.395 + - 57.12 + - 57.375 +outputs_nodes: +do_quantization: False +dataset: "./ResNet50_vd_infer/dataset.txt" +``` + +**在CPU上做normalize**可以参考以下yaml: +```yaml +model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx +output_folder: ./ResNet50_vd_infer +mean: + - + - 0 + - 0 + - 0 +std: + - + - 1 + - 1 + - 1 +outputs_nodes: +do_quantization: False +dataset: "./ResNet50_vd_infer/dataset.txt" +``` +这里我们选择在NPU上执行normalize操作. + + +### ONNX模型转RKNN模型 +```shell +python tools/rknpu2/export.py \ + --config_path tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml \ + --target_platform rk3588 +``` + +## 其他链接 +- [Cpp部署](./cpp) +- [Python部署](./python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/examples/vision/classification/paddleclas/rv1126/README.md b/examples/vision/classification/paddleclas/rv1126/README.md index 5410940ecd..38ed27825c 100755 --- a/examples/vision/classification/paddleclas/rv1126/README.md +++ b/examples/vision/classification/paddleclas/rv1126/README.md @@ -1,11 +1,12 @@ -# PaddleClas 量化模型在 RV1126 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PaddleClas 量化模型到 RV1126 上。 +English | [简体中文](README_CN.md) +# PaddleClas Quantification Model Deployment on RV1126 +FastDeploy currently supports the deployment of PaddleClas quantification models to RV1126 based on Paddle Lite. -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -在 RV1126 上只支持 C++ 的部署。 +Only C++ deployment is supported on RV1126. -- [C++部署](cpp) +- [C++ Deployment](cpp) diff --git a/examples/vision/classification/paddleclas/rv1126/README_CN.md b/examples/vision/classification/paddleclas/rv1126/README_CN.md new file mode 100644 index 0000000000..4130a7bad2 --- /dev/null +++ b/examples/vision/classification/paddleclas/rv1126/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# PaddleClas 量化模型在 RV1126 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 PaddleClas 量化模型到 RV1126 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 RV1126 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/classification/paddleclas/serving/README.md b/examples/vision/classification/paddleclas/serving/README.md index abfe6529b8..97a7899cdb 100644 --- a/examples/vision/classification/paddleclas/serving/README.md +++ b/examples/vision/classification/paddleclas/serving/README.md @@ -1,50 +1,51 @@ -# PaddleClas 服务化部署示例 +English | [简体中文](README_CN.md) +# PaddleClas Service Deployment Example -在服务化部署前,需确认 +Before the service deployment, please confirm -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) +- 1. Refer to [FastDeploy Service Deployment](../../../../../serving/README_CN.md) for software and hardware environment requirements and image pull commands -## 启动服务 +## Start the Service ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/classification/paddleclas/serving -# 下载ResNet50_vd模型文件和测试图片 +# Download ResNet50_vd model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz tar -xvf ResNet50_vd_infer.tgz wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# 将配置文件放入预处理目录 +# Put the configuration file into the preprocessing directory mv ResNet50_vd_infer/inference_cls.yaml models/preprocess/1/inference_cls.yaml -# 将模型放入 models/runtime/1目录下, 并重命名为model.pdmodel和model.pdiparams +# Place the model under models/runtime/1 and rename them to model.pdmodel和model.pdiparams mv ResNet50_vd_infer/inference.pdmodel models/runtime/1/model.pdmodel mv ResNet50_vd_infer/inference.pdiparams models/runtime/1/model.pdiparams -# 拉取fastdeploy镜像(x.y.z为镜像版本号,需参照serving文档替换为数字) -# GPU镜像 +# Pull the fastdeploy image (x.y.z represent the image version. Refer to the serving document to replace them with numbers) +# GPU image docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 -# CPU镜像 +# CPU image docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-cpu-only-21.10 -# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /serving 目录 +# Run the container named fd_serving and mount it in the /serving directory of the container nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash -# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) +# Start the service (The CUDA_VISIBLE_DEVICES environment variable is not set, which entitles the scheduling authority of all GPU cards) CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/serving/models --backend-config=python,shm-default-byte-size=10485760 ``` ->> **注意**: +>> **Attention**: ->> 拉取其他硬件上的镜像请看[服务化部署主文档](../../../../../serving/README_CN.md) +>> To pull images from other hardware, refer to [Service Deployment Master Document](../../../../../serving/README_CN.md) ->> 执行fastdeployserver启动服务出现"Address already in use", 请使用`--grpc-port`指定端口号来启动服务,同时更改客户端示例中的请求端口号. +>> If "Address already in use" appears when running fastdeployserver to start the service, use `--grpc-port` to specify the port number and change the request port number in the client demo. ->> 其他启动参数可以使用 fastdeployserver --help 查看 +>> Other startup parameters can be checked by fastdeployserver --help -服务启动成功后, 会有以下输出: +Successful service start brings the following output: ``` ...... I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 @@ -53,26 +54,26 @@ I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0 ``` -## 客户端请求 +## Client Request -在物理机器中执行以下命令,发送grpc请求并输出结果 +Execute the following command in the physical machine to send the grpc request and output the result ``` -#下载测试图片 +# Download test images wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -#安装客户端依赖 +# Install client dependencies python3 -m pip install tritonclient\[all\] -# 发送请求 +# Send the request python3 paddlecls_grpc_client.py ``` -发送请求成功后,会返回json格式的检测结果并打印输出: +The result is returned in json format and printed after sending the request: ``` output_name: CLAS_RESULT {'label_ids': [153], 'scores': [0.6862289905548096]} ``` -## 配置修改 +## Configuration Change -当前默认配置在GPU上运行TensorRT引擎, 如果要在CPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) +The current default configuration runs the TensorRT engine on GPU. If you want to run it on CPU or other inference engines, please modify the configuration in `models/runtime/config.pbtxt`. Refer to [Configuration Document](../../../../../serving/docs/zh_CN/model_configuration.md) for more information. diff --git a/examples/vision/classification/paddleclas/serving/README_CN.md b/examples/vision/classification/paddleclas/serving/README_CN.md new file mode 100644 index 0000000000..ea8abdf1bd --- /dev/null +++ b/examples/vision/classification/paddleclas/serving/README_CN.md @@ -0,0 +1,79 @@ +[English](README.md) | 简体中文 +# PaddleClas 服务化部署示例 + +在服务化部署前,需确认 + +- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) + + +## 启动服务 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/classification/paddleclas/serving + +# 下载ResNet50_vd模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz +tar -xvf ResNet50_vd_infer.tgz +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + +# 将配置文件放入预处理目录 +mv ResNet50_vd_infer/inference_cls.yaml models/preprocess/1/inference_cls.yaml + +# 将模型放入 models/runtime/1目录下, 并重命名为model.pdmodel和model.pdiparams +mv ResNet50_vd_infer/inference.pdmodel models/runtime/1/model.pdmodel +mv ResNet50_vd_infer/inference.pdiparams models/runtime/1/model.pdiparams + +# 拉取fastdeploy镜像(x.y.z为镜像版本号,需参照serving文档替换为数字) +# GPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +# CPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-cpu-only-21.10 + +# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /serving 目录 +nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash + +# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) +CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/serving/models --backend-config=python,shm-default-byte-size=10485760 +``` +>> **注意**: + +>> 拉取其他硬件上的镜像请看[服务化部署主文档](../../../../../serving/README_CN.md) + +>> 执行fastdeployserver启动服务出现"Address already in use", 请使用`--grpc-port`指定端口号来启动服务,同时更改客户端示例中的请求端口号. + +>> 其他启动参数可以使用 fastdeployserver --help 查看 + +服务启动成功后, 会有以下输出: +``` +...... +I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 +I0928 04:51:15.785177 206 http_server.cc:2815] Started HTTPService at 0.0.0.0:8000 +I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0:8002 +``` + + +## 客户端请求 + +在物理机器中执行以下命令,发送grpc请求并输出结果 +``` +#下载测试图片 +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + +#安装客户端依赖 +python3 -m pip install tritonclient\[all\] + +# 发送请求 +python3 paddlecls_grpc_client.py +``` + +发送请求成功后,会返回json格式的检测结果并打印输出: +``` +output_name: CLAS_RESULT +{'label_ids': [153], 'scores': [0.6862289905548096]} +``` + +## 配置修改 + +当前默认配置在GPU上运行TensorRT引擎, 如果要在CPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) diff --git a/examples/vision/classification/paddleclas/web/README.md b/examples/vision/classification/paddleclas/web/README.md index 710dd53ad4..7dcf4c8915 100644 --- a/examples/vision/classification/paddleclas/web/README.md +++ b/examples/vision/classification/paddleclas/web/README.md @@ -1,36 +1,35 @@ +English | [简体中文](README_CN.md) +# MobileNet Front-end Deployment Example -# MobileNet 前端部署示例 +This document introduces the deployment of PaddleClas's mobilenet models for image classification to run in the browser, and the js interface in the @paddle-js-models/mobilenet npm package. -本节介绍部署PaddleClas的图像分类mobilenet模型在浏览器中运行,以及@paddle-js-models/mobilenet npm包中的js接口。 +## Front-end Deployment of Image Classification Model -## 前端部署图像分类模型 +To use the web demo of image classification models, refer to [**Reference Document**](../../../../application/js/web_demo/) -图像分类模型web demo使用[**参考文档**](../../../../application/js/web_demo/) - -## MobileNet js接口 +## MobileNet js Interface ``` import * as mobilenet from "@paddle-js-models/mobilenet"; -# mobilenet模型加载和初始化 +# mobilenet model loading and initialization await mobilenet.load() -# mobilenet模型执行预测,并获得分类的类别 +# mobilenet model performs the prediction and obtains the classification result const res = await mobilenet.classify(img); console.log(res); ``` -**load()函数参数** - -> * **Config**(dict): 图像分类模型配置参数,默认值为 {Path: 'https://paddlejs.bj.bcebos.com/models/fuse/mobilenet/mobileNetV2_fuse_activation/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; 其中,modelPath为js模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差。 +**load() function parameter** +> * **Config**(dict): The configuration parameter for the image classification model. Default {Path: 'https://paddlejs.bj.bcebos.com/models/fuse/mobilenet/mobileNetV2_fuse_activation/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; Among them, modelPath is the path of the js model, fill is the padding value in the image pre-processing, and mean/std are the mean and standard deviation in the pre-processing -**classify()函数参数** -> * **img**(HTMLImageElement): 输入图像参数,类型为HTMLImageElement。 +**classify() function parameter** +> * **img**(HTMLImageElement): Enter an image parameter in HTMLImageElement. -## 其它文档 +## Other Documents -- [PaddleClas模型 python部署](../../paddleclas/python/) -- [PaddleClas模型 C++部署](../cpp/) +- [PaddleClas model python deployment](../../paddleclas/python/) +- [PaddleClas model C++ deployment](../cpp/) diff --git a/examples/vision/classification/paddleclas/web/README_CN.md b/examples/vision/classification/paddleclas/web/README_CN.md new file mode 100644 index 0000000000..d08d08cca4 --- /dev/null +++ b/examples/vision/classification/paddleclas/web/README_CN.md @@ -0,0 +1,36 @@ +[English](README.md) | 简体中文 +# MobileNet 前端部署示例 + +本节介绍部署PaddleClas的图像分类mobilenet模型在浏览器中运行,以及@paddle-js-models/mobilenet npm包中的js接口。 + + +## 前端部署图像分类模型 + +图像分类模型web demo使用[**参考文档**](../../../../application/js/web_demo/) + + +## MobileNet js接口 + +``` +import * as mobilenet from "@paddle-js-models/mobilenet"; +# mobilenet模型加载和初始化 +await mobilenet.load() +# mobilenet模型执行预测,并获得分类的类别 +const res = await mobilenet.classify(img); +console.log(res); +``` + +**load()函数参数** + +> * **Config**(dict): 图像分类模型配置参数,默认值为 {Path: 'https://paddlejs.bj.bcebos.com/models/fuse/mobilenet/mobileNetV2_fuse_activation/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; 其中,modelPath为js模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差。 + + +**classify()函数参数** +> * **img**(HTMLImageElement): 输入图像参数,类型为HTMLImageElement。 + + + +## 其它文档 + +- [PaddleClas模型 python部署](../../paddleclas/python/) +- [PaddleClas模型 C++部署](../cpp/) diff --git a/examples/vision/classification/resnet/README.md b/examples/vision/classification/resnet/README.md index dd20562fb5..fae19264f5 100644 --- a/examples/vision/classification/resnet/README.md +++ b/examples/vision/classification/resnet/README.md @@ -1,41 +1,42 @@ -# ResNet准备部署模型 +English | [简体中文](README_CN.md) +# ResNet Ready-to-deploy Model -- ResNet部署实现来自[Torchvision](https://github.com/pytorch/vision/tree/v0.12.0)的代码,和[基于ImageNet2012的预训练模型](https://github.com/pytorch/vision/tree/v0.12.0)。 +- ResNet Deployment is based on the code of [Torchvision](https://github.com/pytorch/vision/tree/v0.12.0) and [Pre-trained Models on ImageNet2012](https://github.com/pytorch/vision/tree/v0.12.0)。 - - (1)[官方库](https://github.com/pytorch/vision/tree/v0.12.0)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)自己数据训练的ResNet模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)Deployment is conducted after [Export ONNX Model](#导出ONNX模型) by the *.pt provided by [Official Repository](https://github.com/pytorch/vision/tree/v0.12.0); + - (2)The ResNet Model trained by personal data should [Export ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B). Please refer to [Detailed Deployment Tutorials](#详细部署文档) for deployment. -## 导出ONNX模型 +## Export the ONNX Model - 导入[Torchvision](https://github.com/pytorch/vision/tree/v0.12.0),加载预训练模型,并进行模型转换,具体转换步骤如下。 + Import [Torchvision](https://github.com/pytorch/vision/tree/v0.12.0), load the pre-trained model, and conduct model transformation as the following steps. ```python import torch import torchvision.models as models model = models.resnet50(pretrained=True) - batch_size = 1 #批处理大小 - input_shape = (3, 224, 224) #输入数据,改成自己的输入shape + batch_size = 1 #Batch size + input_shape = (3, 224, 224) #Input data, and change to personal input shape # #set the model to inference mode model.eval() - x = torch.randn(batch_size, *input_shape) # 生成张量 - export_onnx_file = "ResNet50.onnx" # 目的ONNX文件名 + x = torch.randn(batch_size, *input_shape) # Generate tensor + export_onnx_file = "ResNet50.onnx" # Purpose ONNX file name torch.onnx.export(model, x, export_onnx_file, opset_version=12, - input_names=["input"], # 输入名 - output_names=["output"], # 输出名 - dynamic_axes={"input":{0:"batch_size"}, # 批处理变量 + input_names=["input"], # Input name + output_names=["output"], # Output name + dynamic_axes={"input":{0:"batch_size"}, # Batch variables "output":{0:"batch_size"}}) ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了ResNet导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by ResNet are provided below. Developers can download them directly. (The model accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [ResNet-18](https://bj.bcebos.com/paddlehub/fastdeploy/resnet18.onnx) | 45MB | | | [ResNet-34](https://bj.bcebos.com/paddlehub/fastdeploy/resnet34.onnx) | 84MB | | @@ -43,11 +44,11 @@ | [ResNet-101](https://bj.bcebos.com/paddlehub/fastdeploy/resnet101.onnx) | 170MB | | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[Torchvision v0.12.0](https://github.com/pytorch/vision/tree/v0.12.0) 编写 +- Document and code are based on [Torchvision v0.12.0](https://github.com/pytorch/vision/tree/v0.12.0) diff --git a/examples/vision/classification/resnet/README_CN.md b/examples/vision/classification/resnet/README_CN.md new file mode 100644 index 0000000000..3662d0bb81 --- /dev/null +++ b/examples/vision/classification/resnet/README_CN.md @@ -0,0 +1,54 @@ +[English](README.md) | 简体中文 +# ResNet准备部署模型 + +- ResNet部署实现来自[Torchvision](https://github.com/pytorch/vision/tree/v0.12.0)的代码,和[基于ImageNet2012的预训练模型](https://github.com/pytorch/vision/tree/v0.12.0)。 + + - (1)[官方库](https://github.com/pytorch/vision/tree/v0.12.0)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)自己数据训练的ResNet模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + +## 导出ONNX模型 + + + 导入[Torchvision](https://github.com/pytorch/vision/tree/v0.12.0),加载预训练模型,并进行模型转换,具体转换步骤如下。 + + ```python + import torch + import torchvision.models as models + + model = models.resnet50(pretrained=True) + batch_size = 1 #批处理大小 + input_shape = (3, 224, 224) #输入数据,改成自己的输入shape + # #set the model to inference mode + model.eval() + x = torch.randn(batch_size, *input_shape) # 生成张量 + export_onnx_file = "ResNet50.onnx" # 目的ONNX文件名 + torch.onnx.export(model, + x, + export_onnx_file, + opset_version=12, + input_names=["input"], # 输入名 + output_names=["output"], # 输出名 + dynamic_axes={"input":{0:"batch_size"}, # 批处理变量 + "output":{0:"batch_size"}}) + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了ResNet导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [ResNet-18](https://bj.bcebos.com/paddlehub/fastdeploy/resnet18.onnx) | 45MB | | +| [ResNet-34](https://bj.bcebos.com/paddlehub/fastdeploy/resnet34.onnx) | 84MB | | +| [ResNet-50](https://bj.bcebos.com/paddlehub/fastdeploy/resnet50.onnx) | 98MB | | +| [ResNet-101](https://bj.bcebos.com/paddlehub/fastdeploy/resnet101.onnx) | 170MB | | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + +## 版本说明 + +- 本版本文档和代码基于[Torchvision v0.12.0](https://github.com/pytorch/vision/tree/v0.12.0) 编写 diff --git a/examples/vision/classification/resnet/cpp/README.md b/examples/vision/classification/resnet/cpp/README.md index fe9c591085..b828d059c8 100644 --- a/examples/vision/classification/resnet/cpp/README.md +++ b/examples/vision/classification/resnet/cpp/README.md @@ -1,42 +1,43 @@ -# ResNet C++部署示例 +English | [简体中文](README_CN.md) +# ResNet C++ Deployment Example -本目录下提供`infer.cc`快速完成ResNet系列模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of ResNet models on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上 ResNet50 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking ResNet50 inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载ResNet模型文件和测试图片 +# Download the ResNet50 model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/resnet50.onnx wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# CPU推理 +# CPU inference ./infer_demo resnet50.onnx ILSVRC2012_val_00000010.jpeg 0 -# GPU推理 +# GPU inference ./infer_demo resnet50.onnx ILSVRC2012_val_00000010.jpeg 1 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo resnet50.onnx ILSVRC2012_val_00000010.jpeg 2 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. Refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) for SDK use-pattern in Windows -## ResNet C++接口 +## ResNet C++ Interface -### ResNet类 +### ResNet Class ```c++ @@ -48,29 +49,29 @@ fastdeploy::vision::classification::ResNet( ``` -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > ResNet::Predict(cv::Mat* im, ClassifyResult* result, int topk = 1) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output results directly. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分类结果,包括label_id,以及相应的置信度, ClassifyResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 +> > * **im**: Input images in HWC or BGR format +> > * **result**: The classification result, including label_id, and the corresponding confidence. Refer to [Visual Model Prediction Results](../../../../../docs/api/vision_results/) for the description of ClassifyResult +> > * **topk**(int): Return the topk classification results with the highest prediction probability. Default 1 -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model prediction results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/resnet/cpp/README_CN.md b/examples/vision/classification/resnet/cpp/README_CN.md new file mode 100644 index 0000000000..411d61778f --- /dev/null +++ b/examples/vision/classification/resnet/cpp/README_CN.md @@ -0,0 +1,77 @@ +[English](README.md) | 简体中文 +# ResNet C++部署示例 + +本目录下提供`infer.cc`快速完成ResNet系列模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上 ResNet50 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载ResNet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/resnet50.onnx +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + + +# CPU推理 +./infer_demo resnet50.onnx ILSVRC2012_val_00000010.jpeg 0 +# GPU推理 +./infer_demo resnet50.onnx ILSVRC2012_val_00000010.jpeg 1 +# GPU上TensorRT推理 +./infer_demo resnet50.onnx ILSVRC2012_val_00000010.jpeg 2 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## ResNet C++接口 + +### ResNet类 + +```c++ + +fastdeploy::vision::classification::ResNet( + const std::string& model_file, + const std::string& params_file = "", + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> ResNet::Predict(cv::Mat* im, ClassifyResult* result, int topk = 1) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分类结果,包括label_id,以及相应的置信度, ClassifyResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 + + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/resnet/python/README.md b/examples/vision/classification/resnet/python/README.md index a115bcdf40..f210d22c6b 100644 --- a/examples/vision/classification/resnet/python/README.md +++ b/examples/vision/classification/resnet/python/README.md @@ -1,30 +1,31 @@ -# ResNet模型 Python部署示例 +English | [简体中文](README_CN.md) +# ResNet Model Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of ResNet50_vd on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/classification/resnet/python -# 下载ResNet50_vd模型文件和测试图片 +# Download the ResNet50_vd model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/resnet50.onnx wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# CPU推理 +# CPU inference python infer.py --model resnet50.onnx --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 -# GPU推理 +# GPU inference python infer.py --model resnet50.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# Use TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model resnet50.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 ``` -运行完成后返回结果如下所示 +The result returned after running is as follows ```bash ClassifyResult( label_ids: 332, @@ -32,41 +33,41 @@ scores: 0.825349, ) ``` -## ResNet Python接口 +## ResNet Python Interface ```python fd.vision.classification.ResNet(model_file, params_file, runtime_option=None, model_format=ModelFormat.ONNX) ``` -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict Function > ```python > ResNet.predict(input_image, topk=1) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output results directly. > -> **参数** +> **parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format +> > * **topk**(int): Return the topk classification results with the highest prediction probability. Default 1 -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.ClassifyResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [ResNet 模型介绍](..) -- [ResNet C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [ResNet Model Description](..) +- [ResNet C++ Deployment](../cpp) +- [Model prediction results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/resnet/python/README_CN.md b/examples/vision/classification/resnet/python/README_CN.md new file mode 100644 index 0000000000..a319c9086d --- /dev/null +++ b/examples/vision/classification/resnet/python/README_CN.md @@ -0,0 +1,73 @@ +[English](README.md) | 简体中文 +# ResNet模型 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/classification/resnet/python + +# 下载ResNet50_vd模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/resnet50.onnx +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + +# CPU推理 +python infer.py --model resnet50.onnx --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 +# GPU推理 +python infer.py --model resnet50.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model resnet50.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 +``` + +运行完成后返回结果如下所示 +```bash +ClassifyResult( +label_ids: 332, +scores: 0.825349, +) +``` + +## ResNet Python接口 + +```python +fd.vision.classification.ResNet(model_file, params_file, runtime_option=None, model_format=ModelFormat.ONNX) +``` + + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +### predict函数 + +> ```python +> ResNet.predict(input_image, topk=1) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 + +> **返回** +> +> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [ResNet 模型介绍](..) +- [ResNet C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/yolov5cls/README.md b/examples/vision/classification/yolov5cls/README.md index 468c9d963b..87ae9ddb98 100644 --- a/examples/vision/classification/yolov5cls/README.md +++ b/examples/vision/classification/yolov5cls/README.md @@ -1,14 +1,16 @@ -# YOLOv5Cls准备部署模型 +English | [简体中文](README_CN.md) -- YOLOv5Cls v6.2部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v6.2),和[基于ImageNet的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v6.2) - - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v6.2)提供的*-cls.pt模型,使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,可直接进行部署; - - (2)开发者基于自己数据训练的YOLOv5Cls v6.2模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。 +# YOLOv5Cls Ready-to-deploy Model +- YOLOv5Cls v6.2 model deployment is based on [YOLOv5](https://github.com/ultralytics/yolov5/tree/v6.2) and [Pre-trained Models on ImageNet](https://github.com/ultralytics/yolov5/releases/tag/v6.2) + - (1)The *-cls.pt model provided by [Official Repository](https://github.com/ultralytics/yolov5/releases/tag/v6.2) can export the ONNX file using `export.py` in [YOLOv5](https://github.com/ultralytics/yolov5), then deployment can be conducted; + - (2)The YOLOv5Cls v6.2 Model trained by personal data should export the ONNX file using `export.py` in [YOLOv5](https://github.com/ultralytics/yolov5). -## 下载预训练ONNX模型 -为了方便开发者的测试,下面提供了YOLOv5Cls导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度(top1) | 精度(top5) | +## Download Pre-trained ONNX Model + +For developers' testing, models exported by YOLOv5Cls are provided below. Developers can download them directly. (The model accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy(top1) | Accuracy(top5) | |:---------------------------------------------------------------- |:----- |:----- |:----- | | [YOLOv5n-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.onnx) | 9.6MB | 64.6% | 85.4% | | [YOLOv5s-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-cls.onnx) | 21MB | 71.5% | 90.2% | @@ -17,11 +19,11 @@ | [YOLOv5x-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x-cls.onnx) | 184MB | 79.0% | 94.4% | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOv5 v6.2](https://github.com/ultralytics/yolov5/tree/v6.2) 编写 +- Document and code are based on [YOLOv5 v6.2](https://github.com/ultralytics/yolov5/tree/v6.2). diff --git a/examples/vision/classification/yolov5cls/README_CN.md b/examples/vision/classification/yolov5cls/README_CN.md new file mode 100644 index 0000000000..1fd7c8f2f3 --- /dev/null +++ b/examples/vision/classification/yolov5cls/README_CN.md @@ -0,0 +1,28 @@ +[English](README.md) | 简体中文 +# YOLOv5Cls准备部署模型 + +- YOLOv5Cls v6.2部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v6.2),和[基于ImageNet的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v6.2) + - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v6.2)提供的*-cls.pt模型,使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,可直接进行部署; + - (2)开发者基于自己数据训练的YOLOv5Cls v6.2模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。 + + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv5Cls导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度(top1) | 精度(top5) | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [YOLOv5n-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.onnx) | 9.6MB | 64.6% | 85.4% | +| [YOLOv5s-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-cls.onnx) | 21MB | 71.5% | 90.2% | +| [YOLOv5m-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m-cls.onnx) | 50MB | 75.9% | 92.9% | +| [YOLOv5l-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l-cls.onnx) | 102MB | 78.0% | 94.0% | +| [YOLOv5x-cls](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x-cls.onnx) | 184MB | 79.0% | 94.4% | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + +## 版本说明 + +- 本版本文档和代码基于[YOLOv5 v6.2](https://github.com/ultralytics/yolov5/tree/v6.2) 编写 diff --git a/examples/vision/classification/yolov5cls/cpp/README.md b/examples/vision/classification/yolov5cls/cpp/README.md index de21e6dc3a..8fb38ec359 100755 --- a/examples/vision/classification/yolov5cls/cpp/README.md +++ b/examples/vision/classification/yolov5cls/cpp/README.md @@ -1,37 +1,38 @@ -# YOLOv5Cls C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv5Cls C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv5Cls在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that ` infer.cc` fast finishes the deployment of YOLOv5Cls models on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的yolov5模型文件和测试图片 +# Download the official converted yolov5 model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.onnx wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# CPU推理 +# CPU inference ./infer_demo yolov5n-cls.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov5n-cls.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo yolov5n-cls.onnx 000000014439.jpg 2 ``` -运行完成后返回结果如下所示 +The result returned after running is as follows ```bash ClassifyResult( label_ids: 265, @@ -39,12 +40,12 @@ scores: 0.196327, ) ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. Refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) for SDK use-pattern in Windows -## YOLOv5Cls C++接口 +## YOLOv5Cls C++ Interface -### YOLOv5Cls类 +### YOLOv5Cls Class ```c++ fastdeploy::vision::classification::YOLOv5Cls( @@ -54,37 +55,36 @@ fastdeploy::vision::classification::YOLOv5Cls( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv5Cls模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv5Cls model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv5Cls::Predict(cv::Mat* im, int topk = 1) > ``` > -> 模型预测接口,输入图像直接输出输出分类topk结果。 +> Model prediction interface. Input images and output classification topk results directly. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format +> > * **topk**(int): Return the topk classification results with the highest prediction probability. Default 1 - -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.ClassifyResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [YOLOv5Cls 模型介绍](..) -- [YOLOv5Cls Python部署](../python) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv5Cls Model Description](..) +- [YOLOv5Cls Python Deployment](../python) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/yolov5cls/cpp/README_CN.md b/examples/vision/classification/yolov5cls/cpp/README_CN.md new file mode 100644 index 0000000000..cd519cb0f9 --- /dev/null +++ b/examples/vision/classification/yolov5cls/cpp/README_CN.md @@ -0,0 +1,91 @@ +[English](README.md) | 简体中文 +# YOLOv5Cls C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv5Cls在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的yolov5模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.onnx +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + + +# CPU推理 +./infer_demo yolov5n-cls.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolov5n-cls.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov5n-cls.onnx 000000014439.jpg 2 +``` + +运行完成后返回结果如下所示 +```bash +ClassifyResult( +label_ids: 265, +scores: 0.196327, +) +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv5Cls C++接口 + +### YOLOv5Cls类 + +```c++ +fastdeploy::vision::classification::YOLOv5Cls( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv5Cls模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv5Cls::Predict(cv::Mat* im, int topk = 1) +> ``` +> +> 模型预测接口,输入图像直接输出输出分类topk结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 + + +> **返回** +> +> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [YOLOv5Cls 模型介绍](..) +- [YOLOv5Cls Python部署](../python) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/yolov5cls/python/README.md b/examples/vision/classification/yolov5cls/python/README.md index 4b024b2980..f964d73b62 100755 --- a/examples/vision/classification/yolov5cls/python/README.md +++ b/examples/vision/classification/yolov5cls/python/README.md @@ -1,30 +1,31 @@ -# YOLOv5Cls Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv5Cls Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv5Cls在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv5Cls on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/classification/yolov5cls/python/ -#下载 YOLOv5Cls 模型文件和测试图片 +# Download the YOLOv5Cls model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.onnx wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -# CPU推理 +# CPU inference python infer.py --model yolov5n-cls.onnx --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 -# GPU推理 +# GPU inference python infer.py --model yolov5n-cls.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolov5n-cls.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True ``` -运行完成后返回结果如下所示 +The result returned after running is as follows ```bash ClassifyResult( label_ids: 265, @@ -32,42 +33,42 @@ scores: 0.196327, ) ``` -## YOLOv5Cls Python接口 +## YOLOv5Cls Python Interface ```python fastdeploy.vision.classification.YOLOv5Cls(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv5Cls模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv5Cls model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict Function > ```python > YOLOv5Cls.predict(image_data, topk=1) > ``` > -> 模型预测结口,输入图像直接输出分类topk结果。 +> Model prediction interface. Input images and output classification topk results directly. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format +> > * **topk**(int): Return the topk classification results with the highest prediction probability. Default 1 -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.ClassifyResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [YOLOv5Cls 模型介绍](..) -- [YOLOv5Cls C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv5Cls Model Description](..) +- [YOLOv5Cls C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/classification/yolov5cls/python/README_CN.md b/examples/vision/classification/yolov5cls/python/README_CN.md new file mode 100644 index 0000000000..bf42ea307a --- /dev/null +++ b/examples/vision/classification/yolov5cls/python/README_CN.md @@ -0,0 +1,74 @@ +[English](README.md) | 简体中文 +# YOLOv5Cls Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv5Cls在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/classification/yolov5cls/python/ + +#下载 YOLOv5Cls 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n-cls.onnx +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg + +# CPU推理 +python infer.py --model yolov5n-cls.onnx --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 +# GPU推理 +python infer.py --model yolov5n-cls.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 +# GPU上使用TensorRT推理 +python infer.py --model yolov5n-cls.onnx --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True +``` + +运行完成后返回结果如下所示 +```bash +ClassifyResult( +label_ids: 265, +scores: 0.196327, +) +``` + +## YOLOv5Cls Python接口 + +```python +fastdeploy.vision.classification.YOLOv5Cls(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv5Cls模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv5Cls.predict(image_data, topk=1) +> ``` +> +> 模型预测结口,输入图像直接输出分类topk结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **topk**(int):返回预测概率最高的topk个分类结果,默认为1 + +> **返回** +> +> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [YOLOv5Cls 模型介绍](..) +- [YOLOv5Cls C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/README.md b/examples/vision/detection/README.md index 522a4d79e1..3271007ebd 100644 --- a/examples/vision/detection/README.md +++ b/examples/vision/detection/README.md @@ -1,20 +1,22 @@ -# 目标检测模型 +English | [简体中文](README_CN.md) -FastDeploy目前支持如下目标检测模型部署 +# Object Detection Model -| 模型 | 说明 | 模型格式 | 版本 | +FastDeploy currently supports the deployment of the following object detection models + +| Model | Description | Model format | Version | | :--- | :--- | :------- | :--- | -| [PaddleDetection/PP-YOLOE](./paddledetection) | PP-YOLOE(含P-PYOLOE+)系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | -| [PaddleDetection/PicoDet](./paddledetection) | PicoDet系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | -| [PaddleDetection/YOLOX](./paddledetection) | Paddle版本的YOLOX系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | -| [PaddleDetection/YOLOv3](./paddledetection) | YOLOv3系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | -| [PaddleDetection/PP-YOLO](./paddledetection) | PP-YOLO系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | -| [PaddleDetection/FasterRCNN](./paddledetection) | FasterRCNN系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | -| [WongKinYiu/YOLOv7](./yolov7) | YOLOv7、YOLOv7-X等系列模型 | ONNX | [Release/v0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) | -| [RangiLyu/NanoDetPlus](./nanodet_plus) | NanoDetPlus 系列模型 | ONNX | [Release/v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) | -| [ultralytics/YOLOv5](./yolov5) | YOLOv5 系列模型 | ONNX | [Release/v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) | -| [ppogg/YOLOv5-Lite](./yolov5lite) | YOLOv5-Lite 系列模型 | ONNX | [Release/v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) | -| [meituan/YOLOv6](./yolov6) | YOLOv6 系列模型 | ONNX | [Release/0.1.0](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) | -| [WongKinYiu/YOLOR](./yolor) | YOLOR 系列模型 | ONNX | [Release/weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) | -| [Megvii-BaseDetection/YOLOX](./yolox) | YOLOX 系列模型 | ONNX | [Release/v0.1.1](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) | -| [WongKinYiu/ScaledYOLOv4](./scaledyolov4) | ScaledYOLOv4 系列模型 | ONNX | [CommitID: 6768003](https://github.com/WongKinYiu/ScaledYOLOv4/commit/676800364a3446900b9e8407bc880ea2127b3415) | +| [PaddleDetection/PP-YOLOE](./paddledetection) | PP-YOLOE(including P-PYOLOE+) models | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/PicoDet](./paddledetection) | PicoDet models | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/YOLOX](./paddledetection) | YOLOX models of Paddle version | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/YOLOv3](./paddledetection) | YOLOv3 models | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/PP-YOLO](./paddledetection) | PP-YOLO models | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/FasterRCNN](./paddledetection) | FasterRCNN models | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [WongKinYiu/YOLOv7](./yolov7) | YOLOv7、YOLOv7-X models | ONNX | [Release/v0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) | +| [RangiLyu/NanoDetPlus](./nanodet_plus) | NanoDetPlus models | ONNX | [Release/v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) | +| [ultralytics/YOLOv5](./yolov5) | YOLOv5 models | ONNX | [Release/v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) | +| [ppogg/YOLOv5-Lite](./yolov5lite) | YOLOv5-Lite models | ONNX | [Release/v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) | +| [meituan/YOLOv6](./yolov6) | YOLOv6 models | ONNX | [Release/0.1.0](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) | +| [WongKinYiu/YOLOR](./yolor) | YOLOR models | ONNX | [Release/weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) | +| [Megvii-BaseDetection/YOLOX](./yolox) | YOLOX models | ONNX | [Release/v0.1.1](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) | +| [WongKinYiu/ScaledYOLOv4](./scaledyolov4) | ScaledYOLOv4 models | ONNX | [CommitID: 6768003](https://github.com/WongKinYiu/ScaledYOLOv4/commit/676800364a3446900b9e8407bc880ea2127b3415) | diff --git a/examples/vision/detection/README_CN.md b/examples/vision/detection/README_CN.md new file mode 100644 index 0000000000..5ebaf0728d --- /dev/null +++ b/examples/vision/detection/README_CN.md @@ -0,0 +1,21 @@ +[English](README.md) | 简体中文 +# 目标检测模型 + +FastDeploy目前支持如下目标检测模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +| :--- | :--- | :------- | :--- | +| [PaddleDetection/PP-YOLOE](./paddledetection) | PP-YOLOE(含P-PYOLOE+)系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/PicoDet](./paddledetection) | PicoDet系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/YOLOX](./paddledetection) | Paddle版本的YOLOX系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/YOLOv3](./paddledetection) | YOLOv3系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/PP-YOLO](./paddledetection) | PP-YOLO系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [PaddleDetection/FasterRCNN](./paddledetection) | FasterRCNN系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | +| [WongKinYiu/YOLOv7](./yolov7) | YOLOv7、YOLOv7-X等系列模型 | ONNX | [Release/v0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) | +| [RangiLyu/NanoDetPlus](./nanodet_plus) | NanoDetPlus 系列模型 | ONNX | [Release/v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) | +| [ultralytics/YOLOv5](./yolov5) | YOLOv5 系列模型 | ONNX | [Release/v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) | +| [ppogg/YOLOv5-Lite](./yolov5lite) | YOLOv5-Lite 系列模型 | ONNX | [Release/v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) | +| [meituan/YOLOv6](./yolov6) | YOLOv6 系列模型 | ONNX | [Release/0.1.0](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) | +| [WongKinYiu/YOLOR](./yolor) | YOLOR 系列模型 | ONNX | [Release/weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) | +| [Megvii-BaseDetection/YOLOX](./yolox) | YOLOX 系列模型 | ONNX | [Release/v0.1.1](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) | +| [WongKinYiu/ScaledYOLOv4](./scaledyolov4) | ScaledYOLOv4 系列模型 | ONNX | [CommitID: 6768003](https://github.com/WongKinYiu/ScaledYOLOv4/commit/676800364a3446900b9e8407bc880ea2127b3415) | diff --git a/examples/vision/detection/fastestdet/cpp/README.md b/examples/vision/detection/fastestdet/cpp/README.md index bf2d01394b..eca2c7b2d9 100644 --- a/examples/vision/detection/fastestdet/cpp/README.md +++ b/examples/vision/detection/fastestdet/cpp/README.md @@ -1,13 +1,13 @@ -# FastestDet C++部署示例 +English | [简体中文](README_CN.md) +# FastestDet C++ Deployment Example -本目录下提供`infer.cc`快速完成FastestDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of FastestDet on CPU/GPU and GPU accelerated by TensorRT. +Before deployment, two steps require confirmation -在部署前,需确认以下两个步骤 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. ```bash mkdir build @@ -17,29 +17,29 @@ tar xvf fastdeploy-linux-x64-1.0.3.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-1.0.3 make -j -#下载官方转换好的FastestDet模型文件和测试图片 +# Download the official converted FastestDet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/FastestDet.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo FastestDet.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo FastestDet.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo FastestDet.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## FastestDet C++接口 +## FastestDet C++ Interface -### FastestDet类 +### FastestDet Class ```c++ fastdeploy::vision::detection::FastestDet( @@ -49,16 +49,16 @@ fastdeploy::vision::detection::FastestDet( const ModelFormat& model_format = ModelFormat::ONNX) ``` -FastestDet模型加载和初始化,其中model_file为导出的ONNX模型格式。 +FastestDet model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > FastestDet::Predict(cv::Mat* im, DetectionResult* result, @@ -66,22 +66,22 @@ FastestDet模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.45) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[352, 352] +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [352, 352] -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/fastestdet/cpp/README_CN.md b/examples/vision/detection/fastestdet/cpp/README_CN.md new file mode 100644 index 0000000000..7c940183ef --- /dev/null +++ b/examples/vision/detection/fastestdet/cpp/README_CN.md @@ -0,0 +1,88 @@ +[English](README.md) | 简体中文 +# FastestDet C++部署示例 + +本目录下提供`infer.cc`快速完成FastestDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 + +```bash +mkdir build +cd build +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.3.tgz +tar xvf fastdeploy-linux-x64-1.0.3.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-1.0.3 +make -j + +#下载官方转换好的FastestDet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/FastestDet.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo FastestDet.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo FastestDet.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo FastestDet.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## FastestDet C++接口 + +### FastestDet类 + +```c++ +fastdeploy::vision::detection::FastestDet( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +FastestDet模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> FastestDet::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.65, +> float nms_iou_threshold = 0.45) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[352, 352] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/fastestdet/python/README.md b/examples/vision/detection/fastestdet/python/README.md index 000bf05cc6..492683ec72 100644 --- a/examples/vision/detection/fastestdet/python/README.md +++ b/examples/vision/detection/fastestdet/python/README.md @@ -1,74 +1,75 @@ -# FastestDet Python部署示例 +English | [简体中文](README_CN.md) +# FastestDet Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成FastestDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of FastestDet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/fastestdet/python/ -#下载fastestdet模型文件和测试图片 +# Download fastestdet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/FastestDet.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model FastestDet.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model FastestDet.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model FastestDet.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## FastestDet Python接口 +## FastestDet Python Interface ```python fastdeploy.vision.detection.FastestDet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -FastestDet模型加载和初始化,其中model_file为导出的ONNX模型格式 +FastestDet model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > FastestDet.predict(image_data) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its structure -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[352, 352] +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [352, 352] -## 其它文档 +## Other Documents -- [FastestDet 模型介绍](..) -- [FastestDet C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [FastestDet Model Description](..) +- [FastestDet C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/fastestdet/python/README_CN.md b/examples/vision/detection/fastestdet/python/README_CN.md new file mode 100644 index 0000000000..dce8e469fb --- /dev/null +++ b/examples/vision/detection/fastestdet/python/README_CN.md @@ -0,0 +1,75 @@ +[English](README.md) | 简体中文 +# FastestDet Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成FastestDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/fastestdet/python/ + +#下载fastestdet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/FastestDet.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model FastestDet.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model FastestDet.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model FastestDet.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## FastestDet Python接口 + +```python +fastdeploy.vision.detection.FastestDet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +FastestDet模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> FastestDet.predict(image_data) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[352, 352] + + +## 其它文档 + +- [FastestDet 模型介绍](..) +- [FastestDet C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/nanodet_plus/README.md b/examples/vision/detection/nanodet_plus/README.md index 883164a3a0..bc5b31f756 100644 --- a/examples/vision/detection/nanodet_plus/README.md +++ b/examples/vision/detection/nanodet_plus/README.md @@ -1,26 +1,27 @@ -# NanoDetPlus准备部署模型 +English | [简体中文](README_CN.md) +# NanoDetPlus Ready-to-deploy Model -- NanoDetPlus部署实现来自[NanoDetPlus](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 的代码,基于coco的[预训练模型](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)。 +- NanoDetPlus deployment is based on the code of [NanoDetPlus](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) and coco's [Pre-trained Model](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1). - - (1)[官方库](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)提供的*.onnx可直接进行部署; - - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)The *.onnx provided by [official repository](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1) can directly conduct the deployment; + - (2)Models trained by developers should export ONNX models. Please refer to [Detailed Deployment Documents](#详细部署文档) for deployment. -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了NanoDetPlus导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by NanoDetPlus are provided below. Developers can download them directly. (The model accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [NanoDetPlus_320](https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx ) | 4.6MB | 27.0% | | [NanoDetPlus_320_sim](https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320-sim.onnx) | 4.6MB | 27.0% | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[NanoDetPlus v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 编写 +- Document and code are based on [NanoDetPlus v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) diff --git a/examples/vision/detection/nanodet_plus/README_CN.md b/examples/vision/detection/nanodet_plus/README_CN.md new file mode 100644 index 0000000000..acc87b05e3 --- /dev/null +++ b/examples/vision/detection/nanodet_plus/README_CN.md @@ -0,0 +1,27 @@ +[English](README.md) | 简体中文 +# NanoDetPlus准备部署模型 + + +- NanoDetPlus部署实现来自[NanoDetPlus](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 的代码,基于coco的[预训练模型](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)。 + + - (1)[官方库](https://github.com/RangiLyu/nanodet/releases/tag/v1.0.0-alpha-1)提供的*.onnx可直接进行部署; + - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了NanoDetPlus导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [NanoDetPlus_320](https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx ) | 4.6MB | 27.0% | +| [NanoDetPlus_320_sim](https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320-sim.onnx) | 4.6MB | 27.0% | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[NanoDetPlus v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) 编写 diff --git a/examples/vision/detection/nanodet_plus/cpp/README.md b/examples/vision/detection/nanodet_plus/cpp/README.md index bf980355d4..8ef4b6a97e 100644 --- a/examples/vision/detection/nanodet_plus/cpp/README.md +++ b/examples/vision/detection/nanodet_plus/cpp/README.md @@ -1,46 +1,47 @@ -# NanoDetPlus C++部署示例 +English | [简体中文](README_CN.md) +# NanoDetPlus C++ Deployment Example -本目录下提供`infer.cc`快速完成NanoDetPlus在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of NanoDetPlus on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的NanoDetPlus模型文件和测试图片 +# Download the official converted NanoDetPlus model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo nanodet-plus-m_320.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo nanodet-plus-m_320.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo nanodet-plus-m_320.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## NanoDetPlus C++接口 +## NanoDetPlus C++ Interface -### NanoDetPlus类 +### NanoDetPlus Class ```c++ fastdeploy::vision::detection::NanoDetPlus( @@ -50,16 +51,16 @@ fastdeploy::vision::detection::NanoDetPlus( const ModelFormat& model_format = ModelFormat::ONNX) ``` -NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格式。 +NanoDetPlus model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > NanoDetPlus::Predict(cv::Mat* im, DetectionResult* result, @@ -67,27 +68,27 @@ NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 - -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 320] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0] -> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle. -> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7. -> > * **downsample_strides**(vector<int>): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64] - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable + +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [320, 320] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [0, 0, 0] +> > * **keep_ratio**(bool): Whether to keep the aspect ratio unchanged during resize. Default fasle +> > * **reg_max**(int): The reg_max parameter in GFL regression. Default 7 +> > * **downsample_strides**(vector<int>): This parameter is used to change the down-sampling multiple of the feature map that generates anchor, containing three integer elements that represent the default down-sampling multiple for generating anchor. Default value [8, 16, 32, 64] + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/nanodet_plus/cpp/README_CN.md b/examples/vision/detection/nanodet_plus/cpp/README_CN.md new file mode 100644 index 0000000000..b8210fb175 --- /dev/null +++ b/examples/vision/detection/nanodet_plus/cpp/README_CN.md @@ -0,0 +1,94 @@ +[English](README.md) | 简体中文 +# NanoDetPlus C++部署示例 + +本目录下提供`infer.cc`快速完成NanoDetPlus在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的NanoDetPlus模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo nanodet-plus-m_320.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo nanodet-plus-m_320.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo nanodet-plus-m_320.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## NanoDetPlus C++接口 + +### NanoDetPlus类 + +```c++ +fastdeploy::vision::detection::NanoDetPlus( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> NanoDetPlus::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 + +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 320] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0] +> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle. +> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7. +> > * **downsample_strides**(vector<int>): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/nanodet_plus/python/README.md b/examples/vision/detection/nanodet_plus/python/README.md index a89e15d1b1..2995cb2977 100644 --- a/examples/vision/detection/nanodet_plus/python/README.md +++ b/examples/vision/detection/nanodet_plus/python/README.md @@ -1,81 +1,81 @@ -# NanoDetPlus Python部署示例 +English | [简体中文](README_CN.md) +# NanoDetPlus Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成NanoDetPlus在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishes the deployment of NanoDetPlus on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/nanodet_plus/python/ -#下载NanoDetPlus模型文件和测试图片 +# Download NanoDetPlus model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## NanoDetPlus Python接口 +## NanoDetPlus Python Interface ```python fastdeploy.vision.detection.NanoDetPlus(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格式 +NanoDetPlus model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > NanoDetPlus.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 320] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0] -> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle. -> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7. -> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含四个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64] +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [320, 320] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [0, 0, 0] +> > * **keep_ratio**(bool): Whether to keep the aspect ratio unchanged during resize. Default false +> > * **reg_max**(int): The reg_max parameter in GFL regression. Default 7. +> > * **downsample_strides**(list[int]): This parameter is used to change the down-sampling multiple of the feature map that generates anchor, containing four integer elements that represent the default down-sampling multiple for generating anchor. Default [8, 16, 32, 64] -## 其它文档 +## Other Documents -- [NanoDetPlus 模型介绍](..) -- [NanoDetPlus C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [NanoDetPlus Model Description](..) +- [NanoDetPlus C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/nanodet_plus/python/README_CN.md b/examples/vision/detection/nanodet_plus/python/README_CN.md new file mode 100644 index 0000000000..63e5a14824 --- /dev/null +++ b/examples/vision/detection/nanodet_plus/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# NanoDetPlus Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成NanoDetPlus在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/nanodet_plus/python/ + +#下载NanoDetPlus模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model nanodet-plus-m_320.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## NanoDetPlus Python接口 + +```python +fastdeploy.vision.detection.NanoDetPlus(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> NanoDetPlus.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 320] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0] +> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle. +> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7. +> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含四个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64] + + + +## 其它文档 + +- [NanoDetPlus 模型介绍](..) +- [NanoDetPlus C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/paddledetection/README.md b/examples/vision/detection/paddledetection/README.md index 11b616ba90..0fdcd24b95 100644 --- a/examples/vision/detection/paddledetection/README.md +++ b/examples/vision/detection/paddledetection/README.md @@ -1,65 +1,56 @@ -# PaddleDetection模型部署 +English | [简体中文](README_CN.md) +# PaddleDetection Model Deployment -## 模型版本说明 +## Model Description - [PaddleDetection Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PP-YOLOE(含PP-YOLOE+)系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) -- [PicoDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) -- [PP-YOLO系列模型(含v2)](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyolo) -- [YOLOv3系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/yolov3) -- [YOLOX系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/yolox) -- [FasterRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/faster_rcnn) -- [MaskRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/mask_rcnn) -- [SSD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ssd) -- [YOLOv5系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov5) -- [YOLOv6系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov6) -- [YOLOv7系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov7) -- [RTMDet系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/rtmdet) -- [CascadeRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/cascade_rcnn) -- [PSSDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/rcnn_enhance) -- [RetinaNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/retinanet) -- [PPYOLOESOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/smalldet) -- [FCOS系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/fcos) -- [TTFNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ttfnet) -- [TOOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/tood) -- [GFL系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/gfl) +- [PP-YOLOE(including PP-YOLOE+) models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) +- [PicoDet models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) +- [PP-YOLO models(including v2)](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyolo) +- [YOLOv3 models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/yolov3) +- [YOLOX models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/yolox) +- [FasterRCNN models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/faster_rcnn) +- [MaskRCNN models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/mask_rcnn) +- [SSD models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ssd) +- [YOLOv5 models](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov5) +- [YOLOv6 models](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov6) +- [YOLOv7 models](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov7) +- [RTMDet models](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/rtmdet) +## Export Deployment Model -## 导出部署模型 +Before deployment, PaddleDetection needs to be exported into the deployment model. Refer to [Export Models](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md) for more details. -在部署前,需要先将PaddleDetection导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md) +**Attention** +- Do not perform NMS removal when exporting the model +- If you are running a native TensorRT backend (not a Paddle Inference backend), do not add the --trt parameter +- Do not add the parameter `fuse_normalize=True` when exporting the model -**注意** -- 在导出模型时不要进行NMS的去除操作,正常导出即可 -- 如果用于跑原生TensorRT后端(非Paddle Inference后端),不要添加--trt参数 -- 导出模型时,不要添加`fuse_normalize=True`参数 +## Download Pre-trained Model -## 下载预训练模型 +For developers' testing, models exported by PaddleDetection are provided below. Developers can download them directly. -为了方便开发者的测试,下面提供了PaddleDetection导出的各系列模型,开发者可直接下载使用。 +The accuracy metric is from model descriptions in PaddleDetection. Refer to them for details. -其中精度指标来源于PaddleDetection中对各模型的介绍,详情各参考PaddleDetection中的说明。 - - -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | | [picodet_l_320_coco_lcnet](https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz) |23MB | Box AP 42.6% | | [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz) |200MB | Box AP 51.4% | | [ppyoloe_plus_crn_m_80e_coco](https://bj.bcebos.com/fastdeploy/models/ppyoloe_plus_crn_m_80e_coco.tgz) |83.3MB | Box AP 49.8% | -| [ppyolo_r50vd_dcn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolo_r50vd_dcn_1x_coco.tgz) | 180MB | Box AP 44.8% | 暂不支持TensorRT | -| [ppyolov2_r101vd_dcn_365e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolov2_r101vd_dcn_365e_coco.tgz) | 282MB | Box AP 49.7% | 暂不支持TensorRT | +| [ppyolo_r50vd_dcn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolo_r50vd_dcn_1x_coco.tgz) | 180MB | Box AP 44.8% | TensorRT not supported yet | +| [ppyolov2_r101vd_dcn_365e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolov2_r101vd_dcn_365e_coco.tgz) | 282MB | Box AP 49.7% | TensorRT not supported yet | | [yolov3_darknet53_270e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov3_darknet53_270e_coco.tgz) |237MB | Box AP 39.1% | | | [yolox_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s_300e_coco.tgz) | 35MB | Box AP 40.4% | | -| [faster_rcnn_r50_vd_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_r50_vd_fpn_2x_coco.tgz) | 160MB | Box AP 40.8%| 暂不支持TensorRT | -| [mask_rcnn_r50_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/mask_rcnn_r50_1x_coco.tgz) | 128M | Box AP 37.4%, Mask AP 32.8%| 暂不支持TensorRT、ORT | -| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 24.9M | Box AP 73.8%| 暂不支持TensorRT、ORT | -| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 106.5M | Box AP 77.8%| 暂不支持TensorRT、ORT | -| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 29.1M | | 暂不支持TensorRT、ORT | +| [faster_rcnn_r50_vd_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_r50_vd_fpn_2x_coco.tgz) | 160MB | Box AP 40.8%| TensorRT not supported yet | +| [mask_rcnn_r50_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/mask_rcnn_r50_1x_coco.tgz) | 128M | Box AP 37.4%, Mask AP 32.8%| TensorRT、ORT not supported yet | +| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 24.9M | Box AP 73.8%| TensorRT、ORT not supported yet | +| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 106.5M | Box AP 77.8%| TensorRT、ORT not supported yet | +| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 29.1M | | TensorRT、ORT not supported yet| | [rtmdet_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_l_300e_coco.tgz) | 224M | Box AP 51.2%| | | [rtmdet_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_s_300e_coco.tgz) | 42M | Box AP 44.5%| | | [yolov5_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_l_300e_coco.tgz) | 183M | Box AP 48.9%| | @@ -68,18 +59,8 @@ | [yolov6_s_400e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_s_400e_coco.tgz) | 68M | Box AP 43.4%| | | [yolov7_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_l_300e_coco.tgz) | 145M | Box AP 51.0%| | | [yolov7_x_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_x_300e_coco.tgz) | 277M | Box AP 53.0%| | -| [cascade_rcnn_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_fpn_1x_coco.tgz) | 271M | Box AP 41.1%| 暂不支持TensorRT、ORT | -| [cascade_rcnn_r50_vd_fpn_ssld_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_vd_fpn_ssld_2x_coco.tgz) | 271M | Box AP 45.0%| 暂不支持TensorRT、ORT | -| [faster_rcnn_enhance_3x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_enhance_3x_coco.tgz) | 119M | Box AP 41.5%| 暂不支持TensorRT、ORT | -| [fcos_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/fcos_r50_fpn_1x_coco.tgz) | 129M | Box AP 39.6%| 暂不支持TensorRT | -| [gfl_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/gfl_r50_fpn_1x_coco.tgz) | 128M | Box AP 41.0%| 暂不支持TensorRT | -| [ppyoloe_crn_l_80e_sliced_visdrone_640_025](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_80e_sliced_visdrone_640_025.tgz) | 200M | Box AP 31.9%| | -| [retinanet_r101_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r101_fpn_2x_coco.tgz) | 210M | Box AP 40.6%| 暂不支持TensorRT、ORT | -| [retinanet_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r50_fpn_1x_coco.tgz) | 136M | Box AP 37.5%| 暂不支持TensorRT、ORT | -| [tood_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/tood_r50_fpn_1x_coco.tgz) | 130M | Box AP 42.5%| 暂不支持TensorRT、ORT | -| [ttfnet_darknet53_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ttfnet_darknet53_1x_coco.tgz) | 178M | Box AP 33.5%| 暂不支持TensorRT、ORT | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/paddledetection/README_CN.md b/examples/vision/detection/paddledetection/README_CN.md new file mode 100644 index 0000000000..f7e78091a0 --- /dev/null +++ b/examples/vision/detection/paddledetection/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# PaddleDetection模型部署 + +## 模型版本说明 + +- [PaddleDetection Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PP-YOLOE(含PP-YOLOE+)系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) +- [PicoDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) +- [PP-YOLO系列模型(含v2)](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyolo) +- [YOLOv3系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/yolov3) +- [YOLOX系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/yolox) +- [FasterRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/faster_rcnn) +- [MaskRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/mask_rcnn) +- [SSD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ssd) +- [YOLOv5系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov5) +- [YOLOv6系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov6) +- [YOLOv7系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov7) +- [RTMDet系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/rtmdet) +- [CascadeRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/cascade_rcnn) +- [PSSDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/rcnn_enhance) +- [RetinaNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/retinanet) +- [PPYOLOESOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/smalldet) +- [FCOS系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/fcos) +- [TTFNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ttfnet) +- [TOOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/tood) +- [GFL系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/gfl) + + +## 导出部署模型 + +在部署前,需要先将PaddleDetection导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md) + +**注意** +- 在导出模型时不要进行NMS的去除操作,正常导出即可 +- 如果用于跑原生TensorRT后端(非Paddle Inference后端),不要添加--trt参数 +- 导出模型时,不要添加`fuse_normalize=True`参数 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleDetection导出的各系列模型,开发者可直接下载使用。 + +其中精度指标来源于PaddleDetection中对各模型的介绍,详情各参考PaddleDetection中的说明。 + + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [picodet_l_320_coco_lcnet](https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz) |23MB | Box AP 42.6% | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz) |200MB | Box AP 51.4% | +| [ppyoloe_plus_crn_m_80e_coco](https://bj.bcebos.com/fastdeploy/models/ppyoloe_plus_crn_m_80e_coco.tgz) |83.3MB | Box AP 49.8% | +| [ppyolo_r50vd_dcn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolo_r50vd_dcn_1x_coco.tgz) | 180MB | Box AP 44.8% | 暂不支持TensorRT | +| [ppyolov2_r101vd_dcn_365e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyolov2_r101vd_dcn_365e_coco.tgz) | 282MB | Box AP 49.7% | 暂不支持TensorRT | +| [yolov3_darknet53_270e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov3_darknet53_270e_coco.tgz) |237MB | Box AP 39.1% | | +| [yolox_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s_300e_coco.tgz) | 35MB | Box AP 40.4% | | +| [faster_rcnn_r50_vd_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_r50_vd_fpn_2x_coco.tgz) | 160MB | Box AP 40.8%| 暂不支持TensorRT | +| [mask_rcnn_r50_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/mask_rcnn_r50_1x_coco.tgz) | 128M | Box AP 37.4%, Mask AP 32.8%| 暂不支持TensorRT、ORT | +| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 24.9M | Box AP 73.8%| 暂不支持TensorRT、ORT | +| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 106.5M | Box AP 77.8%| 暂不支持TensorRT、ORT | +| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 29.1M | | 暂不支持TensorRT、ORT | +| [rtmdet_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_l_300e_coco.tgz) | 224M | Box AP 51.2%| | +| [rtmdet_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_s_300e_coco.tgz) | 42M | Box AP 44.5%| | +| [yolov5_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_l_300e_coco.tgz) | 183M | Box AP 48.9%| | +| [yolov5_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_s_300e_coco.tgz) | 31M | Box AP 37.6%| | +| [yolov6_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_l_300e_coco.tgz) | 229M | Box AP 51.0%| | +| [yolov6_s_400e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_s_400e_coco.tgz) | 68M | Box AP 43.4%| | +| [yolov7_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_l_300e_coco.tgz) | 145M | Box AP 51.0%| | +| [yolov7_x_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_x_300e_coco.tgz) | 277M | Box AP 53.0%| | +| [cascade_rcnn_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_fpn_1x_coco.tgz) | 271M | Box AP 41.1%| 暂不支持TensorRT、ORT | +| [cascade_rcnn_r50_vd_fpn_ssld_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_vd_fpn_ssld_2x_coco.tgz) | 271M | Box AP 45.0%| 暂不支持TensorRT、ORT | +| [faster_rcnn_enhance_3x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_enhance_3x_coco.tgz) | 119M | Box AP 41.5%| 暂不支持TensorRT、ORT | +| [fcos_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/fcos_r50_fpn_1x_coco.tgz) | 129M | Box AP 39.6%| 暂不支持TensorRT | +| [gfl_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/gfl_r50_fpn_1x_coco.tgz) | 128M | Box AP 41.0%| 暂不支持TensorRT | +| [ppyoloe_crn_l_80e_sliced_visdrone_640_025](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_80e_sliced_visdrone_640_025.tgz) | 200M | Box AP 31.9%| | +| [retinanet_r101_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r101_fpn_2x_coco.tgz) | 210M | Box AP 40.6%| 暂不支持TensorRT、ORT | +| [retinanet_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r50_fpn_1x_coco.tgz) | 136M | Box AP 37.5%| 暂不支持TensorRT、ORT | +| [tood_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/tood_r50_fpn_1x_coco.tgz) | 130M | Box AP 42.5%| 暂不支持TensorRT、ORT | +| [ttfnet_darknet53_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ttfnet_darknet53_1x_coco.tgz) | 178M | Box AP 33.5%| 暂不支持TensorRT、ORT | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/detection/paddledetection/a311d/README.md b/examples/vision/detection/paddledetection/a311d/README.md index 0619e788a3..916a41cf97 100755 --- a/examples/vision/detection/paddledetection/a311d/README.md +++ b/examples/vision/detection/paddledetection/a311d/README.md @@ -1,11 +1,12 @@ -# PP-YOLOE 量化模型在 A311D 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 量化模型到 A311D 上。 +English | [简体中文](README_CN.md) +# Deploy PP-YOLOE Quantification Model on A311D +Now FastDeploy supports the deployment of PP-YOLOE quantification model to A311D on Paddle Lite. -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +For model quantification and download, refer to [Model Quantification](../quantize/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -在 A311D 上只支持 C++ 的部署。 +Only C++ deployment is supported on A311D -- [C++部署](cpp) +- [C++ deployment](cpp) diff --git a/examples/vision/detection/paddledetection/a311d/README_CN.md b/examples/vision/detection/paddledetection/a311d/README_CN.md new file mode 100644 index 0000000000..2bb531e531 --- /dev/null +++ b/examples/vision/detection/paddledetection/a311d/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# PP-YOLOE 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/detection/paddledetection/android/README.md b/examples/vision/detection/paddledetection/android/README.md index 3669bc2a43..311a6b06e9 100644 --- a/examples/vision/detection/paddledetection/android/README.md +++ b/examples/vision/detection/paddledetection/android/README.md @@ -1,87 +1,88 @@ -# 目标检测 PicoDet Android Demo 使用文档 +English | [简体中文](README_CN.md) +# Target Detection PicoDet Android Demo Tutorial -在 Android 上实现实时的目标检测功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 +Real-time target detection on Android. This Demo is simple to use for everyone. For example, you can run your own trained model in the Demo. -## 环境准备 +## Prepare the Environment -1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 -2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` +1. Install Android Studio in your local environment. Refer to [Android Studio Official Website](https://developer.android.com/studio) for detailed tutorial. +2. Prepare an Android phone and turn on the USB debug mode: `Settings -> Find developer options -> Open developer options and USB debug mode` -## 部署步骤 +## Deployment Steps -1. 目标检测 PicoDet Demo 位于 `fastdeploy/examples/vision/detection/paddledetection/android` 目录 -2. 用 Android Studio 打开 paddledetection/android 工程 -3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) +1. The target detection PicoDet Demo is located in the `fastdeploy/examples/vision/detection/paddledetection/android` directory +2. Open paddledetection/android project with Android Studio +3. Connect the phone to the computer, turn on USB debug mode and file transfer mode, and connect your phone to Android Studio (allow the phone to install software from USB)

image

-> **注意:** ->> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 +> **Attention:** +>> If you encounter an NDK configuration error during import, compilation or running, open ` File > Project Structure > SDK Location` and change the path of SDK configured by the `Andriod SDK location`. -4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) -成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 +4. Click the Run button to automatically compile the APP and install it to the phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files. Internet is required). +The final effect is as follows. Figure 1: Install the APP on the phone; Figure 2: The effect when opening the APP. It will automatically recognize and mark the objects in the image; Figure 3: APP setting option. Click setting in the upper right corner and modify your options. -| APP 图标 | APP 效果 | APP设置项 +| APP Icon | APP Effect | APP Settings | --- | --- | --- | | image | image | image | -### PicoDet Java API 说明 -- 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。PicoDet初始化参数说明如下: - - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel - - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams - - configFile: String, 模型推理的预处理配置文件,如 infer_cfg.yml - - labelFile: String, 可选参数,表示label标签文件所在路径,用于可视化,如 coco_label_list.txt,每一行包含一个label - - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 +### PicoDet Java API Description +- Model initialized API: The initialized API contains two ways: Firstly, initialize directly through the constructor. Secondly, initialize at the appropriate program node by calling the init function. PicoDet initialization parameters are as follows. + - modelFile: String. Model file path in paddle format, such as model.pdmodel + - paramFile: String. Parameter file path in paddle format, such as model.pdiparams + - configFile: String. Preprocessing file for model inference, such as infer_cfg.yml + - labelFile: String. This optional parameter indicates the path of the label file and is used for visualization, such as coco_label_list.txt, each line containing one label + - option: RuntimeOption. Optional parameter for model initialization. Default runtime options if not passing the parameter. ```java -// 构造函数: constructor w/o label file -public PicoDet(); // 空构造函数,之后可以调用init初始化 +// Constructor: constructor w/o label file +public PicoDet(); // An empty constructor, which can be initialized by calling init public PicoDet(String modelFile, String paramsFile, String configFile); public PicoDet(String modelFile, String paramsFile, String configFile, String labelFile); public PicoDet(String modelFile, String paramsFile, String configFile, RuntimeOption option); public PicoDet(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); -// 手动调用init初始化: call init manually w/o label file +// Call init manually for initialization: call init manually w/o label file public boolean init(String modelFile, String paramsFile, String configFile, RuntimeOption option); public boolean init(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); ``` -- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +- Model Prediction API: The Model Prediction API contains an API for direct prediction and an API for visualization. In direct prediction, we do not save the image and render the result on Bitmap. Instead, we merely predict the inference result. For prediction and visualization, the results are both predicted and visualized, the visualized images are saved to the specified path, and the visualized results are rendered in Bitmap (Now Bitmap in ARGB8888 format is supported). Afterward, the Bitmap can be displayed on the camera. ```java -// 直接预测:不保存图片以及不渲染结果到Bitmap上 +// Direct prediction: No image saving and no result rendering to Bitmap public DetectionResult predict(Bitmap ARGB8888Bitmap); -// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +// Prediction and visualization: Predict and visualize the results, save the visualized image to the specified path, and render the visualized results on Bitmap public DetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold); -public DetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // 只渲染 不保存图片 +public DetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // Render without saving images ``` -- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +- Model resource release API: Call release() API to release model resources. Return true for successful release and false for failure; call initialized() to determine whether the model was initialized successfully, with true indicating successful initialization and false indicating failure. ```java -public boolean release(); // 释放native资源 -public boolean initialized(); // 检查是否初始化成功 +public boolean release(); // Release native resources +public boolean initialized(); // Check if the initialization is successful ``` -- RuntimeOption设置说明 +- RuntimeOption settings ```java -public void enableLiteFp16(); // 开启fp16精度推理 -public void disableLiteFP16(); // 关闭fp16精度推理 -public void setCpuThreadNum(int threadNum); // 设置线程数 -public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 -public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +public void enableLiteFp16(); // Enable fp16 accuracy inference +public void disableLiteFP16(); // Disable fp16 accuracy inference +public void setCpuThreadNum(int threadNum); // Set thread numbers +public void setLitePowerMode(LitePowerMode mode); // Set power mode +public void setLitePowerMode(String modeStr); // Set power mode through character string ``` -- 模型结果DetectionResult说明 +- Model DetectionResult ```java public class DetectionResult { - public float[][] mBoxes; // [n,4] 检测框 (x1,y1,x2,y2) - public float[] mScores; // [n] 每个检测框得分(置信度,概率值) - public int[] mLabelIds; // [n] 分类ID - public boolean initialized(); // 检测结果是否有效 + public float[][] mBoxes; // [n,4] Detection box (x1,y1,x2,y2) + public float[] mScores; // [n] Score (confidence, probability) + public int[] mLabelIds; // [n] Classification ID + public boolean initialized(); // Whether the result is valid } ``` -其他参考:C++/Python对应的DetectionResult说明: [api/vision_results/detection_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/detection_result.md) +Refer to [api/vision_results/detection_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/detection_result.md) for C++/Python DetectionResult -- 模型调用示例1:使用构造函数以及默认的RuntimeOption +- Model Calling Example 1: Using Constructor and the default RuntimeOption ```java import java.nio.ByteBuffer; import android.graphics.Bitmap; @@ -90,63 +91,63 @@ import android.opengl.GLES20; import com.baidu.paddle.fastdeploy.vision.DetectionResult; import com.baidu.paddle.fastdeploy.vision.detection.PicoDet; -// 初始化模型 +// Initialize the model PicoDet model = new PicoDet("picodet_s_320_coco_lcnet/model.pdmodel", "picodet_s_320_coco_lcnet/model.pdiparams", "picodet_s_320_coco_lcnet/infer_cfg.yml"); -// 读取图片: 以下仅为读取Bitmap的伪代码 +// Read the image: The following is merely the pseudo code to read 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); -// 模型推理 +// Model inference DetectionResult result = model.predict(ARGB8888ImageBitmap); -// 释放模型资源 +// Release model resources model.release(); ``` -- 模型调用示例2: 在合适的程序节点,手动调用init,并自定义RuntimeOption +- Model calling example 2: Manually call init at the appropriate program node and self-define RuntimeOption ```java -// import 同上 ... +// import is as the above... import com.baidu.paddle.fastdeploy.RuntimeOption; import com.baidu.paddle.fastdeploy.LitePowerMode; import com.baidu.paddle.fastdeploy.vision.DetectionResult; import com.baidu.paddle.fastdeploy.vision.detection.PicoDet; -// 新建空模型 +// Create an empty model PicoDet model = new PicoDet(); -// 模型路径 +// Model path String modelFile = "picodet_s_320_coco_lcnet/model.pdmodel"; String paramFile = "picodet_s_320_coco_lcnet/model.pdiparams"; String configFile = "picodet_s_320_coco_lcnet/infer_cfg.yml"; -// 指定RuntimeOption +// Specify RuntimeOption RuntimeOption option = new RuntimeOption(); option.setCpuThreadNum(2); option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); option.enableLiteFp16(); -// 使用init函数初始化 +// Use init function for initialization model.init(modelFile, paramFile, configFile, option); -// Bitmap读取、模型预测、资源释放 同上 ... +// Bitmap reading, model prediction, and resource release are as above... ``` -更详细的用法请参考 [DetectionMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java) 中的用法 +Refer to [DetectionMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java) for more information. -## 替换 FastDeploy SDK和模型 -替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/picodet_s_320_coco_lcnet`。 -- 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: - - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +## Replace FastDeploy SDK and Models +It’s simple to replace the FastDeploy prediction library and models. The prediction library is located at `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` represents the version of your prediction library. The models are located at `app/src/main/assets/models/picodet_s_320_coco_lcnet`. +- Replace the FastDeploy Android SDK: Download or compile the latest FastDeploy Android SDK, unzip and place it in the `app/libs` directory; For detailed configuration, refer to + - [FastDeploy Java SDK in Android](../../../../../java/android/) -- 替换PicoDet模型的步骤: - - 将您的PicoDet模型放在 `app/src/main/assets/models` 目录下; - - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +- Steps to replace PicoDet models: + - Put your PicoDet model in `app/src/main/assets/models`; + - Modify the default value of the model path in `app/src/main/res/values/strings.xml`. For example: ```xml - + models/picodet_s_320_coco_lcnet labels/coco_label_list.txt ``` -## 更多参考文档 -如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: -- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) -- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) +## More Reference Documents +For more FastDeploy Java API documentes and how to access FastDeploy C++ API via JNI, refer to: +- [FastDeploy Java SDK in Android](../../../../../java/android/) +- [FastDeploy C++ SDK in Android](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/detection/paddledetection/android/README_CN.md b/examples/vision/detection/paddledetection/android/README_CN.md new file mode 100644 index 0000000000..c2eea2ab22 --- /dev/null +++ b/examples/vision/detection/paddledetection/android/README_CN.md @@ -0,0 +1,153 @@ +[English](README.md) | 简体中文 +# 目标检测 PicoDet Android Demo 使用文档 + +在 Android 上实现实时的目标检测功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 + +## 环境准备 + +1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 +2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` + +## 部署步骤 + +1. 目标检测 PicoDet Demo 位于 `fastdeploy/examples/vision/detection/paddledetection/android` 目录 +2. 用 Android Studio 打开 paddledetection/android 工程 +3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) + +

+image +

+ +> **注意:** +>> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 + +4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) +成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 + +| APP 图标 | APP 效果 | APP设置项 + | --- | --- | --- | + | image | image | image | + + +### PicoDet Java API 说明 +- 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。PicoDet初始化参数说明如下: + - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel + - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams + - configFile: String, 模型推理的预处理配置文件,如 infer_cfg.yml + - labelFile: String, 可选参数,表示label标签文件所在路径,用于可视化,如 coco_label_list.txt,每一行包含一个label + - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 + +```java +// 构造函数: constructor w/o label file +public PicoDet(); // 空构造函数,之后可以调用init初始化 +public PicoDet(String modelFile, String paramsFile, String configFile); +public PicoDet(String modelFile, String paramsFile, String configFile, String labelFile); +public PicoDet(String modelFile, String paramsFile, String configFile, RuntimeOption option); +public PicoDet(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); +// 手动调用init初始化: call init manually w/o label file +public boolean init(String modelFile, String paramsFile, String configFile, RuntimeOption option); +public boolean init(String modelFile, String paramsFile, String configFile, String labelFile, RuntimeOption option); +``` +- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +```java +// 直接预测:不保存图片以及不渲染结果到Bitmap上 +public DetectionResult predict(Bitmap ARGB8888Bitmap); +// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +public DetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold); +public DetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // 只渲染 不保存图片 +``` +- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +```java +public boolean release(); // 释放native资源 +public boolean initialized(); // 检查是否初始化成功 +``` + +- RuntimeOption设置说明 +```java +public void enableLiteFp16(); // 开启fp16精度推理 +public void disableLiteFP16(); // 关闭fp16精度推理 +public void setCpuThreadNum(int threadNum); // 设置线程数 +public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 +public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +``` + +- 模型结果DetectionResult说明 +```java +public class DetectionResult { + public float[][] mBoxes; // [n,4] 检测框 (x1,y1,x2,y2) + public float[] mScores; // [n] 每个检测框得分(置信度,概率值) + public int[] mLabelIds; // [n] 分类ID + public boolean initialized(); // 检测结果是否有效 +} +``` +其他参考:C++/Python对应的DetectionResult说明: [api/vision_results/detection_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/detection_result.md) + +- 模型调用示例1:使用构造函数以及默认的RuntimeOption +```java +import java.nio.ByteBuffer; +import android.graphics.Bitmap; +import android.opengl.GLES20; + +import com.baidu.paddle.fastdeploy.vision.DetectionResult; +import com.baidu.paddle.fastdeploy.vision.detection.PicoDet; + +// 初始化模型 +PicoDet model = new PicoDet("picodet_s_320_coco_lcnet/model.pdmodel", + "picodet_s_320_coco_lcnet/model.pdiparams", + "picodet_s_320_coco_lcnet/infer_cfg.yml"); + +// 读取图片: 以下仅为读取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); + +// 模型推理 +DetectionResult result = model.predict(ARGB8888ImageBitmap); + +// 释放模型资源 +model.release(); +``` + +- 模型调用示例2: 在合适的程序节点,手动调用init,并自定义RuntimeOption +```java +// import 同上 ... +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.DetectionResult; +import com.baidu.paddle.fastdeploy.vision.detection.PicoDet; +// 新建空模型 +PicoDet model = new PicoDet(); +// 模型路径 +String modelFile = "picodet_s_320_coco_lcnet/model.pdmodel"; +String paramFile = "picodet_s_320_coco_lcnet/model.pdiparams"; +String configFile = "picodet_s_320_coco_lcnet/infer_cfg.yml"; +// 指定RuntimeOption +RuntimeOption option = new RuntimeOption(); +option.setCpuThreadNum(2); +option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +option.enableLiteFp16(); +// 使用init函数初始化 +model.init(modelFile, paramFile, configFile, option); +// Bitmap读取、模型预测、资源释放 同上 ... +``` +更详细的用法请参考 [DetectionMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java) 中的用法 + +## 替换 FastDeploy SDK和模型 +替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/picodet_s_320_coco_lcnet`。 +- 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: + - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) + +- 替换PicoDet模型的步骤: + - 将您的PicoDet模型放在 `app/src/main/assets/models` 目录下; + - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +```xml + +models/picodet_s_320_coco_lcnet +labels/coco_label_list.txt +``` + +## 更多参考文档 +如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: +- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/detection/paddledetection/cpp/README.md b/examples/vision/detection/paddledetection/cpp/README.md index 0e944a465a..8ca675bd6f 100755 --- a/examples/vision/detection/paddledetection/cpp/README.md +++ b/examples/vision/detection/paddledetection/cpp/README.md @@ -1,54 +1,48 @@ -# PaddleDetection C++部署示例 +English | [简体中文](README_CN.md) +# PaddleDetection C++ Deployment Example -本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet/CascadeRCNN/PSSDet/RetinaNet/PPYOLOESOD/FCOS/TTFNet/TOOD/GFL在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer_xxx.cc` fast finishes the deployment of PaddleDetection models, including PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash -以ppyoloe为例进行推理部署 +ppyoloe is taken as an example for inference deployment mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载PPYOLOE模型文件和测试图片 +# Download the PPYOLOE model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg tar xvf ppyoloe_crn_l_300e_coco.tgz -# CPU推理 +# CPU inference ./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 2 -# 昆仑芯XPU推理 -./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 3 -# 华为昇腾推理 -./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 4 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) +## PaddleDetection C++ Interface -## PaddleDetection C++接口 +### Model Class -### 模型类 - -PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API +PaddleDetection currently supports 6 kinds of models, including `PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`. The constructors and predictors for all 6 kinds are consistent in terms of parameters. This document takes PPYOLOE as an example to introduce its API ```c++ fastdeploy::vision::detection::PPYOLOE( const string& model_file, @@ -60,28 +54,28 @@ fastdeploy::vision::detection::PPYOLOE( PaddleDetection PPYOLOE模型加载和初始化,其中model_file为导出的ONNX模型格式。 -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 配置文件路径,即PaddleDetection导出的部署yaml文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为PADDLE格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): • Configuration file path, which is the deployment yaml file exported by PaddleDetection +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output results directly. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection result, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for DetectionResult -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model prediction results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/paddledetection/cpp/README_CN.md b/examples/vision/detection/paddledetection/cpp/README_CN.md new file mode 100644 index 0000000000..a8cf19bf64 --- /dev/null +++ b/examples/vision/detection/paddledetection/cpp/README_CN.md @@ -0,0 +1,88 @@ +[English](README.md) | 简体中文 +# PaddleDetection C++部署示例 + +本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet/CascadeRCNN/PSSDet/RetinaNet/PPYOLOESOD/FCOS/TTFNet/TOOD/GFL在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +以ppyoloe为例进行推理部署 + +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载PPYOLOE模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +tar xvf ppyoloe_crn_l_300e_coco.tgz + + +# CPU推理 +./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 0 +# GPU推理 +./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 2 +# 昆仑芯XPU推理 +./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 3 +# 华为昇腾推理 +./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 4 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +## PaddleDetection C++接口 + +### 模型类 + +PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API +```c++ +fastdeploy::vision::detection::PPYOLOE( + const string& model_file, + const string& params_file, + const string& config_file + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleDetection PPYOLOE模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 配置文件路径,即PaddleDetection导出的部署yaml文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为PADDLE格式 + +#### Predict函数 + +> ```c++ +> PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/paddledetection/python/README.md b/examples/vision/detection/paddledetection/python/README.md index 856629a568..baec5fe06e 100755 --- a/examples/vision/detection/paddledetection/python/README.md +++ b/examples/vision/detection/paddledetection/python/README.md @@ -1,40 +1,37 @@ -# PaddleDetection Python部署示例 +English | [简体中文](README_CN.md) +# PaddleDetection Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer_xxx.py`快速完成PPYOLOE/PicoDet等模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer_xxx.py` fast finishes the deployment of PPYOLOE/PicoDet models on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/detection/paddledetection/python/ -#下载PPYOLOE模型文件和测试图片 +# Download the PPYOLOE model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg tar xvf ppyoloe_crn_l_300e_coco.tgz -# CPU推理 +# CPU inference python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 -python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device kunlunxin -# 华为昇腾推理 -python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device ascend ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PaddleDetection Python接口 +## PaddleDetection Python Interface ```python fastdeploy.vision.detection.PPYOLOE(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) @@ -49,46 +46,38 @@ fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, r fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.CascadeRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.PSSDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.RetinaNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.PPYOLOESOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.FCOS(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.TTFNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.TOOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -fastdeploy.vision.detection.GFL(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件 +PaddleDetection model loading and initialization, among which model_file and params_file are the exported Paddle model format. config_file is the configuration yaml file exported by PaddleDetection simultaneously -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理配置yaml文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference configuration yaml file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict Function -PaddleDetection中各个模型,包括PPYOLOE/PicoDet/PaddleYOLOX/YOLOv3/PPYOLO/FasterRCNN,均提供如下同样的成员函数用于进行图像的检测 +PaddleDetection models, including PPYOLOE/PicoDet/PaddleYOLOX/YOLOv3/PPYOLO/FasterRCNN, all provide the following member functions for image detection > ```python > PPYOLOE.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output results directly. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [PaddleDetection 模型介绍](..) -- [PaddleDetection C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PaddleDetection Model Description](..) +- [PaddleDetection C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/paddledetection/python/README_CN.md b/examples/vision/detection/paddledetection/python/README_CN.md new file mode 100644 index 0000000000..902782c866 --- /dev/null +++ b/examples/vision/detection/paddledetection/python/README_CN.md @@ -0,0 +1,95 @@ +[English](README.md) | 简体中文 +# PaddleDetection Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer_xxx.py`快速完成PPYOLOE/PicoDet等模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/detection/paddledetection/python/ + +#下载PPYOLOE模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +tar xvf ppyoloe_crn_l_300e_coco.tgz + +# CPU推理 +python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device cpu +# GPU推理 +python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device kunlunxin +# 华为昇腾推理 +python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device ascend +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PaddleDetection Python接口 + +```python +fastdeploy.vision.detection.PPYOLOE(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PicoDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOX(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.YOLOv3(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PPYOLO(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.FasterRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.MaskRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.SSD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.CascadeRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PSSDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.RetinaNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PPYOLOESOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.FCOS(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.TTFNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.TOOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.GFL(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理配置yaml文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle + +### predict函数 + +PaddleDetection中各个模型,包括PPYOLOE/PicoDet/PaddleYOLOX/YOLOv3/PPYOLO/FasterRCNN,均提供如下同样的成员函数用于进行图像的检测 +> ```python +> PPYOLOE.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +## 其它文档 + +- [PaddleDetection 模型介绍](..) +- [PaddleDetection C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/paddledetection/quantize/README.md b/examples/vision/detection/paddledetection/quantize/README.md index f0caf81123..abbedf77b1 100755 --- a/examples/vision/detection/paddledetection/quantize/README.md +++ b/examples/vision/detection/paddledetection/quantize/README.md @@ -1,45 +1,46 @@ -# PaddleDetection 量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. +English | [简体中文](README_CN.md) +# PaddleDetection Quantification Model Deployment +FastDeploy supports the deployment of quantification models and provides a convenient tool for automatic model compression. +Users can use it to deploy models after quantification or directly deploy quantized models provided by FastDeploy. -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) +## FastDeploy one-click model auto-compression tool +FastDeploy provides a one-click auto-compression tool that allows users to quantize models by simply entering a configuration file. +Refer to [one-click auto-compression tool](../../../../../tools/common_tools/auto_compression/) for details. -## 下载量化完成的PP-YOLOE-l模型 -用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) +## Download the quantized PP-YOLOE-l model +Users can also directly download the quantized models in the table below. (Click the model name to download it) -Benchmark表格说明: -- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. -- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. -- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. -- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 -- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 -- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. -- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. -- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. +Benchmark table description: +- Runtime latency: model’s inference latency on multiple Runtimes, including CPU->GPU data copy, GPU inference, and GPU->CPU data copy time. It does not include the pre and post processing time of the model. +- End2End latency: model’s latency in the actual inference scenario, including the pre and post processing time of the model. +- Measured latency: The average latency after 1000 times of inference in milliseconds. +- INT8 + FP16: Enable FP16 inference for Runtime while inferring the INT8 quantification model +- INT8 + FP16 + PM: Use Pinned Memory to speed up the GPU->CPU data copy while inferring the INT8 quantization model with FP16 turned on. +- Maximum speedup ratio: Obtained by dividing the FP32 latency by the highest INT8 inference latency. +- The strategy is to use a few unlabeled data sets to train the model for quantification and to verify the accuracy on the full validation set. The INT8 accuracy does not represent the highest value. +- The CPU is Intel(R) Xeon(R) Gold 6271C, , and the number of CPU threads is fixed to 1. The GPU is Tesla T4 with TensorRT version 8.4.15. #### Runtime Benchmark -| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| Model |Inference Backend |Deployment Hardware | FP32 Runtime Latency | INT8 Runtime Latency | INT8 + FP16 Runtime Latency | INT8+FP16+PM Runtime Latency | Maximum Speedup Ratio | FP32 mAP | INT8 mAP | Quantification Method | | ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | TensorRT | GPU | 27.90 | 6.39 |6.44|5.95 | 4.67 | 51.4 | 50.7 | 量化蒸馏训练 | -| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | Paddle-TensorRT | GPU | 30.89 |None | 13.78 |14.01 | 2.24 | 51.4 | 50.5 | 量化蒸馏训练 | -| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar) | ONNX Runtime | CPU | 1057.82 | 449.52 |None|None | 2.35 |51.4 | 50.0 |量化蒸馏训练 | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | TensorRT | GPU | 27.90 | 6.39 |6.44|5.95 | 4.67 | 51.4 | 50.7 | Quantized distillation training | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | Paddle-TensorRT | GPU | 30.89 |None | 13.78 |14.01 | 2.24 | 51.4 | 50.5 | Quantized distillation training | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar) | ONNX Runtime | CPU | 1057.82 | 449.52 |None|None | 2.35 |51.4 | 50.0 | Quantized distillation training | NOTE: -- TensorRT比Paddle-TensorRT快的原因是在runtime移除了multiclass_nms3算子 +- The reason why TensorRT is faster than Paddle-TensorRT is that the multiclass_nms3 operator is removed during runtime -#### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +#### End2End Benchmark +| Model | Inference Backend |Deployment Hardware | FP32 End2End Latency | INT8 End2End Latency | INT8 + FP16 End2End Latency | INT8+FP16+PM End2End Latency | Maximum Speedup Ratio | FP32 mAP | INT8 mAP | Quantification Method | | ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | TensorRT | GPU | 35.75 | 15.42 |20.70|20.85 | 2.32 | 51.4 | 50.7 | 量化蒸馏训练 | -| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | Paddle-TensorRT | GPU | 33.48 |None | 18.47 |18.03 | 1.81 | 51.4 | 50.5 | 量化蒸馏训练 | -| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar) | ONNX Runtime | CPU | 1067.17 | 461.037 |None|None | 2.31 |51.4 | 50.0 |量化蒸馏训练 | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | TensorRT | GPU | 35.75 | 15.42 |20.70|20.85 | 2.32 | 51.4 | 50.7 | Quantized distillation training | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | Paddle-TensorRT | GPU | 33.48 |None | 18.47 |18.03 | 1.81 | 51.4 | 50.5 | Quantized distillation training | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar) | ONNX Runtime | CPU | 1067.17 | 461.037 |None|None | 2.31 |51.4 | 50.0 | Quantized distillation training | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/paddledetection/quantize/README_CN.md b/examples/vision/detection/paddledetection/quantize/README_CN.md new file mode 100644 index 0000000000..8cc12636aa --- /dev/null +++ b/examples/vision/detection/paddledetection/quantize/README_CN.md @@ -0,0 +1,46 @@ +[English](README.md) | 简体中文 +# PaddleDetection 量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. + +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) + +## 下载量化完成的PP-YOLOE-l模型 +用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) + + +Benchmark表格说明: +- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. +- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. +- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. +- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 +- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 +- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. +- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. +- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. + + +#### Runtime Benchmark +| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | TensorRT | GPU | 27.90 | 6.39 |6.44|5.95 | 4.67 | 51.4 | 50.7 | 量化蒸馏训练 | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | Paddle-TensorRT | GPU | 30.89 |None | 13.78 |14.01 | 2.24 | 51.4 | 50.5 | 量化蒸馏训练 | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar) | ONNX Runtime | CPU | 1057.82 | 449.52 |None|None | 2.35 |51.4 | 50.0 |量化蒸馏训练 | + +NOTE: +- TensorRT比Paddle-TensorRT快的原因是在runtime移除了multiclass_nms3算子 + +#### 端到端 Benchmark +| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | TensorRT | GPU | 35.75 | 15.42 |20.70|20.85 | 2.32 | 51.4 | 50.7 | 量化蒸馏训练 | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar ) | Paddle-TensorRT | GPU | 33.48 |None | 18.47 |18.03 | 1.81 | 51.4 | 50.5 | 量化蒸馏训练 | +| [ppyoloe_crn_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco_qat.tar) | ONNX Runtime | CPU | 1067.17 | 461.037 |None|None | 2.31 |51.4 | 50.0 |量化蒸馏训练 | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/detection/paddledetection/rknpu2/README.md b/examples/vision/detection/paddledetection/rknpu2/README.md index 5fad37cebe..1476952e46 100644 --- a/examples/vision/detection/paddledetection/rknpu2/README.md +++ b/examples/vision/detection/paddledetection/rknpu2/README.md @@ -1,45 +1,45 @@ -# PaddleDetection RKNPU2部署示例 +English | [简体中文](README_CN.md) +# PaddleDetection RKNPU2 Deployment Example -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 -- [PicoDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) +Now FastDeploy supports the deployment of the following models +- [PicoDet models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) -## 准备PaddleDetection部署模型以及转换模型 -RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: -* Paddle动态图模型转换为ONNX模型,请参考[PaddleDetection导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md) - ,注意在转换时请设置**export.nms=True**. -* ONNX模型转换RKNN模型的过程,请参考[转换文档](../../../../../docs/cn/faq/rknpu2/export.md)进行转换。 +## Prepare PaddleDetection deployment models and convert models +Before RKNPU deployment, you need to transform Paddle model to RKNN model: +* From Paddle dynamic map to ONNX model, refer to [PaddleDetection Model Export](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md) + , and set **export.nms=True** during transformation. +* From ONNX model to RKNN model, refer to [Transformation Document](../../../../../docs/cn/faq/rknpu2/export.md). -## 模型转换example -以下步骤均在Ubuntu电脑上完成,请参考配置文档完成转换模型环境配置。下面以Picodet-s为例子,教大家如何转换PaddleDetection模型到RKNN模型。 - -### 导出ONNX模型 +## Model Transformation Example +The following steps are conducted on Ubuntu computers, refer to the configuration document to prepare the environment. Taking Picodet-s as an example, this document demonstrates how to transform PaddleDetection model to RKNN model. +### Export the ONNX model ```bash -# 下载Paddle静态图模型并解压 +# Download Paddle static map model and unzip it wget https://paddledet.bj.bcebos.com/deploy/Inference/picodet_s_416_coco_lcnet.tar tar xvf picodet_s_416_coco_lcnet.tar -# 静态图转ONNX模型,注意,这里的save_file请和压缩包名对齐 +# From static map to ONNX model. Attention: Align the save_file with the zip file name paddle2onnx --model_dir picodet_s_416_coco_lcnet \ --model_filename model.pdmodel \ --params_filename model.pdiparams \ --save_file picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \ --enable_dev_version True -# 固定shape +# Fix shape python -m paddle2onnx.optimize --input_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \ --output_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \ --input_shape_dict "{'image':[1,3,416,416]}" ``` -### 编写模型导出配置文件 -以转化RK3568的RKNN模型为例子,我们需要编辑tools/rknpu2/config/RK3568/picodet_s_416_coco_lcnet.yaml,来转换ONNX模型到RKNN模型。 +### Write the model export configuration file +Taking the example of RKNN model from RK3588, we need to edit tools/rknpu2/config/RK3568/picodet_s_416_coco_lcnet.yaml to convert ONNX model to RKNN model. -**修改normalize参数** +**Modify normalize parameter** -如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如: +If you need to perform the normalize operation on NPU, configure the normalize parameters based on your model. For example: ```yaml model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx output_folder: ./picodet_s_416_coco_lcnet @@ -50,13 +50,13 @@ normalize: outputs: ['tmp_17','p2o.Concat.9'] ``` -**修改outputs参数** -由于Paddle2ONNX版本的不同,转换模型的输出节点名称也有所不同,请使用[Netron](https://netron.app),并找到以下蓝色方框标记的NonMaxSuppression节点,红色方框的节点名称即为目标名称。 +**Modify outputs parameter** +The output node names of the transformation model are various based on different versions of Paddle2ONNX. Please use [Netron](https://netron.app) and find the NonMaxSuppression node marked by the blue box below, and the node name in the red box is the target name. -例如,使用Netron可视化后,得到以下图片: +For example, we can obtain the following image after visualization with Netron: ![](https://user-images.githubusercontent.com/58363586/202728663-4af0b843-d012-4aeb-8a66-626b7b87ca69.png) -找到蓝色方框标记的NonMaxSuppression节点,可以看到红色方框标记的两个节点名称为tmp_17和p2o.Concat.9,因此需要修改outputs参数,修改后如下: +Find the NonMaxSuppression node marked by the blue box,and we can see the names of the two nodes marked by the red box: tmp_17 and p2o.Concat.9. So we need to modify the outputs parameter: ```yaml model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx output_folder: ./picodet_s_416_coco_lcnet @@ -65,22 +65,22 @@ normalize: None outputs: ['tmp_17','p2o.Concat.9'] ``` -### 转换模型 +### model transformation ```bash -# ONNX模型转RKNN模型 -# 转换模型,模型将生成在picodet_s_320_coco_lcnet_non_postprocess目录下 +# Transform ONNX modle to RKNN model +# The transformed model is in the picodet_s_320_coco_lcnet_non_postprocess directory python tools/rknpu2/export.py --config_path tools/rknpu2/config/picodet_s_416_coco_lcnet.yaml \ --target_platform rk3588 ``` -### 修改模型运行时的配置文件 +### Modify the configuration file during runtime -配置文件中,我们只需要修改**Preprocess**下的**Normalize**和**Permute**. +n the config file, we need to modify **Normalize** and **Permute** under **Preprocess**. -**删除Permute** +**Remove Permute** -RKNPU只支持NHWC的输入格式,因此需要删除Permute操作.删除后,配置文件Precess部分后如下: +The Permute operation needs removing considering that RKNPU only supports the input format of NHWC. After removal, the Precess is as follows: ```yaml Preprocess: - interp: 2 @@ -101,9 +101,9 @@ Preprocess: type: NormalizeImage ``` -**根据模型转换文件决定是否删除Normalize** +**Decide whether to remove Normalize based on model transformation file** -RKNPU支持使用NPU进行Normalize操作,如果你在导出模型时配置了Normalize参数,请删除**Normalize**.删除后配置文件Precess部分如下: +RKNPU supports Normalize on NPU. Remove **Normalize** if you configured the Normalize parameter when exporting the model. After removal, the Precess is as follows: ```yaml Preprocess: - interp: 2 @@ -114,7 +114,7 @@ Preprocess: type: Resize ``` -## 其他链接 -- [Cpp部署](./cpp) -- [Python部署](./python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) +## Other Links +- [Cpp Deployment](./cpp) +- [Python Deployment](./python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/paddledetection/rknpu2/README_CN.md b/examples/vision/detection/paddledetection/rknpu2/README_CN.md new file mode 100644 index 0000000000..aa390351a7 --- /dev/null +++ b/examples/vision/detection/paddledetection/rknpu2/README_CN.md @@ -0,0 +1,121 @@ +[English](README.md) | 简体中文 +# PaddleDetection RKNPU2部署示例 + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 +- [PicoDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/picodet) + +## 准备PaddleDetection部署模型以及转换模型 +RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: +* Paddle动态图模型转换为ONNX模型,请参考[PaddleDetection导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.4/deploy/EXPORT_MODEL.md) + ,注意在转换时请设置**export.nms=True**. +* ONNX模型转换RKNN模型的过程,请参考[转换文档](../../../../../docs/cn/faq/rknpu2/export.md)进行转换。 + + +## 模型转换example +以下步骤均在Ubuntu电脑上完成,请参考配置文档完成转换模型环境配置。下面以Picodet-s为例子,教大家如何转换PaddleDetection模型到RKNN模型。 + +### 导出ONNX模型 +```bash +# 下载Paddle静态图模型并解压 +wget https://paddledet.bj.bcebos.com/deploy/Inference/picodet_s_416_coco_lcnet.tar +tar xvf picodet_s_416_coco_lcnet.tar + +# 静态图转ONNX模型,注意,这里的save_file请和压缩包名对齐 +paddle2onnx --model_dir picodet_s_416_coco_lcnet \ + --model_filename model.pdmodel \ + --params_filename model.pdiparams \ + --save_file picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \ + --enable_dev_version True + +# 固定shape +python -m paddle2onnx.optimize --input_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \ + --output_model picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx \ + --input_shape_dict "{'image':[1,3,416,416]}" +``` + +### 编写模型导出配置文件 +以转化RK3568的RKNN模型为例子,我们需要编辑tools/rknpu2/config/RK3568/picodet_s_416_coco_lcnet.yaml,来转换ONNX模型到RKNN模型。 + +**修改normalize参数** + +如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如: +```yaml +model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx +output_folder: ./picodet_s_416_coco_lcnet +target_platform: RK3568 +normalize: + mean: [[0.485,0.456,0.406]] + std: [[0.229,0.224,0.225]] +outputs: ['tmp_17','p2o.Concat.9'] +``` + +**修改outputs参数** +由于Paddle2ONNX版本的不同,转换模型的输出节点名称也有所不同,请使用[Netron](https://netron.app),并找到以下蓝色方框标记的NonMaxSuppression节点,红色方框的节点名称即为目标名称。 + +例如,使用Netron可视化后,得到以下图片: +![](https://user-images.githubusercontent.com/58363586/202728663-4af0b843-d012-4aeb-8a66-626b7b87ca69.png) + +找到蓝色方框标记的NonMaxSuppression节点,可以看到红色方框标记的两个节点名称为tmp_17和p2o.Concat.9,因此需要修改outputs参数,修改后如下: +```yaml +model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx +output_folder: ./picodet_s_416_coco_lcnet +target_platform: RK3568 +normalize: None +outputs: ['tmp_17','p2o.Concat.9'] +``` + +### 转换模型 +```bash + +# ONNX模型转RKNN模型 +# 转换模型,模型将生成在picodet_s_320_coco_lcnet_non_postprocess目录下 +python tools/rknpu2/export.py --config_path tools/rknpu2/config/picodet_s_416_coco_lcnet.yaml \ + --target_platform rk3588 +``` + +### 修改模型运行时的配置文件 + +配置文件中,我们只需要修改**Preprocess**下的**Normalize**和**Permute**. + +**删除Permute** + +RKNPU只支持NHWC的输入格式,因此需要删除Permute操作.删除后,配置文件Precess部分后如下: +```yaml +Preprocess: +- interp: 2 + keep_ratio: false + target_size: + - 416 + - 416 + type: Resize +- is_scale: true + mean: + - 0.485 + - 0.456 + - 0.406 + std: + - 0.229 + - 0.224 + - 0.225 + type: NormalizeImage +``` + +**根据模型转换文件决定是否删除Normalize** + +RKNPU支持使用NPU进行Normalize操作,如果你在导出模型时配置了Normalize参数,请删除**Normalize**.删除后配置文件Precess部分如下: +```yaml +Preprocess: +- interp: 2 + keep_ratio: false + target_size: + - 416 + - 416 + type: Resize +``` + +## 其他链接 +- [Cpp部署](./cpp) +- [Python部署](./python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/paddledetection/rv1126/README.md b/examples/vision/detection/paddledetection/rv1126/README.md index a68c3b75d6..0a12b36fd3 100755 --- a/examples/vision/detection/paddledetection/rv1126/README.md +++ b/examples/vision/detection/paddledetection/rv1126/README.md @@ -1,11 +1,12 @@ -# PP-YOLOE 量化模型在 RV1126 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 量化模型到 RV1126 上。 +English | [简体中文](README_CN.md) +# Deploy PP-YOLOE Quantification Model on RV1126 +Now FastDeploy supports the deployment of PP-YOLOE quantification model to RV1126 based on Paddle Lite. -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +For model quantification and download, refer to [Model Quantification](../quantize/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -在 RV1126 上只支持 C++ 的部署。 +Only C++ deployment is supported on RV1126. -- [C++部署](cpp) +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/paddledetection/rv1126/README_CN.md b/examples/vision/detection/paddledetection/rv1126/README_CN.md new file mode 100644 index 0000000000..8875b82aa1 --- /dev/null +++ b/examples/vision/detection/paddledetection/rv1126/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# PP-YOLOE 量化模型在 RV1126 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-YOLOE 量化模型到 RV1126 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 RV1126 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/detection/paddledetection/serving/README.md b/examples/vision/detection/paddledetection/serving/README.md index adfa190932..ec1571736a 100644 --- a/examples/vision/detection/paddledetection/serving/README.md +++ b/examples/vision/detection/paddledetection/serving/README.md @@ -1,64 +1,65 @@ -# PaddleDetection 服务化部署示例 +English | [简体中文](README_CN.md) +# PaddleDetection Serving Deployment Example -本文档以PP-YOLOE模型(ppyoloe_crn_l_300e_coco)为例,进行详细介绍。其他PaddleDetection模型都已支持服务化部署,只需将下述命令中的模型和配置名字修改成要部署模型的名字。 +This document gives a detailed introduction to the deployment of PP-YOLOE models(ppyoloe_crn_l_300e_coco). Other PaddleDetection model all support serving deployment. So users just need to change the model and config name in the following command. -PaddleDetection模型导出和预训练模型下载请看[PaddleDetection模型部署](../README.md)文档。 +For PaddleDetection model export and download of pre-trained models, refer to [PaddleDetection Model Deployment](../README.md). -在服务化部署前,需确认 +Confirm before the serving deployment -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) +- 1. Refer to [FastDeploy Serving Deployment](../../../../../serving/README_CN.md) for software and hardware environment requirements and image pull commands -## 启动服务 +## Start Service ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/detection/paddledetection/serving -#下载PPYOLOE模型文件和测试图片 +# Download PPYOLOE model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg tar xvf ppyoloe_crn_l_300e_coco.tgz -# 将配置文件放入预处理目录 +# Put the configuration file into the preprocessing directory mv ppyoloe_crn_l_300e_coco/infer_cfg.yml models/preprocess/1/ -# 将模型放入 models/runtime/1目录下, 并重命名为model.pdmodel和model.pdiparams +# Place the model under models/runtime/1 and rename them to model.pdmodel and model.pdiparams mv ppyoloe_crn_l_300e_coco/model.pdmodel models/runtime/1/model.pdmodel mv ppyoloe_crn_l_300e_coco/model.pdiparams models/runtime/1/model.pdiparams -# 将ppdet和runtime中的ppyoloe配置文件重命名成标准的config名字 -# 其他模型比如faster_rcc就将faster_rcnn_config.pbtxt重命名为config.pbtxt +# Rename the ppyoloe config files in ppdet and runtime to standard config names +# For other models like faster_rcc, rename faster_rcnn_config.pbtxt to config.pbtxt cp models/ppdet/ppyoloe_config.pbtxt models/ppdet/config.pbtxt cp models/runtime/ppyoloe_runtime_config.pbtxt models/runtime/config.pbtxt -# 注意: 由于mask_rcnn模型多一个输出,需要将后处理目录(models/postprocess)中的mask_config.pbtxt重命名为config.pbtxt +# Attention: Given that the mask_rcnn model has one more output, we need to rename mask_config.pbtxt to config.pbtxt in the postprocess directory (models/postprocess) -# 拉取fastdeploy镜像(x.y.z为镜像版本号,需替换成fastdeploy版本数字) -# GPU镜像 +# Pull the FastDeploy image (x.y.z represent the image version. Users need to replace them with numbers) +# GPU image docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 -# CPU镜像 +# CPU image docker pull paddlepaddle/fastdeploy:z.y.z-cpu-only-21.10 -# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /serving 目录 +# Run the container named fd_serving and mount it in the /serving directory of the container nvidia-docker run -it --net=host --name fd_serving --shm-size="1g" -v `pwd`/:/serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash -# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) +# Start Service (The CUDA_VISIBLE_DEVICES environment variable is not set, which entitles the scheduling authority of all GPU cards) CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/serving/models ``` ->> **注意**: +>> **Attention**: ->> 由于mask_rcnn模型多一个输出,部署mask_rcnn需要将后处理目录(models/postprocess)中的mask_config.pbtxt重命名为config.pbtxt +>> Given that the mask_rcnn model has one more output, we need to rename mask_config.pbtxt to config.pbtxt in the postprocess directory (models/postprocess) ->> 拉取镜像请看[服务化部署主文档](../../../../../serving/README_CN.md) +>> To pull images, refer to [Service Deployment Master Document](../../../../../serving/README_CN.md) ->> 执行fastdeployserver启动服务出现"Address already in use", 请使用`--grpc-port`指定grpc端口号来启动服务,同时更改客户端示例中的请求端口号. +>> If "Address already in use" appears when running fastdeployserver to start the service, use `--grpc-port` to specify the port number and change the request port number in the client demo. ->> 其他启动参数可以使用 fastdeployserver --help 查看 +>> Other startup parameters can be checked by fastdeployserver --help -服务启动成功后, 会有以下输出: +Successful service start brings the following output: ``` ...... I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 @@ -67,21 +68,21 @@ I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0 ``` -## 客户端请求 +## Client Request -在物理机器中执行以下命令,发送grpc请求并输出结果 +Execute the following command in the physical machine to send the grpc request and output the results ``` -#下载测试图片 +# Download test images wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -#安装客户端依赖 +# Install client dependencies python3 -m pip install tritonclient[all] -# 发送请求 +# Send requests python3 paddledet_grpc_client.py ``` -发送请求成功后,会返回json格式的检测结果并打印输出: +The result is returned in json format and printed after sending the request: ``` output_name: DET_RESULT [[159.93016052246094, 82.35527038574219, 199.8546600341797, 164.68682861328125], @@ -89,6 +90,6 @@ output_name: DET_RESULT [60.200584411621094, 123.73260498046875, 108.83859252929688, 169.07467651367188]] ``` -## 配置修改 +## Configuration Change -当前默认配置在GPU上运行Paddle引擎, 如果要在CPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) +The current default configuration runs on GPU. If you want to run it on CPU or other inference engines, please modify the configuration in `models/runtime/config.pbtxt`. Refer to [Configuration Document](../../../../../serving/docs/zh_CN/model_configuration.md) for more information. diff --git a/examples/vision/detection/paddledetection/serving/README_CN.md b/examples/vision/detection/paddledetection/serving/README_CN.md new file mode 100644 index 0000000000..cc1fc2f5b0 --- /dev/null +++ b/examples/vision/detection/paddledetection/serving/README_CN.md @@ -0,0 +1,95 @@ +[English](README.md) | 简体中文 +# PaddleDetection 服务化部署示例 + +本文档以PP-YOLOE模型(ppyoloe_crn_l_300e_coco)为例,进行详细介绍。其他PaddleDetection模型都已支持服务化部署,只需将下述命令中的模型和配置名字修改成要部署模型的名字。 + +PaddleDetection模型导出和预训练模型下载请看[PaddleDetection模型部署](../README.md)文档。 + +在服务化部署前,需确认 + +- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) + + +## 启动服务 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/detection/paddledetection/serving + +#下载PPYOLOE模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +tar xvf ppyoloe_crn_l_300e_coco.tgz + +# 将配置文件放入预处理目录 +mv ppyoloe_crn_l_300e_coco/infer_cfg.yml models/preprocess/1/ + +# 将模型放入 models/runtime/1目录下, 并重命名为model.pdmodel和model.pdiparams +mv ppyoloe_crn_l_300e_coco/model.pdmodel models/runtime/1/model.pdmodel +mv ppyoloe_crn_l_300e_coco/model.pdiparams models/runtime/1/model.pdiparams + +# 将ppdet和runtime中的ppyoloe配置文件重命名成标准的config名字 +# 其他模型比如faster_rcc就将faster_rcnn_config.pbtxt重命名为config.pbtxt +cp models/ppdet/ppyoloe_config.pbtxt models/ppdet/config.pbtxt +cp models/runtime/ppyoloe_runtime_config.pbtxt models/runtime/config.pbtxt + +# 注意: 由于mask_rcnn模型多一个输出,需要将后处理目录(models/postprocess)中的mask_config.pbtxt重命名为config.pbtxt + +# 拉取fastdeploy镜像(x.y.z为镜像版本号,需替换成fastdeploy版本数字) +# GPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +# CPU镜像 +docker pull paddlepaddle/fastdeploy:z.y.z-cpu-only-21.10 + + +# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /serving 目录 +nvidia-docker run -it --net=host --name fd_serving --shm-size="1g" -v `pwd`/:/serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash + +# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) +CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/serving/models +``` +>> **注意**: + +>> 由于mask_rcnn模型多一个输出,部署mask_rcnn需要将后处理目录(models/postprocess)中的mask_config.pbtxt重命名为config.pbtxt + +>> 拉取镜像请看[服务化部署主文档](../../../../../serving/README_CN.md) + +>> 执行fastdeployserver启动服务出现"Address already in use", 请使用`--grpc-port`指定grpc端口号来启动服务,同时更改客户端示例中的请求端口号. + +>> 其他启动参数可以使用 fastdeployserver --help 查看 + +服务启动成功后, 会有以下输出: +``` +...... +I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 +I0928 04:51:15.785177 206 http_server.cc:2815] Started HTTPService at 0.0.0.0:8000 +I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0:8002 +``` + + +## 客户端请求 + +在物理机器中执行以下命令,发送grpc请求并输出结果 +``` +#下载测试图片 +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +#安装客户端依赖 +python3 -m pip install tritonclient[all] + +# 发送请求 +python3 paddledet_grpc_client.py +``` + +发送请求成功后,会返回json格式的检测结果并打印输出: +``` +output_name: DET_RESULT +[[159.93016052246094, 82.35527038574219, 199.8546600341797, 164.68682861328125], +... ..., +[60.200584411621094, 123.73260498046875, 108.83859252929688, 169.07467651367188]] +``` + +## 配置修改 + +当前默认配置在GPU上运行Paddle引擎, 如果要在CPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) diff --git a/examples/vision/detection/rkyolo/README.md b/examples/vision/detection/rkyolo/README.md index 015e225064..3161aac1bc 100644 --- a/examples/vision/detection/rkyolo/README.md +++ b/examples/vision/detection/rkyolo/README.md @@ -1,18 +1,19 @@ -# RKYOLO准备部署模型 +English | [简体中文](README_CN.md) -RKYOLO参考[rknn_model_zoo](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo)的代码 -对RKYOLO系列模型进行了封装,目前支持RKYOLOV5系列模型的部署。 +# RKYOLO Ready-to-deploy Model -## 支持模型列表 +RKYOLO models are encapsulated with reference to the code of [rknn_model_zoo](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo). Now we support the deployment of RKYOLOV5 models. + +## List of Supported Models * RKYOLOV5 -## 模型转换example +## Model Transformation Example -请参考[RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert) +Please refer to [RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert) -## 其他链接 -- [Cpp部署](./cpp) -- [Python部署](./python) -- [视觉模型预测结果](../../../../docs/api/vision_results/) +## Other Links +- [Cpp deployment](./cpp) +- [Python deployment](./python) +- [Visual model predicting results](../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/rkyolo/README_CN.md b/examples/vision/detection/rkyolo/README_CN.md new file mode 100644 index 0000000000..1cc44a9200 --- /dev/null +++ b/examples/vision/detection/rkyolo/README_CN.md @@ -0,0 +1,19 @@ +[English](README.md) | 简体中文 +# RKYOLO准备部署模型 + +RKYOLO参考[rknn_model_zoo](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo)的代码 +对RKYOLO系列模型进行了封装,目前支持RKYOLOV5系列模型的部署。 + +## 支持模型列表 + +* RKYOLOV5 + +## 模型转换example + +请参考[RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert) + + +## 其他链接 +- [Cpp部署](./cpp) +- [Python部署](./python) +- [视觉模型预测结果](../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/scaledyolov4/README.md b/examples/vision/detection/scaledyolov4/README.md index df3799282e..9ed068f732 100644 --- a/examples/vision/detection/scaledyolov4/README.md +++ b/examples/vision/detection/scaledyolov4/README.md @@ -1,48 +1,51 @@ -# ScaledYOLOv4准备部署模型 +English | [简体中文](README_CN.md) +# ScaledYOLOv4 Ready-to-deploy Model -- ScaledYOLOv4部署实现来自[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4)的代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/ScaledYOLOv4)。 +- The ScaledYOLOv4 deployment is based on the code of [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4) and [Pre-trained Model on COCO](https://github.com/WongKinYiu/ScaledYOLOv4). - - (1)[官方库](https://github.com/WongKinYiu/ScaledYOLOv4)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)自己数据训练的ScaledYOLOv4模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)The *.pt provided by [Official Repository](https://github.com/WongKinYiu/ScaledYOLOv4) should [Export the ONNX Model](#导出ONNX模型) to complete the deployment; + - (2)The ScaledYOLOv4 model trained by personal data should [Export the ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B). Refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 导出ONNX模型 +## Export the ONNX Model - 访问[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4)官方github库,按照指引下载安装,下载`scaledyolov4.pt` 模型,利用 `models/export.py` 得到`onnx`格式文件。如果您导出的`onnx`模型出现问题,可以参考[ScaledYOLOv4#401](https://github.com/WongKinYiu/ScaledYOLOv4/issues/401)的解决办法 + Visit the official [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4) github repository, follow the guidelines to download the `scaledyolov4.pt` model, and employ `models/export.py` to get the file in `onnx` format. If you have any problems with the exported `onnx` model, refer to [ScaledYOLOv4#401](https://github.com/WongKinYiu/ScaledYOLOv4/issues/401) for solution. + ```bash - #下载ScaledYOLOv4模型文件 + # Download the ScaledYOLOv4 model file Download from the goole drive https://drive.google.com/file/d/1aXZZE999sHMP1gev60XhNChtHPRMH3Fz/view?usp=sharing - # 导出onnx格式文件 + # Export the file in onnx format python models/export.py --weights PATH/TO/scaledyolov4-xx.pt --img-size 640 ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了ScaledYOLOv4导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +For developers' testing, models exported by ScaledYOLOv4 are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:----- | -| [ScaledYOLOv4-P5-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5-896.onnx) | 271MB | 51.2% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P5+BoF-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_-896.onnx) | 271MB | 51.7% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6-1280.onnx) | 487MB | 53.9% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P6+BoF-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_-1280.onnx) | 487MB | 54.4% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P7-1536](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7-1536.onnx) | 1.1GB | 55.0% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P5](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx) | 271MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P5+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_.onnx) | 271MB | -| 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P6](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6.onnx) | 487MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P6+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_.onnx) | 487MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -| [ScaledYOLOv4-P7](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7.onnx) | 1.1GB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5-896.onnx) | 271MB | 51.2% | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5+BoF-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_-896.onnx) | 271MB | 51.7% | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6-1280.onnx) | 487MB | 53.9% | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6+BoF-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_-1280.onnx) | 487MB | 54.4% | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P7-1536](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7-1536.onnx) | 1.1GB | 55.0% | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx) | 271MB | - | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_.onnx) | 271MB | -| This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6.onnx) | 487MB | - | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_.onnx) | 487MB | - | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P7](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7.onnx) | 1.1GB | - | This model file is sourced from [ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | -## 详细部署文档 -- [Python部署](python) -- [C++部署](cpp) +## Detailed Deployment Documents +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 -- 本版本文档和代码基于[ScaledYOLOv4 CommitID: 6768003](https://github.com/WongKinYiu/ScaledYOLOv4/commit/676800364a3446900b9e8407bc880ea2127b3415) 编写 +## Release Note + +- Document and code are based on [ScaledYOLOv4 CommitID: 6768003](https://github.com/WongKinYiu/ScaledYOLOv4/commit/676800364a3446900b9e8407bc880ea2127b3415) diff --git a/examples/vision/detection/scaledyolov4/README_CN.md b/examples/vision/detection/scaledyolov4/README_CN.md new file mode 100644 index 0000000000..60ada81734 --- /dev/null +++ b/examples/vision/detection/scaledyolov4/README_CN.md @@ -0,0 +1,49 @@ +[English](README.md) | 简体中文 +# ScaledYOLOv4准备部署模型 + +- ScaledYOLOv4部署实现来自[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4)的代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/ScaledYOLOv4)。 + + - (1)[官方库](https://github.com/WongKinYiu/ScaledYOLOv4)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)自己数据训练的ScaledYOLOv4模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + +## 导出ONNX模型 + + + 访问[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4)官方github库,按照指引下载安装,下载`scaledyolov4.pt` 模型,利用 `models/export.py` 得到`onnx`格式文件。如果您导出的`onnx`模型出现问题,可以参考[ScaledYOLOv4#401](https://github.com/WongKinYiu/ScaledYOLOv4/issues/401)的解决办法 + + ```bash + #下载ScaledYOLOv4模型文件 + Download from the goole drive https://drive.google.com/file/d/1aXZZE999sHMP1gev60XhNChtHPRMH3Fz/view?usp=sharing + + # 导出onnx格式文件 + python models/export.py --weights PATH/TO/scaledyolov4-xx.pt --img-size 640 + ``` + + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了ScaledYOLOv4导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [ScaledYOLOv4-P5-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5-896.onnx) | 271MB | 51.2% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5+BoF-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_-896.onnx) | 271MB | 51.7% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6-1280.onnx) | 487MB | 53.9% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6+BoF-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_-1280.onnx) | 487MB | 54.4% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P7-1536](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7-1536.onnx) | 1.1GB | 55.0% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx) | 271MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P5+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_.onnx) | 271MB | -| 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6.onnx) | 487MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P6+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_.onnx) | 487MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | +| [ScaledYOLOv4-P7](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7.onnx) | 1.1GB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[ScaledYOLOv4 CommitID: 6768003](https://github.com/WongKinYiu/ScaledYOLOv4/commit/676800364a3446900b9e8407bc880ea2127b3415) 编写 diff --git a/examples/vision/detection/scaledyolov4/cpp/README.md b/examples/vision/detection/scaledyolov4/cpp/README.md index f40c205857..e87b875079 100644 --- a/examples/vision/detection/scaledyolov4/cpp/README.md +++ b/examples/vision/detection/scaledyolov4/cpp/README.md @@ -1,46 +1,47 @@ -# ScaledYOLOv4 C++部署示例 +English | [简体中文](README_CN.md) +# ScaledYOLOv4 C++ Deployment Example -本目录下提供`infer.cc`快速完成ScaledYOLOv4在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of ScaledYOLOv4 on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的ScaledYOLOv4模型文件和测试图片 +# Download the official converted ScaledYOLOv4 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo scaled_yolov4-p5.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo scaled_yolov4-p5.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo scaled_yolov4-p5.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## ScaledYOLOv4 C++接口 +## ScaledYOLOv4 C++ Interface -### ScaledYOLOv4类 +### ScaledYOLOv4 Class ```c++ fastdeploy::vision::detection::ScaledYOLOv4( @@ -50,16 +51,16 @@ fastdeploy::vision::detection::ScaledYOLOv4( const ModelFormat& model_format = ModelFormat::ONNX) ``` -ScaledYOLOv4模型加载和初始化,其中model_file为导出的ONNX模型格式。 +ScaledYOLOv4 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Parameter > ```c++ > ScaledYOLOv4::Predict(cv::Mat* im, DetectionResult* result, @@ -67,26 +68,26 @@ ScaledYOLOv4模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding or not. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/scaledyolov4/cpp/README_CN.md b/examples/vision/detection/scaledyolov4/cpp/README_CN.md new file mode 100644 index 0000000000..53fbc412db --- /dev/null +++ b/examples/vision/detection/scaledyolov4/cpp/README_CN.md @@ -0,0 +1,93 @@ +[English](README.md) | 简体中文 +# ScaledYOLOv4 C++部署示例 + +本目录下提供`infer.cc`快速完成ScaledYOLOv4在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的ScaledYOLOv4模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo scaled_yolov4-p5.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo scaled_yolov4-p5.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo scaled_yolov4-p5.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## ScaledYOLOv4 C++接口 + +### ScaledYOLOv4类 + +```c++ +fastdeploy::vision::detection::ScaledYOLOv4( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +ScaledYOLOv4模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> ScaledYOLOv4::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/scaledyolov4/python/README.md b/examples/vision/detection/scaledyolov4/python/README.md index cb89fdb729..ff67320e39 100644 --- a/examples/vision/detection/scaledyolov4/python/README.md +++ b/examples/vision/detection/scaledyolov4/python/README.md @@ -1,84 +1,82 @@ -# ScaledYOLOv4 Python部署示例 +English | [简体中文](README_CN.md) +# ScaledYOLOv4 Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成ScaledYOLOv4在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishes the deployment of ScaledYOLOv4 on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/scaledyolov4/python/ -#下载scaledyolov4模型文件和测试图片 +# Download scaledyolov4 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model scaled_yolov4-p5.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model scaled_yolov4-p5.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model scaled_yolov4-p5.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## ScaledYOLOv4 Python接口 +## ScaledYOLOv4 Python Interface ```python fastdeploy.vision.detection.ScaledYOLOv4(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -ScaledYOLOv4模型加载和初始化,其中model_file为导出的ONNX模型格式 +ScaledYOLOv4 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > ScaledYOLOv4.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [ScaledYOLOv4 模型介绍](..) -- [ScaledYOLOv4 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [ScaledYOLOv4 Model Description](..) +- [ScaledYOLOv4 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/scaledyolov4/python/README_CN.md b/examples/vision/detection/scaledyolov4/python/README_CN.md new file mode 100644 index 0000000000..2cc4ec0efa --- /dev/null +++ b/examples/vision/detection/scaledyolov4/python/README_CN.md @@ -0,0 +1,85 @@ +[English](README.md) | 简体中文 +# ScaledYOLOv4 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成ScaledYOLOv4在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/scaledyolov4/python/ + +#下载scaledyolov4模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model scaled_yolov4-p5.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model scaled_yolov4-p5.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model scaled_yolov4-p5.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## ScaledYOLOv4 Python接口 + +```python +fastdeploy.vision.detection.ScaledYOLOv4(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +ScaledYOLOv4模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> ScaledYOLOv4.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [ScaledYOLOv4 模型介绍](..) +- [ScaledYOLOv4 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolor/README.md b/examples/vision/detection/yolor/README.md index c9749a0886..f3b966b8b2 100644 --- a/examples/vision/detection/yolor/README.md +++ b/examples/vision/detection/yolor/README.md @@ -1,46 +1,47 @@ -# YOLOR准备部署模型 +English | [简体中文](README_CN.md) +# YOLOR Ready-to-deploy Model -- YOLOR部署实现来自[YOLOR](https://github.com/WongKinYiu/yolor/releases/tag/weights)的代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolor/releases/tag/weights)。 +- The YOLOR deployment is based on the code of [YOLOR](https://github.com/WongKinYiu/yolor/releases/tag/weights) and [Pre-trained Model Based on COCO](https://github.com/WongKinYiu/yolor/releases/tag/weights). - - (1)[官方库](https://github.com/WongKinYiu/yolor/releases/tag/weights)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署,*.pose模型不支持部署; - - (2)自己数据训练的YOLOR模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)The *.pt provided by [Official Repository](https://github.com/WongKinYiu/yolor/releases/tag/weights) should [Export the ONNX Model](#导出ONNX模型) to complete the deployment. The *.pose model’s deployment is not supported; + - (2)The ScaledYOLOv4 model trained by personal data should [Export the ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B). Please refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 导出ONNX模型 +## Export the ONNX Model - 访问[YOLOR](https://github.com/WongKinYiu/yolor)官方github库,按照指引下载安装,下载`yolor.pt` 模型,利用 `models/export.py` 得到`onnx`格式文件。如果您导出的`onnx`模型出现精度不达标或者是数据维度的问题,可以参考[yolor#32](https://github.com/WongKinYiu/yolor/issues/32)的解决办法 + Visit the official [YOLOR](https://github.com/WongKinYiu/yolor) github repository, follow the guidelines to download the `yolor.pt` model, and employ `models/export.py` to get the file in `onnx` format. If the exported `onnx` model has a substandard accuracy or other problems about data dimension, you can refer to [yolor#32](https://github.com/WongKinYiu/yolor/issues/32) for the solution. ```bash - #下载yolor模型文件 + # Download yolor model file wget https://github.com/WongKinYiu/yolor/releases/download/weights/yolor-d6-paper-570.pt - # 导出onnx格式文件 + # Export the file in onnx format python models/export.py --weights PATH/TO/yolor-xx-xx-xx.pt --img-size 640 ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了YOLOR导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +For developers' testing, models exported by YOLOR are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:----- | -| [YOLOR-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-1280-1280.onnx) | 143MB | 54.1% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-W6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-1280-1280.onnx) | 305MB | 55.5% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-E6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-1280-1280.onnx ) | 443MB | 56.4% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-1280-1280.onnx) | 580MB | 57.0% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-1280-1280.onnx) | 580MB | 57.3% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-P6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx) | 143MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-W6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-640-640.onnx) | 305MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-E6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-640-640.onnx ) | 443MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-640-640.onnx) | 580MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-640-640.onnx) | 580MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-1280-1280.onnx) | 143MB | 54.1% | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-W6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-1280-1280.onnx) | 305MB | 55.5% | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-E6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-1280-1280.onnx ) | 443MB | 56.4% | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-1280-1280.onnx) | 580MB | 57.0% | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-1280-1280.onnx) | 580MB | 57.3% | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-P6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx) | 143MB | - | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-W6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-640-640.onnx) | 305MB | - | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-E6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-640-640.onnx ) | 443MB | - | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-640-640.onnx) | 580MB | - | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-640-640.onnx) | 580MB | - | This model file is sourced from [YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOR weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) 编写 +- Document and code are based on [YOLOR weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) diff --git a/examples/vision/detection/yolor/README_CN.md b/examples/vision/detection/yolor/README_CN.md new file mode 100644 index 0000000000..7e487057a5 --- /dev/null +++ b/examples/vision/detection/yolor/README_CN.md @@ -0,0 +1,48 @@ +[English](README.md) | 简体中文 +# YOLOR准备部署模型 + +- YOLOR部署实现来自[YOLOR](https://github.com/WongKinYiu/yolor/releases/tag/weights)的代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolor/releases/tag/weights)。 + + - (1)[官方库](https://github.com/WongKinYiu/yolor/releases/tag/weights)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署,*.pose模型不支持部署; + - (2)自己数据训练的YOLOR模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + +## 导出ONNX模型 + + + 访问[YOLOR](https://github.com/WongKinYiu/yolor)官方github库,按照指引下载安装,下载`yolor.pt` 模型,利用 `models/export.py` 得到`onnx`格式文件。如果您导出的`onnx`模型出现精度不达标或者是数据维度的问题,可以参考[yolor#32](https://github.com/WongKinYiu/yolor/issues/32)的解决办法 + + ```bash + #下载yolor模型文件 + wget https://github.com/WongKinYiu/yolor/releases/download/weights/yolor-d6-paper-570.pt + + # 导出onnx格式文件 + python models/export.py --weights PATH/TO/yolor-xx-xx-xx.pt --img-size 640 + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOR导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [YOLOR-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-1280-1280.onnx) | 143MB | 54.1% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-W6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-1280-1280.onnx) | 305MB | 55.5% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-E6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-1280-1280.onnx ) | 443MB | 56.4% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-1280-1280.onnx) | 580MB | 57.0% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-1280-1280.onnx) | 580MB | 57.3% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-P6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx) | 143MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-W6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-640-640.onnx) | 305MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-E6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-640-640.onnx ) | 443MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-640-640.onnx) | 580MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | +| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-640-640.onnx) | 580MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + +## 版本说明 + +- 本版本文档和代码基于[YOLOR weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) 编写 + diff --git a/examples/vision/detection/yolor/cpp/README.md b/examples/vision/detection/yolor/cpp/README.md index 89bccb487d..d410fecb61 100644 --- a/examples/vision/detection/yolor/cpp/README.md +++ b/examples/vision/detection/yolor/cpp/README.md @@ -1,46 +1,47 @@ -# YOLOR C++部署示例 +English | [简体中文](README_CN.md) +# YOLOR C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOR on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的YOLOR模型文件和测试图片 +# Download the official converted YOLOR model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo yolor-p6-paper-541-640-640.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolor-p6-paper-541-640-640.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolor-p6-paper-541-640-640.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOR C++接口 +## YOLOR C++ Interface -### YOLOR类 +### YOLOR Class ```c++ fastdeploy::vision::detection::YOLOR( @@ -50,16 +51,16 @@ fastdeploy::vision::detection::YOLOR( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOR模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOR model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOR::Predict(cv::Mat* im, DetectionResult* result, @@ -67,26 +68,26 @@ YOLOR模型加载和初始化,其中model_file为导出的ONNX模型格式。 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolor/cpp/README_CN.md b/examples/vision/detection/yolor/cpp/README_CN.md new file mode 100644 index 0000000000..a2f7b10064 --- /dev/null +++ b/examples/vision/detection/yolor/cpp/README_CN.md @@ -0,0 +1,93 @@ +[English](README.md) | 简体中文 +# YOLOR C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的YOLOR模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo yolor-p6-paper-541-640-640.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolor-p6-paper-541-640-640.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolor-p6-paper-541-640-640.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOR C++接口 + +### YOLOR类 + +```c++ +fastdeploy::vision::detection::YOLOR( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOR模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOR::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolor/python/README.md b/examples/vision/detection/yolor/python/README.md index ed433c0745..68e423742a 100644 --- a/examples/vision/detection/yolor/python/README.md +++ b/examples/vision/detection/yolor/python/README.md @@ -1,81 +1,81 @@ -# YOLOR Python部署示例 +English | [简体中文](README_CN.md) +# YOLOR Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成YOLOR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` ast finishes the deployment of YOLOR on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolor/python/ -#下载YOLOR模型文件和测试图片 +# Download YOLOR model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model yolor-p6-paper-541-640-640.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolor-p6-paper-541-640-640.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolor-p6-paper-541-640-640.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOR Python接口 +## YOLOR Python Interface ```python fastdeploy.vision.detection.YOLOR(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOR模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOR model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOR.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOR 模型介绍](..) -- [YOLOR C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOR Model Description](..) +- [YOLOR C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolor/python/README_CN.md b/examples/vision/detection/yolor/python/README_CN.md new file mode 100644 index 0000000000..0fa1cb294d --- /dev/null +++ b/examples/vision/detection/yolor/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# YOLOR Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/yolor/python/ + +#下载YOLOR模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model yolor-p6-paper-541-640-640.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model yolor-p6-paper-541-640-640.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolor-p6-paper-541-640-640.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOR Python接口 + +```python +fastdeploy.vision.detection.YOLOR(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOR模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOR.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOR 模型介绍](..) +- [YOLOR C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5/README.md b/examples/vision/detection/yolov5/README.md index 5ffe3f046a..918b7d2537 100644 --- a/examples/vision/detection/yolov5/README.md +++ b/examples/vision/detection/yolov5/README.md @@ -1,28 +1,30 @@ -# YOLOv5准备部署模型 +English | [简体中文](README_CN.md) -- YOLOv5 v7.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v7.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v7.0) - - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v7.0)提供的*.onnx可直接进行部署; - - (2)开发者基于自己数据训练的YOLOv5 v7.0模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。 +# YOLOv5 Ready-to-deploy Model +- The deployment of the YOLOv5 v7.0 model is based on [YOLOv5](https://github.com/ultralytics/yolov5/tree/v7.0) and [Pre-trained Model Based on COCO](https://github.com/ultralytics/yolov5/releases/tag/v7.0) + - (1)The *.onnx provided by [Official Repository](https://github.com/ultralytics/yolov5/releases/tag/v7.0) can be deployed directly; + - (2)The YOLOv5 v7.0 model trained by personal data should employ `export.py` in [YOLOv5](https://github.com/ultralytics/yolov5) to export the ONNX files for deployment. -## 下载预训练ONNX模型 -为了方便开发者的测试,下面提供了YOLOv5导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +## Download Pre-trained ONNX Model + +For developers' testing, models exported by YOLOv5 are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:---- | -| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | -| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | -| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | -| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% | This model file is sourced from [YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% | This model file is sourced from [YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% | This model file is sourced from [YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% | This model file is sourced from [YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% | This model file is sourced from [YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) -- [服务化部署](serving) +- [Python Deployment](python) +- [C++ Deployment](cpp) +- [Serving Deployment](serving) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOv5 v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) 编写 +- Document and code are based on [YOLOv5 v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) diff --git a/examples/vision/detection/yolov5/README_CN.md b/examples/vision/detection/yolov5/README_CN.md new file mode 100644 index 0000000000..591c359ee2 --- /dev/null +++ b/examples/vision/detection/yolov5/README_CN.md @@ -0,0 +1,29 @@ +[English](README.md) | 简体中文 +# YOLOv5准备部署模型 + +- YOLOv5 v7.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v7.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v7.0) + - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v7.0)提供的*.onnx可直接进行部署; + - (2)开发者基于自己数据训练的YOLOv5 v7.0模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。 + + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv5导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:---- | +| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | +| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) +- [服务化部署](serving) + +## 版本说明 + +- 本版本文档和代码基于[YOLOv5 v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) 编写 diff --git a/examples/vision/detection/yolov5/a311d/README.md b/examples/vision/detection/yolov5/a311d/README.md index 2f8451c60e..47917fbb0a 100755 --- a/examples/vision/detection/yolov5/a311d/README.md +++ b/examples/vision/detection/yolov5/a311d/README.md @@ -1,8 +1,12 @@ -# YOLOv5 量化模型在 A311D 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 量化模型到 A311D 上。 +English | [简体中文](README_CN.md) +# Deploy YOLOv5 Quantification Model on A311D +Now FastDeploy supports the deployment of YOLOv5 quantification model to A311D based on Paddle Lite. -## 详细部署文档 +For model quantification and download, refer to [Model Quantification](../quantize/README.md) -在 A311D 上只支持 C++ 的部署。 -- [C++部署](cpp) +## Detailed Deployment Tutorials + +Only C++ deployment is supported on A311D. + +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov5/a311d/README_CN.md b/examples/vision/detection/yolov5/a311d/README_CN.md new file mode 100644 index 0000000000..767518b56e --- /dev/null +++ b/examples/vision/detection/yolov5/a311d/README_CN.md @@ -0,0 +1,9 @@ +[English](README.md) | 简体中文 +# YOLOv5 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 量化模型到 A311D 上。 + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/detection/yolov5/cpp/README.md b/examples/vision/detection/yolov5/cpp/README.md index c70d0d1188..39e105cd9e 100755 --- a/examples/vision/detection/yolov5/cpp/README.md +++ b/examples/vision/detection/yolov5/cpp/README.md @@ -1,66 +1,61 @@ -# YOLOv5 C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv5 C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv5在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv5 on CPU/GPU and GPU accelerated by TensorRT. +Before deployment, two steps require confirmation -在部署前,需确认以下两个步骤 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeployPrecompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载 FastDeploy 预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的 yolov5 Paddle 模型文件和测试图片 +# Download the official converted yolov5 Paddle model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar tar -xvf yolov5s_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_paddle_demo yolov5s_infer 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_paddle_demo yolov5s_infer 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_paddle_demo yolov5s_infer 000000014439.jpg 2 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_paddle_demo yolov5s_infer 000000014439.jpg 3 -# 华为昇腾推理 -./infer_paddle_demo yolov5s_infer 000000014439.jpg 4 ``` -上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤: +The above steps apply to the inference of Paddle models. If you want to conduct the inference of ONNX models, follow these steps: ```bash -# 1. 下载官方转换好的 yolov5 ONNX 模型文件和测试图片 +# 1. Download the official converted yolov5 ONNX model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo yolov5s.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov5s.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolov5s.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) - -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOv5 C++接口 +## YOLOv5 C++ Interface -### YOLOv5类 +### YOLOv5 Class ```c++ fastdeploy::vision::detection::YOLOv5( @@ -70,16 +65,16 @@ fastdeploy::vision::detection::YOLOv5( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv5模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv5 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv5::Predict(cv::Mat* im, DetectionResult* result, @@ -87,26 +82,26 @@ YOLOv5模型加载和初始化,其中model_file为导出的ONNX模型格式。 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5/cpp/README_CN.md b/examples/vision/detection/yolov5/cpp/README_CN.md new file mode 100644 index 0000000000..d8499ec231 --- /dev/null +++ b/examples/vision/detection/yolov5/cpp/README_CN.md @@ -0,0 +1,113 @@ +[English](README.md) | 简体中文 +# YOLOv5 C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv5在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载 FastDeploy 预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j +#下载官方转换好的 yolov5 Paddle 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar +tar -xvf yolov5s_infer.tar +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 0 +# GPU推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 2 +# 昆仑芯XPU推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 3 +# 华为昇腾推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 4 +``` + +上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤: +```bash +# 1. 下载官方转换好的 yolov5 ONNX 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +./infer_demo yolov5s.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolov5s.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov5s.onnx 000000014439.jpg 2 +``` +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +## YOLOv5 C++接口 + +### YOLOv5类 + +```c++ +fastdeploy::vision::detection::YOLOv5( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv5模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv5::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5/python/README.md b/examples/vision/detection/yolov5/python/README.md index de93ef0ecb..b1c56a0541 100755 --- a/examples/vision/detection/yolov5/python/README.md +++ b/examples/vision/detection/yolov5/python/README.md @@ -1,86 +1,85 @@ -# YOLOv5 Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv5 Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv5在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv5 on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolov5/python/ -#下载yolov5模型文件和测试图片 +# Download yolov5 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar tar -xf yolov5s_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 +# KunlunXin XPU inference python infer.py --model yolov5s_infer --image 000000014439.jpg --device kunlunxin -# 华为昇腾推理 -python infer.py --model yolov5s_infer --image 000000014439.jpg --device ascend ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOv5 Python接口 +## YOLOv5 Python Interface ```python fastdeploy.vision.detection.YOLOv5(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv5模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv5 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv5.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOv5 模型介绍](..) -- [YOLOv5 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv5 Model Description](..) +- [YOLOv5 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5/python/README_CN.md b/examples/vision/detection/yolov5/python/README_CN.md new file mode 100644 index 0000000000..e575472ce4 --- /dev/null +++ b/examples/vision/detection/yolov5/python/README_CN.md @@ -0,0 +1,87 @@ +[English](README.md) | 简体中文 +# YOLOv5 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv5在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/yolov5/python/ + +#下载yolov5模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar +tar -xf yolov5s_infer.tar +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python infer.py --model yolov5s_infer --image 000000014439.jpg --device kunlunxin +# 华为昇腾推理 +python infer.py --model yolov5s_infer --image 000000014439.jpg --device ascend +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv5 Python接口 + +```python +fastdeploy.vision.detection.YOLOv5(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv5模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv5.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOv5 模型介绍](..) +- [YOLOv5 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5/quantize/README.md b/examples/vision/detection/yolov5/quantize/README.md index aa0a8d5431..4d97b7578c 100755 --- a/examples/vision/detection/yolov5/quantize/README.md +++ b/examples/vision/detection/yolov5/quantize/README.md @@ -1,44 +1,30 @@ -# YOLOv5量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. - -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) - -## 下载量化完成的YOLOv5s模型 -用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) - -Benchmark表格说明: -- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. -- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. -- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. -- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 -- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 -- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. -- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. -- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. - - -#### Runtime Benchmark -| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | TensorRT | GPU | 7.87 | 4.51 | 4.31 | 3.17 | 2.48 | 37.6 | 36.7 | 量化蒸馏训练 | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle-TensorRT | GPU | 7.99 | None | 4.46 | 3.31 | 2.41 | 37.6 | 36.8 | 量化蒸馏训练 | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | ONNX Runtime | CPU | 176.41 | 91.90 | None | None | 1.90 | 37.6 | 33.1 |量化蒸馏训练 | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle Inference| CPU | 213.73 | 130.19 | None | None | 1.64 |37.6 | 35.2 | 量化蒸馏训练 | - -#### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | TensorRT | GPU | 24.61 | 21.20 | 20.78 | 20.94 | 1.18 | 37.6 | 36.7 | 量化蒸馏训练 | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle-TensorRT | GPU | 23.53 | None | 21.98 | 19.84 | 1.28 | 37.6 | 36.8 | 量化蒸馏训练 | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | ONNX Runtime | CPU | 197.323 | 110.99 | None | None | 1.78 | 37.6 | 33.1 |量化蒸馏训练 | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle Inference| CPU | 235.73 | 144.82 | None | None | 1.63 |37.6 | 35.2 | 量化蒸馏训练 | - - - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) +English | [简体中文](README_CN.md) +# YOLOv5 Quantized Model Deployment + +FastDeploy supports the deployment of quantized models and provides a one-click model quantization tool. +Users can use the one-click model quantization tool to quantize and deploy the models themselves or download the quantized models provided by FastDeploy directly for deployment. + +## FastDeploy One-Click Model Quantization Tool + +FastDeploy provides a one-click quantization tool that allows users to quantize a model simply with a configuration file. +For a detailed tutorial, please refer to: [One-Click Model Quantization Tool](../../../../../tools/common_tools/auto_compression/) + +## Download Quantized YOLOv5s Model + +Users can also directly download the quantized models in the table below for deployment. + +| Model | Inference Backend | Hardware | FP32 Inference Time Delay | INT8  Inference Time Delay | Acceleration ratio | FP32 mAP | INT8 mAP | Method | +| ----------------------------------------------------------------------- | ----------------- | -------- | ------------------------- | -------------------------- | ------------------ | -------- | -------- | ------------------------------- | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | TensorRT | GPU | 8.79 | 5.17 | 1.70 | 37.6 | 36.6 | Quantized distillation training | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle Inference | CPU | 217.05 | 133.31 | 1.63 | 37.6 | 36.8 | Quantized distillation training | + +The data in the above table shows the end-to-end inference performance of FastDeploy deployment before and after model quantization. + +- The test images are from COCO val2017. +- The inference time delay is the inference latency on different Runtime in milliseconds. +- CPU is Intel(R) Xeon(R) Gold 6271C, GPU is Tesla T4, TensorRT version 8.4.15, and the fixed CPU thread is 1 for all tests. + +## More Detailed Tutorials + +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov5/quantize/README_CN.md b/examples/vision/detection/yolov5/quantize/README_CN.md new file mode 100755 index 0000000000..dc85b1e329 --- /dev/null +++ b/examples/vision/detection/yolov5/quantize/README_CN.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 +# YOLOv5量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. + +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) + +## 下载量化完成的YOLOv5s模型 +用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) + +Benchmark表格说明: +- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. +- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. +- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. +- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 +- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 +- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. +- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. +- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. + + +#### Runtime Benchmark +| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | TensorRT | GPU | 7.87 | 4.51 | 4.31 | 3.17 | 2.48 | 37.6 | 36.7 | 量化蒸馏训练 | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle-TensorRT | GPU | 7.99 | None | 4.46 | 3.31 | 2.41 | 37.6 | 36.8 | 量化蒸馏训练 | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | ONNX Runtime | CPU | 176.41 | 91.90 | None | None | 1.90 | 37.6 | 33.1 |量化蒸馏训练 | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle Inference| CPU | 213.73 | 130.19 | None | None | 1.64 |37.6 | 35.2 | 量化蒸馏训练 | + +#### 端到端 Benchmark +| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | TensorRT | GPU | 24.61 | 21.20 | 20.78 | 20.94 | 1.18 | 37.6 | 36.7 | 量化蒸馏训练 | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle-TensorRT | GPU | 23.53 | None | 21.98 | 19.84 | 1.28 | 37.6 | 36.8 | 量化蒸馏训练 | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | ONNX Runtime | CPU | 197.323 | 110.99 | None | None | 1.78 | 37.6 | 33.1 |量化蒸馏训练 | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle Inference| CPU | 235.73 | 144.82 | None | None | 1.63 |37.6 | 35.2 | 量化蒸馏训练 | + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/detection/yolov5/quantize/README_EN.md b/examples/vision/detection/yolov5/quantize/README_EN.md deleted file mode 100755 index d897710f98..0000000000 --- a/examples/vision/detection/yolov5/quantize/README_EN.md +++ /dev/null @@ -1,29 +0,0 @@ -# YOLOv5 Quantized Model Deployment - -FastDeploy supports the deployment of quantized models and provides a one-click model quantization tool. -Users can use the one-click model quantization tool to quantize and deploy the models themselves or download the quantized models provided by FastDeploy directly for deployment. - -## FastDeploy One-Click Model Quantization Tool - -FastDeploy provides a one-click quantization tool that allows users to quantize a model simply with a configuration file. -For a detailed tutorial, please refer to: [One-Click Model Quantization Tool](../../../../../tools/common_tools/auto_compression/) - -## Download Quantized YOLOv5s Model - -Users can also directly download the quantized models in the table below for deployment. - -| Model | Inference Backend | Hardware | FP32 Inference Time Delay | INT8  Inference Time Delay | Acceleration ratio | FP32 mAP | INT8 mAP | Method | -| ----------------------------------------------------------------------- | ----------------- | -------- | ------------------------- | -------------------------- | ------------------ | -------- | -------- | ------------------------------- | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | TensorRT | GPU | 8.79 | 5.17 | 1.70 | 37.6 | 36.6 | Quantized distillation training | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_quant.tar) | Paddle Inference | CPU | 217.05 | 133.31 | 1.63 | 37.6 | 36.8 | Quantized distillation training | - -The data in the above table shows the end-to-end inference performance of FastDeploy deployment before and after model quantization. - -- The test images are from COCO val2017. -- The inference time delay is the inference latency on different Runtime in milliseconds. -- CPU is Intel(R) Xeon(R) Gold 6271C, GPU is Tesla T4, TensorRT version 8.4.15, and the fixed CPU thread is 1 for all tests. - -## More Detailed Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov5/rv1126/README.md b/examples/vision/detection/yolov5/rv1126/README.md index 5bac651e20..736b963dce 100755 --- a/examples/vision/detection/yolov5/rv1126/README.md +++ b/examples/vision/detection/yolov5/rv1126/README.md @@ -1,8 +1,12 @@ -# YOLOv5 量化模型在 RV1126 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 量化模型到 RV1126 上。 +English | [简体中文](README_CN.md) +# Deploy YOLOv5 Quantification Model on RV1126 +Now FastDeploy supports the deployment of YOLOv5 quantification model to RV1126 based on Paddle Lite. -## 详细部署文档 +For model quantification and download, refer to [Model Quantification](../quantize/README.md) -在 RV1126 上只支持 C++ 的部署。 -- [C++部署](cpp) +## Detailed Deployment Tutorials + +Only C++ deployment is supported on RV1126. + +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov5/rv1126/README_CN.md b/examples/vision/detection/yolov5/rv1126/README_CN.md new file mode 100644 index 0000000000..11a1afc7df --- /dev/null +++ b/examples/vision/detection/yolov5/rv1126/README_CN.md @@ -0,0 +1,9 @@ +[English](README.md) | 简体中文 +# YOLOv5 量化模型在 RV1126 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 量化模型到 RV1126 上。 + +## 详细部署文档 + +在 RV1126 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/detection/yolov5/serving/README.md b/examples/vision/detection/yolov5/serving/README.md index 8ad6218496..50500fa398 100644 --- a/examples/vision/detection/yolov5/serving/README.md +++ b/examples/vision/detection/yolov5/serving/README.md @@ -1,38 +1,27 @@ -# YOLOv5 服务化部署示例 +English | [简体中文](README_CN.md) +# YOLOv5 Serving Deployment Demo -在服务化部署前,需确认 - -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) - - -## 启动服务 +## Launch Serving ```bash -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/detection/yolov5/serving/ - -#下载yolov5模型文件 +#Download yolov5 model file wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx -# 将模型放入 models/runtime/1目录下, 并重命名为model.onnx -mv yolov5s.onnx models/runtime/1/model.onnx +# Save the model under models/infer/1 and rename it as model.onnx +mv yolov5s.onnx models/infer/1/ -# 拉取fastdeploy镜像(x.y.z为镜像版本号,需参照serving文档替换为数字) -# GPU镜像 -docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 -# CPU镜像 -docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-cpu-only-21.10 +# Pull fastdeploy image, x.y.z is FastDeploy version, example 1.0.0. +docker pull paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 -# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /yolov5_serving 目录 -nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/yolov5_serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash +# Run the docker. The docker name is fd_serving, and the current directory is mounted as the docker's /yolov5_serving directory +nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/yolov5_serving paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash -# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) -CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/yolov5_serving/models --backend-config=python,shm-default-byte-size=10485760 +# Start the service (Without setting the CUDA_VISIBLE_DEVICES environment variable, it will have scheduling privileges for all GPU cards) +CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=models --backend-config=python,shm-default-byte-size=10485760 ``` ->> **注意**: 当出现"Address already in use", 请使用`--grpc-port`指定端口号来启动服务,同时更改yolov5_grpc_client.py中的请求端口号 -服务启动成功后, 会有以下输出: +Output the following contents if serving is launched + ``` ...... I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 @@ -40,27 +29,30 @@ I0928 04:51:15.785177 206 http_server.cc:2815] Started HTTPService at 0.0.0.0:80 I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0:8002 ``` +## Client Requests -## 客户端请求 +Execute the following command in the physical machine to send a grpc request and output the result -在物理机器中执行以下命令,发送grpc请求并输出结果 ``` -#下载测试图片 +#Download test images wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -#安装客户端依赖 -python3 -m pip install tritonclient[all] +#Installing client-side dependencies +python3 -m pip install tritonclient\[all\] -# 发送请求 +# Send requests python3 yolov5_grpc_client.py ``` -发送请求成功后,会返回json格式的检测结果并打印输出: +When the request is sent successfully, the results are returned in json format and printed out: + ``` output_name: detction_result {'boxes': [[268.48028564453125, 81.05305480957031, 298.69476318359375, 169.43902587890625], [104.73116302490234, 45.66197204589844, 127.58382415771484, 93.44938659667969], [378.9093933105469, 39.75013732910156, 395.6086120605469, 84.24342346191406], [158.552978515625, 80.36149597167969, 199.18576049804688, 168.18191528320312], [414.37530517578125, 90.94805908203125, 506.3218994140625, 280.40521240234375], [364.00341796875, 56.608917236328125, 381.97857666015625, 115.96823120117188], [351.7251281738281, 42.635345458984375, 366.9103088378906, 98.04837036132812], [505.8882751464844, 114.36674499511719, 593.1248779296875, 275.99530029296875], [327.7086181640625, 38.36369323730469, 346.84991455078125, 80.89302062988281], [583.493408203125, 114.53289794921875, 612.3546142578125, 175.87353515625], [186.4706573486328, 44.941375732421875, 199.6645050048828, 61.037628173828125], [169.6158905029297, 48.01460266113281, 178.1415557861328, 60.88859558105469], [25.81019401550293, 117.19969177246094, 59.88878631591797, 152.85012817382812], [352.1452941894531, 46.71272277832031, 381.9460754394531, 106.75212097167969], [1.875, 150.734375, 37.96875, 173.78125], [464.65728759765625, 15.901412963867188, 472.512939453125, 34.11640930175781], [64.625, 135.171875, 84.5, 154.40625], [57.8125, 151.234375, 103.0, 174.15625], [165.890625, 88.609375, 527.90625, 339.953125], [101.40625, 152.5625, 118.890625, 169.140625]], 'scores': [0.8965693116188049, 0.8695310950279236, 0.8684297800064087, 0.8429877758026123, 0.8358422517776489, 0.8151364326477051, 0.8089362382888794, 0.801361083984375, 0.7947245836257935, 0.7606497406959534, 0.6325908303260803, 0.6139386892318726, 0.5906146764755249, 0.505328893661499, 0.40457233786582947, 0.3460320234298706, 0.33283042907714844, 0.3325657248497009, 0.2594234347343445, 0.25389009714126587], 'label_ids': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 24, 24, 33, 24], 'masks': [], 'contain_masks': False} ``` -## 配置修改 +## Modify Configs + + -当前默认配置在CPU上运行ONNXRuntime引擎, 如果要在GPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) +The default is to run ONNXRuntime on CPU. If developers need to run it on GPU or other inference engines, please see the [Configs File](../../../../../serving/docs/zh_CN/model_configuration.md) to modify the configs in `models/runtime/config.pbtxt`. diff --git a/examples/vision/detection/yolov5/serving/README_EN.md b/examples/vision/detection/yolov5/serving/README_CN.md similarity index 56% rename from examples/vision/detection/yolov5/serving/README_EN.md rename to examples/vision/detection/yolov5/serving/README_CN.md index 46deb29f1c..4fc0b3800e 100644 --- a/examples/vision/detection/yolov5/serving/README_EN.md +++ b/examples/vision/detection/yolov5/serving/README_CN.md @@ -1,26 +1,39 @@ -# YOLOv5 Serving Deployment Demo +[English](README.md) | 简体中文 +# YOLOv5 服务化部署示例 -## Launch Serving +在服务化部署前,需确认 + +- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) + + +## 启动服务 ```bash -#Download yolov5 model file +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/detection/yolov5/serving/ + +#下载yolov5模型文件 wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx -# Save the model under models/infer/1 and rename it as model.onnx -mv yolov5s.onnx models/infer/1/ +# 将模型放入 models/runtime/1目录下, 并重命名为model.onnx +mv yolov5s.onnx models/runtime/1/model.onnx -# Pull fastdeploy image, x.y.z is FastDeploy version, example 1.0.0. -docker pull paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +# 拉取fastdeploy镜像(x.y.z为镜像版本号,需参照serving文档替换为数字) +# GPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +# CPU镜像 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-cpu-only-21.10 -# Run the docker. The docker name is fd_serving, and the current directory is mounted as the docker's /yolov5_serving directory -nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/yolov5_serving paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash +# 运行容器.容器名字为 fd_serving, 并挂载当前目录为容器的 /yolov5_serving 目录 +nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/yolov5_serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash -# Start the service (Without setting the CUDA_VISIBLE_DEVICES environment variable, it will have scheduling privileges for all GPU cards) -CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=models --backend-config=python,shm-default-byte-size=10485760 +# 启动服务(不设置CUDA_VISIBLE_DEVICES环境变量,会拥有所有GPU卡的调度权限) +CUDA_VISIBLE_DEVICES=0 fastdeployserver --model-repository=/yolov5_serving/models --backend-config=python,shm-default-byte-size=10485760 ``` +>> **注意**: 当出现"Address already in use", 请使用`--grpc-port`指定端口号来启动服务,同时更改yolov5_grpc_client.py中的请求端口号 -Output the following contents if serving is launched - +服务启动成功后, 会有以下输出: ``` ...... I0928 04:51:15.784517 206 grpc_server.cc:4117] Started GRPCInferenceService at 0.0.0.0:8001 @@ -28,30 +41,27 @@ I0928 04:51:15.785177 206 http_server.cc:2815] Started HTTPService at 0.0.0.0:80 I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0:8002 ``` -## Client Requests -Execute the following command in the physical machine to send a grpc request and output the result +## 客户端请求 +在物理机器中执行以下命令,发送grpc请求并输出结果 ``` -#Download test images +#下载测试图片 wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -#Installing client-side dependencies -python3 -m pip install tritonclient\[all\] +#安装客户端依赖 +python3 -m pip install tritonclient[all] -# Send requests +# 发送请求 python3 yolov5_grpc_client.py ``` -When the request is sent successfully, the results are returned in json format and printed out: - +发送请求成功后,会返回json格式的检测结果并打印输出: ``` output_name: detction_result {'boxes': [[268.48028564453125, 81.05305480957031, 298.69476318359375, 169.43902587890625], [104.73116302490234, 45.66197204589844, 127.58382415771484, 93.44938659667969], [378.9093933105469, 39.75013732910156, 395.6086120605469, 84.24342346191406], [158.552978515625, 80.36149597167969, 199.18576049804688, 168.18191528320312], [414.37530517578125, 90.94805908203125, 506.3218994140625, 280.40521240234375], [364.00341796875, 56.608917236328125, 381.97857666015625, 115.96823120117188], [351.7251281738281, 42.635345458984375, 366.9103088378906, 98.04837036132812], [505.8882751464844, 114.36674499511719, 593.1248779296875, 275.99530029296875], [327.7086181640625, 38.36369323730469, 346.84991455078125, 80.89302062988281], [583.493408203125, 114.53289794921875, 612.3546142578125, 175.87353515625], [186.4706573486328, 44.941375732421875, 199.6645050048828, 61.037628173828125], [169.6158905029297, 48.01460266113281, 178.1415557861328, 60.88859558105469], [25.81019401550293, 117.19969177246094, 59.88878631591797, 152.85012817382812], [352.1452941894531, 46.71272277832031, 381.9460754394531, 106.75212097167969], [1.875, 150.734375, 37.96875, 173.78125], [464.65728759765625, 15.901412963867188, 472.512939453125, 34.11640930175781], [64.625, 135.171875, 84.5, 154.40625], [57.8125, 151.234375, 103.0, 174.15625], [165.890625, 88.609375, 527.90625, 339.953125], [101.40625, 152.5625, 118.890625, 169.140625]], 'scores': [0.8965693116188049, 0.8695310950279236, 0.8684297800064087, 0.8429877758026123, 0.8358422517776489, 0.8151364326477051, 0.8089362382888794, 0.801361083984375, 0.7947245836257935, 0.7606497406959534, 0.6325908303260803, 0.6139386892318726, 0.5906146764755249, 0.505328893661499, 0.40457233786582947, 0.3460320234298706, 0.33283042907714844, 0.3325657248497009, 0.2594234347343445, 0.25389009714126587], 'label_ids': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 24, 24, 33, 24], 'masks': [], 'contain_masks': False} ``` -## Modify Configs - - +## 配置修改 -The default is to run ONNXRuntime on CPU. If developers need to run it on GPU or other inference engines, please see the [Configs File](../../../../../serving/docs/zh_CN/model_configuration.md) to modify the configs in `models/runtime/config.pbtxt`. +当前默认配置在CPU上运行ONNXRuntime引擎, 如果要在GPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) diff --git a/examples/vision/detection/yolov5lite/README.md b/examples/vision/detection/yolov5lite/README.md index 0429758b84..aa4343a3d7 100644 --- a/examples/vision/detection/yolov5lite/README.md +++ b/examples/vision/detection/yolov5lite/README.md @@ -1,71 +1,72 @@ -# YOLOv5Lite准备部署模型 +English | [简体中文](README_CN.md) +# YOLOv5Lite Ready-to-deploy Model -- YOLOv5Lite部署实现来自[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) -代码,和[基于COCO的预训练模型](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4)。 +- The YOLOv5Lite Deployment is based on the code of [YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) +and [Pre-trained Model Based on COCO](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4)。 - - (1)[官方库](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)自己数据训练的YOLOv5Lite模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)The *.pt provided by [Official Repository](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) should [Export the ONNX Model](#导出ONNX模型)to complete the deployment; + - (2)The YOLOv5Lite model trained by personal data should [Export the ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B). Refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 导出ONNX模型 +## Export the ONNX Model -- 自动获取 - 访问[YOLOv5Lite](https://github.com/ppogg/YOLOv5-Lite) -官方github库,按照指引下载安装,下载`yolov5-lite-xx.onnx` 模型(Tips:官方提供的ONNX文件目前是没有decode模块的) +- Auto-acquisition + Visit official [YOLOv5Lite](https://github.com/ppogg/YOLOv5-Lite) +github repository, follow the guidelines to download the `yolov5-lite-xx.onnx` model(Tips: The official ONNX files are currently provided without the decode module) ```bash - #下载yolov5-lite模型文件(.onnx) + # Download yolov5-lite model files(.onnx) Download from https://drive.google.com/file/d/1bJByk9eoS6pv8Z3N4bcLRCV3i7uk24aU/view - 官方Repo也支持百度云下载 + Official Repo also supports Baidu cloud download ``` -- 手动获取 +- Manual Acquisition - 访问[YOLOv5Lite](https://github.com/ppogg/YOLOv5-Lite) -官方github库,按照指引下载安装,下载`yolov5-lite-xx.pt` 模型,利用 `export.py` 得到`onnx`格式文件。 + Visit official [YOLOv5Lite](https://github.com/ppogg/YOLOv5-Lite) +github repository, follow the guidelines to download the `yolov5-lite-xx.pt` model, and employ `export.py` to get files in `onnx` format. - - 导出含有decode模块的ONNX文件 + - Export ONNX files with the decode module - 首先需要参考[YOLOv5-Lite#189](https://github.com/ppogg/YOLOv5-Lite/pull/189)的解决办法,修改代码。 + First refer to [YOLOv5-Lite#189](https://github.com/ppogg/YOLOv5-Lite/pull/189) to modify the code. ```bash - #下载yolov5-lite模型文件(.pt) + # Download yolov5-lite model files(.pt) Download from https://drive.google.com/file/d/1oftzqOREGqDCerf7DtD5BZp9YWELlkMe/view - 官方Repo也支持百度云下载 + Official Repo also supports Baidu cloud download - # 导出onnx格式文件 + # Export files in onnx format python export.py --grid --dynamic --concat --weights PATH/TO/yolov5-lite-xx.pt ``` - - 导出无decode模块的ONNX文件(不需要修改代码) + - Export ONNX files without the docode module(No code changes are required) ```bash - #下载yolov5-lite模型文件 + # Download yolov5-lite model files Download from https://drive.google.com/file/d/1oftzqOREGqDCerf7DtD5BZp9YWELlkMe/view - 官方Repo也支持百度云下载 + Official Repo also supports Baidu cloud download - # 导出onnx格式文件 + # Export files in onnx format python export.py --grid --dynamic --weights PATH/TO/yolov5-lite-xx.pt ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了YOLOv5Lite导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +For developers' testing, models exported by YOLOv5Lite are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:----- | -| [YOLOv5Lite-e](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-e-sim-320.onnx) | 3.1MB | 35.1% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | -| [YOLOv5Lite-s](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-s-sim-416.onnx) | 6.3MB | 42.0% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | -| [YOLOv5Lite-c](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-c-sim-512.onnx) | 18MB | 50.9% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | -| [YOLOv5Lite-g](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx) | 21MB | 57.6% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-e](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-e-sim-320.onnx) | 3.1MB | 35.1% | This model file is sourced from [YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-s](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-s-sim-416.onnx) | 6.3MB | 42.0% | This model file is sourced from [YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-c](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-c-sim-512.onnx) | 18MB | 50.9% | This model file is sourced from[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-g](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx) | 21MB | 57.6% | This model file is sourced from [YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOv5-Lite v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) 编写 +- Document and code are based on [YOLOv5-Lite v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) diff --git a/examples/vision/detection/yolov5lite/README_CN.md b/examples/vision/detection/yolov5lite/README_CN.md new file mode 100644 index 0000000000..c69c2d9920 --- /dev/null +++ b/examples/vision/detection/yolov5lite/README_CN.md @@ -0,0 +1,72 @@ +[English](README.md) | 简体中文 +# YOLOv5Lite准备部署模型 + +- YOLOv5Lite部署实现来自[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) +代码,和[基于COCO的预训练模型](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4)。 + + - (1)[官方库](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)自己数据训练的YOLOv5Lite模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + +## 导出ONNX模型 + +- 自动获取 + 访问[YOLOv5Lite](https://github.com/ppogg/YOLOv5-Lite) +官方github库,按照指引下载安装,下载`yolov5-lite-xx.onnx` 模型(Tips:官方提供的ONNX文件目前是没有decode模块的) + ```bash + #下载yolov5-lite模型文件(.onnx) + Download from https://drive.google.com/file/d/1bJByk9eoS6pv8Z3N4bcLRCV3i7uk24aU/view + 官方Repo也支持百度云下载 + ``` + +- 手动获取 + + 访问[YOLOv5Lite](https://github.com/ppogg/YOLOv5-Lite) +官方github库,按照指引下载安装,下载`yolov5-lite-xx.pt` 模型,利用 `export.py` 得到`onnx`格式文件。 + + - 导出含有decode模块的ONNX文件 + + 首先需要参考[YOLOv5-Lite#189](https://github.com/ppogg/YOLOv5-Lite/pull/189)的解决办法,修改代码。 + + ```bash + #下载yolov5-lite模型文件(.pt) + Download from https://drive.google.com/file/d/1oftzqOREGqDCerf7DtD5BZp9YWELlkMe/view + 官方Repo也支持百度云下载 + + # 导出onnx格式文件 + python export.py --grid --dynamic --concat --weights PATH/TO/yolov5-lite-xx.pt + + + ``` + - 导出无decode模块的ONNX文件(不需要修改代码) + + ```bash + #下载yolov5-lite模型文件 + Download from https://drive.google.com/file/d/1oftzqOREGqDCerf7DtD5BZp9YWELlkMe/view + 官方Repo也支持百度云下载 + + # 导出onnx格式文件 + python export.py --grid --dynamic --weights PATH/TO/yolov5-lite-xx.pt + + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv5Lite导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [YOLOv5Lite-e](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-e-sim-320.onnx) | 3.1MB | 35.1% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-s](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-s-sim-416.onnx) | 6.3MB | 42.0% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-c](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-c-sim-512.onnx) | 18MB | 50.9% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | +| [YOLOv5Lite-g](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx) | 21MB | 57.6% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOv5-Lite v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) 编写 diff --git a/examples/vision/detection/yolov5lite/cpp/README.md b/examples/vision/detection/yolov5lite/cpp/README.md index 43ec415807..7edbc3b739 100644 --- a/examples/vision/detection/yolov5lite/cpp/README.md +++ b/examples/vision/detection/yolov5lite/cpp/README.md @@ -1,46 +1,47 @@ -# YOLOv5Lite C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv5Lite C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv5Lite在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv5Lite on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的YOLOv5Lite模型文件和测试图片 +# Download the official converted YOLOv5Lite model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo v5Lite-g-sim-640.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo v5Lite-g-sim-640.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo v5Lite-g-sim-640.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOv5Lite C++接口 +## YOLOv5Lite C++ Interface -### YOLOv5Lite类 +### YOLOv5Lite Class ```c++ fastdeploy::vision::detection::YOLOv5Lite( @@ -50,16 +51,16 @@ fastdeploy::vision::detection::YOLOv5Lite( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv5Lite模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv5Lite model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv5Lite::Predict(cv::Mat* im, DetectionResult* result, @@ -67,26 +68,26 @@ YOLOv5Lite模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5lite/cpp/README_CN.md b/examples/vision/detection/yolov5lite/cpp/README_CN.md new file mode 100644 index 0000000000..46b918f5c8 --- /dev/null +++ b/examples/vision/detection/yolov5lite/cpp/README_CN.md @@ -0,0 +1,93 @@ +[English](README.md) | 简体中文 +# YOLOv5Lite C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv5Lite在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的YOLOv5Lite模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo v5Lite-g-sim-640.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo v5Lite-g-sim-640.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo v5Lite-g-sim-640.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv5Lite C++接口 + +### YOLOv5Lite类 + +```c++ +fastdeploy::vision::detection::YOLOv5Lite( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv5Lite模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv5Lite::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5lite/python/README.md b/examples/vision/detection/yolov5lite/python/README.md index ebf8fba944..55a05e1273 100644 --- a/examples/vision/detection/yolov5lite/python/README.md +++ b/examples/vision/detection/yolov5lite/python/README.md @@ -1,81 +1,82 @@ -# YOLOv5Lite Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv5Lite Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv5Lite在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv5Lite on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolov5lite/python/ -#下载YOLOv5Lite模型文件和测试图片 +# Download YOLOv5Lite model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model v5Lite-g-sim-640.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model v5Lite-g-sim-640.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model v5Lite-g-sim-640.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOv5Lite Python接口 +## YOLOv5Lite Python Interface ```python fastdeploy.vision.detection.YOLOv5Lite(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv5Lite模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv5Lite model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv5Lite.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOv5Lite 模型介绍](..) -- [YOLOv5Lite C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv5Lite Model Description](..) +- [YOLOv5Lite C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov5lite/python/README_CN.md b/examples/vision/detection/yolov5lite/python/README_CN.md new file mode 100644 index 0000000000..87f5e8bcdf --- /dev/null +++ b/examples/vision/detection/yolov5lite/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# YOLOv5Lite Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv5Lite在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/yolov5lite/python/ + +#下载YOLOv5Lite模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model v5Lite-g-sim-640.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model v5Lite-g-sim-640.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model v5Lite-g-sim-640.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv5Lite Python接口 + +```python +fastdeploy.vision.detection.YOLOv5Lite(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv5Lite模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv5Lite.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOv5Lite 模型介绍](..) +- [YOLOv5Lite C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov6/README.md b/examples/vision/detection/yolov6/README.md index d31622a8b3..6a63dc07e0 100644 --- a/examples/vision/detection/yolov6/README.md +++ b/examples/vision/detection/yolov6/README.md @@ -1,30 +1,33 @@ -# YOLOv6准备部署模型 +English | [简体中文](README_CN.md) +# YOLOv6 Ready-to-deploy Model -- YOLOv6 部署实现来自[YOLOv6](https://github.com/meituan/YOLOv6/releases/tag/0.1.0),和[基于coco的预训练模型](https://github.com/meituan/YOLOv6/releases/tag/0.1.0)。 - - (1)[官方库](https://github.com/meituan/YOLOv6/releases/tag/0.1.0)提供的*.onnx可直接进行部署; - - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 +- The YOLOv6 deployment is based on [YOLOv6](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) and [Pre-trained Model Based on COCO](https://github.com/meituan/YOLOv6/releases/tag/0.1.0). + - (1)The *.onnx provided by [Official Repository](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) can directly conduct deployemnt; + - (2)Personal models trained by developers should export the ONNX model. Refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 下载预训练ONNX模型 -为了方便开发者的测试,下面提供了YOLOv6导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +## Download Pre-trained ONNX Model + +For developers' testing, models exported by YOLOv6 are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:----- | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx) | 66MB | 43.1% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | -| [YOLOv6s_640](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s-640x640.onnx) | 66MB | 43.1% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | -| [YOLOv6t](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6t.onnx) | 58MB | 41.3% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | -| [YOLOv6n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6n.onnx) | 17MB | 35.0% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx) | 66MB | 43.1% | This model file is sourced from [YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6s_640](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s-640x640.onnx) | 66MB | 43.1% | This model file is sourced from [YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6t](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6t.onnx) | 58MB | 41.3% | This model file is sourced from [YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6n.onnx) | 17MB | 35.0% | This model file is sourced from [YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | + -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployement](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOv6 0.1.0版本](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) 编写 +- Document and code are based on [YOLOv6 0.1.0 version](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) diff --git a/examples/vision/detection/yolov6/README_CN.md b/examples/vision/detection/yolov6/README_CN.md new file mode 100644 index 0000000000..6324969196 --- /dev/null +++ b/examples/vision/detection/yolov6/README_CN.md @@ -0,0 +1,31 @@ +[English](README.md) | 简体中文 +# YOLOv6准备部署模型 + + +- YOLOv6 部署实现来自[YOLOv6](https://github.com/meituan/YOLOv6/releases/tag/0.1.0),和[基于coco的预训练模型](https://github.com/meituan/YOLOv6/releases/tag/0.1.0)。 + + - (1)[官方库](https://github.com/meituan/YOLOv6/releases/tag/0.1.0)提供的*.onnx可直接进行部署; + - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + + + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv6导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx) | 66MB | 43.1% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6s_640](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s-640x640.onnx) | 66MB | 43.1% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6t](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6t.onnx) | 58MB | 41.3% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | +| [YOLOv6n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6n.onnx) | 17MB | 35.0% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOv6 0.1.0版本](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) 编写 diff --git a/examples/vision/detection/yolov6/cpp/README.md b/examples/vision/detection/yolov6/cpp/README.md index eceb5bc46f..75633dfead 100755 --- a/examples/vision/detection/yolov6/cpp/README.md +++ b/examples/vision/detection/yolov6/cpp/README.md @@ -1,66 +1,67 @@ -# YOLOv6 C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv6 C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv6在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv6 on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载Paddle模型文件和测试图片 +# Download Paddle model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_infer.tar tar -xf yolov6s_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_paddle_demo yolov6s_infer 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_paddle_demo yolov6s_infer 000000014439.jpg 1 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_paddle_demo yolov6s_infer 000000014439.jpg 2 -# 华为昇腾推理 +# HUAWEI Ascend inference ./infer_paddle_demo yolov6s_infer 000000014439.jpg 3 ``` -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) +If you use HUAWEI Ascend NPU deployment, refer to the following document to initialize deployment environment: +- [How to use HUAWEI Ascend NPU deployment](../../../../../docs/cn/faq/use_sdk_on_ascend.md) -如果想要验证ONNX模型的推理,可以参考如下命令: +If you want to verify the inference of ONNX models, refer to the following commands: ```bash -#下载官方转换好的YOLOv6 ONNX模型文件和测试图片 +# Download the official converted YOLOv6 ONNX model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo yolov6s.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov6s.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolov6s.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOv6 C++接口 +## YOLOv6 C++ Interface -### YOLOv6类 +### YOLOv6 Class ```c++ fastdeploy::vision::detection::YOLOv6( @@ -70,16 +71,16 @@ fastdeploy::vision::detection::YOLOv6( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv6模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv6 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv6::Predict(cv::Mat* im, DetectionResult* result, @@ -87,26 +88,26 @@ YOLOv6模型加载和初始化,其中model_file为导出的ONNX模型格式。 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `is_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov6/cpp/README_CN.md b/examples/vision/detection/yolov6/cpp/README_CN.md new file mode 100644 index 0000000000..901977676a --- /dev/null +++ b/examples/vision/detection/yolov6/cpp/README_CN.md @@ -0,0 +1,113 @@ +[English](README.md) | 简体中文 +# YOLOv6 C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv6在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载Paddle模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_infer.tar +tar -xf yolov6s_infer.tar +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +./infer_paddle_demo yolov6s_infer 000000014439.jpg 0 +# GPU推理 +./infer_paddle_demo yolov6s_infer 000000014439.jpg 1 +# 昆仑芯XPU推理 +./infer_paddle_demo yolov6s_infer 000000014439.jpg 2 +# 华为昇腾推理 +./infer_paddle_demo yolov6s_infer 000000014439.jpg 3 +``` + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + + +如果想要验证ONNX模型的推理,可以参考如下命令: +```bash +#下载官方转换好的YOLOv6 ONNX模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +./infer_demo yolov6s.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolov6s.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov6s.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv6 C++接口 + +### YOLOv6类 + +```c++ +fastdeploy::vision::detection::YOLOv6( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv6模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv6::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov6/python/README.md b/examples/vision/detection/yolov6/python/README.md index 37a06fd5ce..82d6ce4abd 100755 --- a/examples/vision/detection/yolov6/python/README.md +++ b/examples/vision/detection/yolov6/python/README.md @@ -1,14 +1,15 @@ -# YOLOv6 Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv6 Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeployEnvironment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv6在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv6 on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolov6/python/ @@ -16,82 +17,80 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_infer.tar tar -xf yolov6s_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device gpu -# 昆仑芯XPU推理 +# KunlunXin XPU inference python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device kunlunxin -# 华为昇腾推理 -python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device ascend ``` -如果想要验证ONNX模型的推理,可以参考如下命令: +If you want to verify the inference of ONNX models, refer to the following command: ```bash -#下载YOLOv6模型文件和测试图片 +# Download YOLOv6 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model yolov6s.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolov6s.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolov6s.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOv6 Python接口 +## YOLOv6 Python Interface ```python fastdeploy.vision.detection.YOLOv6(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv6模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv6 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv6.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`is_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `is_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOv6 模型介绍](..) -- [YOLOv6 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv6 Model Description](..) +- [YOLOv6 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov6/python/README_CN.md b/examples/vision/detection/yolov6/python/README_CN.md new file mode 100644 index 0000000000..0f9f91b625 --- /dev/null +++ b/examples/vision/detection/yolov6/python/README_CN.md @@ -0,0 +1,98 @@ +[English](README.md) | 简体中文 +# YOLOv6 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv6在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/yolov6/python/ + +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_infer.tar +tar -xf yolov6s_infer.tar +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device cpu +# GPU推理 +python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device gpu +# 昆仑芯XPU推理 +python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device kunlunxin +# 华为昇腾推理 +python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device ascend +``` +如果想要验证ONNX模型的推理,可以参考如下命令: +```bash +#下载YOLOv6模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model yolov6s.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model yolov6s.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov6s.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv6 Python接口 + +```python +fastdeploy.vision.detection.YOLOv6(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv6模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv6.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`is_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOv6 模型介绍](..) +- [YOLOv6 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov6/quantize/README.md b/examples/vision/detection/yolov6/quantize/README.md index 57c71cedbf..ce2bbe823e 100755 --- a/examples/vision/detection/yolov6/quantize/README.md +++ b/examples/vision/detection/yolov6/quantize/README.md @@ -1,44 +1,30 @@ -# YOLOv6量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. - -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) -## 下载量化完成的YOLOv6s模型 -用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) - -Benchmark表格说明: -- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. -- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. -- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. -- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 -- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 -- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. -- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. -- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. - -#### Runtime Benchmark -| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | TensorRT | GPU | 9.47 | 3.23 | 4.09 |2.81 | 3.37 | 42.5 | 40.7|量化蒸馏训练 | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle-TensorRT | GPU | 9.31 | None| 4.17 | 2.95 | 3.16 | 42.5 | 40.7|量化蒸馏训练 | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | ONNX Runtime | CPU | 334.65 | 126.38 | None | None| 2.65 |42.5| 36.8|量化蒸馏训练 | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle Inference | CPU | 352.87 | 123.12 |None | None| 2.87 |42.5| 40.8|量化蒸馏训练 | - - -#### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | TensorRT | GPU | 15.66 | 11.30 | 10.25 |9.59 | 1.63 | 42.5 | 40.7|量化蒸馏训练 | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle-TensorRT | GPU | 15.03 | None| 11.36 | 9.32 | 1.61 | 42.5 | 40.7|量化蒸馏训练 | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | ONNX Runtime | CPU | 348.21 | 126.38 | None | None| 2.82 |42.5| 36.8|量化蒸馏训练 | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle Inference | CPU | 352.87 | 121.64 |None | None| 3.04 |42.5| 40.8|量化蒸馏训练 | - - - - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) +English | [简体中文](README_CN.md) +# YOLOv6 Quantized Model Deployment + +FastDeploy supports the deployment of quantized models and provides a one-click model quantization tool. +Users can use the one-click model quantization tool to quantize and deploy the models themselves or download the quantized models provided by FastDeploy directly for deployment. + +## FastDeploy One-Click Model Quantization Tool + +FastDeploy provides a one-click quantization tool that allows users to quantize a model simply with a configuration file. +For detailed tutorial, please refer to : [One-Click Model Quantization Tool](../../../../../tools/common_tools/auto_compression/) + +## Download Quantized YOLOv6s Model + +Users can also directly download the quantized models in the table below for deployment. + +| Model | Inference Backend | Hardware | FP32  Inference Time Delay | INT8 Inference Time Delay | Acceleration ratio | FP32 mAP | INT8 mAP | Method | +| ----------------------------------------------------------------------- | ----------------- | -------- | -------------------------- | ------------------------- | ------------------ | -------- | -------- | ------------------------------- | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_quant.tar) | TensorRT | GPU | 8.60 | 5.16 | 1.67 | 42.5 | 40.6 | Quantized distillation training | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_quant.tar) | Paddle Inference | CPU | 356.62 | 125.72 | 2.84 | 42.5 | 41.2 | Quantized distillation training | + +The data in the above table shows the end-to-end inference performance of FastDeploy deployment before and after model quantization. + +- The test images are from COCO val2017. +- The inference time delay is the inference latency on different Runtimes in milliseconds. +- CPU is Intel(R) Xeon(R) Gold 6271C, GPU is Tesla T4, TensorRT version 8.4.15, and the fixed CPU thread is 1 for all tests. + +## More Detailed Tutorials + +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov6/quantize/README_CN.md b/examples/vision/detection/yolov6/quantize/README_CN.md new file mode 100755 index 0000000000..d0b57d82d5 --- /dev/null +++ b/examples/vision/detection/yolov6/quantize/README_CN.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 +# YOLOv6量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. + +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) +## 下载量化完成的YOLOv6s模型 +用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) + +Benchmark表格说明: +- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. +- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. +- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. +- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 +- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 +- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. +- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. +- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. + +#### Runtime Benchmark +| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | TensorRT | GPU | 9.47 | 3.23 | 4.09 |2.81 | 3.37 | 42.5 | 40.7|量化蒸馏训练 | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle-TensorRT | GPU | 9.31 | None| 4.17 | 2.95 | 3.16 | 42.5 | 40.7|量化蒸馏训练 | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | ONNX Runtime | CPU | 334.65 | 126.38 | None | None| 2.65 |42.5| 36.8|量化蒸馏训练 | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle Inference | CPU | 352.87 | 123.12 |None | None| 2.87 |42.5| 40.8|量化蒸馏训练 | + + +#### 端到端 Benchmark +| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | TensorRT | GPU | 15.66 | 11.30 | 10.25 |9.59 | 1.63 | 42.5 | 40.7|量化蒸馏训练 | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle-TensorRT | GPU | 15.03 | None| 11.36 | 9.32 | 1.61 | 42.5 | 40.7|量化蒸馏训练 | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | ONNX Runtime | CPU | 348.21 | 126.38 | None | None| 2.82 |42.5| 36.8|量化蒸馏训练 | +| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_ptq_model.tar) | Paddle Inference | CPU | 352.87 | 121.64 |None | None| 3.04 |42.5| 40.8|量化蒸馏训练 | + + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/detection/yolov6/quantize/README_EN.md b/examples/vision/detection/yolov6/quantize/README_EN.md deleted file mode 100755 index 7a13ef7d0e..0000000000 --- a/examples/vision/detection/yolov6/quantize/README_EN.md +++ /dev/null @@ -1,29 +0,0 @@ -# YOLOv6 Quantized Model Deployment - -FastDeploy supports the deployment of quantized models and provides a one-click model quantization tool. -Users can use the one-click model quantization tool to quantize and deploy the models themselves or download the quantized models provided by FastDeploy directly for deployment. - -## FastDeploy One-Click Model Quantization Tool - -FastDeploy provides a one-click quantization tool that allows users to quantize a model simply with a configuration file. -For detailed tutorial, please refer to : [One-Click Model Quantization Tool](../../../../../tools/common_tools/auto_compression/) - -## Download Quantized YOLOv6s Model - -Users can also directly download the quantized models in the table below for deployment. - -| Model | Inference Backend | Hardware | FP32  Inference Time Delay | INT8 Inference Time Delay | Acceleration ratio | FP32 mAP | INT8 mAP | Method | -| ----------------------------------------------------------------------- | ----------------- | -------- | -------------------------- | ------------------------- | ------------------ | -------- | -------- | ------------------------------- | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_quant.tar) | TensorRT | GPU | 8.60 | 5.16 | 1.67 | 42.5 | 40.6 | Quantized distillation training | -| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_quant.tar) | Paddle Inference | CPU | 356.62 | 125.72 | 2.84 | 42.5 | 41.2 | Quantized distillation training | - -The data in the above table shows the end-to-end inference performance of FastDeploy deployment before and after model quantization. - -- The test images are from COCO val2017. -- The inference time delay is the inference latency on different Runtimes in milliseconds. -- CPU is Intel(R) Xeon(R) Gold 6271C, GPU is Tesla T4, TensorRT version 8.4.15, and the fixed CPU thread is 1 for all tests. - -## More Detailed Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov7/README.md b/examples/vision/detection/yolov7/README.md index d07350fbc5..7a89007a76 100644 --- a/examples/vision/detection/yolov7/README.md +++ b/examples/vision/detection/yolov7/README.md @@ -1,48 +1,43 @@ -简体中文 | [English](README_EN.md) -# YOLOv7准备部署模型 +English | [简体中文](README_CN.md) -- YOLOv7部署实现来自[YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)分支代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)。 +# YOLOv7 Prepare the model for Deployment - - (1)[官方库](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;*.trt和*.pose模型不支持部署; - - (2)自己数据训练的YOLOv7模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 +- YOLOv7 deployment is based on [YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1) branching code, and [COCO Pre-Trained Models](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1). + - (1)The *.pt provided by the [Official Library](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1) can be deployed after the [export ONNX model](#export ONNX model) operation; *.trt and *.pose models do not support deployment. + - (2)As for YOLOv7 model trained on customized data, please follow the operations guidelines in [Export ONNX model](#Export-ONNX-Model) and then refer to [Detailed Deployment Tutorials](#Detailed-Deployment-Tutorials) to complete the deployment. - - -## 导出ONNX模型 +## Export ONNX Model ```bash -# 下载yolov7模型文件 +# Download yolov7 model file wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt -# 导出onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码) +# Export onnx file (Tips: in accordance with YOLOv7 release v0.1 code) python models/export.py --grid --dynamic --weights PATH/TO/yolov7.pt -# 如果您的代码版本中有支持NMS的ONNX文件导出,请使用如下命令导出ONNX文件,并且参考`yolov7end2end_ort` 或 `yolov7end2end_trt`示例使用 +# If your code supports exporting ONNX files with NMS, please use the following command to export ONNX files, then refer to the example of `yolov7end2end_ort` or `yolov7end2end_ort` python models/export.py --grid --dynamic --end2end --weights PATH/TO/yolov7.pt - - ``` -## 下载预训练ONNX模型 - -为了方便开发者的测试,下面提供了YOLOv7导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | -|:---------------------------------------------------------------- |:----- |:----- | :----- | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +## Download the pre-trained ONNX model +To facilitate testing for developers, we provide below the models exported by YOLOv7, which developers can download and use directly. (The accuracy of the models in the table is sourced from the official library) -## 详细部署文档 +| Model | Size | Accuracy | Note | +| ------------------------------------------------------------------------ | ----- | -------- | -------- | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | +| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | +| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | +| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | +| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | +| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | -- [Python部署](python) -- [C++部署](cpp) +## Detailed Deployment Tutorials +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Version -- 本版本文档和代码基于[YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) 编写 +- This tutorial and related code are written based on [YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) diff --git a/examples/vision/detection/yolov7/README_CN.md b/examples/vision/detection/yolov7/README_CN.md new file mode 100644 index 0000000000..3d7a911f4d --- /dev/null +++ b/examples/vision/detection/yolov7/README_CN.md @@ -0,0 +1,48 @@ +[English](README.md) | 简体中文 +# YOLOv7准备部署模型 + +- YOLOv7部署实现来自[YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)分支代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)。 + + - (1)[官方库](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;*.trt和*.pose模型不支持部署; + - (2)自己数据训练的YOLOv7模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + + + +## 导出ONNX模型 + +```bash +# 下载yolov7模型文件 +wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt + +# 导出onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码) +python models/export.py --grid --dynamic --weights PATH/TO/yolov7.pt + +# 如果您的代码版本中有支持NMS的ONNX文件导出,请使用如下命令导出ONNX文件,并且参考`yolov7end2end_ort` 或 `yolov7end2end_trt`示例使用 +python models/export.py --grid --dynamic --end2end --weights PATH/TO/yolov7.pt + + +``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv7导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :----- | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) 编写 diff --git a/examples/vision/detection/yolov7/README_EN.md b/examples/vision/detection/yolov7/README_EN.md deleted file mode 100644 index 04001beb7b..0000000000 --- a/examples/vision/detection/yolov7/README_EN.md +++ /dev/null @@ -1,43 +0,0 @@ -[简体中文](README.md) | English - -# YOLOv7 Prepare the model for Deployment - -- YOLOv7 deployment is based on [YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1) branching code, and [COCO Pre-Trained Models](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1). - - - (1)The *.pt provided by the [Official Library](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1) can be deployed after the [export ONNX model](#export ONNX model) operation; *.trt and *.pose models do not support deployment. - - (2)As for YOLOv7 model trained on customized data, please follow the operations guidelines in [Export ONNX model](#Export-ONNX-Model) and then refer to [Detailed Deployment Tutorials](#Detailed-Deployment-Tutorials) to complete the deployment. - -## Export ONNX Model - -```bash -# Download yolov7 model file -wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt - -# Export onnx file (Tips: in accordance with YOLOv7 release v0.1 code) -python models/export.py --grid --dynamic --weights PATH/TO/yolov7.pt - -# If your code supports exporting ONNX files with NMS, please use the following command to export ONNX files, then refer to the example of `yolov7end2end_ort` or `yolov7end2end_ort` -python models/export.py --grid --dynamic --end2end --weights PATH/TO/yolov7.pt -``` - -## Download the pre-trained ONNX model - -To facilitate testing for developers, we provide below the models exported by YOLOv7, which developers can download and use directly. (The accuracy of the models in the table is sourced from the official library) - -| Model | Size | Accuracy | Note | -| ------------------------------------------------------------------------ | ----- | -------- | -------- | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | -| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | -| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | -| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | -| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | -| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License | - -## Detailed Deployment Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) - -## Version - -- This tutorial and related code are written based on [YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) diff --git a/examples/vision/detection/yolov7/cpp/README.md b/examples/vision/detection/yolov7/cpp/README.md index 5308f7ddbe..ab5e086074 100755 --- a/examples/vision/detection/yolov7/cpp/README.md +++ b/examples/vision/detection/yolov7/cpp/README.md @@ -1,18 +1,19 @@ -# YOLOv7 C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv7 C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv7在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv7 on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x @@ -22,44 +23,38 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_infer.tar tar -xf yolov7_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_paddle_model_demo yolov7_infer 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_paddle_model_demo yolov7_infer 000000014439.jpg 1 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_paddle_model_demo yolov7_infer 000000014439.jpg 2 -# 华为昇腾推理 -./infer_paddle_model_demo yolov7_infer 000000014439.jpg 3 ``` - -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) - -如果想要验证ONNX模型的推理,可以参考如下命令: +If you want to verify the inference of ONNX models, refer to the following command: ```bash -#下载官方转换好的yolov7 ONNX模型文件和测试图片 +# Download the official converted yolov7 ONNX model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo yolov7.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov7.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolov7.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOv7 C++接口 +## YOLOv7 C++ Interface -### YOLOv7类 +### YOLOv7 Class ```c++ fastdeploy::vision::detection::YOLOv7( @@ -69,16 +64,16 @@ fastdeploy::vision::detection::YOLOv7( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv7 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv7::Predict(cv::Mat* im, DetectionResult* result, @@ -86,26 +81,26 @@ YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7/cpp/README_CN.md b/examples/vision/detection/yolov7/cpp/README_CN.md new file mode 100644 index 0000000000..5de2c9c2cc --- /dev/null +++ b/examples/vision/detection/yolov7/cpp/README_CN.md @@ -0,0 +1,112 @@ +[English](README.md) | 简体中文 +# YOLOv7 C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv7在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_infer.tar +tar -xf yolov7_infer.tar +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +./infer_paddle_model_demo yolov7_infer 000000014439.jpg 0 +# GPU推理 +./infer_paddle_model_demo yolov7_infer 000000014439.jpg 1 +# 昆仑芯XPU推理 +./infer_paddle_model_demo yolov7_infer 000000014439.jpg 2 +# 华为昇腾推理 +./infer_paddle_model_demo yolov7_infer 000000014439.jpg 3 +``` + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +如果想要验证ONNX模型的推理,可以参考如下命令: +```bash +#下载官方转换好的yolov7 ONNX模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo yolov7.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolov7.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov7.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv7 C++接口 + +### YOLOv7类 + +```c++ +fastdeploy::vision::detection::YOLOv7( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv7::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7/python/README.md b/examples/vision/detection/yolov7/python/README.md index a925e78efa..2df6126ede 100755 --- a/examples/vision/detection/yolov7/python/README.md +++ b/examples/vision/detection/yolov7/python/README.md @@ -1,98 +1,99 @@ -简体中文 | [English](README_EN.md) +English | [简体中文](README_CN.md) -# YOLOv7 Python部署示例 -在部署前,需确认以下两个步骤 +# YOLOv7 Python Deployment Demo -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +Two steps before deployment: -本目录下提供`infer.py`快速完成YOLOv7在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. The hardware and software environment meets the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Please refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + + +This doc provides a quick `infer.py` demo of YOLOv7 deployment on CPU/GPU, and accelerated GPU deployment by TensorRT. Run the following command: ```bash -#下载部署示例代码 +# Download sample deployment code git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolov7/python/ - wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_infer.tar tar -xf yolov7_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device cpu -# GPU推理 +# GPU python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device gpu -# 昆仑芯XPU推理 +# KunlunXin XPU python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device kunlunxin -# 华为昇腾推理 +# Huawei Ascend python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device ascend ``` -如果想要验证ONNX模型的推理,可以参考如下命令: +If you want to test ONNX model: ```bash -#下载yolov7模型文件和测试图片 +# Download yolov7 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU Inference python infer.py --model yolov7.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU python infer.py --model yolov7.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 +# Infer with TensorRT on GPU python infer.py --model yolov7.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualisation of the results is as follows. -## YOLOv7 Python接口 +## YOLOv7 Python Interface ```python fastdeploy.vision.detection.YOLOv7(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv7 model loading and initialisation, with model_file being the exported ONNX model format. -**参数** +**Parameters** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. If the model format is ONNX, the parameter can be filled with an empty string. +> * **runtime_option**(RuntimeOption): Back-end inference configuration. The default is None, i.e. the default is applied +> * **model_format**(ModelFormat): Model format. The default is ONNX format -### predict函数 +### Predict Function > ```python > YOLOv7.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface with direct output of detection results from the image input. > -> **参数** +> **Parameters** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input image. Images need to be in HWC or BGR format +> > * **conf_threshold**(float): Filter threshold for detection box confidence +> > * **nms_iou_threshold**(float): iou thresholds during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return to`fastdeploy.vision.DetectionResult`Struct. For more details, please refer to [Vision Model Results](../../../../../docs/api/vision_results/) -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variables -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +#### Pre-processing parameters +Users can modify the following pre-processing parameters for their needs. This will affect the final reasoning and deployment results +> > * **size**(list[int]): This parameter modifies the 'resize' during preprocessing and contains two integer elements representing [width, height]. The default value is [640, 640]. +> > * **padding_value**(list[float]): This parameter modifies the value of the padding when resizing the image. It contains three floating-point elements, representing the values of the three channels. The default value is [114, 114, 114]. +> > * **is_no_pad**(bool): This parameter determines whether the image is resized by padding, `is_no_pad=ture` means no padding is used. The default value is `is_no_pad=false`. +> > * **is_mini_pad**(bool): This parameter allows the width and height of the image after resize to be the closest value to the `size` member variable, which the pixel size of the padding can be divided by the `stride` member variable. The default value is `is_mini_pad=false`. +> > * **stride**(int): Used with`stris_mini_pad` member value. The default value is`stride=32` -## 其它文档 +## Related files -- [YOLOv7 模型介绍](..) -- [YOLOv7 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv7 Model Introduction](..) +- [YOLOv7 C++ Deployment](../cpp) +- [Vision Model Results](../../../../../docs/api/vision_results/) +- [how to change inference backend](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7/python/README_CN.md b/examples/vision/detection/yolov7/python/README_CN.md new file mode 100755 index 0000000000..bb6d56e777 --- /dev/null +++ b/examples/vision/detection/yolov7/python/README_CN.md @@ -0,0 +1,98 @@ +[English](README.md) | 简体中文 + +# YOLOv7 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv7在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/yolov7/python/ + +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_infer.tar +tar -xf yolov7_infer.tar +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device cpu +# GPU推理 +python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device gpu +# 昆仑芯XPU推理 +python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device kunlunxin +# 华为昇腾推理 +python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device ascend +``` +如果想要验证ONNX模型的推理,可以参考如下命令: +```bash +#下载yolov7模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model yolov7.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model yolov7.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov7.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv7 Python接口 + +```python +fastdeploy.vision.detection.YOLOv7(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv7.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOv7 模型介绍](..) +- [YOLOv7 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7/python/README_EN.md b/examples/vision/detection/yolov7/python/README_EN.md deleted file mode 100755 index ee7b486b3c..0000000000 --- a/examples/vision/detection/yolov7/python/README_EN.md +++ /dev/null @@ -1,98 +0,0 @@ -English | [简体中文](README.md) - -# YOLOv7 Python Deployment Demo - -Two steps before deployment: - -- 1. The hardware and software environment meets the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Please refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - - -This doc provides a quick `infer.py` demo of YOLOv7 deployment on CPU/GPU, and accelerated GPU deployment by TensorRT. Run the following command: - -```bash -# Download sample deployment code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/detection/yolov7/python/ -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_infer.tar -tar -xf yolov7_infer.tar -wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg - -# CPU -python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device cpu -# GPU -python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device gpu -# KunlunXin XPU -python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device kunlunxin -# Huawei Ascend -python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device ascend -``` -If you want to test ONNX model: -```bash -# Download yolov7 model files and test images -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx -wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg - -# CPU Inference -python infer.py --model yolov7.onnx --image 000000014439.jpg --device cpu -# GPU -python infer.py --model yolov7.onnx --image 000000014439.jpg --device gpu -# Infer with TensorRT on GPU -python infer.py --model yolov7.onnx --image 000000014439.jpg --device gpu --use_trt True -``` - -The visualisation of the results is as follows. - - - -## YOLOv7 Python Interface - -```python -fastdeploy.vision.detection.YOLOv7(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) -``` - -YOLOv7 model loading and initialisation, with model_file being the exported ONNX model format. - -**Parameters** - -> * **model_file**(str): Model file path -> * **params_file**(str): Parameter file path. If the model format is ONNX, the parameter can be filled with an empty string. -> * **runtime_option**(RuntimeOption): Back-end inference configuration. The default is None, i.e. the default is applied -> * **model_format**(ModelFormat): Model format. The default is ONNX format - -### Predict Function - -> ```python -> YOLOv7.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) -> ``` -> -> Model prediction interface with direct output of detection results from the image input. -> -> **Parameters** -> -> > * **image_data**(np.ndarray): Input image. Images need to be in HWC or BGR format -> > * **conf_threshold**(float): Filter threshold for detection box confidence -> > * **nms_iou_threshold**(float): iou thresholds during NMS processing - -> **Return** -> -> > Return to`fastdeploy.vision.DetectionResult`Struct. For more details, please refer to [Vision Model Results](../../../../../docs/api/vision_results/) - -### Class Member Variables - -#### Pre-processing parameters - -Users can modify the following pre-processing parameters for their needs. This will affect the final reasoning and deployment results - -> > * **size**(list[int]): This parameter modifies the 'resize' during preprocessing and contains two integer elements representing [width, height]. The default value is [640, 640]. -> > * **padding_value**(list[float]): This parameter modifies the value of the padding when resizing the image. It contains three floating-point elements, representing the values of the three channels. The default value is [114, 114, 114]. -> > * **is_no_pad**(bool): This parameter determines whether the image is resized by padding, `is_no_pad=ture` means no padding is used. The default value is `is_no_pad=false`. -> > * **is_mini_pad**(bool): This parameter allows the width and height of the image after resize to be the closest value to the `size` member variable, which the pixel size of the padding can be divided by the `stride` member variable. The default value is `is_mini_pad=false`. -> > * **stride**(int): Used with`stris_mini_pad` member value. The default value is`stride=32` - -## Related files - -- [YOLOv7 Model Introduction](..) -- [YOLOv7 C++ Deployment](../cpp) -- [Vision Model Results](../../../../../docs/api/vision_results/) -- [how to change inference backend](../../../../../docs/en/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7/quantize/README.md b/examples/vision/detection/yolov7/quantize/README.md index e1bbc2f699..9034a4b232 100755 --- a/examples/vision/detection/yolov7/quantize/README.md +++ b/examples/vision/detection/yolov7/quantize/README.md @@ -1,42 +1,30 @@ -# YOLOv7量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. - -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) - -## 下载量化完成的YOLOv7模型 -用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) - - -Benchmark表格说明: -- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. -- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. -- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. -- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 -- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 -- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. -- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. -- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. - -#### Runtime Benchmark -| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | TensorRT | GPU | 27.47 | 6.52 | 6.74| 5.19| 5.29 | 51.1| 50.4|量化蒸馏训练 | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle-TensorRT | GPU | 27.87|None|6.91|5.86 | 4.76 | 51.1| 50.4|量化蒸馏训练 | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | ONNX Runtime | CPU | 996.65 | 467.15 |None|None | 2.13 | 51.1 | 43.3|量化蒸馏训练 | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle Inference | CPU | 995.85 | 477.93|None|None | 2.08 |51.1 | 46.2|量化蒸馏训练 | - -#### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | TensorRT | GPU | 36.47 | 18.81 | 20.33| 17.58| 2.07 | 51.1| 50.4|量化蒸馏训练 | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle-TensorRT | GPU | 37.06|None|20.26|17.53 | 2.11 | 51.1| 50.4|量化蒸馏训练 | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | ONNX Runtime | CPU | 988.85 | 478.08 |None|None | 2.07 | 51.1 | 43.3|量化蒸馏训练 | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle Inference | CPU | 1031.73 | 500.12|None|None | 2.06 |51.1 | 46.2|量化蒸馏训练 | - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) +English | [简体中文](README_CN.md) +# YOLOv7 Quantized Model Deployment + +FastDeploy supports the deployment of quantized models and provides a one-click model quantization tool. +Users can use the one-click model quantization tool to quantize and deploy the models themselves or download the quantized models provided by FastDeploy directly for deployment. + +## FastDeploy One-Click Model Quantization Tool + +FastDeploy provides a one-click quantization tool that allows users to quantize a model simply with a configuration file. +For detailed tutorial, please refer to : [One-Click Model Quantization Tool](../../../../../tools/common_tools/auto_compression/) + +## Download Quantized YOLOv7 Model + +Users can also directly download the quantized models in the table below for deployment. + +| Model | Inference Backend | Hardware | FP32 Inference Time Delay | FP32 Inference Time Delay | Acceleration ratio | FP32 mAP | INT8 mAP | Method | +| --------------------------------------------------------------------- | ----------------- | -------- | ------------------------- | ------------------------- | ------------------ | -------- | -------- | ------------------------------- | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | TensorRT | GPU | 24.57 | 9.40 | 2.61 | 51.1 | 50.8 | Quantized distillation training | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle Inference | CPU | 1022.55 | 490.87 | 2.08 | 51.1 | 46.3 | Quantized distillation training | + +The data in the above table shows the end-to-end inference performance of FastDeploy deployment before and after model quantization. + +- The test images are from COCO val2017. +- The inference time delay is the inference latency on different Runtimes in milliseconds. +- CPU is Intel(R) Xeon(R) Gold 6271C, GPU is Tesla T4, TensorRT version 8.4.15, and the fixed CPU thread is 1 for all tests. + +## More Detailed Tutorials + +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov7/quantize/README_CN.md b/examples/vision/detection/yolov7/quantize/README_CN.md new file mode 100755 index 0000000000..6d5482b5a5 --- /dev/null +++ b/examples/vision/detection/yolov7/quantize/README_CN.md @@ -0,0 +1,43 @@ +[English](README.md) | 简体中文 +# YOLOv7量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. + +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) + +## 下载量化完成的YOLOv7模型 +用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) + + +Benchmark表格说明: +- Runtime时延为模型在各种Runtime上的推理时延,包含CPU->GPU数据拷贝,GPU推理,GPU->CPU数据拷贝时间. 不包含模型各自的前后处理时间. +- 端到端时延为模型在实际推理场景中的时延, 包含模型的前后处理. +- 所测时延均为推理1000次后求得的平均值, 单位是毫秒. +- INT8 + FP16 为在推理INT8量化模型的同时, 给Runtime 开启FP16推理选项 +- INT8 + FP16 + PM, 为在推理INT8量化模型和开启FP16的同时, 开启使用Pinned Memory的选项,可加速GPU->CPU数据拷贝的速度 +- 最大加速比, 为FP32时延除以INT8推理的最快时延,得到最大加速比. +- 策略为量化蒸馏训练时, 采用少量无标签数据集训练得到量化模型, 并在全量验证集上验证精度, INT8精度并不代表最高的INT8精度. +- CPU为Intel(R) Xeon(R) Gold 6271C, 所有测试中固定CPU线程数为1. GPU为Tesla T4, TensorRT版本8.4.15. + +#### Runtime Benchmark +| 模型 |推理后端 |部署硬件 | FP32 Runtime时延 | INT8 Runtime时延 | INT8 + FP16 Runtime时延 | INT8+FP16+PM Runtime时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | TensorRT | GPU | 27.47 | 6.52 | 6.74| 5.19| 5.29 | 51.1| 50.4|量化蒸馏训练 | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle-TensorRT | GPU | 27.87|None|6.91|5.86 | 4.76 | 51.1| 50.4|量化蒸馏训练 | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | ONNX Runtime | CPU | 996.65 | 467.15 |None|None | 2.13 | 51.1 | 43.3|量化蒸馏训练 | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle Inference | CPU | 995.85 | 477.93|None|None | 2.08 |51.1 | 46.2|量化蒸馏训练 | + +#### 端到端 Benchmark +| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mAP | INT8 mAP | 量化方式 | +| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | TensorRT | GPU | 36.47 | 18.81 | 20.33| 17.58| 2.07 | 51.1| 50.4|量化蒸馏训练 | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle-TensorRT | GPU | 37.06|None|20.26|17.53 | 2.11 | 51.1| 50.4|量化蒸馏训练 | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | ONNX Runtime | CPU | 988.85 | 478.08 |None|None | 2.07 | 51.1 | 43.3|量化蒸馏训练 | +| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle Inference | CPU | 1031.73 | 500.12|None|None | 2.06 |51.1 | 46.2|量化蒸馏训练 | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/detection/yolov7/quantize/README_EN.md b/examples/vision/detection/yolov7/quantize/README_EN.md deleted file mode 100755 index 5a1add2e6c..0000000000 --- a/examples/vision/detection/yolov7/quantize/README_EN.md +++ /dev/null @@ -1,29 +0,0 @@ -# YOLOv7 Quantized Model Deployment - -FastDeploy supports the deployment of quantized models and provides a one-click model quantization tool. -Users can use the one-click model quantization tool to quantize and deploy the models themselves or download the quantized models provided by FastDeploy directly for deployment. - -## FastDeploy One-Click Model Quantization Tool - -FastDeploy provides a one-click quantization tool that allows users to quantize a model simply with a configuration file. -For detailed tutorial, please refer to : [One-Click Model Quantization Tool](../../../../../tools/common_tools/auto_compression/) - -## Download Quantized YOLOv7 Model - -Users can also directly download the quantized models in the table below for deployment. - -| Model | Inference Backend | Hardware | FP32 Inference Time Delay | FP32 Inference Time Delay | Acceleration ratio | FP32 mAP | INT8 mAP | Method | -| --------------------------------------------------------------------- | ----------------- | -------- | ------------------------- | ------------------------- | ------------------ | -------- | -------- | ------------------------------- | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | TensorRT | GPU | 24.57 | 9.40 | 2.61 | 51.1 | 50.8 | Quantized distillation training | -| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_quant.tar) | Paddle Inference | CPU | 1022.55 | 490.87 | 2.08 | 51.1 | 46.3 | Quantized distillation training | - -The data in the above table shows the end-to-end inference performance of FastDeploy deployment before and after model quantization. - -- The test images are from COCO val2017. -- The inference time delay is the inference latency on different Runtimes in milliseconds. -- CPU is Intel(R) Xeon(R) Gold 6271C, GPU is Tesla T4, TensorRT version 8.4.15, and the fixed CPU thread is 1 for all tests. - -## More Detailed Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) diff --git a/examples/vision/detection/yolov7end2end_ort/README.md b/examples/vision/detection/yolov7end2end_ort/README.md index 8b733bd25f..3b393b7ff7 100644 --- a/examples/vision/detection/yolov7end2end_ort/README.md +++ b/examples/vision/detection/yolov7end2end_ort/README.md @@ -1,41 +1,43 @@ -# YOLOv7End2EndORT 准备部署模型 +English | [简体中文](README_CN.md) -YOLOv7End2EndORT 部署实现来自[YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)分支代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)。注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 +# YOLOv7End2EndORT Ready-to-deploy Model - - (1)[官方库](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;*.trt和*.pose模型不支持部署; - - (2)自己数据训练的YOLOv7模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 +The YOLOv7End2EndORT deployment is based on [YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)branch code and [Pre-trained Model Based on COCO](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1). Attention: YOLOv7End2EndORT is designed for the inference of exported End2End models in the [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) version in YOLOv7. YOLOv7 class is for the inference of models without nms. YOLOv7End2EndTRT is for the inference of End2End models in the [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) version. + - (1)*.pt provided by [Official Repository](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1) should [Export the ONNX Model](#导出ONNX模型) to complete the employment. The deployment of *.trt and *.pose models is not supported. + - (2)The YOLOv7 model trained by personal data should [Export the ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B). Refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 导出ONNX模型 + +## Export the ONNX Model ```bash -# 下载yolov7模型文件 +# Download yolov7 model files wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt -# 导出带ORT_NMS的onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码) +# Export files in onnx format with ORT_NMS (Tips: Corresponding to the code of YOLOv7 release v0.1) python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640 -# 导出其他模型的命令类似 将yolov7.pt替换成 yolov7x.pt yolov7-d6.pt yolov7-w6.pt ... +# The commands for exporting other models are similar Replace yolov7.pt with yolov7x.pt yolov7-d6.pt yolov7-w6.pt ... ``` -## 下载预训练ONNX模型 +## Download the Pre-trained ONNX Model -为了方便开发者的测试,下面提供了YOLOv7End2EndORT导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +For developers' testing, models exported by YOLOv7End2EndORT are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:----- | -| [yolov7-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7x-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-ort-nms.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-w6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-ort-nms.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-e6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-ort-nms.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-d6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-ort-nms.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-e6e-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-ort-nms.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx) | 141MB | 51.4% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7x-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-ort-nms.onnx) | 273MB | 53.1% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-w6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-ort-nms.onnx) | 269MB | 54.9% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-ort-nms.onnx) | 372MB | 56.0% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-d6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-ort-nms.onnx) | 511MB | 56.6% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6e-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-ort-nms.onnx) | 579MB | 56.8% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) 编写 +- Document and code are based on [YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) diff --git a/examples/vision/detection/yolov7end2end_ort/README_CN.md b/examples/vision/detection/yolov7end2end_ort/README_CN.md new file mode 100644 index 0000000000..af0a5dfe7c --- /dev/null +++ b/examples/vision/detection/yolov7end2end_ort/README_CN.md @@ -0,0 +1,42 @@ +[English](README.md) | 简体中文 +# YOLOv7End2EndORT 准备部署模型 + +YOLOv7End2EndORT 部署实现来自[YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)分支代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)。注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 + + - (1)[官方库](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;*.trt和*.pose模型不支持部署; + - (2)自己数据训练的YOLOv7模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + +## 导出ONNX模型 + +```bash +# 下载yolov7模型文件 +wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt + +# 导出带ORT_NMS的onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码) +python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640 +# 导出其他模型的命令类似 将yolov7.pt替换成 yolov7x.pt yolov7-d6.pt yolov7-w6.pt ... +``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv7End2EndORT导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [yolov7-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7x-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-ort-nms.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-w6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-ort-nms.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-ort-nms.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-d6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-ort-nms.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6e-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-ort-nms.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) 编写 diff --git a/examples/vision/detection/yolov7end2end_ort/cpp/README.md b/examples/vision/detection/yolov7end2end_ort/cpp/README.md index b5c18f183e..fc2128a1bf 100644 --- a/examples/vision/detection/yolov7end2end_ort/cpp/README.md +++ b/examples/vision/detection/yolov7end2end_ort/cpp/README.md @@ -1,50 +1,51 @@ -# YOLOv7End2EndORT C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv7End2EndORT C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv7End2EndORT在CPU/GPU部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv7End2EndORT on CPU/GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的yolov7模型文件和测试图片 +# Download the official converted yolov7 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo yolov7-end2end-ort-nms.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov7-end2end-ort-nms.onnx 000000014439.jpg 1 -# TensorRT + GPU 部署 (暂不支持 会回退到 ORT + GPU) +# TensorRT + GPU deployment (Not supported yet. Back to ORT + GPU) ./infer_demo yolov7-end2end-ort-nms.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
image
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 +Attention: YOLOv7End2EndORT is designed for the inference of End2End models with [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) among the YOLOv7 exported models. For models without nms, use YOLOv7 class for inference. For End2End models with [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111), use YOLOv7End2EndTRT for inference. -## YOLOv7End2EndORT C++接口 +## YOLOv7End2EndORT C++ Interface -### YOLOv7End2EndORT 类 +### YOLOv7End2EndORT Class ```c++ fastdeploy::vision::detection::YOLOv7End2EndORT( @@ -54,41 +55,41 @@ fastdeploy::vision::detection::YOLOv7End2EndORT( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv7End2EndORT 模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv7End2EndORT model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict function > ```c++ > YOLOv7End2EndORT::Predict(cv::Mat* im, DetectionResult* result, > float conf_threshold = 0.25) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence. But considering that YOLOv7 End2End models have a score threshold specified during ONNX export, this parameter will be effective when being greater than the specified one. + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default`is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_ort/cpp/README_CN.md b/examples/vision/detection/yolov7end2end_ort/cpp/README_CN.md new file mode 100644 index 0000000000..c801426c90 --- /dev/null +++ b/examples/vision/detection/yolov7end2end_ort/cpp/README_CN.md @@ -0,0 +1,95 @@ +[English](README.md) | 简体中文 +# YOLOv7End2EndORT C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv7End2EndORT在CPU/GPU部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的yolov7模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo yolov7-end2end-ort-nms.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolov7-end2end-ort-nms.onnx 000000014439.jpg 1 +# TensorRT + GPU 部署 (暂不支持 会回退到 ORT + GPU) +./infer_demo yolov7-end2end-ort-nms.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + +
+ image +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 + +## YOLOv7End2EndORT C++接口 + +### YOLOv7End2EndORT 类 + +```c++ +fastdeploy::vision::detection::YOLOv7End2EndORT( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv7End2EndORT 模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv7End2EndORT::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_ort/python/README.md b/examples/vision/detection/yolov7end2end_ort/python/README.md index 3f34e66d3f..09cb20ccd0 100644 --- a/examples/vision/detection/yolov7end2end_ort/python/README.md +++ b/examples/vision/detection/yolov7end2end_ort/python/README.md @@ -1,85 +1,86 @@ -# YOLOv7End2EndORT Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv7End2EndORT Python Deployment Example -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv7End2End在CPU/GPU部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv7End2End on CPU/GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/detection/yolov7end2end_ort/python/ -# 如果预编译的Python wheel包还没有支持该模型,请从develop分支源码编译最新python包进行安装 +# If the precompiled Python wheel package does not support the model, compile the latest python package from the source code of develop branch and install it. -#下载yolov7模型文件和测试图片 +# Download yolov7 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model yolov7-end2end-ort-nms.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolov7-end2end-ort-nms.onnx --image 000000014439.jpg --device gpu -# TensorRT + GPU推理 (暂不支持 会回退到 ORT + GPU) +# TensorRT + GPU inference (Not supported yet. Back to ORT + GPU) python infer.py --model yolov7-end2end-ort-nms.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
image
-注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 +Attention: YOLOv7End2EndORT is designed for the inference of End2End models with [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) among the YOLOv7 exported models. For models without nms, use YOLOv7 class for inference. For End2End models with [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111), use YOLOv7End2EndTRT for inference. -## YOLOv7End2EndORT Python接口 +## YOLOv7End2EndORT Python Interface ```python fastdeploy.vision.detection.YOLOv7End2EndORT(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv7End2EndORT模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv7End2EndORT model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv7End2EndORT.predict(image_data, conf_threshold=0.25) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence. But considering that YOLOv7 End2End models have a score threshold specified during ONNX export, this parameter will be effective when being greater than the specified one. -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOv7End2EndORT 模型介绍](..) -- [YOLOv7End2EndORT C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv7End2EndORT Model Description](..) +- [YOLOv7End2EndORT C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_ort/python/README_CN.md b/examples/vision/detection/yolov7end2end_ort/python/README_CN.md new file mode 100644 index 0000000000..b9887629dd --- /dev/null +++ b/examples/vision/detection/yolov7end2end_ort/python/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# YOLOv7End2EndORT Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv7End2End在CPU/GPU部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/detection/yolov7end2end_ort/python/ +# 如果预编译的Python wheel包还没有支持该模型,请从develop分支源码编译最新python包进行安装 + +#下载yolov7模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model yolov7-end2end-ort-nms.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model yolov7-end2end-ort-nms.onnx --image 000000014439.jpg --device gpu +# TensorRT + GPU推理 (暂不支持 会回退到 ORT + GPU) +python infer.py --model yolov7-end2end-ort-nms.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + +
+ image +
+ +注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 + +## YOLOv7End2EndORT Python接口 + +```python +fastdeploy.vision.detection.YOLOv7End2EndORT(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv7End2EndORT模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv7End2EndORT.predict(image_data, conf_threshold=0.25) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOv7End2EndORT 模型介绍](..) +- [YOLOv7End2EndORT C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_trt/README.md b/examples/vision/detection/yolov7end2end_trt/README.md index 04be6f5687..f05c53bdf1 100644 --- a/examples/vision/detection/yolov7end2end_trt/README.md +++ b/examples/vision/detection/yolov7end2end_trt/README.md @@ -1,43 +1,43 @@ -# YOLOv7End2EndTRT 准备部署模型 +English | [简体中文](README_CN.md) +# YOLOv7End2EndTRT Ready-to-deploy Model -YOLOv7End2EndTRT 部署实现来自[YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)分支代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)。注意,YOLOv7End2EndTRT 是专门用于推理YOLOv7中导出模型带[TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型请使用YOLOv7End2EndORT进行推理。 +The YOLOv7End2EndTRT deployment is based on [YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1) branch code and [Pre-trained Model Baesd on COCO](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1). Attention: YOLOv7End2EndTRT is designed for the inference of exported End2End models in the [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) version in YOLOv7. YOLOv7 class is for the inference of models without nms. YOLOv7End2EndORT is for the inference of End2End models in the [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) version. - - (1)[官方库](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;*.trt和*.pose模型不支持部署; - - (2)自己数据训练的YOLOv7模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)*.pt provided by [Official Repository](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1) should [Export the ONNX Model](#导出ONNX模型) to complete the deployment. The deployment of *.trt and *.pose models is not supported. + - (2)The YOLOv7 model trained by personal data should [Export the ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B). Please refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 导出ONNX模型 +## Export the ONNX Model ```bash -# 下载yolov7模型文件 +# Download yolov7 Model Files wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt -# 导出带TRT_NMS的onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码) +# Export file in onnx format with TRT_NMS (Tips: corresponding to the code of YOLOv7 release v0.1) python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 -# 导出其他模型的命令类似 将yolov7.pt替换成 yolov7x.pt yolov7-d6.pt yolov7-w6.pt ... -# 使用YOLOv7End2EndTRT只需提供onnx文件,不需要额外再转trt文件,推理时自动转换 +# The commands for exporting other models are similar. Replace yolov7.pt with yolov7x.pt yolov7-d6.pt yolov7-w6.pt ... +# Only onnx files are required to employ YOLOv7End2EndTRT. Additional trt files are not required because automatic switching happens during inference. ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Models -为了方便开发者的测试,下面提供了YOLOv7End2EndTRT 导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | 备注 | +For developers' testing, models exported by YOLOv7End2EndTRT are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- |:----- | -| [yolov7-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7x-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-trt-nms.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-w6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-trt-nms.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-e6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-trt-nms.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-d6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-trt-nms.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | -| [yolov7-e6e-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-trt-nms.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx) | 141MB | 51.4% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7x-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-trt-nms.onnx) | 273MB | 53.1% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-w6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-trt-nms.onnx) | 269MB | 54.9% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-trt-nms.onnx) | 372MB | 56.0% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-d6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-trt-nms.onnx) | 511MB | 56.6% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6e-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-trt-nms.onnx) | 579MB | 56.8% | This model file is sourced from [YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +## Detailed Deployment Documents -## 详细部署文档 +- [Python Deployment](python) +- [C++ Deployement](cpp) -- [Python部署](python) -- [C++部署](cpp) +## Release Note -## 版本说明 - -- 本版本文档和代码基于[YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) 编写 +- Document and code are based on [YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) diff --git a/examples/vision/detection/yolov7end2end_trt/README_CN.md b/examples/vision/detection/yolov7end2end_trt/README_CN.md new file mode 100644 index 0000000000..af0a5dfe7c --- /dev/null +++ b/examples/vision/detection/yolov7end2end_trt/README_CN.md @@ -0,0 +1,42 @@ +[English](README.md) | 简体中文 +# YOLOv7End2EndORT 准备部署模型 + +YOLOv7End2EndORT 部署实现来自[YOLOv7](https://github.com/WongKinYiu/yolov7/tree/v0.1)分支代码,和[基于COCO的预训练模型](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)。注意,YOLOv7End2EndORT是专门用于推理YOLOv7中导出模型带[ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型请使用YOLOv7End2EndTRT进行推理。 + + - (1)[官方库](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署;*.trt和*.pose模型不支持部署; + - (2)自己数据训练的YOLOv7模型,按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)操作后,参考[详细部署文档](#详细部署文档)完成部署。 + + +## 导出ONNX模型 + +```bash +# 下载yolov7模型文件 +wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt + +# 导出带ORT_NMS的onnx格式文件 (Tips: 对应 YOLOv7 release v0.1 代码) +python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640 +# 导出其他模型的命令类似 将yolov7.pt替换成 yolov7x.pt yolov7-d6.pt yolov7-w6.pt ... +``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv7End2EndORT导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- |:----- | +| [yolov7-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7x-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-ort-nms.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-w6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-ort-nms.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-ort-nms.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-d6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-ort-nms.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | +| [yolov7-e6e-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-ort-nms.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOv7 0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) 编写 diff --git a/examples/vision/detection/yolov7end2end_trt/cpp/README.md b/examples/vision/detection/yolov7end2end_trt/cpp/README.md index 52baee9233..c39a8105b0 100644 --- a/examples/vision/detection/yolov7end2end_trt/cpp/README.md +++ b/examples/vision/detection/yolov7end2end_trt/cpp/README.md @@ -1,45 +1,46 @@ -# YOLOv7End2EndTRT C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv7End2EndTRT C++ Deployment Example -本目录下提供`infer.cc`快速完成GPU上通过TensorRT加速部署的示例,该类只支持TensorRT部署。 +This directory provides examples that `infer.cc` fast finishes the deployment on GPU accelerated by TensorRT. Now only TensorRT deployment is supported. -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的yolov7模型文件和测试图片 +# Download the official converted yolov7 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# TensorRT GPU推理 +# TensorRT inference on GPU ./infer_demo yolov7-end2end-trt-nms.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
image
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -注意,YOLOv7End2EndTRT 是专门用于推理YOLOv7中导出模型带[TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型请使用YOLOv7End2EndORT进行推理。 +Attention: YOLOv7End2EndORT is designed for the inference of End2End models with [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) among the YOLOv7 exported models. For models without nms, use YOLOv7 class for inference. For End2End models with [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87), use YOLOv7End2EndTRT for inference. -## YOLOv7End2EndTRT C++接口 +## YOLOv7End2EndTRT C++ Interface -### YOLOv7End2EndTRT 类 +### YOLOv7End2EndTRT Class ```c++ fastdeploy::vision::detection::YOLOv7End2EndTRT( @@ -49,41 +50,41 @@ fastdeploy::vision::detection::YOLOv7End2EndTRT( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv7End2EndTRT 模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv7End2EndTRT model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv7End2EndTRT::Predict(cv::Mat* im, DetectionResult* result, > float conf_threshold = 0.25) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence. But considering that YOLOv7 End2End models have a score threshold specified during ONNX export, this parameter will be effective when being greater than the specified one. + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_trt/cpp/README_CN.md b/examples/vision/detection/yolov7end2end_trt/cpp/README_CN.md new file mode 100644 index 0000000000..b79c4b1a10 --- /dev/null +++ b/examples/vision/detection/yolov7end2end_trt/cpp/README_CN.md @@ -0,0 +1,90 @@ +[English](README.md) | 简体中文 +# YOLOv7End2EndTRT C++部署示例 + +本目录下提供`infer.cc`快速完成GPU上通过TensorRT加速部署的示例,该类只支持TensorRT部署。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的yolov7模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# TensorRT GPU推理 +./infer_demo yolov7-end2end-trt-nms.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + +
+ image +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +注意,YOLOv7End2EndTRT 是专门用于推理YOLOv7中导出模型带[TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型请使用YOLOv7End2EndORT进行推理。 + +## YOLOv7End2EndTRT C++接口 + +### YOLOv7End2EndTRT 类 + +```c++ +fastdeploy::vision::detection::YOLOv7End2EndTRT( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv7End2EndTRT 模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv7End2EndTRT::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_trt/python/README.md b/examples/vision/detection/yolov7end2end_trt/python/README.md index 6e0264b392..be7b3eec7c 100644 --- a/examples/vision/detection/yolov7end2end_trt/python/README.md +++ b/examples/vision/detection/yolov7end2end_trt/python/README.md @@ -1,81 +1,81 @@ -# YOLOv7End2EndTRT Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv7End2EndTRT Python Deployment Example -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成YOLOv7End2EndTRT在TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl p ackage. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv7End2EndTRT accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/detection/yolov7end2end_trt/python/ -#下载yolov7模型文件和测试图片 +# Download yolov7 model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# TensorRT GPU推理 +# TensorRT inference on GPU python infer.py --model yolov7-end2end-trt-nms.onnx --image 000000014439.jpg --device gpu --use_trt True -# 若安装的python包没有支持该类 则请自行从源码develop分支编译最新的FastDeploy Python Wheel包进行安装 +# If it is not supported by the python package, compile the latest FastDeploy Python Wheel package from the source code in develop branch and install it. ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
image
-注意,YOLOv7End2EndTRT 是专门用于推理YOLOv7中导出模型带[TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型请使用YOLOv7End2EndORT进行推理。 +Attention: YOLOv7End2EndTRT is designed for the inference of End2End models with [TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) among the YOLOv7 exported models. For models without nms, use YOLOv7 class for inference. For End2End models with [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87), use YOLOv7End2EndTRT for inference. -## YOLOv7End2EndTRT Python接口 +## YOLOv7End2EndTRT Python Interface ```python fastdeploy.vision.detection.YOLOv7End2EndTRT(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv7End2EndTRT 模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv7End2EndTRT model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv7End2EndTRT.predict(image_data, conf_threshold=0.25) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence. But considering that YOLOv7 End2End models have a score threshold specified during ONNX export, this parameter will be effective when being greater than the specified one. -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOv7End2EndTRT 模型介绍](..) -- [YOLOv7End2EndTRT C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOv7End2EndTRT Model Description](..) +- [YOLOv7End2EndTRT C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolov7end2end_trt/python/README_CN.md b/examples/vision/detection/yolov7end2end_trt/python/README_CN.md new file mode 100644 index 0000000000..649ab53880 --- /dev/null +++ b/examples/vision/detection/yolov7end2end_trt/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# YOLOv7End2EndTRT Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv7End2EndTRT在TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/detection/yolov7end2end_trt/python/ + +#下载yolov7模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# TensorRT GPU推理 +python infer.py --model yolov7-end2end-trt-nms.onnx --image 000000014439.jpg --device gpu --use_trt True +# 若安装的python包没有支持该类 则请自行从源码develop分支编译最新的FastDeploy Python Wheel包进行安装 +``` + +运行完成可视化结果如下图所示 + +
+ image +
+ +注意,YOLOv7End2EndTRT 是专门用于推理YOLOv7中导出模型带[TRT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L111) 版本的End2End模型,不带nms的模型推理请使用YOLOv7类,而 [ORT_NMS](https://github.com/WongKinYiu/yolov7/blob/main/models/experimental.py#L87) 版本的End2End模型请使用YOLOv7End2EndORT进行推理。 + +## YOLOv7End2EndTRT Python接口 + +```python +fastdeploy.vision.detection.YOLOv7End2EndTRT(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv7End2EndTRT 模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv7End2EndTRT.predict(image_data, conf_threshold=0.25) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值,但由于YOLOv7 End2End的模型在导出成ONNX时已经指定了score阈值,因此该参数只有在大于已经指定的阈值时才会有效。 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` + + + +## 其它文档 + +- [YOLOv7End2EndTRT 模型介绍](..) +- [YOLOv7End2EndTRT C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolox/README.md b/examples/vision/detection/yolox/README.md index eea8763627..13fe8ea4d2 100644 --- a/examples/vision/detection/yolox/README.md +++ b/examples/vision/detection/yolox/README.md @@ -1,17 +1,19 @@ -# YOLOX准备部署模型 +English | [简体中文](README_CN.md) +# YOLOX Ready-to-deploy Model -- YOLOX部署实现来自[YOLOX](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0),基于[coco的预训练模型](https://github.com/Megvii-BaseDetection/YOLOX/releases/tag/0.1.1rc0)。 +- The YOLOX deployment is based on [YOLOX](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) and [coco's pre-trained models](https://github.com/Megvii-BaseDetection/YOLOX/releases/tag/0.1.1rc0)。 - - (1)[官方库](https://github.com/Megvii-BaseDetection/YOLOX/releases/tag/0.1.1rc0)提供中的*.pth通过导出ONNX模型操作后,可进行部署; - - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)The *.pth provided by [Official Repository](https://github.com/Megvii-BaseDetection/YOLOX/releases/tag/0.1.1rc0) should export the ONNX model to complete the deployment; + - (2)The YOLOX model trained by personal data should export the ONNX model. Refer to [Detailed Deployment Documents](#详细部署文档) to complete the deployment. -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Models -为了方便开发者的测试,下面提供了YOLOX导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | + +For developers' testing, models exported by YOLOX are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [YOLOX-s](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s.onnx) | 35MB | 39.6% | | [YOLOX-m](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_m.onnx) | 97MB | 46.4.5% | @@ -21,12 +23,12 @@ -## 详细部署文档 +## Detailed Deployment Documents -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOX v0.1.1版本](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) 编写 +- Document and code are based on [YOLOX v0.1.1 version](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) diff --git a/examples/vision/detection/yolox/README_CN.md b/examples/vision/detection/yolox/README_CN.md new file mode 100644 index 0000000000..7be0ed628d --- /dev/null +++ b/examples/vision/detection/yolox/README_CN.md @@ -0,0 +1,33 @@ +[English](README.md) | 简体中文 +# YOLOX准备部署模型 + + +- YOLOX部署实现来自[YOLOX](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0),基于[coco的预训练模型](https://github.com/Megvii-BaseDetection/YOLOX/releases/tag/0.1.1rc0)。 + + - (1)[官方库](https://github.com/Megvii-BaseDetection/YOLOX/releases/tag/0.1.1rc0)提供中的*.pth通过导出ONNX模型操作后,可进行部署; + - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + + + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOX导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [YOLOX-s](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s.onnx) | 35MB | 39.6% | +| [YOLOX-m](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_m.onnx) | 97MB | 46.4.5% | +| [YOLOX-l](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_l.onnx) | 207MB | 50.0% | +| [YOLOX-x](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_x.onnx) | 378MB | 51.2% | + + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOX v0.1.1版本](https://github.com/Megvii-BaseDetection/YOLOX/tree/0.1.1rc0) 编写 diff --git a/examples/vision/detection/yolox/cpp/README.md b/examples/vision/detection/yolox/cpp/README.md index 3cc857aec4..f7343de01a 100644 --- a/examples/vision/detection/yolox/cpp/README.md +++ b/examples/vision/detection/yolox/cpp/README.md @@ -1,46 +1,49 @@ -# YOLOX C++部署示例 +English | [简体中文](README_CN.md) -本目录下提供`infer.cc`快速完成YOLOX在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +# YOLOX C++ Deployment Example -在部署前,需确认以下两个步骤 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOX on CPU/GPU and GPU accelerated by TensorRT. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +Two steps before deployment -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的YOLOX模型文件和测试图片 +# Download the official converted YOLOX model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference ./infer_demo yolox_s.onnx 000000014439.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolox_s.onnx 000000014439.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolox_s.onnx 000000014439.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: + +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOX C++接口 +## YOLOX C++ Interface -### YOLOX类 +### YOLOX Class ```c++ fastdeploy::vision::detection::YOLOX( @@ -50,42 +53,45 @@ fastdeploy::vision::detection::YOLOX( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOX模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOX model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOX::Predict(cv::Mat* im, DetectionResult* result, -> float conf_threshold = 0.25, -> float nms_iou_threshold = 0.5) +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_decode_exported**(bool): 表示导出的YOLOX的onnx模型文件是否带坐标反算的decode部分, 默认值为`is_decode_exported=false`,官方默认的导出不带decode部分,如果您导出的模型带了decode,请将此参数设置为true - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for DetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable + +#### Pre-processing Parameter + +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_decode_exported**(bool): Whether the decode part with coordinate inversion is contained in the exported YOLOX onnx model files. Default `is_decode_exported=false`. The default export doesn’t cover this part. Set this parameter to true if your model is decode exported + + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolox/cpp/README_CN.md b/examples/vision/detection/yolox/cpp/README_CN.md new file mode 100644 index 0000000000..cec212445d --- /dev/null +++ b/examples/vision/detection/yolox/cpp/README_CN.md @@ -0,0 +1,92 @@ +[English](README.md) | 简体中文 +# YOLOX C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOX在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的YOLOX模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + + +# CPU推理 +./infer_demo yolox_s.onnx 000000014439.jpg 0 +# GPU推理 +./infer_demo yolox_s.onnx 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolox_s.onnx 000000014439.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOX C++接口 + +### YOLOX类 + +```c++ +fastdeploy::vision::detection::YOLOX( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOX模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOX::Predict(cv::Mat* im, DetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_decode_exported**(bool): 表示导出的YOLOX的onnx模型文件是否带坐标反算的decode部分, 默认值为`is_decode_exported=false`,官方默认的导出不带decode部分,如果您导出的模型带了decode,请将此参数设置为true + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolox/python/README.md b/examples/vision/detection/yolox/python/README.md index b4029d9654..308802698b 100644 --- a/examples/vision/detection/yolox/python/README.md +++ b/examples/vision/detection/yolox/python/README.md @@ -1,79 +1,80 @@ -# YOLOX Python部署示例 +English | [简体中文](README_CN.md) +# YOLOX Python Deployment Example -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOX在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOX on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolox/python/ -#下载YOLOX模型文件和测试图片 +# Download YOLOX model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s.onnx wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg -# CPU推理 +# CPU inference python infer.py --model yolox_s.onnx --image 000000014439.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolox_s.onnx --image 000000014439.jpg --device gpu -# GPU上使用TensorRT推理 (TensorRT在SDK中已包含,不需要单独安装) +# TensorRT inference on GPU (TensorRT in SDK. No need Separate installation) python infer.py --model yolox_s.onnx --image 000000014439.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOX Python接口 +## YOLOX Python Interface ```python fastdeploy.vision.detection.YOLOX(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOX模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOX model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOX.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output results > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.DetectionResult` structure, refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> >* **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> >* **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> >* **is_decode_exported**(bool): 表示导出的YOLOX的onnx模型文件是否带坐标反算的decode部分, 默认值为`is_decode_exported=False`,官方默认的导出不带decode部分,如果您导出的模型带了decode,请将此参数设置为True +> >* **size**(list[int]): This parameter changes the size of the resize during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> >* **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default [114, 114, 114] +> >* **is_decode_exported**(bool): The default value is `is_decode_exported=False`. The official default export does not have the decoded part. If you export the model with the decoded part, please set this parameter to true -## 其它文档 +## Other Documents -- [YOLOX 模型介绍](..) -- [YOLOX C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [YOLOX Model Description](..) +- [YOLOX C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/detection/yolox/python/README_CN.md b/examples/vision/detection/yolox/python/README_CN.md new file mode 100644 index 0000000000..59af2fc58b --- /dev/null +++ b/examples/vision/detection/yolox/python/README_CN.md @@ -0,0 +1,80 @@ +[English](README.md) | 简体中文 +# YOLOX Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOX在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/detection/yolox/python/ + +#下载YOLOX模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# CPU推理 +python infer.py --model yolox_s.onnx --image 000000014439.jpg --device cpu +# GPU推理 +python infer.py --model yolox_s.onnx --image 000000014439.jpg --device gpu +# GPU上使用TensorRT推理 (TensorRT在SDK中已包含,不需要单独安装) +python infer.py --model yolox_s.onnx --image 000000014439.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOX Python接口 + +```python +fastdeploy.vision.detection.YOLOX(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOX模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOX.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.DetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> >* **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> >* **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> >* **is_decode_exported**(bool): 表示导出的YOLOX的onnx模型文件是否带坐标反算的decode部分, 默认值为`is_decode_exported=False`,官方默认的导出不带decode部分,如果您导出的模型带了decode,请将此参数设置为True + + + +## 其它文档 + +- [YOLOX 模型介绍](..) +- [YOLOX C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/README.md b/examples/vision/facealign/README.md index df0b441112..07059d7567 100644 --- a/examples/vision/facealign/README.md +++ b/examples/vision/facealign/README.md @@ -1,9 +1,10 @@ -# 人脸对齐(人脸关键点检测)模型 +English | [简体中文](README_CN.md) +# Face Alignment (Keypoint Detection) Model -FastDeploy目前支持如下人脸对齐(关键点检测)模型部署 +FastDeploy currently supports the deployment of the following face alignment (keypoint detection) models -| 模型 | 说明 | 模型格式 | 版本 | +| Model | Description | Model Format | Version | | :--- | :--- | :------- | :--- | -| [Hsintao/pfld_106_face_landmarks](./pfld) | PFLD 系列模型 | ONNX | [CommitID:e150195](https://github.com/Hsintao/pfld_106_face_landmarks/commit/e150195) | -| [Single430/FaceLandmark1000](./face_landmark_1000) | FaceLandmark1000 系列模型 | ONNX | [CommitID:1a951b6](https://github.com/Single430/FaceLandmark1000/tree/1a951b6) | -| [jhb86253817/PIPNet](./pipnet) | PIPNet 系列模型 | ONNX | [CommitID:b9eab58](https://github.com/jhb86253817/PIPNet/tree/b9eab58) | +| [Hsintao/pfld_106_face_landmarks](./pfld) | PFLD models | ONNX | [CommitID:e150195](https://github.com/Hsintao/pfld_106_face_landmarks/commit/e150195) | +| [Single430/FaceLandmark1000](./face_landmark_1000) | FaceLandmark1000 models | ONNX | [CommitID:1a951b6](https://github.com/Single430/FaceLandmark1000/tree/1a951b6) | +| [jhb86253817/PIPNet](./pipnet) | PIPNet models | ONNX | [CommitID:b9eab58](https://github.com/jhb86253817/PIPNet/tree/b9eab58) | diff --git a/examples/vision/facealign/README_CN.md b/examples/vision/facealign/README_CN.md new file mode 100644 index 0000000000..c8cc23e979 --- /dev/null +++ b/examples/vision/facealign/README_CN.md @@ -0,0 +1,10 @@ +[English](README.md) | 简体中文 +# 人脸对齐(人脸关键点检测)模型 + +FastDeploy目前支持如下人脸对齐(关键点检测)模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +| :--- | :--- | :------- | :--- | +| [Hsintao/pfld_106_face_landmarks](./pfld) | PFLD 系列模型 | ONNX | [CommitID:e150195](https://github.com/Hsintao/pfld_106_face_landmarks/commit/e150195) | +| [Single430/FaceLandmark1000](./face_landmark_1000) | FaceLandmark1000 系列模型 | ONNX | [CommitID:1a951b6](https://github.com/Single430/FaceLandmark1000/tree/1a951b6) | +| [jhb86253817/PIPNet](./pipnet) | PIPNet 系列模型 | ONNX | [CommitID:b9eab58](https://github.com/jhb86253817/PIPNet/tree/b9eab58) | diff --git a/examples/vision/facealign/face_landmark_1000/README.md b/examples/vision/facealign/face_landmark_1000/README.md index ce45cc285b..fa536df78f 100644 --- a/examples/vision/facealign/face_landmark_1000/README.md +++ b/examples/vision/facealign/face_landmark_1000/README.md @@ -1,25 +1,26 @@ -# FaceLandmark 模型部署 +English | [简体中文](README_CN.md) +# FaceLandmark Model Deployment -## 模型版本说明 +## Model Description - [FaceLandmark1000](https://github.com/Single430/FaceLandmark1000/tree/1a951b6) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [FaceLandmark1000 模型](https://github.com/Single430/FaceLandmark1000) +- [FaceLandmark1000 Model](https://github.com/Single430/FaceLandmark1000) -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了FaceLandmark导出的各系列模型,开发者可直接下载使用。 +For developers' testing, models exported by FaceLandmark are provided below. Developers can download and use them directly. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | | [FaceLandmark1000](https://bj.bcebos.com/paddlehub/fastdeploy/FaceLandmark1000.onnx) | 2.1M | - | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/facealign/face_landmark_1000/README_CN.md b/examples/vision/facealign/face_landmark_1000/README_CN.md new file mode 100644 index 0000000000..05abfca47d --- /dev/null +++ b/examples/vision/facealign/face_landmark_1000/README_CN.md @@ -0,0 +1,26 @@ +[English](README.md) | 简体中文 +# FaceLandmark 模型部署 + +## 模型版本说明 + +- [FaceLandmark1000](https://github.com/Single430/FaceLandmark1000/tree/1a951b6) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [FaceLandmark1000 模型](https://github.com/Single430/FaceLandmark1000) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了FaceLandmark导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [FaceLandmark1000](https://bj.bcebos.com/paddlehub/fastdeploy/FaceLandmark1000.onnx) | 2.1M | - | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/facealign/face_landmark_1000/cpp/README.md b/examples/vision/facealign/face_landmark_1000/cpp/README.md index 00b5391b5e..00a5c2b40f 100644 --- a/examples/vision/facealign/face_landmark_1000/cpp/README.md +++ b/examples/vision/facealign/face_landmark_1000/cpp/README.md @@ -1,47 +1,48 @@ -# FaceLandmark1000 C++部署示例 +English | [简体中文](README_CN.md) +# FaceLandmark1000 C++ Deployment Example -本目录下提供`infer.cc`快速完成FaceLandmark1000在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of FaceLandmark1000 on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.2 or above (x.x.x>=1.0.2), or nightly built version is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的 FaceLandmark1000 模型文件和测试图片 +# Download the official converted FaceLandmark1000 model file and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/FaceLandmark1000.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png -# CPU推理 +# CPU inference ./infer_demo --model FaceLandmark1000.onnx --image facealign_input.png --device cpu -# GPU推理 +# GPU inference ./infer_demo --model FaceLandmark1000.onnx --image facealign_input.png --device gpu -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo --model FaceLandmark1000.onnx --image facealign_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## FaceLandmark1000 C++接口 +## FaceLandmark1000 C++ Interface -### FaceLandmark1000 类 +### FaceLandmark1000 Class ```c++ fastdeploy::vision::facealign::FaceLandmark1000( @@ -51,35 +52,35 @@ fastdeploy::vision::facealign::FaceLandmark1000( const ModelFormat& model_format = ModelFormat::ONNX) ``` -FaceLandmark1000模型加载和初始化,其中model_file为导出的ONNX模型格式。 +FaceLandmark1000 model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > FaceLandmark1000::Predict(cv::Mat* im, FaceAlignmentResult* result) > ``` > -> 模型预测接口,输入图像直接输出landmarks结果。 +> Model prediction interface. Input images and output landmarks results directly. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: landmarks结果, FaceAlignmentResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: landmarks result. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for FaceAlignmentResult -### 类成员变量 +### Class Member Variable -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[128, 128] +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [128, 128] -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/face_landmark_1000/cpp/README_CN.md b/examples/vision/facealign/face_landmark_1000/cpp/README_CN.md new file mode 100644 index 0000000000..6a24e9125a --- /dev/null +++ b/examples/vision/facealign/face_landmark_1000/cpp/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# FaceLandmark1000 C++部署示例 + +本目录下提供`infer.cc`快速完成FaceLandmark1000在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的 FaceLandmark1000 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/FaceLandmark1000.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png + +# CPU推理 +./infer_demo --model FaceLandmark1000.onnx --image facealign_input.png --device cpu +# GPU推理 +./infer_demo --model FaceLandmark1000.onnx --image facealign_input.png --device gpu +# GPU上TensorRT推理 +./infer_demo --model FaceLandmark1000.onnx --image facealign_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## FaceLandmark1000 C++接口 + +### FaceLandmark1000 类 + +```c++ +fastdeploy::vision::facealign::FaceLandmark1000( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +FaceLandmark1000模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> FaceLandmark1000::Predict(cv::Mat* im, FaceAlignmentResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出landmarks结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: landmarks结果, FaceAlignmentResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员变量 + +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[128, 128] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/face_landmark_1000/python/README.md b/examples/vision/facealign/face_landmark_1000/python/README.md index 380d1cb270..7521023480 100644 --- a/examples/vision/facealign/face_landmark_1000/python/README.md +++ b/examples/vision/facealign/face_landmark_1000/python/README.md @@ -1,71 +1,71 @@ -# FaceLandmark1000 Python部署示例 +English | [简体中文](README_CN.md) +# FaceLandmark1000 Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成FaceLandmark1000在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.7.0 支持FaceLandmark1000模型。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of FaceLandmark1000 models on CPU/GPU and GPU accelerated by TensorRT. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/facealign/facelandmark1000/python -# 下载FaceLandmark1000模型文件和测试图片 -## 原版ONNX模型 +# Download the FaceLandmark1000 model file and test images +## Original ONNX Model wget https://bj.bcebos.com/paddlehub/fastdeploy/FaceLandmark1000.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png -# CPU推理 +# CPU inference python infer.py --model FaceLandmark1000.onnx --image facealign_input.png --device cpu -# GPU推理 +# GPU inference python infer.py --model FaceLandmark1000.onnx --image facealign_input.png --device gpu -# TRT推理 +# TRT inference python infer.py --model FaceLandmark1000.onnx --image facealign_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## FaceLandmark1000 Python接口 +## FaceLandmark1000 Python Interface ```python fd.vision.facealign.FaceLandmark1000(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -FaceLandmark1000模型加载和初始化,其中model_file为导出的ONNX模型格式 +FaceLandmark1000 model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict Function > ```python > FaceLandmark1000.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出landmarks坐标结果。 +> Model prediction interface. Input images and output landmarks results directly. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 - -> **返回** +> > * **input_image**(np.ndarray): Input data in HWC or BGR format +> **Return** > -> > 返回`fastdeploy.vision.FaceAlignmentResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceAlignmentResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure -## 其它文档 +## Other Documents -- [FaceLandmark1000 模型介绍](..) -- [FaceLandmark1000 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [FaceLandmark1000 Model Description](..) +- [FaceLandmark1000 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/face_landmark_1000/python/README_CN.md b/examples/vision/facealign/face_landmark_1000/python/README_CN.md new file mode 100644 index 0000000000..224d0791f5 --- /dev/null +++ b/examples/vision/facealign/face_landmark_1000/python/README_CN.md @@ -0,0 +1,72 @@ +[English](README.md) | 简体中文 +# FaceLandmark1000 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成FaceLandmark1000在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.7.0 支持FaceLandmark1000模型。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/facealign/facelandmark1000/python + +# 下载FaceLandmark1000模型文件和测试图片 +## 原版ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/FaceLandmark1000.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png + +# CPU推理 +python infer.py --model FaceLandmark1000.onnx --image facealign_input.png --device cpu +# GPU推理 +python infer.py --model FaceLandmark1000.onnx --image facealign_input.png --device gpu +# TRT推理 +python infer.py --model FaceLandmark1000.onnx --image facealign_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +## FaceLandmark1000 Python接口 + +```python +fd.vision.facealign.FaceLandmark1000(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +FaceLandmark1000模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> FaceLandmark1000.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出landmarks坐标结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceAlignmentResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [FaceLandmark1000 模型介绍](..) +- [FaceLandmark1000 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pfld/README.md b/examples/vision/facealign/pfld/README.md index 3742f1f4b3..488ba85863 100644 --- a/examples/vision/facealign/pfld/README.md +++ b/examples/vision/facealign/pfld/README.md @@ -1,26 +1,27 @@ -# PFLD 模型部署 +English | [简体中文](README_CN.md) +# PFLD Model Deployment -## 模型版本说明 +## Model Description - [PFLD](https://github.com/Hsintao/pfld_106_face_landmarks/commit/e150195) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PFLD 模型](https://github.com/Hsintao/pfld_106_face_landmarks) +- [PFLD Model](https://github.com/Hsintao/pfld_106_face_landmarks) -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了PFLD导出的各系列模型,开发者可直接下载使用。 +For developers' testing, models exported by PFLD are provided below. Developers can download and use them directly. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | | [pfld-106-v2.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-v2.onnx) | 4.9M | - | | [pfld-106-v3.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-v3.onnx) | 5.6MB | - | | [pfld-106-lite.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-lite.onnx) | 1.1MB | - | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/facealign/pfld/README_CN.md b/examples/vision/facealign/pfld/README_CN.md new file mode 100644 index 0000000000..51c3eaa2c5 --- /dev/null +++ b/examples/vision/facealign/pfld/README_CN.md @@ -0,0 +1,27 @@ +[English](README.md) | 简体中文 +# PFLD 模型部署 + +## 模型版本说明 + +- [PFLD](https://github.com/Hsintao/pfld_106_face_landmarks/commit/e150195) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PFLD 模型](https://github.com/Hsintao/pfld_106_face_landmarks) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PFLD导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [pfld-106-v2.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-v2.onnx) | 4.9M | - | +| [pfld-106-v3.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-v3.onnx) | 5.6MB | - | +| [pfld-106-lite.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-lite.onnx) | 1.1MB | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/facealign/pfld/cpp/README.md b/examples/vision/facealign/pfld/cpp/README.md index 06ce4a2f42..c2040faa07 100644 --- a/examples/vision/facealign/pfld/cpp/README.md +++ b/examples/vision/facealign/pfld/cpp/README.md @@ -1,47 +1,48 @@ -# PFLD C++部署示例 +English | [简体中文](README_CN.md) +# PFLD C++ Deployment Example -本目录下提供`infer.cc`快速完成PFLD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PFLD on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.2 or above (x.x.x>=1.0.2), or the nightly built version is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的 PFLD 模型文件和测试图片 +# Download the official converted PFLD model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-lite.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png -# CPU推理 +# CPU inference ./infer_demo --model pfld-106-lite.onnx --image facealign_input.png --device cpu -# GPU推理 +# GPU inference ./infer_demo --model pfld-106-lite.onnx --image facealign_input.png --device gpu -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo --model pfld-106-lite.onnx --image facealign_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PFLD C++接口 +## PFLD C++ Interface -### PFLD 类 +### PFLD Class ```c++ fastdeploy::vision::facealign::PFLD( @@ -51,35 +52,35 @@ fastdeploy::vision::facealign::PFLD( const ModelFormat& model_format = ModelFormat::ONNX) ``` -PFLD模型加载和初始化,其中model_file为导出的ONNX模型格式。 +PFLD model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > PFLD::Predict(cv::Mat* im, FaceAlignmentResult* result) > ``` > -> 模型预测接口,输入图像直接输出landmarks结果。 +> Model prediction interface. Input images and output landmarks results directly. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: landmarks结果, FaceAlignmentResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: landmarks result. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of FaceAlignmentResult -### 类成员变量 +### Class Member Variable -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [112, 112] -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pfld/cpp/README_CN.md b/examples/vision/facealign/pfld/cpp/README_CN.md new file mode 100644 index 0000000000..69c0dfc821 --- /dev/null +++ b/examples/vision/facealign/pfld/cpp/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# PFLD C++部署示例 + +本目录下提供`infer.cc`快速完成PFLD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的 PFLD 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-lite.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png + +# CPU推理 +./infer_demo --model pfld-106-lite.onnx --image facealign_input.png --device cpu +# GPU推理 +./infer_demo --model pfld-106-lite.onnx --image facealign_input.png --device gpu +# GPU上TensorRT推理 +./infer_demo --model pfld-106-lite.onnx --image facealign_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PFLD C++接口 + +### PFLD 类 + +```c++ +fastdeploy::vision::facealign::PFLD( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +PFLD模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> PFLD::Predict(cv::Mat* im, FaceAlignmentResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出landmarks结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: landmarks结果, FaceAlignmentResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员变量 + +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pfld/python/README.md b/examples/vision/facealign/pfld/python/README.md index d68e2d083b..25f665eb55 100755 --- a/examples/vision/facealign/pfld/python/README.md +++ b/examples/vision/facealign/pfld/python/README.md @@ -1,70 +1,71 @@ -# PFLD Python部署示例 +English | [简体中文](README_CN.md) +# PFLD Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成PFLD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.6.0 支持PFLD模型。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of PFLD on CPU/GPU and GPU accelerated by TensorRT. FastDeploy version 0.6.0 or above is required to support this model. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/facealign/pfld/python -# 下载PFLD模型文件和测试图片以及视频 -## 原版ONNX模型 +# Download the PFLD model files, test images, and videos +## Original ONNX Model wget https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-lite.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png -# CPU推理 +# CPU inference python infer.py --model pfld-106-lite.onnx --image facealign_input.png --device cpu -# GPU推理 +# GPU inference python infer.py --model pfld-106-lite.onnx --image facealign_input.png --device gpu -# TRT推理 +# TRT inference python infer.py --model pfld-106-lite.onnx --image facealign_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PFLD Python接口 +## PFLD Python Interface ```python fd.vision.facealign.PFLD(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -PFLD模型加载和初始化,其中model_file为导出的ONNX模型格式 +PFLD model loading and initialization, among which model_file is the exported ONNX model format **参数** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict Parameter > ```python > PFLD.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出landmarks坐标结果。 +> Model prediction interface. Input images and output landmarks results directly > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceAlignmentResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceAlignmentResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [PFLD 模型介绍](..) -- [PFLD C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PFLD Model Description](..) +- [PFLD C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pfld/python/README_CN.md b/examples/vision/facealign/pfld/python/README_CN.md new file mode 100644 index 0000000000..2eba34ceab --- /dev/null +++ b/examples/vision/facealign/pfld/python/README_CN.md @@ -0,0 +1,71 @@ +[English](README.md) | 简体中文 +# PFLD Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PFLD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.6.0 支持PFLD模型。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/facealign/pfld/python + +# 下载PFLD模型文件和测试图片以及视频 +## 原版ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/pfld-106-lite.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png +# CPU推理 +python infer.py --model pfld-106-lite.onnx --image facealign_input.png --device cpu +# GPU推理 +python infer.py --model pfld-106-lite.onnx --image facealign_input.png --device gpu +# TRT推理 +python infer.py --model pfld-106-lite.onnx --image facealign_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +## PFLD Python接口 + +```python +fd.vision.facealign.PFLD(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +PFLD模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> PFLD.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出landmarks坐标结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceAlignmentResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [PFLD 模型介绍](..) +- [PFLD C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pipnet/README.md b/examples/vision/facealign/pipnet/README.md index 504aac2241..8180cc7af0 100644 --- a/examples/vision/facealign/pipnet/README.md +++ b/examples/vision/facealign/pipnet/README.md @@ -1,20 +1,20 @@ -# PIPNet 模型部署 +English | [简体中文](README_CN.md) +# PIPNet Model Deployment -## 模型版本说明 +## Model Description - [PIPNet](https://github.com/jhb86253817/PIPNet/tree/b9eab58) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PIPNet 模型](https://github.com/jhb86253817/PIPNet) +- [PIPNet Model](https://github.com/jhb86253817/PIPNet) -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了PIPNet导出的各系列模型,开发者可直接下载使用。 - -| 模型 | 参数大小 | 精度 | 备注 | +For developers' testing, models exported by PIPNet are provided below. Developers can download and use them directly. +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | | [PIPNet19_ResNet18_AFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x19x32x256_aflw.onnx) | 45.6M | - | | [PIPNet29_ResNet18_COFW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x29x32x256_cofw.onnx) | 46.1M | - | @@ -27,7 +27,7 @@ -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/facealign/pipnet/README_CN.md b/examples/vision/facealign/pipnet/README_CN.md new file mode 100644 index 0000000000..e3dae73337 --- /dev/null +++ b/examples/vision/facealign/pipnet/README_CN.md @@ -0,0 +1,34 @@ +[English](README.md) | 简体中文 +# PIPNet 模型部署 + +## 模型版本说明 + +- [PIPNet](https://github.com/jhb86253817/PIPNet/tree/b9eab58) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PIPNet 模型](https://github.com/jhb86253817/PIPNet) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PIPNet导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [PIPNet19_ResNet18_AFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x19x32x256_aflw.onnx) | 45.6M | - | +| [PIPNet29_ResNet18_COFW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x29x32x256_cofw.onnx) | 46.1M | - | +| [PIPNet68_ResNet18_300W](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x68x32x256_300w.onnx) | 47.9M | - | +| [PIPNet98_ResNet18_WFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x98x32x256_wflw.onnx) | 49.3M | - | +| [PIPNet19_ResNet101_AFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x19x32x256_aflw.onnx) | 173.4M | - | +| [PIPNet29_ResNet101_COFW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x29x32x256_cofw.onnx) | 175.3M | - | +| [PIPNet68_ResNet101_300W](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x68x32x256_300w.onnx) | 182.6M | - | +| [PIPNet98_ResNet101_WFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x98x32x256_wflw.onnx) | 188.3M | - | + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/facealign/pipnet/cpp/README.md b/examples/vision/facealign/pipnet/cpp/README.md index 81778d7d5a..cd55a20f6f 100644 --- a/examples/vision/facealign/pipnet/cpp/README.md +++ b/examples/vision/facealign/pipnet/cpp/README.md @@ -1,47 +1,48 @@ -# PIPNet C++部署示例 +English | [简体中文](README_CN.md) +# PIPNet C++ Deployment Example -本目录下提供`infer.cc`快速完成PIPNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PIPNet on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的 PIPNet 模型文件和测试图片 +# Download the official converted PIPNet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x19x32x256_aflw.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png -# CPU推理 +# CPU inference ./infer_demo --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device cpu -# GPU推理 +# GPU inference ./infer_demo --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device gpu -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PIPNet C++接口 +## PIPNet C++ Interface -### PIPNet 类 +### PIPNet Class ```c++ fastdeploy::vision::facealign::PIPNet( @@ -51,35 +52,35 @@ fastdeploy::vision::facealign::PIPNet( const ModelFormat& model_format = ModelFormat::ONNX) ``` -PIPNet模型加载和初始化,其中model_file为导出的ONNX模型格式。 +PIPNet model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > PIPNet::Predict(cv::Mat* im, FaceAlignmentResult* result) > ``` > -> 模型预测接口,输入图像直接输出landmarks结果。 +> Model prediction interface. Input images and output landmarks results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: landmarks结果, FaceAlignmentResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: landmarks result. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for FaceAlignmentResult -### 类成员变量 +### Class Member Variable -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[256, 256] +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [256, 256] -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pipnet/cpp/README_CN.md b/examples/vision/facealign/pipnet/cpp/README_CN.md new file mode 100644 index 0000000000..31fa99767f --- /dev/null +++ b/examples/vision/facealign/pipnet/cpp/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# PIPNet C++部署示例 + +本目录下提供`infer.cc`快速完成PIPNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的 PIPNet 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x19x32x256_aflw.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png + +# CPU推理 +./infer_demo --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device cpu +# GPU推理 +./infer_demo --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device gpu +# GPU上TensorRT推理 +./infer_demo --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PIPNet C++接口 + +### PIPNet 类 + +```c++ +fastdeploy::vision::facealign::PIPNet( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +PIPNet模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> PIPNet::Predict(cv::Mat* im, FaceAlignmentResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出landmarks结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: landmarks结果, FaceAlignmentResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员变量 + +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[256, 256] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pipnet/python/README.md b/examples/vision/facealign/pipnet/python/README.md index ae46849c38..297a0bfd19 100644 --- a/examples/vision/facealign/pipnet/python/README.md +++ b/examples/vision/facealign/pipnet/python/README.md @@ -1,71 +1,72 @@ -# PIPNet Python部署示例 +English | [简体中文](README_CN.md) +# PIPNet Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成PIPNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.7.0 支持PIPNet模型。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of PIPNet on CPU/GPU and GPU accelerated by TensorRT. FastDeploy version 0.7.0 or above is required to support this model. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/facealign/pipnet/python -# 下载PIPNet模型文件和测试图片以及视频 -## 原版ONNX模型 +# Download PIPNet model files, test images and videos +## Original ONNX Model wget https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x19x32x256_aflw.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/facealign_input.png -# CPU推理 +# CPU inference python infer.py --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device cpu -# GPU推理 +# GPU inference python infer.py --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device gpu -# TRT推理 +# TRT inference python infer.py --model pipnet_resnet18_10x19x32x256_aflw.onnx --image facealign_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PIPNet Python接口 +## PIPNet Python Interface ```python fd.vision.facealign.PIPNet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -PIPNet模型加载和初始化,其中model_file为导出的ONNX模型格式 +PIPNet model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > PIPNet.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出landmarks坐标结果。 +> Model prediction interface. Input images and output landmarks results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceAlignmentResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceAlignmentResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [PIPNet 模型介绍](..) -- [PIPNet C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PIPNet Model Description](..) +- [PIPNet C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facealign/pipnet/python/README_CN.md b/examples/vision/facealign/pipnet/python/README_CN.md new file mode 100644 index 0000000000..e3dae73337 --- /dev/null +++ b/examples/vision/facealign/pipnet/python/README_CN.md @@ -0,0 +1,34 @@ +[English](README.md) | 简体中文 +# PIPNet 模型部署 + +## 模型版本说明 + +- [PIPNet](https://github.com/jhb86253817/PIPNet/tree/b9eab58) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PIPNet 模型](https://github.com/jhb86253817/PIPNet) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PIPNet导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [PIPNet19_ResNet18_AFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x19x32x256_aflw.onnx) | 45.6M | - | +| [PIPNet29_ResNet18_COFW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x29x32x256_cofw.onnx) | 46.1M | - | +| [PIPNet68_ResNet18_300W](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x68x32x256_300w.onnx) | 47.9M | - | +| [PIPNet98_ResNet18_WFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet18_10x98x32x256_wflw.onnx) | 49.3M | - | +| [PIPNet19_ResNet101_AFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x19x32x256_aflw.onnx) | 173.4M | - | +| [PIPNet29_ResNet101_COFW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x29x32x256_cofw.onnx) | 175.3M | - | +| [PIPNet68_ResNet101_300W](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x68x32x256_300w.onnx) | 182.6M | - | +| [PIPNet98_ResNet101_WFLW](https://bj.bcebos.com/paddlehub/fastdeploy/pipnet_resnet101_10x98x32x256_wflw.onnx) | 188.3M | - | + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/facedet/README.md b/examples/vision/facedet/README.md index cde8c71b80..31868c3f5f 100644 --- a/examples/vision/facedet/README.md +++ b/examples/vision/facedet/README.md @@ -1,10 +1,12 @@ -# 人脸检测模型 +English | [简体中文](README_CN.md) +# Face Detection Model -FastDeploy目前支持如下人脸检测模型部署 +FastDeploy currently supports the deployment of the following face detection models -| 模型 | 说明 | 模型格式 | 版本 | + +| Model | Description | Model Format | Version | | :--- | :--- | :------- | :--- | -| [biubug6/RetinaFace](./retinaface) | RetinaFace 系列模型 | ONNX | [CommitID:b984b4b](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) | -| [Linzaer/UltraFace](./ultraface) | UltraFace 系列模型 | ONNX |[CommitID:dffdddd](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) | -| [deepcam-cn/YOLOv5Face](./yolov5face) | YOLOv5Face 系列模型 | ONNX | [CommitID:4fd1ead](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) | -| [deepinsight/SCRFD](./scrfd) | SCRFD 系列模型 | ONNX | [CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) | +| [biubug6/RetinaFace](./retinaface) | RetinaFace Models | ONNX | [CommitID:b984b4b](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) | +| [Linzaer/UltraFace](./ultraface) | UltraFace Models | ONNX |[CommitID:dffdddd](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) | +| [deepcam-cn/YOLOv5Face](./yolov5face) | YOLOv5Face Models | ONNX | [CommitID:4fd1ead](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) | +| [deepinsight/SCRFD](./scrfd) | SCRFD Models | ONNX | [CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) | diff --git a/examples/vision/facedet/README_CN.md b/examples/vision/facedet/README_CN.md new file mode 100644 index 0000000000..0410646d9b --- /dev/null +++ b/examples/vision/facedet/README_CN.md @@ -0,0 +1,11 @@ +[English](README.md) | 简体中文 +# 人脸检测模型 + +FastDeploy目前支持如下人脸检测模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +| :--- | :--- | :------- | :--- | +| [biubug6/RetinaFace](./retinaface) | RetinaFace 系列模型 | ONNX | [CommitID:b984b4b](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) | +| [Linzaer/UltraFace](./ultraface) | UltraFace 系列模型 | ONNX |[CommitID:dffdddd](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) | +| [deepcam-cn/YOLOv5Face](./yolov5face) | YOLOv5Face 系列模型 | ONNX | [CommitID:4fd1ead](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) | +| [deepinsight/SCRFD](./scrfd) | SCRFD 系列模型 | ONNX | [CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) | diff --git a/examples/vision/facedet/retinaface/README.md b/examples/vision/facedet/retinaface/README.md index 54d94c5f3a..c25eebc01c 100644 --- a/examples/vision/facedet/retinaface/README.md +++ b/examples/vision/facedet/retinaface/README.md @@ -1,42 +1,43 @@ -# RetinaFace准备部署模型 +English | [简体中文](README_CN.md) +# RetinaFace Ready-to-deploy Model - [RetinaFace](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) - - (1)[官方库](https://github.com/biubug6/Pytorch_Retinaface/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)自己数据训练的RetinaFace模型,可按照[导出ONNX模型](#导出ONNX模型)后,完成部署。 + - (1)The *.pt provided by the[Official Library](https://github.com/biubug6/Pytorch_Retinaface/) can be deployed after the [Export ONNX Model](#导出ONNX模型); + - (2)As for RetinaFace model trained on customized data, please follow the [Export ONNX Model](#导出ONNX模型) to complete the deployment. -## 导出ONNX模型 +## Export ONNX Model -[下载预训练ONNX模型](#下载预训练ONNX模型)已事先转换成ONNX;如果从RetinaFace官方repo下载的模型,需要按如下教程导出ONNX。 +[Download the pre-trained ONNX model](#下载预训练ONNX模型)The model has been converted to ONNX. If you downloaded the model from the RetinaFace official repo, please follow the tutorial below to export ONNX. -* 下载官方仓库并 +* Download the official repository ```bash git clone https://github.com/biubug6/Pytorch_Retinaface.git ``` -* 下载预训练权重并放在weights文件夹 +* Download the pre-trained weights and place them in the weights folder ```text ./weights/ mobilenet0.25_Final.pth mobilenetV1X0.25_pretrain.tar Resnet50_Final.pth ``` -* 运行convert_to_onnx.py导出ONNX模型文件 +* run convert_to_onnx.py to export ONNX model files ```bash PYTHONPATH=. python convert_to_onnx.py --trained_model ./weights/mobilenet0.25_Final.pth --network mobile0.25 --long_side 640 --cpu PYTHONPATH=. python convert_to_onnx.py --trained_model ./weights/Resnet50_Final.pth --network resnet50 --long_side 640 --cpu ``` -注意:需要先对convert_to_onnx.py脚本中的--long_side参数增加类型约束,type=int. -* 使用onnxsim对模型进行简化 +Attention: We need to add a type constraint, type=int, to the --long_side parameter in the convert_to_onnx.py script. +* Use onnxsim to simplify the model ```bash onnxsim FaceDetector.onnx Pytorch_RetinaFace_mobile0.25-640-640.onnx # mobilenet onnxsim FaceDetector.onnx Pytorch_RetinaFace_resnet50-640-640.onnx # resnet50 ``` -## 下载预训练ONNX模型 +## Download pre-trained ONNX models -为了方便开发者的测试,下面提供了RetinaFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by RetinaFace are provided below. Developers can download and use them directly. (The accuracy of the models in the table is sourced from the official library) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [RetinaFace_mobile0.25-640](https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-640-640.onnx) | 1.7MB | - | | [RetinaFace_mobile0.25-720](https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-720-1080.onnx) | 1.7MB | -| @@ -47,12 +48,12 @@ onnxsim FaceDetector.onnx Pytorch_RetinaFace_resnet50-640-640.onnx # resnet50 -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[RetinaFace CommitID:b984b4b](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) 编写 +- This tutorial and related code are written based on [RetinaFace CommitID:b984b4b](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) diff --git a/examples/vision/facedet/retinaface/README_CN.md b/examples/vision/facedet/retinaface/README_CN.md new file mode 100644 index 0000000000..e0c662ad1a --- /dev/null +++ b/examples/vision/facedet/retinaface/README_CN.md @@ -0,0 +1,59 @@ +[English](README.md) | 简体中文 +# RetinaFace准备部署模型 + +- [RetinaFace](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) + - (1)[官方库](https://github.com/biubug6/Pytorch_Retinaface/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)自己数据训练的RetinaFace模型,可按照[导出ONNX模型](#导出ONNX模型)后,完成部署。 + + +## 导出ONNX模型 + +[下载预训练ONNX模型](#下载预训练ONNX模型)已事先转换成ONNX;如果从RetinaFace官方repo下载的模型,需要按如下教程导出ONNX。 + + +* 下载官方仓库并 +```bash +git clone https://github.com/biubug6/Pytorch_Retinaface.git +``` +* 下载预训练权重并放在weights文件夹 +```text +./weights/ + mobilenet0.25_Final.pth + mobilenetV1X0.25_pretrain.tar + Resnet50_Final.pth +``` +* 运行convert_to_onnx.py导出ONNX模型文件 +```bash +PYTHONPATH=. python convert_to_onnx.py --trained_model ./weights/mobilenet0.25_Final.pth --network mobile0.25 --long_side 640 --cpu +PYTHONPATH=. python convert_to_onnx.py --trained_model ./weights/Resnet50_Final.pth --network resnet50 --long_side 640 --cpu +``` +注意:需要先对convert_to_onnx.py脚本中的--long_side参数增加类型约束,type=int. +* 使用onnxsim对模型进行简化 +```bash +onnxsim FaceDetector.onnx Pytorch_RetinaFace_mobile0.25-640-640.onnx # mobilenet +onnxsim FaceDetector.onnx Pytorch_RetinaFace_resnet50-640-640.onnx # resnet50 +``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了RetinaFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [RetinaFace_mobile0.25-640](https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-640-640.onnx) | 1.7MB | - | +| [RetinaFace_mobile0.25-720](https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-720-1080.onnx) | 1.7MB | -| +| [RetinaFace_resnet50-640](https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_resnet50-720-1080.onnx) | 105MB | - | +| [RetinaFace_resnet50-720](https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_resnet50-640-640.onnx) | 105MB | - | + + + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[RetinaFace CommitID:b984b4b](https://github.com/biubug6/Pytorch_Retinaface/commit/b984b4b) 编写 diff --git a/examples/vision/facedet/retinaface/cpp/README.md b/examples/vision/facedet/retinaface/cpp/README.md index 15d71d9a4e..f935658126 100644 --- a/examples/vision/facedet/retinaface/cpp/README.md +++ b/examples/vision/facedet/retinaface/cpp/README.md @@ -1,45 +1,46 @@ -# RetinaFace C++部署示例 +English | [简体中文](README_CN.md) +# RetinaFace C++ Deployment Example -本目录下提供`infer.cc`快速完成RetinaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of RetinaFace on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的RetinaFace模型文件和测试图片 +# Download RetinaFace model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-640-640.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference ./infer_demo Pytorch_RetinaFace_mobile0.25-640-640.onnx test_lite_face_detector_3.jpg 0 -# GPU推理 +# GPU inference ./infer_demo Pytorch_RetinaFace_mobile0.25-640-640.onnx test_lite_face_detector_3.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo Pytorch_RetinaFace_mobile0.25-640-640.onnx test_lite_face_detector_3.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## RetinaFace C++接口 +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) +## RetinaFace C++ Interface -### RetinaFace类 +### RetinaFace Class ```c++ fastdeploy::vision::facedet::RetinaFace( @@ -49,16 +50,16 @@ fastdeploy::vision::facedet::RetinaFace( const ModelFormat& model_format = ModelFormat::ONNX) ``` -RetinaFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 +RetinaFace model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict function > ```c++ > RetinaFace::Predict(cv::Mat* im, FaceDetectionResult* result, @@ -66,26 +67,26 @@ RetinaFace模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **variance**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0] -> > * **min_sizes**(vector<vector<int>>): retinaface中的anchor的宽高设置,默认是 {{16, 32}, {64, 128}, {256, 512}},分别和步长8、16和32对应 -> > * **downsample_strides**(vector<int>): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] -> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for FaceDetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **variance**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [0, 0, 0] +> > * **min_sizes**(vector<vector<int>>): Set width and height of anchor in retinaface. Default {{16, 32}, {64, 128}, {256, 512}}, corresponding to step size 8, 16 and 32 +> > * **downsample_strides**(vector<int>): This parameter is used to change the down-sampling multiple of the feature map that generates anchor, containing three integer elements that represent the default down-sampling multiple for generating anchor. Default value [8, 16, 32] +> > * **landmarks_per_face**(int): Specify the number of keypoints in the face detected. Default 5 + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/retinaface/cpp/README_CN.md b/examples/vision/facedet/retinaface/cpp/README_CN.md new file mode 100644 index 0000000000..1f0621c321 --- /dev/null +++ b/examples/vision/facedet/retinaface/cpp/README_CN.md @@ -0,0 +1,92 @@ +[English](README.md) | 简体中文 +# RetinaFace C++部署示例 + +本目录下提供`infer.cc`快速完成RetinaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的RetinaFace模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-640-640.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + + +# CPU推理 +./infer_demo Pytorch_RetinaFace_mobile0.25-640-640.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo Pytorch_RetinaFace_mobile0.25-640-640.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo Pytorch_RetinaFace_mobile0.25-640-640.onnx test_lite_face_detector_3.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +## RetinaFace C++接口 + +### RetinaFace类 + +```c++ +fastdeploy::vision::facedet::RetinaFace( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +RetinaFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> RetinaFace::Predict(cv::Mat* im, FaceDetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **variance**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0] +> > * **min_sizes**(vector<vector<int>>): retinaface中的anchor的宽高设置,默认是 {{16, 32}, {64, 128}, {256, 512}},分别和步长8、16和32对应 +> > * **downsample_strides**(vector<int>): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] +> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/retinaface/python/README.md b/examples/vision/facedet/retinaface/python/README.md index 88136301e6..9a99974710 100644 --- a/examples/vision/facedet/retinaface/python/README.md +++ b/examples/vision/facedet/retinaface/python/README.md @@ -1,81 +1,82 @@ -# RetinaFace Python部署示例 +English | [简体中文](README_CN.md) +# RetinaFace Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成RetinaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of RetinaFace on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision//retinaface/python/ -#下载retinaface模型文件和测试图片 +# Download retinaface model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-640-640.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference python infer.py --model Pytorch_RetinaFace_mobile0.25-640-640.onnx --image test_lite_face_detector_3.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model Pytorch_RetinaFace_mobile0.25-640-640.onnx --image test_lite_face_detector_3.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model Pytorch_RetinaFace_mobile0.25-640-640.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## RetinaFace Python接口 +## RetinaFace Python Interface ```python fastdeploy.vision.facedet.RetinaFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -RetinaFace模型加载和初始化,其中model_file为导出的ONNX模型格式 +RetinaFace model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > RetinaFace.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **variance**(list[float]): 通过此参数可以指定retinaface中的方差variance值,默认是[0.1,0.2], 一般不用修改. -> > * **min_sizes**(list[list[int]]): retinaface中的anchor的宽高设置,默认是 {{16, 32}, {64, 128}, {256, 512}},分别和步长8、16和32对应 -> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] -> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **variance**(list[float]): Specify the variance value in retinaface. Default [0.1,0.2]. Normally without modification. +> > * **min_sizes**(list[list[int]]): Set width and height of anchor in retinaface. Default {{16, 32}, {64, 128}, {256, 512}}, corresponding to the step size 8, 16 and 32 +> > * **downsample_strides**(list[int]): This parameter is used to change the down-sampling multiple of the feature map that generates anchor, containing three integer elements that represent the default down-sampling multiple for generating anchor. Default value [8, 16, 32] +> > * **landmarks_per_face**(int): Specify the number of keypoints in the face detected. Default 5. -## 其它文档 +## Other Documents -- [RetinaFace 模型介绍](..) -- [RetinaFace C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [RetinaFace Model Description](..) +- [RetinaFace C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/retinaface/python/README_CN.md b/examples/vision/facedet/retinaface/python/README_CN.md new file mode 100644 index 0000000000..a4a32739b4 --- /dev/null +++ b/examples/vision/facedet/retinaface/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# RetinaFace Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成RetinaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision//retinaface/python/ + +#下载retinaface模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/Pytorch_RetinaFace_mobile0.25-640-640.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + +# CPU推理 +python infer.py --model Pytorch_RetinaFace_mobile0.25-640-640.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model Pytorch_RetinaFace_mobile0.25-640-640.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model Pytorch_RetinaFace_mobile0.25-640-640.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## RetinaFace Python接口 + +```python +fastdeploy.vision.facedet.RetinaFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +RetinaFace模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> RetinaFace.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **variance**(list[float]): 通过此参数可以指定retinaface中的方差variance值,默认是[0.1,0.2], 一般不用修改. +> > * **min_sizes**(list[list[int]]): retinaface中的anchor的宽高设置,默认是 {{16, 32}, {64, 128}, {256, 512}},分别和步长8、16和32对应 +> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] +> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. + + + +## 其它文档 + +- [RetinaFace 模型介绍](..) +- [RetinaFace C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/scrfd/README.md b/examples/vision/facedet/scrfd/README.md index a2aaffce87..8a06ef8ed5 100644 --- a/examples/vision/facedet/scrfd/README.md +++ b/examples/vision/facedet/scrfd/README.md @@ -1,39 +1,40 @@ -# SCRFD准备部署模型 +English | [简体中文](README_CN.md) +# SCRFD Ready-to-deploy Model - [SCRFD](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) - - (1)[官方库](https://github.com/deepinsight/insightface/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)开发者基于自己数据训练的SCRFD模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + - (1)The *.pt provided by the [Official Library](https://github.com/deepinsight/insightface/) can be deployed after the [Export ONNX Model](#导出ONNX模型) to complete the deployment; + - (2)As for SCRFD model trained on customized data, please follow [Export ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B) to complete the deployment. -## 导出ONNX模型 +## Export ONNX Model ```bash - #下载scrfd模型文件 + # Download scrfd model files e.g. download from https://onedrive.live.com/?authkey=%21ABbFJx2JMhNjhNA&id=4A83B6B633B029CC%215542&cid=4A83B6B633B029CC - # 安装官方库配置环境,此版本导出环境为: - - 手动配置环境 + # Install the official library to configure the environment. This version should be exported in the following environment: + - Configure the environment manually torch==1.8.0 mmcv==1.3.5 mmdet==2.7.0 - - 通过docker配置 + - Configure via docker docker pull qyjdefdocker/onnx-scrfd-converter:v0.3 - # 导出onnx格式文件 - - 手动生成 + # Export files in onnx format + - Manual generation python tools/scrfd2onnx.py configs/scrfd/scrfd_500m.py weights/scrfd_500m.pth --shape 640 --input-img face-xxx.jpg - docker - docker的onnx目录中已有生成好的onnx文件 + onnx files are in docker's onnx directory ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Models -为了方便开发者的测试,下面提供了SCRFD导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by SCRFD are provided below. Developers can download and use them directly. (The accuracy of the models in the table is sourced from the official library) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [SCRFD-500M-kps-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape160x160.onnx) | 2.5MB | - | | [SCRFD-500M-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_shape160x160.onnx) | 2.2MB | - | @@ -57,12 +58,12 @@ | [SCRFD-10G-kps-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_bnkps_shape1280x1280.onnx) | 17MB | - | | [SCRFD-10G-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_shape1280x1280.onnx) | 15MB | - | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployement](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[SCRFD CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) 编写 +- This tutorial and related code are written based on [SCRFD CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) diff --git a/examples/vision/facedet/scrfd/README_CN.md b/examples/vision/facedet/scrfd/README_CN.md new file mode 100644 index 0000000000..16b6a232e8 --- /dev/null +++ b/examples/vision/facedet/scrfd/README_CN.md @@ -0,0 +1,69 @@ +[English](README.md) | 简体中文 +# SCRFD准备部署模型 + + +- [SCRFD](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) + - (1)[官方库](https://github.com/deepinsight/insightface/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)开发者基于自己数据训练的SCRFD模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + + +## 导出ONNX模型 + + ```bash + #下载scrfd模型文件 + e.g. download from https://onedrive.live.com/?authkey=%21ABbFJx2JMhNjhNA&id=4A83B6B633B029CC%215542&cid=4A83B6B633B029CC + + # 安装官方库配置环境,此版本导出环境为: + - 手动配置环境 + torch==1.8.0 + mmcv==1.3.5 + mmdet==2.7.0 + + - 通过docker配置 + docker pull qyjdefdocker/onnx-scrfd-converter:v0.3 + + # 导出onnx格式文件 + - 手动生成 + python tools/scrfd2onnx.py configs/scrfd/scrfd_500m.py weights/scrfd_500m.pth --shape 640 --input-img face-xxx.jpg + + - docker + docker的onnx目录中已有生成好的onnx文件 + + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了SCRFD导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [SCRFD-500M-kps-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape160x160.onnx) | 2.5MB | - | +| [SCRFD-500M-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_shape160x160.onnx) | 2.2MB | - | +| [SCRFD-500M-kps-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape320x320.onnx) | 2.5MB | - | +| [SCRFD-500M-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_shape320x320.onnx) | 2.2MB | - | +| [SCRFD-500M-kps-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape640x640.onnx) | 2.5MB | 90.97% | +| [SCRFD-500M-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_shape640x640.onnx) | 2.2MB | 90.57% | +| [SCRFD-1G-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_1g_shape160x160.onnx ) | 2.5MB | - | +| [SCRFD-1G-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_1g_shape320x320.onnx) | 2.5MB | - | +| [SCRFD-1G-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_1g_shape640x640.onnx) | 2.5MB | 92.38% | +| [SCRFD-2.5G-kps-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_2.5g_bnkps_shape160x160.onnx) | 3.2MB | - | +| [SCRFD-2.5G-160](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_2.5g_shape160x160.onnx) | 2.6MB | - | +| [SCRFD-2.5G-kps-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_2.5g_bnkps_shape320x320.onnx) | 3.2MB | - | +| [SCRFD-2.5G-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_2.5g_shape320x320.onnx) | 2.6MB | - | +| [SCRFD-2.5G-kps-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_2.5g_bnkps_shape640x640.onnx) | 3.2MB | 93.8% | +| [SCRFD-2.5G-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_2.5g_shape640x640.onnx) | 2.6MB | 93.78% | +| [SCRFD-10G-kps-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_bnkps_shape320x320.onnx) | 17MB | - | +| [SCRFD-10G-320](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_shape320x320.onnx) | 15MB | - | +| [SCRFD-10G-kps-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_bnkps_shape640x640.onnx) | 17MB | 95.4% | +| [SCRFD-10G-640](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_shape640x640.onnx) | 15MB | 95.16% | +| [SCRFD-10G-kps-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_bnkps_shape1280x1280.onnx) | 17MB | - | +| [SCRFD-10G-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_10g_shape1280x1280.onnx) | 15MB | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[SCRFD CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) 编写 diff --git a/examples/vision/facedet/scrfd/android/README.md b/examples/vision/facedet/scrfd/android/README.md index 000c8a419e..289d10063b 100644 --- a/examples/vision/facedet/scrfd/android/README.md +++ b/examples/vision/facedet/scrfd/android/README.md @@ -1,84 +1,85 @@ -# 目标检测 SCRFD Android Demo 使用文档 +English | [简体中文](README_CN.md) +# Target Detection SCRFD Android Demo Tutorial -在 Android 上实现实时的人脸检测功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 +Real-time target detection on Android. This Demo is simple to use for everyone. For example, you can run your own trained model in the Demo. -## 环境准备 +## Prepare the Environment -1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 -2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` +1. Install Android Studio in your local environment. Refer to [Android Stuido Official Website](https://developer.android.com/studio) for detailed tutorial. +2. Prepare an Android phone and turn on the USB debug mode: `Settings -> Find developer options -> Open developer options and USB debug mode` -## 部署步骤 +## Deployment steps -1. 目标检测 SCRFD Demo 位于 `fastdeploy/examples/vision/facedet/scrfd/android` 目录 -2. 用 Android Studio 打开 scrfd/android 工程 -3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) +1. The target detection SCRFD Demo is located in the `fastdeploy/examples/vision/facedet/scrfd/android` directory +2. Use Android Studio to open the scrfd/android project +3. Connect the phone to the computer, turn on USB debug mode and file transfer mode, and connect your phone to Android Studio (allow the phone to install software from USB)

image

-> **注意:** ->> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 +> **Attention:** +>> If you encounter an NDK configuration error during import, compilation or running, open ` File > Project Structure > SDK Location` and change the path of SDK configured by the `Andriod SDK location`. -4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) -成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的人脸并绘制框;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 +4. Click the Run button to automatically compile the APP and install it to the phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files. Internet is required). +The final effect is as follows. Figure 1: Install the APP on the phone; Figure 2: The effect when opening the APP. It will automatically recognize and mark the objects in the image; Figure 3: APP setting option. Click setting in the upper right corner and modify your options. - | APP 图标 | APP 效果 | APP设置项 + | APP Icon | APP Effect | APP Settings | --- | --- | --- | | image | image | image | -## SCRFD Java API 说明 -- 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。PaddleSegModel初始化参数说明如下: - - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel - - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams - - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 +## SCRFD Java API Description +- Model initialized API: The initialized API contains two ways: Firstly, initialize directly through the constructor. Secondly, initialize at the appropriate program node by calling the init function. PicoDet initialization parameters are as follows: + - modelFile: String. Model file path in paddle format, such as model.pdmodel + - paramFile: String. Parameter file path in paddle format, such as model.pdiparams + - option: RuntimeOption. Optional parameter for model initialization. Default runtime options if not passing the parameter. ```java -// 构造函数: constructor w/o label file +// Constructor: constructor w/o label file public SCRFD(); // 空构造函数,之后可以调用init初始化 public SCRFD(String modelFile, String paramsFile); public SCRFD(String modelFile, String paramsFile, RuntimeOption option); -// 手动调用init初始化: call init manually w/o label file +// Call init manually for initialization: call init manually w/o label file public boolean init(String modelFile, String paramsFile, RuntimeOption option); ``` -- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +- Model Prediction API: The Model Prediction API contains an API for direct prediction and an API for visualization. In direct prediction, we do not save the image and render the result on Bitmap. Instead, we merely predict the inference result. For prediction and visualization, the results are both predicted and visualized, the visualized images are saved to the specified path, and the visualized results are rendered in Bitmap (Now Bitmap in ARGB8888 format is supported). Afterward, the Bitmap can be displayed on the camera. ```java -// 直接预测:不保存图片以及不渲染结果到Bitmap上 +// Direct prediction: No image saving and no result rendering to Bitmap public FaceDetectionResult predict(Bitmap ARGB8888Bitmap); -public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // 设置置信度阈值和NMS阈值 -// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // Set confidence threshold and NMS threshold +// Prediction and visualization: Predict and visualize the results, save the visualized image to the specified path, and render the visualized results on Bitmap public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float confThreshold, float nmsIouThreshold); -public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // 只渲染 不保存图片 +public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // Render without saving images ``` -- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +- Model resource release API: Call release() API to release model resources. Return true for successful release and false for failure; call initialized() to determine whether the model was initialized successfully, with true indicating successful initialization and false indicating failure. ```java -public boolean release(); // 释放native资源 -public boolean initialized(); // 检查是否初始化成功 +public boolean release(); // Release native resources +public boolean initialized(); // Check if initialization is successful ``` -- RuntimeOption设置说明 +- RuntimeOption settings ```java -public void enableLiteFp16(); // 开启fp16精度推理 -public void disableLiteFP16(); // 关闭fp16精度推理 -public void setCpuThreadNum(int threadNum); // 设置线程数 -public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 -public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +public void enableLiteFp16(); // Enable fp16 accuracy inference +public void disableLiteFP16(); // Disable fp16 accuracy inference +public void setCpuThreadNum(int threadNum); // Set thread numbers +public void setLitePowerMode(LitePowerMode mode); // Set power mode +public void setLitePowerMode(String modeStr); // Set power mode through character string ``` -- 模型结果SegmentationResult说明 +- Model SegmentationResult ```java public class FaceDetectionResult { - public float[][] mBoxes; // [n,4] 检测框 (x1,y1,x2,y2) - public float[] mScores; // [n] 每个检测框得分(置信度,概率值) - public float[][] mLandmarks; // [nx?,2] 每个检测到的人脸对应关键点 - int mLandmarksPerFace = 0; // 每个人脸对应的关键点个数 - public boolean initialized(); // 检测结果是否有效 + public float[][] mBoxes; // [n,4] Detection box (x1,y1,x2,y2) + public float[] mScores; // [n] Score of each detection box (confidence, probability) + public float[][] mLandmarks; // [nx?,2] Each detected face keypoints + int mLandmarksPerFace = 0; // Number of detected face keypoints + public boolean initialized(); // Whether the result is valid } ``` -其他参考:C++/Python对应的FaceDetectionResult说明: [api/vision_results/face_detection_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/face_detection_result.md) +Refer to [api/vision_results/face_detection_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/face_detection_result.md) for C++/Python DetectionResult -- 模型调用示例1:使用构造函数以及默认的RuntimeOption +- Model Calling Example 1: Using Constructor and the default RuntimeOption ```java import java.nio.ByteBuffer; import android.graphics.Bitmap; @@ -87,62 +88,62 @@ import android.opengl.GLES20; import com.baidu.paddle.fastdeploy.vision.FaceDetectionResult; import com.baidu.paddle.fastdeploy.vision.facedet.SCRFD; -// 初始化模型 +// Initialize the model SCRFD model = new SCRFD( "scrfd_500m_bnkps_shape320x320_pd/model.pdmodel", "scrfd_500m_bnkps_shape320x320_pd/model.pdiparams"); -// 读取图片: 以下仅为读取Bitmap的伪代码 +// Read the image: The following is merely the pseudo code to read 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); -// 直接预测返回 FaceDetectionResult +// Return FaceDetectionResult after direct prediction FaceDetectionResult result = model.predict(ARGB8888ImageBitmap); -// 释放模型资源 +// Release model resources model.release(); ``` -- 模型调用示例2: 在合适的程序节点,手动调用init,并自定义RuntimeOption +- Model calling example 2: Manually call init at the appropriate program node and self-define RuntimeOption ```java -// import 同上 ... +// import is as the above... import com.baidu.paddle.fastdeploy.RuntimeOption; import com.baidu.paddle.fastdeploy.LitePowerMode; import com.baidu.paddle.fastdeploy.vision.FaceDetectionResult; import com.baidu.paddle.fastdeploy.vision.facedet.SCRFD; -// 新建空模型 +// Create an empty model SCRFD model = new SCRFD(); -// 模型路径 +// Model path String modelFile = "scrfd_500m_bnkps_shape320x320_pd/model.pdmodel"; String paramFile = "scrfd_500m_bnkps_shape320x320_pd/model.pdiparams"; -// 指定RuntimeOption +// Specify RuntimeOption RuntimeOption option = new RuntimeOption(); option.setCpuThreadNum(2); option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); option.enableLiteFp16(); -// 使用init函数初始化 +// Use init function for initialization model.init(modelFile, paramFile, option); -// Bitmap读取、模型预测、资源释放 同上 ... +// Bitmap reading, model prediction, and resource release are as above ... ``` -更详细的用法请参考 [FaceDetMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetMainActivity.java) 中的用法 +Refer to [FaceDetMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetMainActivity.java) for more details -## 替换 FastDeploy SDK和模型 -替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/scrfd_500m_bnkps_shape320x320_pd`。 -- 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: - - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +## Replace FastDeploy SDK and Models +It’s simple to replace the FastDeploy prediction library and models. The prediction library is located at `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` represents the version of your prediction library. The models are located at `app/src/main/assets/models/scrfd_500m_bnkps_shape320x320_pd`。 +- Replace the FastDeploy Android SDK: Download or compile the latest FastDeploy Android SDK, unzip and place it in the `app/libs` directory; For detailed configuration, refer to + - [FastDeploy Java SDK in Android](../../../../../java/android/) -- 替换SCRFD模型的步骤: - - 通过X2Paddle导出其他版本的SCRFD模型,请参考 [SCRFD文档](../README.md) 以及 [X2Paddle](https://github.com/PaddlePaddle/X2Paddle) - - 将您的SCRFD模型放在 `app/src/main/assets/models` 目录下; - - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +- Steps to replace SCRFD models: + - Other SCRFD models exported by X2Paddle, refer to [SCRFD document](../README.md) and [X2Paddle](https://github.com/PaddlePaddle/X2Paddle) + - Put your SCRFD model in `app/src/main/assets/models` directory; + - Modify the default value of the model path in `app/src/main/res/values/strings.xml`. For example, ```xml - + models/scrfd_500m_bnkps_shape320x320_pd ``` -## 更多参考文档 -如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: -- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) -- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) +## More Reference Documents +For more FastDeploy Java API documentes and how to access FastDeploy C++ API via JNI, refer to: +- [FastDeploy Java SDK in Android](../../../../../java/android/) +- [FastDeploy C++ SDK in Android](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/facedet/scrfd/android/README_CN.md b/examples/vision/facedet/scrfd/android/README_CN.md new file mode 100644 index 0000000000..bcf6b7f7f3 --- /dev/null +++ b/examples/vision/facedet/scrfd/android/README_CN.md @@ -0,0 +1,149 @@ +[English](README.md) | 简体中文 +# 目标检测 SCRFD Android Demo 使用文档 + +在 Android 上实现实时的人脸检测功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 + +## 环境准备 + +1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 +2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` + +## 部署步骤 + +1. 目标检测 SCRFD Demo 位于 `fastdeploy/examples/vision/facedet/scrfd/android` 目录 +2. 用 Android Studio 打开 scrfd/android 工程 +3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) + +

+image +

+ +> **注意:** +>> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 + +4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) +成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的人脸并绘制框;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 + + | APP 图标 | APP 效果 | APP设置项 + | --- | --- | --- | + | image | image | image | + +## SCRFD Java API 说明 +- 模型初始化 API: 模型初始化API包含两种方式,方式一是通过构造函数直接初始化;方式二是,通过调用init函数,在合适的程序节点进行初始化。PaddleSegModel初始化参数说明如下: + - modelFile: String, paddle格式的模型文件路径,如 model.pdmodel + - paramFile: String, paddle格式的参数文件路径,如 model.pdiparams + - option: RuntimeOption,可选参数,模型初始化option。如果不传入该参数则会使用默认的运行时选项。 + +```java +// 构造函数: constructor w/o label file +public SCRFD(); // 空构造函数,之后可以调用init初始化 +public SCRFD(String modelFile, String paramsFile); +public SCRFD(String modelFile, String paramsFile, RuntimeOption option); +// 手动调用init初始化: call init manually w/o label file +public boolean init(String modelFile, String paramsFile, RuntimeOption option); +``` +- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +```java +// 直接预测:不保存图片以及不渲染结果到Bitmap上 +public FaceDetectionResult predict(Bitmap ARGB8888Bitmap); +public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // 设置置信度阈值和NMS阈值 +// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float confThreshold, float nmsIouThreshold); +public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // 只渲染 不保存图片 +``` +- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +```java +public boolean release(); // 释放native资源 +public boolean initialized(); // 检查是否初始化成功 +``` + +- RuntimeOption设置说明 +```java +public void enableLiteFp16(); // 开启fp16精度推理 +public void disableLiteFP16(); // 关闭fp16精度推理 +public void setCpuThreadNum(int threadNum); // 设置线程数 +public void setLitePowerMode(LitePowerMode mode); // 设置能耗模式 +public void setLitePowerMode(String modeStr); // 通过字符串形式设置能耗模式 +``` + +- 模型结果SegmentationResult说明 +```java +public class FaceDetectionResult { + public float[][] mBoxes; // [n,4] 检测框 (x1,y1,x2,y2) + public float[] mScores; // [n] 每个检测框得分(置信度,概率值) + public float[][] mLandmarks; // [nx?,2] 每个检测到的人脸对应关键点 + int mLandmarksPerFace = 0; // 每个人脸对应的关键点个数 + public boolean initialized(); // 检测结果是否有效 +} +``` +其他参考:C++/Python对应的FaceDetectionResult说明: [api/vision_results/face_detection_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/face_detection_result.md) + + +- 模型调用示例1:使用构造函数以及默认的RuntimeOption +```java +import java.nio.ByteBuffer; +import android.graphics.Bitmap; +import android.opengl.GLES20; + +import com.baidu.paddle.fastdeploy.vision.FaceDetectionResult; +import com.baidu.paddle.fastdeploy.vision.facedet.SCRFD; + +// 初始化模型 +SCRFD model = new SCRFD( + "scrfd_500m_bnkps_shape320x320_pd/model.pdmodel", + "scrfd_500m_bnkps_shape320x320_pd/model.pdiparams"); + +// 读取图片: 以下仅为读取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); + +// 直接预测返回 FaceDetectionResult +FaceDetectionResult result = model.predict(ARGB8888ImageBitmap); + +// 释放模型资源 +model.release(); +``` + +- 模型调用示例2: 在合适的程序节点,手动调用init,并自定义RuntimeOption +```java +// import 同上 ... +import com.baidu.paddle.fastdeploy.RuntimeOption; +import com.baidu.paddle.fastdeploy.LitePowerMode; +import com.baidu.paddle.fastdeploy.vision.FaceDetectionResult; +import com.baidu.paddle.fastdeploy.vision.facedet.SCRFD; +// 新建空模型 +SCRFD model = new SCRFD(); +// 模型路径 +String modelFile = "scrfd_500m_bnkps_shape320x320_pd/model.pdmodel"; +String paramFile = "scrfd_500m_bnkps_shape320x320_pd/model.pdiparams"; +// 指定RuntimeOption +RuntimeOption option = new RuntimeOption(); +option.setCpuThreadNum(2); +option.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); +option.enableLiteFp16(); +// 使用init函数初始化 +model.init(modelFile, paramFile, option); +// Bitmap读取、模型预测、资源释放 同上 ... +``` +更详细的用法请参考 [FaceDetMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetMainActivity.java) 中的用法 + +## 替换 FastDeploy SDK和模型 +替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/scrfd_500m_bnkps_shape320x320_pd`。 +- 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: + - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) + +- 替换SCRFD模型的步骤: + - 通过X2Paddle导出其他版本的SCRFD模型,请参考 [SCRFD文档](../README.md) 以及 [X2Paddle](https://github.com/PaddlePaddle/X2Paddle) + - 将您的SCRFD模型放在 `app/src/main/assets/models` 目录下; + - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +```xml + +models/scrfd_500m_bnkps_shape320x320_pd +``` + +## 更多参考文档 +如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: +- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/facedet/scrfd/cpp/README.md b/examples/vision/facedet/scrfd/cpp/README.md index b59acc1edf..e3110c8655 100644 --- a/examples/vision/facedet/scrfd/cpp/README.md +++ b/examples/vision/facedet/scrfd/cpp/README.md @@ -1,46 +1,47 @@ -# SCRFD C++部署示例 +English | [简体中文](README_CN.md) +# SCRFD C++ Deployment Example -本目录下提供`infer.cc`快速完成SCRFD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of SCRFD on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的SCRFD模型文件和测试图片 +# Download the official converted SCRFD model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape640x640.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference ./infer_demo scrfd_500m_bnkps_shape640x640.onnx test_lite_face_detector_3.jpg 0 -# GPU推理 +# GPU inference ./infer_demo scrfd_500m_bnkps_shape640x640.onnx test_lite_face_detector_3.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo scrfd_500m_bnkps_shape640x640.onnx test_lite_face_detector_3.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## SCRFD C++接口 +## SCRFD C++ Interface -### SCRFD类 +### SCRFD Class ```c++ fastdeploy::vision::facedet::SCRFD( @@ -50,16 +51,16 @@ fastdeploy::vision::facedet::SCRFD( const ModelFormat& model_format = ModelFormat::ONNX) ``` -SCRFD模型加载和初始化,其中model_file为导出的ONNX模型格式。 +SCRFD model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > SCRFD::Predict(cv::Mat* im, FaceDetectionResult* result, @@ -67,30 +68,30 @@ SCRFD模型加载和初始化,其中model_file为导出的ONNX模型格式。 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` -> > * **downsample_strides**(vector<int>): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] -> > * **landmarks_per_face**(int): 如果使用具有人脸关键点的输出, 可以修改人脸关键点数量, 默认值为`landmarks_per_face=5` -> > * **use_kps**(bool): 通过此参数可以设置模型是否使用关键点,如果ONNX文件没有关键点输出则需要将`use_kps=false`, 并将`landmarks_per_face=0`, 默认值为`use_kps=true` -> > * **num_anchors**(int): 通过此参数可以设置每个锚点预测的anchor数量, 需要跟进训练模型的参数设定, 默认值为`num_anchors=2` - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for FaceDetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding or not. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `stris_mini_pad` member variable. Default `stride=32` +> > * **downsample_strides**(vector<int>): This parameter is used to change the down-sampling multiple of the feature map that generates anchor, containing three integer elements that represent the default down-sampling multiple for generating anchor. Default [8, 16, 32] +> > * **landmarks_per_face**(int): Modify the number of face keypoints if we use an output with face keypoints. Default `landmarks_per_face=5` +> > * **use_kps**(bool): Whether to use keypoints or not. If the ONNX file has no keypoint output, set `use_kps=false` and `landmarks_per_face=0`. Default `use_kps=true` +> > * **num_anchors**(int): Set the number predicted by each anchor. The parameters of the trained model need modification accordingly. Default `num_anchors=2` + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/scrfd/cpp/README_CN.md b/examples/vision/facedet/scrfd/cpp/README_CN.md new file mode 100644 index 0000000000..1c01173b24 --- /dev/null +++ b/examples/vision/facedet/scrfd/cpp/README_CN.md @@ -0,0 +1,97 @@ +[English](README.md) | 简体中文 +# SCRFD C++部署示例 + +本目录下提供`infer.cc`快速完成SCRFD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的SCRFD模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape640x640.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + + +# CPU推理 +./infer_demo scrfd_500m_bnkps_shape640x640.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo scrfd_500m_bnkps_shape640x640.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo scrfd_500m_bnkps_shape640x640.onnx test_lite_face_detector_3.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## SCRFD C++接口 + +### SCRFD类 + +```c++ +fastdeploy::vision::facedet::SCRFD( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +SCRFD模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> SCRFD::Predict(cv::Mat* im, FaceDetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`stris_mini_pad`成员变量使用, 默认值为`stride=32` +> > * **downsample_strides**(vector<int>): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] +> > * **landmarks_per_face**(int): 如果使用具有人脸关键点的输出, 可以修改人脸关键点数量, 默认值为`landmarks_per_face=5` +> > * **use_kps**(bool): 通过此参数可以设置模型是否使用关键点,如果ONNX文件没有关键点输出则需要将`use_kps=false`, 并将`landmarks_per_face=0`, 默认值为`use_kps=true` +> > * **num_anchors**(int): 通过此参数可以设置每个锚点预测的anchor数量, 需要跟进训练模型的参数设定, 默认值为`num_anchors=2` + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/scrfd/python/README.md b/examples/vision/facedet/scrfd/python/README.md index d437fac96f..924913e332 100644 --- a/examples/vision/facedet/scrfd/python/README.md +++ b/examples/vision/facedet/scrfd/python/README.md @@ -1,84 +1,84 @@ -# SCRFD Python部署示例 +English | [简体中文](README_CN.md) +# SCRFD Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成SCRFD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishes the deployment of SCRFD on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/facedet/scrfd/python/ -#下载SCRFD模型文件和测试图片 +# Download SCRFD model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape640x640.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference python infer.py --model scrfd_500m_bnkps_shape640x640.onnx --image test_lite_face_detector_3.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model scrfd_500m_bnkps_shape640x640.onnx --image test_lite_face_detector_3.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model scrfd_500m_bnkps_shape640x640.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## SCRFD Python接口 +## SCRFD Python Interface ```python fastdeploy.vision.facedet.SCRFD(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -SCRFD模型加载和初始化,其中model_file为导出的ONNX模型格式 +SCRFD model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > SCRFD.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` -> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] -> > * **landmarks_per_face**(int): 如果使用具有人脸关键点的输出, 可以修改人脸关键点数量, 默认值为`landmarks_per_face=5` -> > * **use_kps**(bool): 通过此参数可以设置模型是否使用关键点,如果ONNX文件没有关键点输出则需要将`use_kps=False`, 并将`landmarks_per_face=0`, 默认值为`use_kps=True` -> > * **num_anchors**(int): 通过此参数可以设置每个锚点预测的anchor数量, 需要跟进训练模型的参数设定, 默认值为`num_anchors=2` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding or not. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `stris_mini_padide` member variable. Default`stride=32` +> > * **downsample_strides**(list[int]): This parameter is used to change the down-sampling multiple of the feature map that generates anchor, containing three integer elements that represent the default down-sampling multiple for generating anchor. Default [8, 16, 32] +> > * **landmarks_per_face**(int): Modify the number of face keypoints if we use an output with face keypoints. Default `landmarks_per_face=5` +> > * **use_kps**(bool): Whether to use keypoints or not. If the ONNX file has no keypoint output, set `use_kps=False` and `landmarks_per_face=0`. Default `use_kps=True` +> > * **num_anchors**(int): Set the number predicted by each anchor. The parameters of the trained model need modification accordingly. Default `num_anchors=2` -## 其它文档 +## Other Documents -- [SCRFD 模型介绍](..) -- [SCRFD C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [SCRFD Model Description](..) +- [SCRFD C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/scrfd/python/README_CN.md b/examples/vision/facedet/scrfd/python/README_CN.md new file mode 100644 index 0000000000..e1a2689634 --- /dev/null +++ b/examples/vision/facedet/scrfd/python/README_CN.md @@ -0,0 +1,85 @@ +[English](README.md) | 简体中文 +# SCRFD Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成SCRFD在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/facedet/scrfd/python/ + +#下载SCRFD模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/scrfd_500m_bnkps_shape640x640.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + +# CPU推理 +python infer.py --model scrfd_500m_bnkps_shape640x640.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model scrfd_500m_bnkps_shape640x640.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model scrfd_500m_bnkps_shape640x640.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## SCRFD Python接口 + +```python +fastdeploy.vision.facedet.SCRFD(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +SCRFD模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> SCRFD.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`stris_mini_padide`成员变量使用, 默认值为`stride=32` +> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32] +> > * **landmarks_per_face**(int): 如果使用具有人脸关键点的输出, 可以修改人脸关键点数量, 默认值为`landmarks_per_face=5` +> > * **use_kps**(bool): 通过此参数可以设置模型是否使用关键点,如果ONNX文件没有关键点输出则需要将`use_kps=False`, 并将`landmarks_per_face=0`, 默认值为`use_kps=True` +> > * **num_anchors**(int): 通过此参数可以设置每个锚点预测的anchor数量, 需要跟进训练模型的参数设定, 默认值为`num_anchors=2` + + +## 其它文档 + +- [SCRFD 模型介绍](..) +- [SCRFD C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/scrfd/rknpu2/README.md b/examples/vision/facedet/scrfd/rknpu2/README.md index b77afe3620..a70dff7e89 100644 --- a/examples/vision/facedet/scrfd/rknpu2/README.md +++ b/examples/vision/facedet/scrfd/rknpu2/README.md @@ -1,10 +1,11 @@ -# SCRFD RKNPU2部署模型 +English | [简体中文](README_CN.md) +# SCRFD RKNPU2 Deployment Models -本教程提供SCRFD模型在RKNPU2环境下的部署,模型的详细介绍已经ONNX模型的下载请查看[模型介绍文档](../README.md)。 +This tutorial demonstrates the deployment of SCRFD models in RKNPU2. For model description and download of ONNX models, refer to [Model Description](../README.md)。 -## ONNX模型转换RKNN模型 +## From ONNX model to RKNN model -下面以scrfd_500m_bnkps_shape640x640为例子,快速的转换SCRFD ONNX模型为RKNN量化模型。 以下命令在Ubuntu18.04下执行: +Taking scrfd_500m_bnkps_shape640x640 as an example, the following commands in Ubuntu18.0 demonstrate how to fast convert SCRFD ONNX models to RKNN quantification models: ```bash wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/scrfd_500m_bnkps_shape640x640.zip unzip scrfd_500m_bnkps_shape640x640.zip @@ -15,12 +16,12 @@ python /Path/To/FastDeploy/tools/rknpu2/export.py \ -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python/README.md) -- [C++部署](cpp/README.md) +- [Python Deployment](python/README.md) +- [C++ Deployment](cpp/README.md) -## 版本说明 +## Release Note -- 本版本文档和代码基于[SCRFD CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) 编写 +- This document and code are written based on [SCRFD CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) diff --git a/examples/vision/facedet/scrfd/rknpu2/README_CN.md b/examples/vision/facedet/scrfd/rknpu2/README_CN.md new file mode 100644 index 0000000000..00a8c08440 --- /dev/null +++ b/examples/vision/facedet/scrfd/rknpu2/README_CN.md @@ -0,0 +1,27 @@ +[English](README.md) | 简体中文 +# SCRFD RKNPU2部署模型 + +本教程提供SCRFD模型在RKNPU2环境下的部署,模型的详细介绍已经ONNX模型的下载请查看[模型介绍文档](../README.md)。 + +## ONNX模型转换RKNN模型 + +下面以scrfd_500m_bnkps_shape640x640为例子,快速的转换SCRFD ONNX模型为RKNN量化模型。 以下命令在Ubuntu18.04下执行: +```bash +wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/scrfd_500m_bnkps_shape640x640.zip +unzip scrfd_500m_bnkps_shape640x640.zip +python /Path/To/FastDeploy/tools/rknpu2/export.py \ + --config_path tools/rknpu2/config/scrfd.yaml \ + --target_platform rk3588 +``` + + + +## 详细部署文档 + +- [Python部署](python/README.md) +- [C++部署](cpp/README.md) + + +## 版本说明 + +- 本版本文档和代码基于[SCRFD CommitID:17cdeab](https://github.com/deepinsight/insightface/tree/17cdeab12a35efcebc2660453a8cbeae96e20950) 编写 diff --git a/examples/vision/facedet/ultraface/README.md b/examples/vision/facedet/ultraface/README.md index 222dde4956..ced821ed82 100644 --- a/examples/vision/facedet/ultraface/README.md +++ b/examples/vision/facedet/ultraface/README.md @@ -1,28 +1,29 @@ -# UltraFace准备部署模型 +English | [简体中文](README_CN.md) +# UltraFace Ready-to-deploy Model - [UltraFace](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) - - (1)[官方库](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/)中提供的*.onnx可下载, 也可以通过下面模型链接下载并进行部署 - - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + - (1)The *.onnx provided by the [Official Library](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/) can be downloaded directly or through the following model link. + - (2)As for the model trained on customized data, export the onnx model and then refer to [Detailed Deployment Tutorials](#详细部署文档) to complete the deployment. -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Models -为了方便开发者的测试,下面提供了UltraFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by UltraFace are provided below. Developers can download and use them directly. (The accuracy of the models in the table is sourced from the official library) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [RFB-320](https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320.onnx) | 1.3MB | 78.7 | | [RFB-320-sim](https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320-sim.onnx) | 1.2MB | 78.7 | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[UltraFace CommitID:dffdddd](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) 编写 +- This tutorial and related code are written based on [UltraFace CommitID:dffdddd](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) diff --git a/examples/vision/facedet/ultraface/README_CN.md b/examples/vision/facedet/ultraface/README_CN.md new file mode 100644 index 0000000000..0d4604d761 --- /dev/null +++ b/examples/vision/facedet/ultraface/README_CN.md @@ -0,0 +1,29 @@ +[English](README.md) | 简体中文 +# UltraFace准备部署模型 + + +- [UltraFace](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) + - (1)[官方库](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/)中提供的*.onnx可下载, 也可以通过下面模型链接下载并进行部署 + - (2)开发者自己训练的模型,导出ONNX模型后,参考[详细部署文档](#详细部署文档)完成部署。 + + + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了UltraFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [RFB-320](https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320.onnx) | 1.3MB | 78.7 | +| [RFB-320-sim](https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320-sim.onnx) | 1.2MB | 78.7 | + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[UltraFace CommitID:dffdddd](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/commit/dffdddd) 编写 diff --git a/examples/vision/facedet/ultraface/cpp/README.md b/examples/vision/facedet/ultraface/cpp/README.md index 8d512af0a9..da0fef6e9a 100644 --- a/examples/vision/facedet/ultraface/cpp/README.md +++ b/examples/vision/facedet/ultraface/cpp/README.md @@ -1,46 +1,49 @@ -# UltraFace C++部署示例 +English | [简体中文](README_CN.md) -本目录下提供`infer.cc`快速完成UltraFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +# UltraFace C++ Deployment Example -在部署前,需确认以下两个步骤 +This directory provides examples that `infer.cc` fast finishes the deployment of UltraFace on CPU/GPU and GPU accelerated by TensorRT. -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +Before deployment, two steps require confirmation -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的UltraFace模型文件和测试图片 +# Download the official converted UltraFace model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference ./infer_demo version-RFB-320.onnx test_lite_face_detector_3.jpg 0 -# GPU推理 +# GPU inference ./infer_demo version-RFB-320.onnx test_lite_face_detector_3.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo version-RFB-320.onnx test_lite_face_detector_3.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: + +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## UltraFace C++接口 +## UltraFace C++ Interface -### UltraFace类 +### UltraFace Class ```c++ fastdeploy::vision::facedet::UltraFace( @@ -50,39 +53,43 @@ fastdeploy::vision::facedet::UltraFace( const ModelFormat& model_format = ModelFormat::ONNX) ``` -UltraFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 +UltraFace model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > UltraFace::Predict(cv::Mat* im, FaceDetectionResult* result, -> float conf_threshold = 0.25, -> float nms_iou_threshold = 0.5) +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for FaceDetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + + + +### Class Member Variable + +#### Pre-processing Parameter -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 240] +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [320, 240] -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/ultraface/cpp/README_CN.md b/examples/vision/facedet/ultraface/cpp/README_CN.md new file mode 100644 index 0000000000..cf21bd25b8 --- /dev/null +++ b/examples/vision/facedet/ultraface/cpp/README_CN.md @@ -0,0 +1,89 @@ +[English](README.md) | 简体中文 +# UltraFace C++部署示例 + +本目录下提供`infer.cc`快速完成UltraFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的UltraFace模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + + +# CPU推理 +./infer_demo version-RFB-320.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo version-RFB-320.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo version-RFB-320.onnx test_lite_face_detector_3.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## UltraFace C++接口 + +### UltraFace类 + +```c++ +fastdeploy::vision::facedet::UltraFace( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +UltraFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> UltraFace::Predict(cv::Mat* im, FaceDetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 240] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/ultraface/python/README.md b/examples/vision/facedet/ultraface/python/README.md index 05fc5205f1..2d94499923 100644 --- a/examples/vision/facedet/ultraface/python/README.md +++ b/examples/vision/facedet/ultraface/python/README.md @@ -1,75 +1,76 @@ -# UltraFace Python部署示例 +English | [简体中文](README_CN.md) +# UltraFace Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成UltraFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of UltraFace on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/facedet/ultraface/python/ -#下载ultraface模型文件和测试图片 +# Download ultraface model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference python infer.py --model version-RFB-320.onnx --image test_lite_face_detector_3.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model version-RFB-320.onnx --image test_lite_face_detector_3.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model version-RFB-320.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## UltraFace Python接口 +## UltraFace Python Interface ```python fastdeploy.vision.facedet.UltraFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -UltraFace模型加载和初始化,其中model_file为导出的ONNX模型格式 +UltraFace model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > UltraFace.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 240] +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [320, 240] -## 其它文档 +## Other Documents -- [UltraFace 模型介绍](..) -- [UltraFace C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [UltraFace Model Description](..) +- [UltraFace C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/ultraface/python/README_CN.md b/examples/vision/facedet/ultraface/python/README_CN.md new file mode 100644 index 0000000000..99c44ab3b9 --- /dev/null +++ b/examples/vision/facedet/ultraface/python/README_CN.md @@ -0,0 +1,76 @@ +[English](README.md) | 简体中文 +# UltraFace Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成UltraFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/facedet/ultraface/python/ + +#下载ultraface模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/version-RFB-320.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + +# CPU推理 +python infer.py --model version-RFB-320.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model version-RFB-320.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model version-RFB-320.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## UltraFace Python接口 + +```python +fastdeploy.vision.facedet.UltraFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +UltraFace模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> UltraFace.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[320, 240] + +## 其它文档 + +- [UltraFace 模型介绍](..) +- [UltraFace C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/facedet/yolov5face/README.md b/examples/vision/facedet/yolov5face/README.md index e845e568c4..4523c44775 100644 --- a/examples/vision/facedet/yolov5face/README.md +++ b/examples/vision/facedet/yolov5face/README.md @@ -1,44 +1,45 @@ -# YOLOv5Face准备部署模型 +English | [简体中文](README_CN.md) +# YOLOv5Face Ready-to-deploy Model - [YOLOv5Face](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) - - (1)[官方库](https://github.com/deepcam-cn/yolov5-face/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)开发者基于自己数据训练的YOLOv5Face模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + - (1)The *.pt provided by the [Official Library](https://github.com/deepcam-cn/yolov5-face/) can be deployed after the [Export ONNX Model](#导出ONNX模型) to complete the deployment; + - (2)As for YOLOv5Face model trained on customized data, please follow the operations guidelines in [Export ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B) to complete the deployment. -## 导出ONNX模型 +## Export ONNX Model -访问[YOLOv5Face](https://github.com/deepcam-cn/yolov5-face)官方github库,按照指引下载安装,下载`yolov5s-face.pt` 模型,利用 `export.py` 得到`onnx`格式文件。 +Visit [YOLOv5Face](https://github.com/deepcam-cn/yolov5-face) official github repository, follow the guidelines to download the `yolov5s-face.pt` model, and employ `export.py` to get the file in `onnx` format. -* 下载yolov5face模型文件 +* Download yolov5face model files ``` Link: https://pan.baidu.com/s/1fyzLxZYx7Ja1_PCIWRhxbw Link: eq0q https://drive.google.com/file/d/1zxaHeLDyID9YU4-hqK7KNepXIwbTkRIO/view?usp=sharing ``` -* 导出onnx格式文件 +* Export files in onnx format ```bash PYTHONPATH=. python export.py --weights weights/yolov5s-face.pt --img_size 640 640 --batch_size 1 ``` -* onnx模型简化(可选) +* onnx model simplification (optional) ```bash onnxsim yolov5s-face.onnx yolov5s-face.onnx ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了YOLOv5Face导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by YOLOv5Face are provided below. Developers can download and use them directly. (The accuracy of the models in the table is sourced from the official library) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [YOLOv5s-Face](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-face.onnx) | 30MB | 94.3 | | [YOLOv5s-Face-bak](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5face-s-640x640.bak.onnx) | 30MB | -| | [YOLOv5l-Face](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5face-l-640x640.onnx ) | 181MB | 95.8 | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[YOLOv5Face CommitID:4fd1ead](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) 编写 +- This tutorial and related code are written based on [YOLOv5Face CommitID:4fd1ead](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) diff --git a/examples/vision/facedet/yolov5face/README_CN.md b/examples/vision/facedet/yolov5face/README_CN.md new file mode 100644 index 0000000000..723c44a900 --- /dev/null +++ b/examples/vision/facedet/yolov5face/README_CN.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 +# YOLOv5Face准备部署模型 + +- [YOLOv5Face](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) + - (1)[官方库](https://github.com/deepcam-cn/yolov5-face/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)开发者基于自己数据训练的YOLOv5Face模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + +## 导出ONNX模型 + +访问[YOLOv5Face](https://github.com/deepcam-cn/yolov5-face)官方github库,按照指引下载安装,下载`yolov5s-face.pt` 模型,利用 `export.py` 得到`onnx`格式文件。 + +* 下载yolov5face模型文件 + ``` + Link: https://pan.baidu.com/s/1fyzLxZYx7Ja1_PCIWRhxbw Link: eq0q + https://drive.google.com/file/d/1zxaHeLDyID9YU4-hqK7KNepXIwbTkRIO/view?usp=sharing + ``` + +* 导出onnx格式文件 + ```bash + PYTHONPATH=. python export.py --weights weights/yolov5s-face.pt --img_size 640 640 --batch_size 1 + ``` +* onnx模型简化(可选) + ```bash + onnxsim yolov5s-face.onnx yolov5s-face.onnx + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了YOLOv5Face导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [YOLOv5s-Face](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-face.onnx) | 30MB | 94.3 | +| [YOLOv5s-Face-bak](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5face-s-640x640.bak.onnx) | 30MB | -| +| [YOLOv5l-Face](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5face-l-640x640.onnx ) | 181MB | 95.8 | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[YOLOv5Face CommitID:4fd1ead](https://github.com/deepcam-cn/yolov5-face/commit/4fd1ead) 编写 diff --git a/examples/vision/facedet/yolov5face/cpp/README.md b/examples/vision/facedet/yolov5face/cpp/README.md index a1df0620dd..1ca2a6bbe1 100644 --- a/examples/vision/facedet/yolov5face/cpp/README.md +++ b/examples/vision/facedet/yolov5face/cpp/README.md @@ -1,46 +1,47 @@ -# YOLOv5Face C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv5Face C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv5Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv5Face on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的YOLOv5Face模型文件和测试图片 +# Download the official converted YOLOv5Face model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-face.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference ./infer_demo yolov5s-face.onnx test_lite_face_detector_3.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov5s-face.onnx test_lite_face_detector_3.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolov5s-face.onnx test_lite_face_detector_3.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOv5Face C++接口 +## YOLOv5Face C++ Interface -### YOLOv5Face类 +### YOLOv5Face Class ```c++ fastdeploy::vision::facedet::YOLOv5Face( @@ -50,16 +51,16 @@ fastdeploy::vision::facedet::YOLOv5Face( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv5Face模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv5Face model loading and initialization, among which model_file is the exported ONNX model format. **参数** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict function > ```c++ > YOLOv5Face::Predict(cv::Mat* im, FaceDetectionResult* result, @@ -67,26 +68,26 @@ YOLOv5Face模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 - -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` -> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` -> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for FaceDetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results + +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(vector<float>): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding or not. `is_no_pad=ture` represents no paddling. Default `is_no_pad=false` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=false` +> > * **stride**(int): Used with the `is_mini_pad` member variable. Default `stride=32` +> > * **landmarks_per_face**(int): Specify the number of keypoints in the face detected. Default 5. + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov5face/cpp/README_CN.md b/examples/vision/facedet/yolov5face/cpp/README_CN.md new file mode 100644 index 0000000000..7f62536844 --- /dev/null +++ b/examples/vision/facedet/yolov5face/cpp/README_CN.md @@ -0,0 +1,93 @@ +[English](README.md) | 简体中文 +# YOLOv5Face C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv5Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的YOLOv5Face模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-face.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + + +# CPU推理 +./infer_demo yolov5s-face.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo yolov5s-face.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov5s-face.onnx test_lite_face_detector_3.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv5Face C++接口 + +### YOLOv5Face类 + +```c++ +fastdeploy::vision::facedet::YOLOv5Face( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv5Face模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv5Face::Predict(cv::Mat* im, FaceDetectionResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(vector<float>): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=ture` 表示不使用填充的方式,默认值为`is_no_pad=false` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=false` +> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` +> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov5face/python/README.md b/examples/vision/facedet/yolov5face/python/README.md index 3148dc02a2..d014e441ff 100644 --- a/examples/vision/facedet/yolov5face/python/README.md +++ b/examples/vision/facedet/yolov5face/python/README.md @@ -1,79 +1,80 @@ -# YOLOv5Face Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv5Face Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv5Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv5Face on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/facedet/yolov5face/python/ -#下载YOLOv5Face模型文件和测试图片 +# Download YOLOv5Face model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-face.onnx wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg -# CPU推理 +# CPU inference python infer.py --model yolov5s-face.onnx --image test_lite_face_detector_3.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolov5s-face.onnx --image test_lite_face_detector_3.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolov5s-face.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOv5Face Python接口 +## YOLOv5Face Python Interface ```python fastdeploy.vision.facedet.YOLOv5Face(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv5Face模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv5Face model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv5Face.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` -> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding or not. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `is_mini_pad` member variable. Default `stride=32` +> > * **landmarks_per_face**(int): Specify the number of keypoints in the face detected. Default 5 -## 其它文档 +## Other documents -- [YOLOv5Face 模型介绍](..) -- [YOLOv5Face C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [YOLOv5Face Model Description](..) +- [YOLOv5Face C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov5face/python/README_CN.md b/examples/vision/facedet/yolov5face/python/README_CN.md new file mode 100644 index 0000000000..472d926b42 --- /dev/null +++ b/examples/vision/facedet/yolov5face/python/README_CN.md @@ -0,0 +1,80 @@ +[English](README.md) | 简体中文 +# YOLOv5Face Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv5Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/facedet/yolov5face/python/ + +#下载YOLOv5Face模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s-face.onnx +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg + +# CPU推理 +python infer.py --model yolov5s-face.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model yolov5s-face.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov5s-face.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv5Face Python接口 + +```python +fastdeploy.vision.facedet.YOLOv5Face(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv5Face模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv5Face.predict(image_data, conf_threshold=0.25, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` +> > * **landmarks_per_face**(int): 指定当前模型检测的人脸所带的关键点个数,默认为5. + +## 其它文档 + +- [YOLOv5Face 模型介绍](..) +- [YOLOv5Face C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov7face/cpp/README.md b/examples/vision/facedet/yolov7face/cpp/README.md index 3b68ff41c0..fd8b2a8f6f 100644 --- a/examples/vision/facedet/yolov7face/cpp/README.md +++ b/examples/vision/facedet/yolov7face/cpp/README.md @@ -1,55 +1,56 @@ -# YOLOv7Face C++部署示例 +English | [简体中文](README_CN.md) +# YOLOv7Face C++ Deployment Example -本目录下提供`infer.cc`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of YOLOv7Face on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2 tar xvf fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2 cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x # x.x.x > 1.0.2 make -j -#下载官方转换好的YOLOv7Face模型文件和测试图片 +# Download the official converted YOLOv7Face model files and test images wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-tiny-face.onnx -#使用yolov7-tiny-face.onnx模型 -# CPU推理 +# Use yolov7-tiny-face.onnx model +# CPU inference ./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 2 -#使用yolov7-lite-e.onnx模型 -# CPU推理 +# Use yolov7-lite-e.onnx model +# CPU inference ./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 0 -# GPU推理 +# GPU inference ./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## YOLOv7Face C++接口 +## YOLOv7Face C++ Interface -### YOLOv7Face类 +### YOLOv7Face Class ```c++ fastdeploy::vision::facedet::YOLOv7Face( @@ -59,16 +60,16 @@ fastdeploy::vision::facedet::YOLOv7Face( const ModelFormat& model_format = ModelFormat::ONNX) ``` -YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式。 +YOLOv7Face model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > YOLOv7Face::Predict(cv::Mat* im, FaceDetectionResult* result, @@ -76,15 +77,15 @@ YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for FaceDetectionResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov7face/cpp/README_CN.md b/examples/vision/facedet/yolov7face/cpp/README_CN.md new file mode 100644 index 0000000000..452751645f --- /dev/null +++ b/examples/vision/facedet/yolov7face/cpp/README_CN.md @@ -0,0 +1,91 @@ +[English](README.md) | 简体中文 +# YOLOv7Face C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2 +tar xvf fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2 +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x # x.x.x > 1.0.2 +make -j + +#下载官方转换好的YOLOv7Face模型文件和测试图片 +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-tiny-face.onnx + +#使用yolov7-tiny-face.onnx模型 +# CPU推理 +./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 2 + +#使用yolov7-lite-e.onnx模型 +# CPU推理 +./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv7Face C++接口 + +### YOLOv7Face类 + +```c++ +fastdeploy::vision::facedet::YOLOv7Face( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv7Face::Predict(cv::Mat* im, FaceDetectionResult* result, +> float conf_threshold = 0.3, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov7face/python/README.md b/examples/vision/facedet/yolov7face/python/README.md index 0c4dd0f57e..431fddd249 100644 --- a/examples/vision/facedet/yolov7face/python/README.md +++ b/examples/vision/facedet/yolov7face/python/README.md @@ -1,87 +1,89 @@ -# YOLOv7Face Python部署示例 +English | [简体中文](README_CN.md) +# YOLOv7Face Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of YOLOv7Face on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/facedet/yolov7face/python/ -#下载YOLOv7Face模型文件和测试图片 +# Download YOLOv7Face model files and test images wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx -#使用yolov7-tiny-face.onnx模型 -# CPU推理 +# Use yolov7-tiny-face.onnx model +# CPU inference python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True -#使用yolov7-lite-e.onnx模型 -# CPU推理 +# Use yolov7-lite-e.onnx model +# CPU inference python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## YOLOv7Face Python接口 +## YOLOv7Face Python Interface ```python fastdeploy.vision.facedet.YOLOv7Face(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式 +YOLOv7Face model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > YOLOv7Face.predict(image_data, conf_threshold=0.3, nms_iou_threshold=0.5) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **conf_threshold**(float): 检测框置信度过滤阈值 -> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format +> > * **conf_threshold**(float): Filtering threshold of detection box confidence +> > * **nms_iou_threshold**(float): iou threshold during NMS processing -> **返回** + +> **Return** > -> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] -> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] -> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` -> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` -> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` +> > * **size**(list[int]): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [640, 640] +> > * **padding_value**(list[float]): This parameter is used to change the padding value of images during resize, containing three floating-point elements that represent the value of three channels. Default value [114, 114, 114] +> > * **is_no_pad**(bool): Specify whether to resize the image through padding or not. `is_no_pad=True` represents no paddling. Default `is_no_pad=False` +> > * **is_mini_pad**(bool): This parameter sets the width and height of the image after resize to the value nearest to the `size` member variable and to the point where the padded pixel size is divisible by the `stride` member variable. Default `is_mini_pad=False` +> > * **stride**(int): Used with the `is_mini_pad` member variable. Default `stride=32` -## 其它文档 +## Other Documents -- [YOLOv7Face 模型介绍](..) -- [YOLOv7Face C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [YOLOv7Face Model Description](..) +- [YOLOv7Face C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov7face/python/README_CN.md b/examples/vision/facedet/yolov7face/python/README_CN.md new file mode 100644 index 0000000000..9da41c6336 --- /dev/null +++ b/examples/vision/facedet/yolov7face/python/README_CN.md @@ -0,0 +1,88 @@ +[English](README.md) | 简体中文 +# YOLOv7Face Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/facedet/yolov7face/python/ + +#下载YOLOv7Face模型文件和测试图片 +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx + +#使用yolov7-tiny-face.onnx模型 +# CPU推理 +python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True + +#使用yolov7-lite-e.onnx模型 +# CPU推理 +python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv7Face Python接口 + +```python +fastdeploy.vision.facedet.YOLOv7Face(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv7Face.predict(image_data, conf_threshold=0.3, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` + +## 其它文档 + +- [YOLOv7Face 模型介绍](..) +- [YOLOv7Face C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) diff --git a/examples/vision/faceid/README.md b/examples/vision/faceid/README.md index b897314cbb..344f73a5f8 100644 --- a/examples/vision/faceid/README.md +++ b/examples/vision/faceid/README.md @@ -1,18 +1,13 @@ -# 人脸识别模型 +English | [简体中文](README_CN.md) +# Face recognition Model -## 模型支持列表 +FastDeploy currently supports the deployment of the following face recognition models -FastDeploy目前支持如下人脸识别模型部署 - -| 模型 | 说明 | 模型格式 | 版本 | +| Model | Description | Model Format | Version | |:---------------------------------------|:---------------|:-----------|:------------------------------------------------------------------------------| -| [deepinsight/ArcFace](./insightface) | ArcFace 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | -| [deepinsight/CosFace](./insightface) | CosFace 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | -| [deepinsight/PartialFC](./insightface) | PartialFC 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | -| [deepinsight/VPL](./insightface) | VPL 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | -| [paddleclas/AdaFace](./adaface) | AdaFace 系列模型 | PADDLE | [CommitID:babb9a5](https://github.com/PaddlePaddle/PaddleClas/tree/v2.4.0) | - -## 模型demo简介 - -ArcFace,CosFace,PartialFC,VPL同属于deepinsight系列,因此demo使用ONNX作为推理框架。AdaFace则采用PaddleInference作为推理框架。 +| [deepinsight/ArcFace](./insightface) | ArcFace models | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [deepinsight/CosFace](./insightface) | CosFace models | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [deepinsight/PartialFC](./insightface) | PartialFC models | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [deepinsight/VPL](./insightface) | VPL models | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [paddleclas/AdaFace](./adaface) | AdaFace models | PADDLE | [CommitID:babb9a5](https://github.com/PaddlePaddle/PaddleClas/tree/v2.4.0) | diff --git a/examples/vision/faceid/README_CN.md b/examples/vision/faceid/README_CN.md new file mode 100644 index 0000000000..260b304c8b --- /dev/null +++ b/examples/vision/faceid/README_CN.md @@ -0,0 +1,19 @@ +[English](README.md) | 简体中文 +# 人脸识别模型 + + +## 模型支持列表 + +FastDeploy目前支持如下人脸识别模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +|:---------------------------------------|:---------------|:-----------|:------------------------------------------------------------------------------| +| [deepinsight/ArcFace](./insightface) | ArcFace 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [deepinsight/CosFace](./insightface) | CosFace 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [deepinsight/PartialFC](./insightface) | PartialFC 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [deepinsight/VPL](./insightface) | VPL 系列模型 | ONNX | [CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) | +| [paddleclas/AdaFace](./adaface) | AdaFace 系列模型 | PADDLE | [CommitID:babb9a5](https://github.com/PaddlePaddle/PaddleClas/tree/v2.4.0) | + +## 模型demo简介 + +ArcFace,CosFace,PartialFC,VPL同属于deepinsight系列,因此demo使用ONNX作为推理框架。AdaFace则采用PaddleInference作为推理框架。 diff --git a/examples/vision/faceid/adaface/README.md b/examples/vision/faceid/adaface/README.md index 6a88af7179..a83c13e3df 100644 --- a/examples/vision/faceid/adaface/README.md +++ b/examples/vision/faceid/adaface/README.md @@ -1,32 +1,32 @@ -# AdaFace准备部署模型 +English | [简体中文](README_CN.md) +# AdaFace Ready-to-deploy Model - [PaddleClas](https://github.com/PaddlePaddle/PaddleClas/) - - [官方库](https://github.com/PaddlePaddle/PaddleClas/)中训练过后的Paddle模型导出Paddle静态图模型操作后,可进行部署; + - Paddle models trained in the [official repository](https://github.com/PaddlePaddle/PaddleClas/) are available for deployment after exporting Paddle static graph models; -## 简介 -一直以来,低质量图像的人脸识别都具有挑战性,因为低质量图像的人脸属性是模糊和退化的。将这样的图片输入模型时,将不能很好的实现分类。 -而在人脸识别任务中,我们经常会利用opencv的仿射变换来矫正人脸数据,这时数据会出现低质量退化的现象。如何解决低质量图片的分类问题成为了模型落地时的痛点问题。 +## Introduction +Face recognition of low-quality images has been challenging because the face attributes of these images are blurred and degraded. We cannot realize optimal classification after such images are fed into the model. +In face recognition, we often use the affine transformation of opencv to correct the face data that will degrade in low quality. The classification of low-quality images becomes a crucial problem during model development. -在AdaFace这项工作中,作者在损失函数中引入了另一个因素,即图像质量。作者认为,强调错误分类样本的策略应根据其图像质量进行调整。 -具体来说,简单或困难样本的相对重要性应该基于样本的图像质量来给定。据此作者提出了一种新的损失函数来通过图像质量强调不同的困难样本的重要性。 +In AdaFace, we introduce another factor in the loss function, namely image quality. We maintain that the strategy of emphasizing misclassified samples should be adjusted according to their image quality. +Specifically, the importance of easy and difficult samples should be given based on the their image quality. Accordingly, we propose a new loss function to emphasize the importance of different difficult samples by their image quality. -由上,AdaFace缓解了低质量图片在输入网络后输出结果精度变低的情况,更加适合在人脸识别任务落地中使用。 +In a nutshell, AdaFace improves the situation that low-quality images become less accurate after input to the network, which is more effective in the task of face recognition. +## Export Paddle Static Graph Model +Taking AdaFace as an example: +Refer to [AIStudio](https://aistudio.baidu.com/aistudio/projectdetail/4479879?contributionType=1) for training and export of the code. -## 导出Paddle静态图模型 -以AdaFace为例: -训练和导出代码,请参考[AIStudio](https://aistudio.baidu.com/aistudio/projectdetail/4479879?contributionType=1) +## Download Pre-trained Paddle Static Graph Model -## 下载预训练Paddle静态图模型 +For developers' testing, converted models are provided below. Developers can download and use them directly. (The accuracy of the models in the table is sourced from the model introduction in AIStudio) -为了方便开发者的测试,下面提供了我转换过的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)其中精度指标来源于AIStudio中对各模型的介绍。 - -| 模型 | 大小 | 精度 (AgeDB_30) | +| Model | Size | Accuracy (AgeDB_30) | |:----------------------------------------------------------------------------------------------|:------|:--------------| | [AdaFace-MobileFacenet](https://bj.bcebos.com/paddlehub/fastdeploy/mobilefacenet_adaface.tgz) | 3.2MB | 95.5 | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/faceid/adaface/README_CN.md b/examples/vision/faceid/adaface/README_CN.md new file mode 100644 index 0000000000..5421bd612f --- /dev/null +++ b/examples/vision/faceid/adaface/README_CN.md @@ -0,0 +1,33 @@ +[English](README.md) | 简体中文 +# AdaFace准备部署模型 + +- [PaddleClas](https://github.com/PaddlePaddle/PaddleClas/) + - [官方库](https://github.com/PaddlePaddle/PaddleClas/)中训练过后的Paddle模型导出Paddle静态图模型操作后,可进行部署; + +## 简介 +一直以来,低质量图像的人脸识别都具有挑战性,因为低质量图像的人脸属性是模糊和退化的。将这样的图片输入模型时,将不能很好的实现分类。 +而在人脸识别任务中,我们经常会利用opencv的仿射变换来矫正人脸数据,这时数据会出现低质量退化的现象。如何解决低质量图片的分类问题成为了模型落地时的痛点问题。 + +在AdaFace这项工作中,作者在损失函数中引入了另一个因素,即图像质量。作者认为,强调错误分类样本的策略应根据其图像质量进行调整。 +具体来说,简单或困难样本的相对重要性应该基于样本的图像质量来给定。据此作者提出了一种新的损失函数来通过图像质量强调不同的困难样本的重要性。 + +由上,AdaFace缓解了低质量图片在输入网络后输出结果精度变低的情况,更加适合在人脸识别任务落地中使用。 + + +## 导出Paddle静态图模型 +以AdaFace为例: +训练和导出代码,请参考[AIStudio](https://aistudio.baidu.com/aistudio/projectdetail/4479879?contributionType=1) + + +## 下载预训练Paddle静态图模型 + +为了方便开发者的测试,下面提供了我转换过的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)其中精度指标来源于AIStudio中对各模型的介绍。 + +| 模型 | 大小 | 精度 (AgeDB_30) | +|:----------------------------------------------------------------------------------------------|:------|:--------------| +| [AdaFace-MobileFacenet](https://bj.bcebos.com/paddlehub/fastdeploy/mobilefacenet_adaface.tgz) | 3.2MB | 95.5 | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/faceid/adaface/cpp/README.md b/examples/vision/faceid/adaface/cpp/README.md index f284b2fd00..a3b99e4544 100755 --- a/examples/vision/faceid/adaface/cpp/README.md +++ b/examples/vision/faceid/adaface/cpp/README.md @@ -1,17 +1,18 @@ -# AdaFace C++部署示例 -本目录下提供infer_xxx.py快速完成AdaFace模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +English | [简体中文](README_CN.md) +# AdaFace C++ Deployment Example +This directory provides examples that `infer_xxx.py` fast finishes the deployment of AdaFace on CPU/GPU and GPU accelerated by TensorRT. -以AdaFace为例提供`infer.cc`快速完成AdaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +Taking AdaFace as an example, we demonstrate how `infer.cc` fast finishes the deployment of AdaFace on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash -# “如果预编译库不包含本模型,请从最新代码编译SDK” +# “If the precompiled library does not contain this model, compile SDK from the latest code” mkdir build cd build wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz @@ -19,19 +20,19 @@ tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载测试图片 +# Download test images wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip unzip face_demo.zip -# 如果为Paddle模型,运行以下代码 +# Run the following code if the model is in Paddle format wget https://bj.bcebos.com/paddlehub/fastdeploy/mobilefacenet_adaface.tgz tar zxvf mobilefacenet_adaface.tgz -C ./ -# CPU推理 +# CPU inference ./infer_adaface_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ face_0.jpg face_1.jpg face_2.jpg 0 -# GPU推理 +# GPU inference ./infer_adaface_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ face_0.jpg face_1.jpg face_2.jpg 1 @@ -41,13 +42,13 @@ tar zxvf mobilefacenet_adaface.tgz -C ./ mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ face_0.jpg face_1.jpg face_2.jpg 2 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ face_0.jpg face_1.jpg face_2.jpg 3 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -55,12 +56,12 @@ tar zxvf mobilefacenet_adaface.tgz -C ./
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## AdaFace C++接口 +## AdaFace C++ Interface -### AdaFace类 +### AdaFace Class ```c++ fastdeploy::vision::faceid::AdaFace( @@ -70,42 +71,41 @@ fastdeploy::vision::faceid::AdaFace( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -AdaFace模型加载和初始化,如果使用PaddleInference推理,model_file和params_file为PaddleInference模型格式; -如果使用ONNXRuntime推理,model_file为ONNX模型格式,params_file为空。 +AdaFace model loading and initialization, model_file and params_file are in PaddleInference format if using PaddleInference for inference; +model_file is in ONNX format and params_file is empty if using ONNXRuntime for inference - -#### Predict函数 +#### Predict Function > ```c++ > AdaFace::Predict(cv::Mat* im, FaceRecognitionResult* result) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceRecognitionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 修改预处理以及后处理的参数 -预处理和后处理的参数的需要通过修改AdaFacePostprocessor,AdaFacePreprocessor的成员变量来进行修改。 - -#### AdaFacePreprocessor成员变量(预处理参数) -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112], - 通过AdaFacePreprocessor::SetSize(std::vector& size)来进行修改 -> > * **alpha**(vector<float>): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5], - 通过AdaFacePreprocessor::SetAlpha(std::vector& alpha)来进行修改 -> > * **beta**(vector<float>): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f], - 通过AdaFacePreprocessor::SetBeta(std::vector& beta)来进行修改 -> > * **permute**(bool): 预处理是否将BGR转换成RGB,默认true, - 通过AdaFacePreprocessor::SetPermute(bool permute)来进行修改 - -#### AdaFacePostprocessor成员变量(后处理参数) -> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认false, - AdaFacePostprocessor::SetL2Normalize(bool& l2_normalize)来进行修改 - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for FaceRecognitionResult. + +### Revise pre-processing and post-processing parameters +Pre-processing and post-processing parameters can be changed by modifying the member variables of AdaFacePostprocessor and AdaFacePreprocessor. + +#### AdaFacePreprocessor member variables (preprocessing parameters) +> > * **size**(vector<int>): This parameter changes the size of the resize during preprocessing, containing two integer elements for [width, height] with default value [112, 112]. + Revise through AdaFacePreprocessor::SetSize(std::vector& size) +> > * **alpha**(vector<float>): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`. alpha defaults to [1. / 127.5, 1.f / 127.5, 1. / 127.5]. + Revise through AdaFacePreprocessor::SetAlpha(std::vector& alpha) +> > * **beta**(vector<float>): Preprocess normalized beta, and calculated as `x'=x*alpha+beta`,beta defaults to [-1.f, -1.f, -1.f], + Revise through AdaFacePreprocessor::SetBeta(std::vector& beta) +> > * **permute**(bool): Whether to convert BGR to RGB in pre-processing. Default true. + Revise through AdaFacePreprocessor::SetPermute(bool permute) + +#### AdaFacePostprocessor member variables (post-processing parameters) +> > * **l2_normalize**(bool): Whether to perform l2 normalization before outputting the face vector. Default false. + Revise through AdaFacePostprocessor::SetL2Normalize(bool& l2_normalize) + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/faceid/adaface/cpp/README_CN.md b/examples/vision/faceid/adaface/cpp/README_CN.md new file mode 100644 index 0000000000..4af9096938 --- /dev/null +++ b/examples/vision/faceid/adaface/cpp/README_CN.md @@ -0,0 +1,112 @@ +[English](README.md) | 简体中文 +# AdaFace C++部署示例 +本目录下提供infer_xxx.py快速完成AdaFace模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +以AdaFace为例提供`infer.cc`快速完成AdaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +# “如果预编译库不包含本模型,请从最新代码编译SDK” +mkdir build +cd build +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip +unzip face_demo.zip + +# 如果为Paddle模型,运行以下代码 +wget https://bj.bcebos.com/paddlehub/fastdeploy/mobilefacenet_adaface.tgz +tar zxvf mobilefacenet_adaface.tgz -C ./ +# CPU推理 +./infer_adaface_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ + mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ + face_0.jpg face_1.jpg face_2.jpg 0 + +# GPU推理 +./infer_adaface_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ + mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ + face_0.jpg face_1.jpg face_2.jpg 1 + +# GPU上TensorRT推理 +./infer_adaface_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ + mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ + face_0.jpg face_1.jpg face_2.jpg 2 + +# 昆仑芯XPU推理 +./infer_demo mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ + mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ + face_0.jpg face_1.jpg face_2.jpg 3 +``` + +运行完成可视化结果如下图所示 + +
+ + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## AdaFace C++接口 + +### AdaFace类 + +```c++ +fastdeploy::vision::faceid::AdaFace( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +AdaFace模型加载和初始化,如果使用PaddleInference推理,model_file和params_file为PaddleInference模型格式; +如果使用ONNXRuntime推理,model_file为ONNX模型格式,params_file为空。 + + + +#### Predict函数 + +> ```c++ +> AdaFace::Predict(cv::Mat* im, FaceRecognitionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceRecognitionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 修改预处理以及后处理的参数 +预处理和后处理的参数的需要通过修改AdaFacePostprocessor,AdaFacePreprocessor的成员变量来进行修改。 + +#### AdaFacePreprocessor成员变量(预处理参数) +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112], + 通过AdaFacePreprocessor::SetSize(std::vector& size)来进行修改 +> > * **alpha**(vector<float>): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5], + 通过AdaFacePreprocessor::SetAlpha(std::vector& alpha)来进行修改 +> > * **beta**(vector<float>): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f], + 通过AdaFacePreprocessor::SetBeta(std::vector& beta)来进行修改 +> > * **permute**(bool): 预处理是否将BGR转换成RGB,默认true, + 通过AdaFacePreprocessor::SetPermute(bool permute)来进行修改 + +#### AdaFacePostprocessor成员变量(后处理参数) +> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认false, + AdaFacePostprocessor::SetL2Normalize(bool& l2_normalize)来进行修改 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/faceid/adaface/python/README.md b/examples/vision/faceid/adaface/python/README.md index 6475b1a325..c1e6ecd50a 100755 --- a/examples/vision/faceid/adaface/python/README.md +++ b/examples/vision/faceid/adaface/python/README.md @@ -1,42 +1,42 @@ -# AdaFace Python部署示例 -本目录下提供infer_xxx.py快速完成AdaFace模型在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +English | [简体中文](README_CN.md) +# AdaFace Python Deployment Example +This directory provides examples that `infer_xxx.py` fast finishes the deployment of AdaFace on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以AdaFace为例子, 提供`infer.py`快速完成AdaFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +Taking AdaFace as an example, we demonstrate how `infer.py` fast finishes the deployment of AdaFace on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/faceid/adaface/python/ -#下载AdaFace模型文件和测试图片 -#下载测试图片 +# Download AdaFace model files and test images +# Download test images wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip unzip face_demo.zip -# 如果为Paddle模型,运行以下代码 +# Run the following code if the model is in Paddle format wget https://bj.bcebos.com/paddlehub/fastdeploy/mobilefacenet_adaface.tgz tar zxvf mobilefacenet_adaface.tgz -C ./ -# CPU推理 +# CPU inference python infer.py --model mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ --params_file mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ --face face_0.jpg \ --face_positive face_1.jpg \ --face_negative face_2.jpg \ --device cpu -# GPU推理 +# GPU inference python infer.py --model mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ --params_file mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ --face face_0.jpg \ --face_positive face_1.jpg \ --face_negative face_2.jpg \ --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ --params_file mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ --face face_0.jpg \ @@ -45,7 +45,7 @@ python infer.py --model mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ --device gpu \ --use_trt True -# 昆仑芯XPU推理 +# KunlunXin XPU inference python infer.py --model mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ --params_file mobilefacenet_adaface/mobilefacenet_adaface.pdiparams \ --face test_lite_focal_arcface_0.JPG \ @@ -54,7 +54,7 @@ python infer.py --model mobilefacenet_adaface/mobilefacenet_adaface.pdmodel \ --device kunlunxin ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -70,56 +70,56 @@ Cosine 01: 0.7483505506964364 Cosine 02: -0.09605773855893639 ``` -## AdaFace Python接口 +## AdaFace Python Interface ```python fastdeploy.vision.faceid.AdaFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -AdaFace模型加载和初始化,其中model_file为导出的ONNX模型格式或PADDLE静态图格式 +AdaFace model loading and initialization, among which model_file is the exported ONNX model format or PADDLE static graph format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为PADDLE +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > AdaFace.predict(image_data) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceRecognitionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceRecognitionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -#### AdaFacePreprocessor的成员变量 -以下变量为AdaFacePreprocessor的成员变量 -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] -> > * **alpha**(list[float]): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] -> > * **beta**(list[float]): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] -> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认True +#### Member variables of AdaFacePreprocessor +The member variables of AdaFacePreprocessor are as follows +> > * **size**(list[int]): This parameter changes the size of the resize during preprocessing, containing two integer elements for [width, height] with default value [112, 112] +> > * **alpha**(list[float]): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`. alpha defaults to [1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(list[float]): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`. beta defaults to [-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): Whether to convert BGR to RGB in pre-processing. Default true -#### AdaFacePostprocessor的成员变量 -以下变量为AdaFacePostprocessor的成员变量 -> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认False +#### Member variables of AdaFacePostprocessor +The member variables of AdaFacePostprocessor are as follows +> > * **l2_normalize**(bool): Whether to perform l2 normalization before outputting the face vector. Default false. -## 其它文档 +## Other Documents -- [AdaFace 模型介绍](..) -- [AdaFace C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [AdaFace Model Description](..) +- [AdaFace C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/faceid/adaface/python/README_CN.md b/examples/vision/faceid/adaface/python/README_CN.md new file mode 100644 index 0000000000..5421bd612f --- /dev/null +++ b/examples/vision/faceid/adaface/python/README_CN.md @@ -0,0 +1,33 @@ +[English](README.md) | 简体中文 +# AdaFace准备部署模型 + +- [PaddleClas](https://github.com/PaddlePaddle/PaddleClas/) + - [官方库](https://github.com/PaddlePaddle/PaddleClas/)中训练过后的Paddle模型导出Paddle静态图模型操作后,可进行部署; + +## 简介 +一直以来,低质量图像的人脸识别都具有挑战性,因为低质量图像的人脸属性是模糊和退化的。将这样的图片输入模型时,将不能很好的实现分类。 +而在人脸识别任务中,我们经常会利用opencv的仿射变换来矫正人脸数据,这时数据会出现低质量退化的现象。如何解决低质量图片的分类问题成为了模型落地时的痛点问题。 + +在AdaFace这项工作中,作者在损失函数中引入了另一个因素,即图像质量。作者认为,强调错误分类样本的策略应根据其图像质量进行调整。 +具体来说,简单或困难样本的相对重要性应该基于样本的图像质量来给定。据此作者提出了一种新的损失函数来通过图像质量强调不同的困难样本的重要性。 + +由上,AdaFace缓解了低质量图片在输入网络后输出结果精度变低的情况,更加适合在人脸识别任务落地中使用。 + + +## 导出Paddle静态图模型 +以AdaFace为例: +训练和导出代码,请参考[AIStudio](https://aistudio.baidu.com/aistudio/projectdetail/4479879?contributionType=1) + + +## 下载预训练Paddle静态图模型 + +为了方便开发者的测试,下面提供了我转换过的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)其中精度指标来源于AIStudio中对各模型的介绍。 + +| 模型 | 大小 | 精度 (AgeDB_30) | +|:----------------------------------------------------------------------------------------------|:------|:--------------| +| [AdaFace-MobileFacenet](https://bj.bcebos.com/paddlehub/fastdeploy/mobilefacenet_adaface.tgz) | 3.2MB | 95.5 | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/faceid/insightface/README.md b/examples/vision/faceid/insightface/README.md index ba17f31c71..00ec594a91 100644 --- a/examples/vision/faceid/insightface/README.md +++ b/examples/vision/faceid/insightface/README.md @@ -1,37 +1,38 @@ -# InsightFace准备部署模型 +English | [简体中文](README_CN.md) +# InsightFace Ready-to-deploy Model - [InsightFace](https://github.com/deepinsight/insightface/commit/babb9a5) - - (1)[官方库](https://github.com/deepinsight/insightface/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)开发者基于自己数据训练的InsightFace模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + - (1)The *.pt provided by the [Official Library](https://github.com/deepinsight/insightface/) can be deployed after the [Export ONNX Model](#导出ONNX模型); + - (2)As for InsightFace model trained on customized data, please follow the operations guidelines in [Export ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B) to complete the deployment. -## 支持模型列表 -目前FastDeploy支持如下模型的部署 +## List of Supported Models +Now FastDeploy supports the deployment of the following models - ArcFace - CosFace - PartialFC - VPL -## 导出ONNX模型 -以ArcFace为例: -访问[ArcFace](https://github.com/deepinsight/insightface/tree/master/recognition/arcface_torch)官方github库,按照指引下载安装,下载pt模型文件,利用 `torch2onnx.py` 得到`onnx`格式文件。 +## Export ONNX Model +Taking ArcFace as an example: +Visit [ArcFace](https://github.com/deepinsight/insightface/tree/master/recognition/arcface_torch) official github repository, follow the guidelines to download pt model files, and employ `torch2onnx.py` to get the file in `onnx` format. -* 下载ArcFace模型文件 +* Download ArcFace model files ```bash Link: https://pan.baidu.com/share/init?surl=CL-l4zWqsI1oDuEEYVhj-g code: e8pw ``` -* 导出onnx格式文件 +* Export files in onnx format ```bash PYTHONPATH=. python ./torch2onnx.py ms1mv3_arcface_r100_fp16/backbone.pth --output ms1mv3_arcface_r100.onnx --network r100 --simplify 1 ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了InsightFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)其中精度指标来源于InsightFace中对各模型的介绍,详情各参考InsightFace中的说明 +For developers' testing, models exported by InsightFace are provided below. Developers can download and use them directly. (The accuracy of the models in the table is sourced from the official library) The accuracy metric is sourced from the model description in InsightFace. Refer to the introduction in InsightFace for more details. -| 模型 | 大小 | 精度 (AgeDB_30) | +| Model | Size | Accuracy (AgeDB_30) | |:-------------------------------------------------------------------------------------------|:------|:--------------| | [CosFace-r18](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r18.onnx) | 92MB | 97.7 | | [CosFace-r34](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r34.onnx) | 131MB | 98.3 | @@ -48,12 +49,12 @@ -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[InsightFace CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) 编写 +- This tutorial and related code are written based on [InsightFace CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) diff --git a/examples/vision/faceid/insightface/README_CN.md b/examples/vision/faceid/insightface/README_CN.md new file mode 100644 index 0000000000..0bdf7864f1 --- /dev/null +++ b/examples/vision/faceid/insightface/README_CN.md @@ -0,0 +1,60 @@ +[English](README.md) | 简体中文 +# InsightFace准备部署模型 + +- [InsightFace](https://github.com/deepinsight/insightface/commit/babb9a5) + - (1)[官方库](https://github.com/deepinsight/insightface/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)开发者基于自己数据训练的InsightFace模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + + +## 支持模型列表 +目前FastDeploy支持如下模型的部署 +- ArcFace +- CosFace +- PartialFC +- VPL + + +## 导出ONNX模型 +以ArcFace为例: +访问[ArcFace](https://github.com/deepinsight/insightface/tree/master/recognition/arcface_torch)官方github库,按照指引下载安装,下载pt模型文件,利用 `torch2onnx.py` 得到`onnx`格式文件。 + +* 下载ArcFace模型文件 + ```bash + Link: https://pan.baidu.com/share/init?surl=CL-l4zWqsI1oDuEEYVhj-g code: e8pw + ``` + +* 导出onnx格式文件 + ```bash + PYTHONPATH=. python ./torch2onnx.py ms1mv3_arcface_r100_fp16/backbone.pth --output ms1mv3_arcface_r100.onnx --network r100 --simplify 1 + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了InsightFace导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)其中精度指标来源于InsightFace中对各模型的介绍,详情各参考InsightFace中的说明 + +| 模型 | 大小 | 精度 (AgeDB_30) | +|:-------------------------------------------------------------------------------------------|:------|:--------------| +| [CosFace-r18](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r18.onnx) | 92MB | 97.7 | +| [CosFace-r34](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r34.onnx) | 131MB | 98.3 | +| [CosFace-r50](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r50.onnx) | 167MB | 98.3 | +| [CosFace-r100](https://bj.bcebos.com/paddlehub/fastdeploy/glint360k_cosface_r100.onnx) | 249MB | 98.4 | +| [ArcFace-r18](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r18.onnx) | 92MB | 97.7 | +| [ArcFace-r34](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r34.onnx) | 131MB | 98.1 | +| [ArcFace-r50](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r50.onnx) | 167MB | - | +| [ArcFace-r100](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r100.onnx) | 249MB | 98.4 | +| [ArcFace-r100_lr0.1](https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_r100_lr01.onnx) | 249MB | 98.4 | +| [PartialFC-r34](https://bj.bcebos.com/paddlehub/fastdeploy/partial_fc_glint360k_r50.onnx) | 167MB | - | +| [PartialFC-r50](https://bj.bcebos.com/paddlehub/fastdeploy/partial_fc_glint360k_r100.onnx) | 249MB | - | + + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[InsightFace CommitID:babb9a5](https://github.com/deepinsight/insightface/commit/babb9a5) 编写 diff --git a/examples/vision/faceid/insightface/cpp/README.md b/examples/vision/faceid/insightface/cpp/README.md index 1722d9d5db..d56b40aa37 100644 --- a/examples/vision/faceid/insightface/cpp/README.md +++ b/examples/vision/faceid/insightface/cpp/README.md @@ -1,13 +1,14 @@ -# InsightFace C++部署示例 -本目录下提供infer_xxx.cc快速完成InsighFace模型包括ArcFace\CosFace\VPL\Partial_FC在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 -以ArcFace为例提供`infer_arcface.cc`快速完成ArcFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +English | [简体中文](README_CN.md) +# InsightFace C++ Deployment Example +This direct ory provides examples that `infer_xxx.cc` fast finishes the deployment of InsighFace, including ArcFace\CosFace\VPL\Partial_FC on CPU/GPU and GPU accelerated by TensorRT. +Taking ArcFace as an example, we demonstrate how `infer_arcface.cc` fast finishes the deployment of InsighFace on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. ```bash mkdir build @@ -17,20 +18,20 @@ tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的ArcFace模型文件和测试图片 +# Download the official converted ArcFace model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r100.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip unzip face_demo.zip -# CPU推理 +# CPU inference ./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 0 -# GPU推理 +# GPU inference ./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -38,12 +39,12 @@ unzip face_demo.zip
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## InsightFace C++接口 +## InsightFace C++ Interface -### ArcFace类 +### ArcFace Class ```c++ fastdeploy::vision::faceid::ArcFace( @@ -53,9 +54,9 @@ fastdeploy::vision::faceid::ArcFace( const ModelFormat& model_format = ModelFormat::ONNX) ``` -ArcFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 +ArcFace model loading and initialization, among which model_file is the exported ONNX model format. -### CosFace类 +### CosFace Class ```c++ fastdeploy::vision::faceid::CosFace( @@ -65,9 +66,9 @@ fastdeploy::vision::faceid::CosFace( const ModelFormat& model_format = ModelFormat::ONNX) ``` -CosFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 +CosFace model loading and initialization, among which model_file is the exported ONNX model format. -### PartialFC类 +### PartialFC Class ```c++ fastdeploy::vision::faceid::PartialFC( @@ -77,9 +78,9 @@ fastdeploy::vision::faceid::PartialFC( const ModelFormat& model_format = ModelFormat::ONNX) ``` -PartialFC模型加载和初始化,其中model_file为导出的ONNX模型格式。 +PartialFC model loading and initialization, among which model_file is the exported ONNX model format. -### VPL类 +### VPL Class ```c++ fastdeploy::vision::faceid::VPL( @@ -89,45 +90,45 @@ fastdeploy::vision::faceid::VPL( const ModelFormat& model_format = ModelFormat::ONNX) ``` -VPL模型加载和初始化,其中model_file为导出的ONNX模型格式。 -**参数** +VPL model loading and initialization, among which model_file is the exported ONNX model format. +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict function > ```c++ > ArcFace::Predict(cv::Mat* im, FaceRecognitionResult* result) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceRecognitionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 修改预处理以及后处理的参数 -预处理和后处理的参数的需要通过修改InsightFaceRecognitionPostprocessor,InsightFaceRecognitionPreprocessor的成员变量来进行修改。 - -#### InsightFaceRecognitionPreprocessor成员变量(预处理参数) -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112], - 通过InsightFaceRecognitionPreprocessor::SetSize(std::vector& size)来进行修改 -> > * **alpha**(vector<float>): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5], - 通过InsightFaceRecognitionPreprocessor::SetAlpha(std::vector& alpha)来进行修改 -> > * **beta**(vector<float>): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f], - 通过InsightFaceRecognitionPreprocessor::SetBeta(std::vector& beta)来进行修改 -> > * **permute**(bool): 预处理是否将BGR转换成RGB,默认true, - 通过InsightFaceRecognitionPreprocessor::SetPermute(bool permute)来进行修改 - -#### InsightFaceRecognitionPostprocessor成员变量(后处理参数) -> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认false, - InsightFaceRecognitionPostprocessor::SetL2Normalize(bool& l2_normalize)来进行修改 - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for FaceRecognitionResult + +### Change pre-processing and post-processing parameters +Pre-processing and post-processing parameters can be changed by modifying the member variables of InsightFaceRecognitionPostprocessor and InsightFaceRecognitionPreprocessor + +#### InsightFaceRecognitionPreprocessor member variables (preprocessing parameters) +> > * **size**(vector<int>): This parameter changes the size of the resize during preprocessing, containing two integer elements for [width, height] with default value [112, 112]. + Revise through InsightFaceRecognitionPreprocessor::SetSize(std::vector& size) +> > * **alpha**(vector<float>): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`. alpha defaults to [1. / 127.5, 1.f / 127.5, 1. / 127.5]. + Revise through InsightFaceRecognitionPreprocessor::SetAlpha(std::vector& alpha) +> > * **beta**(vector<float>): Preprocess normalized beta, and calculated as `x'=x*alpha+beta`. beta defaults to [-1.f, -1.f, -1.f]. + Revise through InsightFaceRecognitionPreprocessor::SetBeta(std::vector& beta) +> > * **permute**(bool): Whether to convert BGR to RGB in pre-processing. Default true + Revise through InsightFaceRecognitionPreprocessor::SetPermute(bool permute) + +#### InsightFaceRecognitionPostprocessor member variables (post-processing parameters) +> > * **l2_normalize**(bool): Whether to perform l2 normalization before outputting the face vector. Default false. + Revise through InsightFaceRecognitionPostprocessor::SetL2Normalize(bool& l2_normalize) + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/faceid/insightface/cpp/README_CN.md b/examples/vision/faceid/insightface/cpp/README_CN.md new file mode 100644 index 0000000000..ff03789ca2 --- /dev/null +++ b/examples/vision/faceid/insightface/cpp/README_CN.md @@ -0,0 +1,134 @@ +[English](README.md) | 简体中文 +# InsightFace C++部署示例 +本目录下提供infer_xxx.cc快速完成InsighFace模型包括ArcFace\CosFace\VPL\Partial_FC在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +以ArcFace为例提供`infer_arcface.cc`快速完成ArcFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 + +```bash +mkdir build +cd build +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的ArcFace模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r100.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip +unzip face_demo.zip + +# CPU推理 +./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 0 +# GPU推理 +./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 1 +# GPU上TensorRT推理 +./infer_arcface_demo ms1mv3_arcface_r100.onnx face_0.jpg face_1.jpg face_2.jpg 2 +``` + +运行完成可视化结果如下图所示 + +
+ + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## InsightFace C++接口 + +### ArcFace类 + +```c++ +fastdeploy::vision::faceid::ArcFace( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +ArcFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +### CosFace类 + +```c++ +fastdeploy::vision::faceid::CosFace( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +CosFace模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +### PartialFC类 + +```c++ +fastdeploy::vision::faceid::PartialFC( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +PartialFC模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +### VPL类 + +```c++ +fastdeploy::vision::faceid::VPL( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +VPL模型加载和初始化,其中model_file为导出的ONNX模型格式。 +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> ArcFace::Predict(cv::Mat* im, FaceRecognitionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceRecognitionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 修改预处理以及后处理的参数 +预处理和后处理的参数的需要通过修改InsightFaceRecognitionPostprocessor,InsightFaceRecognitionPreprocessor的成员变量来进行修改。 + +#### InsightFaceRecognitionPreprocessor成员变量(预处理参数) +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112], + 通过InsightFaceRecognitionPreprocessor::SetSize(std::vector& size)来进行修改 +> > * **alpha**(vector<float>): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5], + 通过InsightFaceRecognitionPreprocessor::SetAlpha(std::vector& alpha)来进行修改 +> > * **beta**(vector<float>): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f], + 通过InsightFaceRecognitionPreprocessor::SetBeta(std::vector& beta)来进行修改 +> > * **permute**(bool): 预处理是否将BGR转换成RGB,默认true, + 通过InsightFaceRecognitionPreprocessor::SetPermute(bool permute)来进行修改 + +#### InsightFaceRecognitionPostprocessor成员变量(后处理参数) +> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认false, + InsightFaceRecognitionPostprocessor::SetL2Normalize(bool& l2_normalize)来进行修改 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/faceid/insightface/python/README.md b/examples/vision/faceid/insightface/python/README.md index b3b44dc921..212c65ccc5 100644 --- a/examples/vision/faceid/insightface/python/README.md +++ b/examples/vision/faceid/insightface/python/README.md @@ -1,36 +1,36 @@ -# InsightFace Python部署示例 -本目录下提供infer_xxx.py快速完成InsighFace模型包括ArcFace\CosFace\VPL\Partial_FC在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +English | [简体中文](README_CN.md) +# InsightFace Python Deployment Example +This directory provides examples that `infer_xxx.py` fast finishes the deployment of InsighFace, including ArcFace\CosFace\VPL\Partial_FC on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以ArcFace为例子, 提供`infer_arcface.py`快速完成ArcFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +Taking ArcFace as an example, we demonstrate how `infer_arcface.py` fast finishes the deployment of ArcFace on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/faceid/insightface/python/ -#下载ArcFace模型文件和测试图片 +# Download ArcFace model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r100.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip unzip face_demo.zip -# CPU推理 +# CPU inference python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ --face face_0.jpg \ --face_positive face_1.jpg \ --face_negative face_2.jpg \ --device cpu -# GPU推理 +# GPU inference python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ --face face_0.jpg \ --face_positive face_1.jpg \ --face_negative face_2.jpg \ --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ --face face_0.jpg \ --face_positive face_1.jpg \ @@ -39,7 +39,7 @@ python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -56,7 +56,7 @@ Detect Done! Cosine 01: 0.814385, Cosine 02:-0.059388 ``` -## InsightFace Python接口 +## InsightFace Python Interface ```python fastdeploy.vision.faceid.ArcFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) @@ -65,50 +65,50 @@ fastdeploy.vision.faceid.PartialFC(model_file, params_file=None, runtime_option= fastdeploy.vision.faceid.VPL(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -ArcFace模型加载和初始化,其中model_file为导出的ONNX模型格式 +ArcFace model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > ArcFace.predict(image_data) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.FaceRecognitionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.FaceRecognitionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -#### AdaFacePreprocessor的成员变量 -以下变量为AdaFacePreprocessor的成员变量 -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] -> > * **alpha**(list[float]): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] -> > * **beta**(list[float]): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] -> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认True +#### Member variables of AdaFacePreprocessor +Member variables of AdaFacePreprocessor are as follows +> > * **size**(list[int]): This parameter changes the size of the resize during preprocessing, containing two integer elements for [width, height] with default value [112, 112] +> > * **alpha**(list[float]): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`. alpha defaults to [1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(list[float]): Preprocess normalized beta, and calculated as `x'=x*alpha+beta`,beta defaults to [-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): Whether to convert BGR to RGB in pre-processing. Default True -#### AdaFacePostprocessor的成员变量 -以下变量为AdaFacePostprocessor的成员变量 -> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认False +#### Member variables of AdaFacePostprocessor +Member variables of AdaFacePostprocessor are as follows +> > * **l2_normalize**(bool): Whether to perform l2 normalization before outputting the face vector. Default False. -## 其它文档 +## Other Documents -- [InsightFace 模型介绍](..) -- [InsightFace C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [InsightFace Model Description](..) +- [InsightFace C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/faceid/insightface/python/README_CN.md b/examples/vision/faceid/insightface/python/README_CN.md new file mode 100644 index 0000000000..b30921b7e7 --- /dev/null +++ b/examples/vision/faceid/insightface/python/README_CN.md @@ -0,0 +1,115 @@ +[English](README.md) | 简体中文 +# InsightFace Python部署示例 +本目录下提供infer_xxx.py快速完成InsighFace模型包括ArcFace\CosFace\VPL\Partial_FC在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以ArcFace为例子, 提供`infer_arcface.py`快速完成ArcFace在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/faceid/insightface/python/ + +#下载ArcFace模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/ms1mv3_arcface_r100.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/rknpu2/face_demo.zip +unzip face_demo.zip + +# CPU推理 +python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ + --face face_0.jpg \ + --face_positive face_1.jpg \ + --face_negative face_2.jpg \ + --device cpu +# GPU推理 +python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ + --face face_0.jpg \ + --face_positive face_1.jpg \ + --face_negative face_2.jpg \ + --device gpu +# GPU上使用TensorRT推理 +python infer_arcface.py --model ms1mv3_arcface_r100.onnx \ + --face face_0.jpg \ + --face_positive face_1.jpg \ + --face_negative face_2.jpg \ + --device gpu \ + --use_trt True +``` + +运行完成可视化结果如下图所示 + +
+ + + +
+ +```bash +Prediction Done! +--- [Face 0]:FaceRecognitionResult: [Dim(512), Min(-2.309220), Max(2.372197), Mean(0.016987)] +--- [Face 1]:FaceRecognitionResult: [Dim(512), Min(-2.288258), Max(1.995104), Mean(-0.003400)] +--- [Face 2]:FaceRecognitionResult: [Dim(512), Min(-3.243411), Max(3.875866), Mean(-0.030682)] +Detect Done! Cosine 01: 0.814385, Cosine 02:-0.059388 + +``` + +## InsightFace Python接口 + +```python +fastdeploy.vision.faceid.ArcFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +fastdeploy.vision.faceid.CosFace(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +fastdeploy.vision.faceid.PartialFC(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +fastdeploy.vision.faceid.VPL(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +ArcFace模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> ArcFace.predict(image_data) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceRecognitionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +#### AdaFacePreprocessor的成员变量 +以下变量为AdaFacePreprocessor的成员变量 +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] +> > * **alpha**(list[float]): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(list[float]): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认True + +#### AdaFacePostprocessor的成员变量 +以下变量为AdaFacePostprocessor的成员变量 +> > * **l2_normalize**(bool): 输出人脸向量之前是否执行l2归一化,默认False + + +## 其它文档 + +- [InsightFace 模型介绍](..) +- [InsightFace C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/generation/anemigan/README.md b/examples/vision/generation/anemigan/README.md index 721ed5644b..c152a4d0b2 100644 --- a/examples/vision/generation/anemigan/README.md +++ b/examples/vision/generation/anemigan/README.md @@ -1,20 +1,21 @@ -# 图像生成模型 +English | [简体中文](README_CN.md) +# Image Generation Model -FastDeploy目前支持PaddleHub预训练模型库中如下风格迁移模型的部署 +Now FastDeploy supports the deployment of the following style transfer models in the PaddleHub pre-trained model repository -| 模型 | 说明 | 模型格式 | +| Model | Description | Model Format | | :--- | :--- | :------- | -|[animegan_v1_hayao_60](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v1_hayao_60&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V1官方开源项目|paddle| -|[animegan_v2_paprika_97](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_97&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_hayao_64](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_64&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_shinkai_53](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_53&en_category=GANs)|可将输入的图像转换成新海诚动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_shinkai_33](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_33&en_category=GANs)|可将输入的图像转换成新海诚动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_paprika_54](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_54&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_hayao_99](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_99&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_paprika_74](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_74&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| -|[animegan_v2_paprika_98](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_98&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| - -## FastDeploy paddle backend部署和hub速度对比(ips, 越高越好) +|[animegan_v1_hayao_60](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v1_hayao_60&en_category=GANs)| Convert the input image into one in Miyazaki anime style with model weights converting from AnimeGAN V1 official open source project |paddle| +|[animegan_v2_paprika_97](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_97&en_category=GANs)| Convert the input image into one in Satoshi Paprika anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_hayao_64](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_64&en_category=GANs)| Convert the input image into one in Miyazaki anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_shinkai_53](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_53&en_category=GANs)| Convert the input image into one in Shinkai anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_shinkai_33](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_33&en_category=GANs)| Convert the input image into one in Shinkai anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_paprika_54](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_54&en_category=GANs)| Convert the input image into one in Satoshi Paprika anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_hayao_99](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_99&en_category=GANs)| Convert the input image into one in Miyazaki anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_paprika_74](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_74&en_category=GANs)| Convert the input image into one in Satoshi Paprika anime style with model weights converting from AnimeGAN V2 official open source project |paddle| +|[animegan_v2_paprika_98](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_98&en_category=GANs)| Convert the input image into one in Satoshi Paprika anime style with model weights converting from AnimeGAN V2 official open source project |paddle| + +## Speed comparison between hub and FastDeploy paddle backend Deployment (ips, higher is better) | Device | FastDeploy | Hub | | :--- | :--- | :------- | | CPU | 0.075 | 0.069| @@ -22,15 +23,15 @@ FastDeploy目前支持PaddleHub预训练模型库中如下风格迁移模型的 -## 下载预训练模型 -使用fastdeploy.download_model即可以下载模型, 例如下载animegan_v1_hayao_60 +## Downloading pre-trained models +Use fastdeploy.download_model to download models. For example, download animegan_v1_hayao_60 ```python import fastdeploy as fd fd.download_model(name='animegan_v1_hayao_60', path='./', format='paddle') ``` -将会在当前目录获得animegan_v1_hayao_60的预训练模型。 +The pre-trained model of animegan_v1_hayao_60 will be available in the current directory. -## 详细部署文档 +## Detailed deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/generation/anemigan/README_CN.md b/examples/vision/generation/anemigan/README_CN.md new file mode 100644 index 0000000000..c01a8e12ef --- /dev/null +++ b/examples/vision/generation/anemigan/README_CN.md @@ -0,0 +1,37 @@ +[English](README.md) | 简体中文 +# 图像生成模型 + +FastDeploy目前支持PaddleHub预训练模型库中如下风格迁移模型的部署 + +| 模型 | 说明 | 模型格式 | +| :--- | :--- | :------- | +|[animegan_v1_hayao_60](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v1_hayao_60&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V1官方开源项目|paddle| +|[animegan_v2_paprika_97](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_97&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_hayao_64](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_64&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_shinkai_53](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_53&en_category=GANs)|可将输入的图像转换成新海诚动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_shinkai_33](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_33&en_category=GANs)|可将输入的图像转换成新海诚动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_paprika_54](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_54&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_hayao_99](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_99&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_paprika_74](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_74&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| +|[animegan_v2_paprika_98](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_98&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle| + +## FastDeploy paddle backend部署和hub速度对比(ips, 越高越好) +| Device | FastDeploy | Hub | +| :--- | :--- | :------- | +| CPU | 0.075 | 0.069| +| GPU | 8.33 | 8.26 | + + + +## 下载预训练模型 +使用fastdeploy.download_model即可以下载模型, 例如下载animegan_v1_hayao_60 +```python +import fastdeploy as fd +fd.download_model(name='animegan_v1_hayao_60', path='./', format='paddle') +``` +将会在当前目录获得animegan_v1_hayao_60的预训练模型。 + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/generation/anemigan/cpp/README.md b/examples/vision/generation/anemigan/cpp/README.md index 9d58c6ad3f..0606f5804f 100755 --- a/examples/vision/generation/anemigan/cpp/README.md +++ b/examples/vision/generation/anemigan/cpp/README.md @@ -1,40 +1,41 @@ -# AnimeGAN C++部署示例 +English | [简体中文](README_CN.md) +# AnimeGAN C++ Deployment Example -本目录下提供`infer.cc`快速完成AnimeGAN在CPU/GPU部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of AnimeGAN on CPU/GPU. -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上AnimeGAN推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2) +Taking the AnimeGAN inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.2 or above (x.x.x>=1.0.2) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载准备好的模型文件和测试图片 +# Download the prepared model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/animegan_v1_hayao_60_v1.0.0.tgz tar xvfz animegan_v1_hayao_60_v1.0.0.tgz -# CPU推理 +# CPU inference ./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device cpu -# GPU推理 +# GPU inference ./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device gpu ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK in Windows, refer to +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## AnimeGAN C++接口 +## AnimeGAN C++ Interface -### AnimeGAN类 +### AnimeGAN Class ```c++ fastdeploy::vision::generation::AnimeGAN( @@ -44,41 +45,41 @@ fastdeploy::vision::generation::AnimeGAN( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -AnimeGAN模型加载和初始化,其中model_file为导出的Paddle模型结构文件,params_file为模型参数文件。 +AnimeGAN model loading and initialization, among which model_file is the exported Paddle model file and params_file is the parameter file. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend Inference configuration. None by default. (use the default configuration) +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > bool AnimeGAN::Predict(cv::Mat& image, cv::Mat* result) > ``` > -> 模型预测入口,输入图像输出风格迁移后的结果。 +> Model prediction interface. Input an image and output the style transfer result > -> **参数** +> **Parameter** > -> > * **image**: 输入数据,注意需为HWC,BGR格式 -> > * **result**: 风格转换后的图像,BGR格式 +> > * **image**: Input data in HWC or BGR format +> > * **result**: Image after style style transfer in BGR format -#### BatchPredict函数 +#### BatchPredict Function > ```c++ > bool AnimeGAN::BatchPredict(const std::vector& images, std::vector* results); > ``` > -> 模型预测入口,输入一组图像并输出风格迁移后的结果。 +> Model prediction interface. Input a set of images and output style transfer results. > -> **参数** +> **Parameter** > -> > * **images**: 输入数据,一组图像数据,注意需为HWC,BGR格式 -> > * **results**: 风格转换后的一组图像,BGR格式 +> > * **images**: Input data in HWC or BGR format +> > * **results**: A set of images after style transfer in BGR format. -- [模型介绍](../../) -- [Python部署](../python) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/generation/anemigan/cpp/README_CN.md b/examples/vision/generation/anemigan/cpp/README_CN.md new file mode 100644 index 0000000000..b6caf590c1 --- /dev/null +++ b/examples/vision/generation/anemigan/cpp/README_CN.md @@ -0,0 +1,85 @@ +[English](README.md) | 简体中文 +# AnimeGAN C++部署示例 + +本目录下提供`infer.cc`快速完成AnimeGAN在CPU/GPU部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上AnimeGAN推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载准备好的模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/animegan_v1_hayao_60_v1.0.0.tgz +tar xvfz animegan_v1_hayao_60_v1.0.0.tgz + +# CPU推理 +./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device cpu +# GPU推理 +./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device gpu +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## AnimeGAN C++接口 + +### AnimeGAN类 + +```c++ +fastdeploy::vision::generation::AnimeGAN( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +AnimeGAN模型加载和初始化,其中model_file为导出的Paddle模型结构文件,params_file为模型参数文件。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> bool AnimeGAN::Predict(cv::Mat& image, cv::Mat* result) +> ``` +> +> 模型预测入口,输入图像输出风格迁移后的结果。 +> +> **参数** +> +> > * **image**: 输入数据,注意需为HWC,BGR格式 +> > * **result**: 风格转换后的图像,BGR格式 + +#### BatchPredict函数 + +> ```c++ +> bool AnimeGAN::BatchPredict(const std::vector& images, std::vector* results); +> ``` +> +> 模型预测入口,输入一组图像并输出风格迁移后的结果。 +> +> **参数** +> +> > * **images**: 输入数据,一组图像数据,注意需为HWC,BGR格式 +> > * **results**: 风格转换后的一组图像,BGR格式 + +- [模型介绍](../../) +- [Python部署](../python) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/generation/anemigan/python/README.md b/examples/vision/generation/anemigan/python/README.md index 9c4562402d..1217b56253 100644 --- a/examples/vision/generation/anemigan/python/README.md +++ b/examples/vision/generation/anemigan/python/README.md @@ -1,70 +1,71 @@ -# AnimeGAN Python部署示例 +English | [简体中文](README_CN.md) +# AnimeGAN Python Deployment Example -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成AnimeGAN在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of AnimeGAN on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -# 下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/generation/anemigan/python -# 下载准备好的测试图片 +# Download prepared test images wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg -# CPU推理 +# CPU inference python infer.py --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device gpu ``` -## AnimeGAN Python接口 +## AnimeGAN Python Interface ```python fd.vision.generation.AnimeGAN(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -AnimeGAN模型加载和初始化,其中model_file和params_file为用于Paddle inference的模型结构文件和参数文件。 +AnimeGAN model loading and initialization, among which model_file and params_file are the model file and parameter file for Paddle inference. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. PADDLE format by default -### predict函数 +### predict function > ```python > AnimeGAN.predict(input_image) > ``` > -> 模型预测入口,输入图像输出风格迁移后的结果。 +> Model prediction interface. Input images and output style transfer results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** np.ndarray, 风格转换后的图像,BGR格式 +> **Return** np.ndarray, the image after style transfer in BGR format -### batch_predict函数 +### batch_predict function > ```python -> AnimeGAN.batch_predict函数(input_images) +> AnimeGAN.batch_predict function (input_images) > ``` > -> 模型预测入口,输入一组图像并输出风格迁移后的结果。 +> Model prediction interface. Input a set of images and output style transfer results > -> **参数** +> **Parameter** > -> > * **input_images**(list(np.ndarray)): 输入数据,一组图像数据,注意需为HWC,BGR格式 +> > * **input_images**(list(np.ndarray)): Input data in HWC or BGR format -> **返回** list(np.ndarray), 风格转换后的一组图像,BGR格式 +> **Return** list(np.ndarray), a set of images after style transfer in BGR format -## 其它文档 +## Other Documents -- [风格迁移 模型介绍](..) -- [C++部署](../cpp) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Style Transfer Model Description](..) +- [C++ Deployment](../cpp) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/generation/anemigan/python/README_CN.md b/examples/vision/generation/anemigan/python/README_CN.md new file mode 100644 index 0000000000..f69c6b46ff --- /dev/null +++ b/examples/vision/generation/anemigan/python/README_CN.md @@ -0,0 +1,71 @@ +[English](README.md) | 简体中文 +# AnimeGAN Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成AnimeGAN在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +# 下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/generation/anemigan/python +# 下载准备好的测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg + +# CPU推理 +python infer.py --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device cpu +# GPU推理 +python infer.py --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device gpu +``` + +## AnimeGAN Python接口 + +```python +fd.vision.generation.AnimeGAN(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +AnimeGAN模型加载和初始化,其中model_file和params_file为用于Paddle inference的模型结构文件和参数文件。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + + +### predict函数 + +> ```python +> AnimeGAN.predict(input_image) +> ``` +> +> 模型预测入口,输入图像输出风格迁移后的结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** np.ndarray, 风格转换后的图像,BGR格式 + +### batch_predict函数 +> ```python +> AnimeGAN.batch_predict函数(input_images) +> ``` +> +> 模型预测入口,输入一组图像并输出风格迁移后的结果。 +> +> **参数** +> +> > * **input_images**(list(np.ndarray)): 输入数据,一组图像数据,注意需为HWC,BGR格式 + +> **返回** list(np.ndarray), 风格转换后的一组图像,BGR格式 + +## 其它文档 + +- [风格迁移 模型介绍](..) +- [C++部署](../cpp) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/headpose/README.md b/examples/vision/headpose/README.md index b727752e0a..eec488e8dd 100755 --- a/examples/vision/headpose/README.md +++ b/examples/vision/headpose/README.md @@ -1,7 +1,8 @@ -# 头部姿态模型 +English | [简体中文](README_CN.md) +# Headpose Model -FastDeploy目前支持如下头部姿态模型部署 +FastDeploy currently supports the deployment of the following headpose models -| 模型 | 说明 | 模型格式 | 版本 | +| Model | Description | Model Format | Version | | :--- | :--- | :------- | :--- | -| [omasaht/headpose-fsanet-pytorch](./fsanet) | FSANet 系列模型 | ONNX | [CommitID:002549c](https://github.com/omasaht/headpose-fsanet-pytorch/commit/002549c) | +| [omasaht/headpose-fsanet-pytorch](./fsanet) | FSANet models | ONNX | [CommitID:002549c](https://github.com/omasaht/headpose-fsanet-pytorch/commit/002549c) | diff --git a/examples/vision/headpose/README_CN.md b/examples/vision/headpose/README_CN.md new file mode 100644 index 0000000000..66ba5e13ba --- /dev/null +++ b/examples/vision/headpose/README_CN.md @@ -0,0 +1,8 @@ +[English](README.md) | 简体中文 +# 头部姿态模型 + +FastDeploy目前支持如下头部姿态模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +| :--- | :--- | :------- | :--- | +| [omasaht/headpose-fsanet-pytorch](./fsanet) | FSANet 系列模型 | ONNX | [CommitID:002549c](https://github.com/omasaht/headpose-fsanet-pytorch/commit/002549c) | diff --git a/examples/vision/headpose/fsanet/README.md b/examples/vision/headpose/fsanet/README.md index 8cddca2cc5..ee52924a28 100644 --- a/examples/vision/headpose/fsanet/README.md +++ b/examples/vision/headpose/fsanet/README.md @@ -1,25 +1,25 @@ -# FSANet 模型部署 +English | [简体中文](README_CN.md) +# FSANet Model Deployment -## 模型版本说明 +## Model Description - [FSANet](https://github.com/omasaht/headpose-fsanet-pytorch/commit/002549c) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +FastDeploy currently supports the deployment of the following models -- [FSANet 模型](https://github.com/omasaht/headpose-fsanet-pytorch) +- [FSANet model](https://github.com/omasaht/headpose-fsanet-pytorch) -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了PFLD导出的各系列模型,开发者可直接下载使用。 - -| 模型 | 参数大小 | 精度 | 备注 | +For developers' testing, models exported by PFLD are provided below. Developers can download and use them directly. +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | | [fsanet-1x1.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-1x1.onnx) | 1.2M | - | | [fsanet-var.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-var.onnx) | 1.2MB | - | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/headpose/fsanet/README_CN.md b/examples/vision/headpose/fsanet/README_CN.md new file mode 100644 index 0000000000..8a14d4f4b0 --- /dev/null +++ b/examples/vision/headpose/fsanet/README_CN.md @@ -0,0 +1,26 @@ +[English](README.md) | 简体中文 +# FSANet 模型部署 + +## 模型版本说明 + +- [FSANet](https://github.com/omasaht/headpose-fsanet-pytorch/commit/002549c) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [FSANet 模型](https://github.com/omasaht/headpose-fsanet-pytorch) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PFLD导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [fsanet-1x1.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-1x1.onnx) | 1.2M | - | +| [fsanet-var.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-var.onnx) | 1.2MB | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/headpose/fsanet/cpp/README.md b/examples/vision/headpose/fsanet/cpp/README.md index 1d1b1e9439..7b7a766e22 100755 --- a/examples/vision/headpose/fsanet/cpp/README.md +++ b/examples/vision/headpose/fsanet/cpp/README.md @@ -1,46 +1,47 @@ -# FSANet C++部署示例 +English | [简体中文](README_CN.md) +# FSANet C++ Deployment Example -本目录下提供`infer.cc`快速完成FSANet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of FSANet on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.2 or above (x.x.x>=1.0.2), or the nightly built version is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的 FSANet 模型文件和测试图片 +# Download the official converted FSANet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-var.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/headpose_input.png -# CPU推理 +# CPU inference ./infer_demo --model fsanet-var.onnx --image headpose_input.png --device cpu -# GPU推理 +# GPU inference ./infer_demo --model fsanet-var.onnx --image headpose_input.png --device gpu -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo --model fsanet-var.onnx --image headpose_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## FSANet C++接口 +## FSANet C++ Interface -### FSANet 类 +### FSANet Class ```c++ fastdeploy::vision::headpose::FSANet( @@ -49,28 +50,28 @@ fastdeploy::vision::headpose::FSANet( const RuntimeOption& runtime_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::ONNX) ``` -FSANet模型加载和初始化,其中model_file为导出的ONNX模型格式。 -**参数** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 -#### Predict函数 +FSANet model loading and initialization, among which model_file is the exported ONNX model format. +**Parameter** +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default +#### Predict Function > ```c++ > FSANet::Predict(cv::Mat* im, HeadPoseResult* result) > ``` > -> 模型预测接口,输入图像直接输出头部姿态预测结果。 +> Model prediction interface. Input images and output head pose prediction results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 头部姿态预测结果, HeadPoseResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -### 类成员变量 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] +> > * **im**: Input images in HWC or BGR format +> > * **result**: Head pose prediction results. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of HeadPoseResult +### Class Member Variable +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [112, 112] -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/headpose/fsanet/cpp/README_CN.md b/examples/vision/headpose/fsanet/cpp/README_CN.md new file mode 100644 index 0000000000..d8b9385316 --- /dev/null +++ b/examples/vision/headpose/fsanet/cpp/README_CN.md @@ -0,0 +1,77 @@ +[English](README.md) | 简体中文 +# FSANet C++部署示例 + +本目录下提供`infer.cc`快速完成FSANet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的 FSANet 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-var.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/headpose_input.png +# CPU推理 +./infer_demo --model fsanet-var.onnx --image headpose_input.png --device cpu +# GPU推理 +./infer_demo --model fsanet-var.onnx --image headpose_input.png --device gpu +# GPU上TensorRT推理 +./infer_demo --model fsanet-var.onnx --image headpose_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## FSANet C++接口 + +### FSANet 类 + +```c++ +fastdeploy::vision::headpose::FSANet( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` +FSANet模型加载和初始化,其中model_file为导出的ONNX模型格式。 +**参数** +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +#### Predict函数 +> ```c++ +> FSANet::Predict(cv::Mat* im, HeadPoseResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出头部姿态预测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 头部姿态预测结果, HeadPoseResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +### 类成员变量 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[112, 112] + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/headpose/fsanet/python/README.md b/examples/vision/headpose/fsanet/python/README.md index 7863fb1f11..c1f6aa35ba 100644 --- a/examples/vision/headpose/fsanet/python/README.md +++ b/examples/vision/headpose/fsanet/python/README.md @@ -1,67 +1,68 @@ -# FSANet Python部署示例 +English | [简体中文](README_CN.md) +# FSANet Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成FSANet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.6.0 支持FSANet模型。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of FSANet on CPU/GPU and GPU accelerated by TensorRT. FastDeploy version 0.6.0 or above is required to support this model. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/headpose/fsanet/python -# 下载FSANet模型文件和测试图片 -## 原版ONNX模型 +# Download the FSANet model files and test images +## Original ONNX Model wget https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-var.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/headpose_input.png -# CPU推理 +# CPU inference python infer.py --model fsanet-var.onnx --image headpose_input.png --device cpu -# GPU推理 +# GPU inference python infer.py --model fsanet-var.onnx --image headpose_input.png --device gpu -# TRT推理 +# TRT inference python infer.py --model fsanet-var.onnx --image headpose_input.png --device gpu --backend trt ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## FSANet Python接口 +## FSANet Python Interface ```python fd.vision.headpose.FSANet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -FSANet 模型加载和初始化,其中model_file为导出的ONNX模型格式 +FSANet model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX -### predict函数 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default +### predict function > ```python > FSANet.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出头部姿态预测结果。 +> Model prediction interface. Input images and output head pose prediction results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> **返回** +> > * **input_image**(np.ndarray): Input data in HWC or BGR format +> **Return** > -> > 返回`fastdeploy.vision.HeadPoseResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.HeadPoseResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure -## 其它文档 +## Other Documents -- [FSANet 模型介绍](..) -- [FSANet C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [FSANet Model Description](..) +- [FSANet C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/headpose/fsanet/python/README_CN.md b/examples/vision/headpose/fsanet/python/README_CN.md new file mode 100644 index 0000000000..26952db2f0 --- /dev/null +++ b/examples/vision/headpose/fsanet/python/README_CN.md @@ -0,0 +1,68 @@ +[English](README.md) | 简体中文 +# FSANet Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成FSANet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例,保证 FastDeploy 版本 >= 0.6.0 支持FSANet模型。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/headpose/fsanet/python + +# 下载FSANet模型文件和测试图片 +## 原版ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/fsanet-var.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/headpose_input.png +# CPU推理 +python infer.py --model fsanet-var.onnx --image headpose_input.png --device cpu +# GPU推理 +python infer.py --model fsanet-var.onnx --image headpose_input.png --device gpu +# TRT推理 +python infer.py --model fsanet-var.onnx --image headpose_input.png --device gpu --backend trt +``` + +运行完成可视化结果如下图所示 + +
+ +
+ +## FSANet Python接口 + +```python +fd.vision.headpose.FSANet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +FSANet 模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX +### predict函数 + +> ```python +> FSANet.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出头部姿态预测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> **返回** +> +> > 返回`fastdeploy.vision.HeadPoseResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +## 其它文档 + +- [FSANet 模型介绍](..) +- [FSANet C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/README.md b/examples/vision/keypointdetection/README.md index bcc368e912..16d1c6f640 100644 --- a/examples/vision/keypointdetection/README.md +++ b/examples/vision/keypointdetection/README.md @@ -1,3 +1,4 @@ +English | [简体中文](README_CN.md) # 关键点检测模型 FastDeploy目前支持两种关键点检测任务方式的部署 diff --git a/examples/vision/keypointdetection/README_CN.md b/examples/vision/keypointdetection/README_CN.md new file mode 100644 index 0000000000..3cc3f31b50 --- /dev/null +++ b/examples/vision/keypointdetection/README_CN.md @@ -0,0 +1,18 @@ +[English](README.md) | 简体中文 +# 关键点检测模型 + +FastDeploy目前支持两种关键点检测任务方式的部署 + +| 任务 | 说明 | 模型格式 | 示例 | 版本 | +| :---| :--- | :--- | :------- | :--- | +| 单人关键点检测 | 部署PP-TinyPose系列模型,输入图像仅包含单人 | Paddle | 参考[tinypose目录](./tiny_pose/) | [Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) | +| 单人/多人关键点检测 | 部署PicoDet + PP-TinyPose的模型串联任务,输入图像先通过检测模型,得到独立的人像子图后,再经过PP-TinyPose模型检测关键点 | Paddle | 参考[det_keypoint_unite目录](./det_keypoint_unite/) |[Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) | + +# 预训练模型准备 +本文档提供了如下预训练模型,开发者可直接下载使用 +| 模型 | 说明 | 模型格式 | 版本 | +| :--- | :--- | :------- | :--- | +| [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 单人关键点检测模型 | Paddle | [Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) | +| [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 单人关键点检测模型 | Paddle | [Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) | +| [PicoDet-S-Lcnet-Pedestrian-192x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_192x192_infer.tgz) + [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 单人关键点检测串联配置 | Paddle |[Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) | +| [PicoDet-S-Lcnet-Pedestrian-320x320](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz) + [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 多人关键点检测串联配置 | Paddle |[Release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose) | diff --git a/examples/vision/keypointdetection/det_keypoint_unite/README.md b/examples/vision/keypointdetection/det_keypoint_unite/README.md index c323a5c1c5..46c647c082 100644 --- a/examples/vision/keypointdetection/det_keypoint_unite/README.md +++ b/examples/vision/keypointdetection/det_keypoint_unite/README.md @@ -1,38 +1,39 @@ -# PP-PicoDet + PP-TinyPose 联合部署(Pipeline) +English | [简体中文](README_CN.md) +# PP-PicoDet + PP-TinyPose Co-deployment (Pipeline) -## 模型版本说明 +## Model Description - [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5) -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PP-PicoDet + PP-TinyPose系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) +- [PP-PicoDet + PP-TinyPose Models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) -## 准备PP-TinyPose部署模型 +## Prepare PP-TinyPose Deployment Model -PP-TinyPose以及PP-PicoDet模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) +Export the PP-TinyPose and PP-PicoDet models. Please refer to [Model Export](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) -**注意**:导出的推理模型包含`model.pdmodel`、`model.pdiparams`和`infer_cfg.yml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息。 +**Attention**: The exported inference model contains three files, including `model.pdmodel`、`model.pdiparams` and `infer_cfg.yml`. FastDeploy will get the pre-processing information for inference from yaml files. -## 下载预训练模型 +## Download Pre-trained Model -为了方便开发者的测试,下面提供了PP-PicoDet + PP-TinyPose(Pipeline)导出的部分模型,开发者可直接下载使用。 +For developers' testing, part of the PP-PicoDet + PP-TinyPose(Pipeline)exported models are provided below. Developers can download and use them directly. -| 应用场景 | 模型 | 参数文件大小 | AP(业务数据集) | AP(COCO Val 单人/多人) | 单人/多人推理耗时 (FP32) | 单人/多人推理耗时(FP16) | +| Application Scenario | Model | Parameter File Size | AP(Service Data set) | AP(COCO Val Single/Multi-person) | Single/Multi-person Inference Time (FP32) | Single/Multi-person Inference Time(FP16) | |:-------------------------------|:--------------------------------- |:----- |:----- | :----- | :----- | :----- | -| 单人模型配置 |[PicoDet-S-Lcnet-Pedestrian-192x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_192x192_infer.tgz) + [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 4.6MB + 5.3MB | 86.2% | 52.8% | 12.90ms | 9.61ms | -| 多人模型配置 |[PicoDet-S-Lcnet-Pedestrian-320x320](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz) + [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 4.6M + 5.3MB | 85.7% | 49.9% | 47.63ms | 34.62ms | +| Single-person Model Configuration |[PicoDet-S-Lcnet-Pedestrian-192x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_192x192_infer.tgz) + [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 4.6MB + 5.3MB | 86.2% | 52.8% | 12.90ms | 9.61ms | +| Multi-person Model Configuration |[PicoDet-S-Lcnet-Pedestrian-320x320](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz) + [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 4.6M + 5.3MB | 85.7% | 49.9% | 47.63ms | 34.62ms | -**说明** -- 关键点检测模型的精度指标是基于对应行人检测模型检测得到的检测框。 -- 精度测试中去除了flip操作,且检测置信度阈值要求0.5。 -- 速度测试环境为qualcomm snapdragon 865,采用arm8下4线程推理。 -- Pipeline速度包含模型的预处理、推理及后处理部分。 -- 精度测试中,为了公平比较,多人数据去除了6人以上(不含6人)的图像。 +**Note** +- The accuracy of the keypoint detection model is based on the detection frame obtained by the pedestrian detection model. +- The flip operation is removed from the accuracy test with the detection confidence threshold of 0.5. +- The speed test environment is qualcomm snapdragon 865 with 4-thread inference under arm8. +- The Pipeline speed covers the preprocessing, inference, and post-processing of the model. +- In the accuracy test, images with more than 6 people (excluding 6 people) were removed from the multi-person data for fair comparison. -更多信息请参考:[PP-TinyPose 官方文档](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) +For more information: refer to [PP-TinyPose official document](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/keypointdetection/det_keypoint_unite/README_CN.md b/examples/vision/keypointdetection/det_keypoint_unite/README_CN.md new file mode 100644 index 0000000000..ab7dba213e --- /dev/null +++ b/examples/vision/keypointdetection/det_keypoint_unite/README_CN.md @@ -0,0 +1,39 @@ +[English](README.md) | 简体中文 +# PP-PicoDet + PP-TinyPose 联合部署(Pipeline) + +## 模型版本说明 + +- [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5) + +目前FastDeploy支持如下模型的部署 + +- [PP-PicoDet + PP-TinyPose系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) + +## 准备PP-TinyPose部署模型 + +PP-TinyPose以及PP-PicoDet模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) + +**注意**:导出的推理模型包含`model.pdmodel`、`model.pdiparams`和`infer_cfg.yml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息。 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PP-PicoDet + PP-TinyPose(Pipeline)导出的部分模型,开发者可直接下载使用。 + +| 应用场景 | 模型 | 参数文件大小 | AP(业务数据集) | AP(COCO Val 单人/多人) | 单人/多人推理耗时 (FP32) | 单人/多人推理耗时(FP16) | +|:-------------------------------|:--------------------------------- |:----- |:----- | :----- | :----- | :----- | +| 单人模型配置 |[PicoDet-S-Lcnet-Pedestrian-192x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_192x192_infer.tgz) + [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 4.6MB + 5.3MB | 86.2% | 52.8% | 12.90ms | 9.61ms | +| 多人模型配置 |[PicoDet-S-Lcnet-Pedestrian-320x320](https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz) + [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 4.6M + 5.3MB | 85.7% | 49.9% | 47.63ms | 34.62ms | + +**说明** +- 关键点检测模型的精度指标是基于对应行人检测模型检测得到的检测框。 +- 精度测试中去除了flip操作,且检测置信度阈值要求0.5。 +- 速度测试环境为qualcomm snapdragon 865,采用arm8下4线程推理。 +- Pipeline速度包含模型的预处理、推理及后处理部分。 +- 精度测试中,为了公平比较,多人数据去除了6人以上(不含6人)的图像。 + +更多信息请参考:[PP-TinyPose 官方文档](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/keypointdetection/det_keypoint_unite/cpp/README.md b/examples/vision/keypointdetection/det_keypoint_unite/cpp/README.md index 57c513cda8..e0f3923511 100755 --- a/examples/vision/keypointdetection/det_keypoint_unite/cpp/README.md +++ b/examples/vision/keypointdetection/det_keypoint_unite/cpp/README.md @@ -1,53 +1,53 @@ -# PP-PicoDet + PP-TinyPose (Pipeline) C++部署示例 +English | [简体中文](README_CN.md) +# PP-PicoDet + PP-TinyPose (Pipeline) C++ Deployment Example -本目录下提供`det_keypoint_unite_infer.cc`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成 ->> **注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../../tiny_pose/cpp/README.md) +This directory provides the `Multi-person keypoint detection in a single image` example that `det_keypoint_unite_infer.cc` fast finishes the deployment of multi-person detection model PP-PicoDet + PP-TinyPose on CPU/GPU and GPU accelerated by TensorRT. The script is as follows -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载PP-TinyPose和PP-PicoDet模型文件和测试图片 +# Download PP-TinyPose+PP-PicoDet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz tar -xvf PP_TinyPose_256x192_infer.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz tar -xvf PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/000000018491.jpg -# CPU推理 +# CPU inference ./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 0 -# GPU推理 +# GPU inference ./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 2 -# 昆仑芯XPU推理 +# kunlunxin XPU inference ./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 3 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PP-TinyPose C++接口 +## PP-TinyPose C++ Interface -### PP-TinyPose类 +### PP-TinyPose Class ```c++ fastdeploy::pipeline::PPTinyPose( @@ -55,32 +55,31 @@ fastdeploy::pipeline::PPTinyPose( fastdeploy::vision::keypointdetection::PPTinyPose* pptinypose_model) ``` -PPTinyPose Pipeline模型加载和初始化。 +PPTinyPose Pipeline model loading and initialization. -**参数** +**Parameter** -> * **model_det_modelfile**(fastdeploy::vision::detection): 初始化后的检测模型,参考[PP-TinyPose](../../tiny_pose/README.md) -> * **pptinypose_model**(fastdeploy::vision::keypointdetection): 初始化后的检测模型[Detection](../../../detection/paddledetection/README.md),暂时只提供PaddleDetection系列 +> * **model_det_modelfile**(fastdeploy::vision::detection): Initialized detection model. Refer to [PP-TinyPose](../../tiny_pose/README.md) +> * **pptinypose_model**(fastdeploy::vision::keypointdetection): Initialized detection model [Detection](../../../detection/paddledetection/README.md). Currently only PaddleDetection series is available. -#### Predict函数 +#### Predict Function > ```c++ > PPTinyPose::Predict(cv::Mat* im, KeyPointDetectionResult* result) > ``` > -> 模型预测接口,输入图像直接输出关键点检测结果。 +> Model prediction interface. Input images and output keypoint detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 关键点检测结果,包括关键点的坐标以及关键点对应的概率值, KeyPointDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 类成员属性 -#### 后处理参数 -> > * **detection_model_score_threshold**(bool): -输入PP-TinyPose模型前,Detectin模型过滤检测框的分数阈值 - -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Keypoint detection results, including coordinates and the corresponding probability value. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of KeyPointDetectionResult + +### Class Member Property +#### Post-processing Parameter +> > * **detection_model_score_threshold**(bool): Score threshold of the Detectin model for filtering detection boxes before entering the PP-TinyPose model + +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/det_keypoint_unite/cpp/README_CN.md b/examples/vision/keypointdetection/det_keypoint_unite/cpp/README_CN.md new file mode 100644 index 0000000000..b6eafe475d --- /dev/null +++ b/examples/vision/keypointdetection/det_keypoint_unite/cpp/README_CN.md @@ -0,0 +1,87 @@ +[English](README.md) | 简体中文 +# PP-PicoDet + PP-TinyPose (Pipeline) C++部署示例 + +本目录下提供`det_keypoint_unite_infer.cc`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成 +>> **注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../../tiny_pose/cpp/README.md) + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载PP-TinyPose和PP-PicoDet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz +tar -xvf PP_TinyPose_256x192_infer.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz +tar -xvf PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/000000018491.jpg + +# CPU推理 +./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 0 +# GPU推理 +./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 1 +# GPU上TensorRT推理 +./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 2 +# 昆仑芯XPU推理 +./infer_demo PP_PicoDet_V2_S_Pedestrian_320x320_infer PP_TinyPose_256x192_infer 000000018491.jpg 3 +``` + +运行完成可视化结果如下图所示 +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PP-TinyPose C++接口 + +### PP-TinyPose类 + +```c++ +fastdeploy::pipeline::PPTinyPose( + fastdeploy::vision::detection::PPYOLOE* det_model, + fastdeploy::vision::keypointdetection::PPTinyPose* pptinypose_model) +``` + +PPTinyPose Pipeline模型加载和初始化。 + +**参数** + +> * **model_det_modelfile**(fastdeploy::vision::detection): 初始化后的检测模型,参考[PP-TinyPose](../../tiny_pose/README.md) +> * **pptinypose_model**(fastdeploy::vision::keypointdetection): 初始化后的检测模型[Detection](../../../detection/paddledetection/README.md),暂时只提供PaddleDetection系列 + +#### Predict函数 + +> ```c++ +> PPTinyPose::Predict(cv::Mat* im, KeyPointDetectionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出关键点检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 关键点检测结果,包括关键点的坐标以及关键点对应的概率值, KeyPointDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 后处理参数 +> > * **detection_model_score_threshold**(bool): +输入PP-TinyPose模型前,Detectin模型过滤检测框的分数阈值 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/det_keypoint_unite/python/README.md b/examples/vision/keypointdetection/det_keypoint_unite/python/README.md index a6366b800e..48621705ce 100755 --- a/examples/vision/keypointdetection/det_keypoint_unite/python/README.md +++ b/examples/vision/keypointdetection/det_keypoint_unite/python/README.md @@ -1,76 +1,77 @@ -# PP-PicoDet + PP-TinyPose (Pipeline) Python部署示例 +English | [简体中文](README_CN.md) +# PP-PicoDet + PP-TinyPose (Pipeline) Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`det_keypoint_unite_infer.py`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成 ->> **注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../../tiny_pose//python/README.md) +This directory provides the `Multi-person keypoint detection in a single image` example that `det_keypoint_unite_infer.py` fast finishes the deployment of multi-person detection model PP-PicoDet + PP-TinyPose on CPU/GPU and GPU accelerated by TensorRT. The script is as follows +>> **Attention**: For standalone deployment of PP-TinyPose single model, refer to [PP-TinyPose Single Model](../../tiny_pose//python/README.md) ```bash -#下载部署示例代码 +# Download the deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/keypointdetection/det_keypoint_unite/python -# 下载PP-TinyPose模型文件和测试图片 +# Download PP-TinyPose model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz tar -xvf PP_TinyPose_256x192_infer.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz tar -xvf PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/000000018491.jpg -# CPU推理 +# CPU inference python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device cpu -# GPU推理 +# GPU inference python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 +# kunlunxin XPU inference python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device kunlunxin ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PPTinyPosePipeline Python接口 +## PPTinyPosePipeline Python Interface ```python fd.pipeline.PPTinyPose(det_model=None, pptinypose_model=None) ``` -PPTinyPosePipeline模型加载和初始化,其中det_model是使用`fd.vision.detection.PicoDet`[参考Detection文档](../../../detection/paddledetection/python/)初始化的检测模型,pptinypose_model是使用`fd.vision.keypointdetection.PPTinyPose`[参考PP-TinyPose文档](../../tiny_pose/python/)初始化的检测模型 +PPTinyPosePipeline model loading and initialization, among which the det_model is the detection model initialized by `fd.vision.detection.PicoDet`[Refer to Detection Document](../../../detection/paddledetection/python/) and pptinypose_model is the detection model initialized by `fd.vision.keypointdetection.PPTinyPose`[Refer to PP-TinyPose Document](../../tiny_pose/python/) -**参数** +**Parameter** -> * **det_model**(str): 初始化后的检测模型 -> * **pptinypose_model**(str): 初始化后的PP-TinyPose模型 +> * **det_model**(str): Initialized detection model +> * **pptinypose_model**(str): Initialized PP-TinyPose model -### predict函数 +### predict function > ```python > PPTinyPosePipeline.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output keypoint detection results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.KeyPointDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.KeyPointDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -### 类成员属性 -#### 后处理参数 +### Class Member Property +#### Post-processing Parameter > > * **detection_model_score_threshold**(bool): -输入PP-TinyPose模型前,Detectin模型过滤检测框的分数阈值 +Score threshold of the Detectin model for filtering detection boxes before entering the PP-TinyPose model -## 其它文档 +## Other Documents -- [Pipeline 模型介绍](..) -- [Pipeline C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Pipeline Model Description](..) +- [Pipeline C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/det_keypoint_unite/python/README_CN.md b/examples/vision/keypointdetection/det_keypoint_unite/python/README_CN.md new file mode 100644 index 0000000000..7f994d826a --- /dev/null +++ b/examples/vision/keypointdetection/det_keypoint_unite/python/README_CN.md @@ -0,0 +1,77 @@ +[English](README.md) | 简体中文 +# PP-PicoDet + PP-TinyPose (Pipeline) Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`det_keypoint_unite_infer.py`快速完成多人模型配置 PP-PicoDet + PP-TinyPose 在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图多人关键点检测`示例。执行如下脚本即可完成 +>> **注意**: PP-TinyPose单模型独立部署,请参考[PP-TinyPose 单模型](../../tiny_pose//python/README.md) + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/keypointdetection/det_keypoint_unite/python + +# 下载PP-TinyPose模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz +tar -xvf PP_TinyPose_256x192_infer.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz +tar -xvf PP_PicoDet_V2_S_Pedestrian_320x320_infer.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/000000018491.jpg +# CPU推理 +python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device cpu +# GPU推理 +python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python det_keypoint_unite_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --det_model_dir PP_PicoDet_V2_S_Pedestrian_320x320_infer --image 000000018491.jpg --device kunlunxin +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PPTinyPosePipeline Python接口 + +```python +fd.pipeline.PPTinyPose(det_model=None, pptinypose_model=None) +``` + +PPTinyPosePipeline模型加载和初始化,其中det_model是使用`fd.vision.detection.PicoDet`[参考Detection文档](../../../detection/paddledetection/python/)初始化的检测模型,pptinypose_model是使用`fd.vision.keypointdetection.PPTinyPose`[参考PP-TinyPose文档](../../tiny_pose/python/)初始化的检测模型 + +**参数** + +> * **det_model**(str): 初始化后的检测模型 +> * **pptinypose_model**(str): 初始化后的PP-TinyPose模型 + +### predict函数 + +> ```python +> PPTinyPosePipeline.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.KeyPointDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 后处理参数 +> > * **detection_model_score_threshold**(bool): +输入PP-TinyPose模型前,Detectin模型过滤检测框的分数阈值 + +## 其它文档 + +- [Pipeline 模型介绍](..) +- [Pipeline C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/tiny_pose/README.md b/examples/vision/keypointdetection/tiny_pose/README.md index 2166a1c03a..99ec0e3651 100644 --- a/examples/vision/keypointdetection/tiny_pose/README.md +++ b/examples/vision/keypointdetection/tiny_pose/README.md @@ -1,37 +1,39 @@ -# PP-TinyPose 模型部署 +English | [简体中文](README_CN.md) +# PP-TinyPose Model Deployment -## 模型版本说明 +## Model Description - [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5) -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PP-TinyPose系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) +- [PP-TinyPose models](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) -## 准备PP-TinyPose部署模型 +## Prepare PP-TinyPose Deployment Model -PP-TinyPose模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) +Export the PP-TinyPose model. Please refer to [Model Export](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) -**注意**:PP-TinyPose导出的模型包含`model.pdmodel`、`model.pdiparams`和`infer_cfg.yml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息。 +**Attention**: The exported PP-TinyPose model contains three files, including `model.pdmodel`、`model.pdiparams` and `infer_cfg.yml`. FastDeploy will get the pre-processing information for inference from yaml files. -## 下载预训练模型 +## Download Pre-trained Model -为了方便开发者的测试,下面提供了PP-TinyPose导出的部分模型,开发者可直接下载使用。 +For developers' testing, part of the PP-TinyPose exported models are provided below. Developers can download and use them directly. -| 模型 | 参数文件大小 |输入Shape | AP(业务数据集) | AP(COCO Val) | FLOPS | 单人推理耗时 (FP32) | 单人推理耗时(FP16) | +| Model | Parameter File Size | Input Shape | AP(Service Data set) | AP(COCO Val) | FLOPS | Single/Multi-person Inference Time (FP32) | Single/Multi-person Inference Time(FP16) | |:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | :----- | :----- | | [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 5.3MB | 128x96 | 84.3% | 58.4% | 81.56 M | 4.57ms | 3.27ms | | [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 5.3M | 256x96 | 91.0% | 68.3% | 326.24M | 14.07ms | 8.33ms | -**说明** -- 关键点检测模型使用`COCO train2017`和`AI Challenger trainset`作为训练集。使用`COCO person keypoints val2017`作为测试集。 -- 关键点检测模型的精度指标所依赖的检测框为ground truth标注得到。 -- 推理速度测试环境为 Qualcomm Snapdragon 865,采用arm8下4线程推理得到。 +**Note** +- The keypoint detection model uses `COCO train2017` and `AI Challenger trainset` as the training sets and `COCO person keypoints val2017` as the test set. +- The detection frame, through which we get the accuracy of the keypoint detection model, is obtained from the ground truth annotation. +- The speed test environment is Qualcomm Snapdragon 865 with 4-thread inference under arm8. -更多信息请参考:[PP-TinyPose 官方文档](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) -## 详细部署文档 +For more information: refer to [PP-TinyPose official document](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) -- [Python部署](python) -- [C++部署](cpp) +## Detailed Deployment Tutorials + +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/keypointdetection/tiny_pose/README_CN.md b/examples/vision/keypointdetection/tiny_pose/README_CN.md new file mode 100644 index 0000000000..8a8c92ab76 --- /dev/null +++ b/examples/vision/keypointdetection/tiny_pose/README_CN.md @@ -0,0 +1,38 @@ +[English](README.md) | 简体中文 +# PP-TinyPose 模型部署 + +## 模型版本说明 + +- [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5) + +目前FastDeploy支持如下模型的部署 + +- [PP-TinyPose系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) + +## 准备PP-TinyPose部署模型 + +PP-TinyPose模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) + +**注意**:PP-TinyPose导出的模型包含`model.pdmodel`、`model.pdiparams`和`infer_cfg.yml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息。 + + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PP-TinyPose导出的部分模型,开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | AP(业务数据集) | AP(COCO Val) | FLOPS | 单人推理耗时 (FP32) | 单人推理耗时(FP16) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | :----- | :----- | +| [PP-TinyPose-128x96](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_128x96_infer.tgz) | 5.3MB | 128x96 | 84.3% | 58.4% | 81.56 M | 4.57ms | 3.27ms | +| [PP-TinyPose-256x192](https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz) | 5.3M | 256x96 | 91.0% | 68.3% | 326.24M | 14.07ms | 8.33ms | + +**说明** +- 关键点检测模型使用`COCO train2017`和`AI Challenger trainset`作为训练集。使用`COCO person keypoints val2017`作为测试集。 +- 关键点检测模型的精度指标所依赖的检测框为ground truth标注得到。 +- 推理速度测试环境为 Qualcomm Snapdragon 865,采用arm8下4线程推理得到。 + +更多信息请参考:[PP-TinyPose 官方文档](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint/tiny_pose/README.md) + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/keypointdetection/tiny_pose/cpp/README.md b/examples/vision/keypointdetection/tiny_pose/cpp/README.md index 867e4251cd..b6e12268b4 100755 --- a/examples/vision/keypointdetection/tiny_pose/cpp/README.md +++ b/examples/vision/keypointdetection/tiny_pose/cpp/README.md @@ -1,52 +1,53 @@ -# PP-TinyPose C++部署示例 +English | [简体中文](README_CN.md) +# PP-TinyPose C++ Deployment Example -本目录下提供`pptinypose_infer.cc`快速完成PP-TinyPose在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图单人关键点检测`示例 ->> **注意**: PP-Tinypose单模型目前只支持单图单人关键点检测,因此输入的图片应只包含一个人或者进行过裁剪的图像。多人关键点检测请参考[PP-TinyPose Pipeline](../../det_keypoint_unite/cpp/README.md) +This directory provides the `Multi-person keypoint detection in a single image` example that `pptinypose_infer.cc` fast finishes the deployment of PP-TinyPose on CPU/GPU and GPU accelerated by TensorRT. The script is as follows +>> **Attention**: PP-Tinypose single model currently supports single-person keypoint detection in a single image. Therefore, the input image should contain one person only or should be cropped. For multi-person keypoint detection, refer to [PP-TinyPose Pipeline](../../det_keypoint_unite/cpp/README.md) -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载PP-TinyPose模型文件和测试图片 +# Download PP-TinyPose model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz tar -xvf PP_TinyPose_256x192_infer.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg -# CPU推理 +# CPU inference ./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 0 -# GPU推理 +# GPU inference ./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 2 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 3 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PP-TinyPose C++接口 +## PP-TinyPose C++ Interface -### PP-TinyPose类 +### PP-TinyPose Class ```c++ fastdeploy::vision::keypointdetection::PPTinyPose( @@ -57,34 +58,34 @@ fastdeploy::vision::keypointdetection::PPTinyPose( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -PPTinyPose模型加载和初始化,其中model_file为导出的Paddle模型格式。 +PPTinyPose model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict function > ```c++ > PPTinyPose::Predict(cv::Mat* im, KeyPointDetectionResult* result) > ``` > -> 模型预测接口,输入图像直接输出关键点检测结果。 +> Model prediction interface. Input images and output keypoint detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 关键点检测结果,包括关键点的坐标以及关键点对应的概率值, KeyPointDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Keypoint detection results, including coordinates and the corresponding probability value. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of KeyPointDetectionResult -### 类成员属性 -#### 后处理参数 -> > * **use_dark**(bool): 是否使用DARK进行后处理[参考论文](https://arxiv.org/abs/1910.06278) +### Class Member Property +#### Post-processing Parameter +> > * **use_dark**(bool): Whether to use DARK for post-processing. Refer to [Reference Paper](https://arxiv.org/abs/1910.06278) -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/tiny_pose/cpp/README_CN.md b/examples/vision/keypointdetection/tiny_pose/cpp/README_CN.md new file mode 100644 index 0000000000..388b8816df --- /dev/null +++ b/examples/vision/keypointdetection/tiny_pose/cpp/README_CN.md @@ -0,0 +1,91 @@ +[English](README.md) | 简体中文 +# PP-TinyPose C++部署示例 + +本目录下提供`pptinypose_infer.cc`快速完成PP-TinyPose在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图单人关键点检测`示例 +>> **注意**: PP-Tinypose单模型目前只支持单图单人关键点检测,因此输入的图片应只包含一个人或者进行过裁剪的图像。多人关键点检测请参考[PP-TinyPose Pipeline](../../det_keypoint_unite/cpp/README.md) + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载PP-TinyPose模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz +tar -xvf PP_TinyPose_256x192_infer.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg + + +# CPU推理 +./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 0 +# GPU推理 +./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 1 +# GPU上TensorRT推理 +./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 2 +# 昆仑芯XPU推理 +./infer_tinypose_demo PP_TinyPose_256x192_infer hrnet_demo.jpg 3 +``` + +运行完成可视化结果如下图所示 +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PP-TinyPose C++接口 + +### PP-TinyPose类 + +```c++ +fastdeploy::vision::keypointdetection::PPTinyPose( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PPTinyPose模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PPTinyPose::Predict(cv::Mat* im, KeyPointDetectionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出关键点检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 关键点检测结果,包括关键点的坐标以及关键点对应的概率值, KeyPointDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 后处理参数 +> > * **use_dark**(bool): 是否使用DARK进行后处理[参考论文](https://arxiv.org/abs/1910.06278) + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/tiny_pose/python/README.md b/examples/vision/keypointdetection/tiny_pose/python/README.md index 4ac811bcae..22b5b89dd6 100755 --- a/examples/vision/keypointdetection/tiny_pose/python/README.md +++ b/examples/vision/keypointdetection/tiny_pose/python/README.md @@ -1,81 +1,81 @@ -# PP-TinyPose Python部署示例 +English | [简体中文](README_CN.md) +# PP-TinyPose Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`pptinypose_infer.py`快速完成PP-TinyPose在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图单人关键点检测`示例。执行如下脚本即可完成 - ->> **注意**: PP-Tinypose单模型目前只支持单图单人关键点检测,因此输入的图片应只包含一个人或者进行过裁剪的图像。多人关键点检测请参考[PP-TinyPose Pipeline](../../det_keypoint_unite/python/README.md) +This directory provides the `Multi-person keypoint detection in a single image` example that `pptinypose_infer.py` fast finishes the deployment of PP-TinyPose on CPU/GPU and GPU accelerated by TensorRT. The script is as follows +>> **Attention**: single model currently only supports single-person keypoint detection in a single image. Therefore, the input image should contain one person only or should be cropped. For multi-person keypoint detection, refer to [PP-TinyPose Pipeline](../../det_keypoint_unite/python/README.md) ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/keypointdetection/tiny_pose/python -# 下载PP-TinyPose模型文件和测试图片 +# Download PP-TinyPose model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz tar -xvf PP_TinyPose_256x192_infer.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg -# CPU推理 +# CPU inference python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device cpu -# GPU推理 +# GPU inference python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 +# KunlunXin XPU inference python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device kunlunxin ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PP-TinyPose Python接口 +## PP-TinyPose Python Interface ```python fd.vision.keypointdetection.PPTinyPose(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PP-TinyPose模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) +PP-TinyPose model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > PPTinyPose.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.KeyPointDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.KeyPointDetectionResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -### 类成员属性 -#### 后处理参数 -用户可按照自己的实际需求,修改下列后处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Post-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **use_dark**(bool): 是否使用DARK进行后处理[参考论文](https://arxiv.org/abs/1910.06278) +> > * **use_dark**(bool): • Whether to use DARK for post-processing. Refer to [Reference Paper](https://arxiv.org/abs/1910.06278) -## 其它文档 +## Other Documents -- [PP-TinyPose 模型介绍](..) -- [PP-TinyPose C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-TinyPose Model Description](..) +- [PP-TinyPose C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/keypointdetection/tiny_pose/python/README_CN.md b/examples/vision/keypointdetection/tiny_pose/python/README_CN.md new file mode 100644 index 0000000000..1879a898b6 --- /dev/null +++ b/examples/vision/keypointdetection/tiny_pose/python/README_CN.md @@ -0,0 +1,82 @@ +[English](README.md) | 简体中文 +# PP-TinyPose Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`pptinypose_infer.py`快速完成PP-TinyPose在CPU/GPU,以及GPU上通过TensorRT加速部署的`单图单人关键点检测`示例。执行如下脚本即可完成 + +>> **注意**: PP-Tinypose单模型目前只支持单图单人关键点检测,因此输入的图片应只包含一个人或者进行过裁剪的图像。多人关键点检测请参考[PP-TinyPose Pipeline](../../det_keypoint_unite/python/README.md) + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/keypointdetection/tiny_pose/python + +# 下载PP-TinyPose模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_TinyPose_256x192_infer.tgz +tar -xvf PP_TinyPose_256x192_infer.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/hrnet_demo.jpg + +# CPU推理 +python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device cpu +# GPU推理 +python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python pptinypose_infer.py --tinypose_model_dir PP_TinyPose_256x192_infer --image hrnet_demo.jpg --device kunlunxin +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PP-TinyPose Python接口 + +```python +fd.vision.keypointdetection.PPTinyPose(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PP-TinyPose模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/EXPORT_MODEL.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PPTinyPose.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.KeyPointDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 后处理参数 +用户可按照自己的实际需求,修改下列后处理参数,从而影响最终的推理和部署效果 + +> > * **use_dark**(bool): 是否使用DARK进行后处理[参考论文](https://arxiv.org/abs/1910.06278) + + +## 其它文档 + +- [PP-TinyPose 模型介绍](..) +- [PP-TinyPose C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/README.md b/examples/vision/matting/README.md index f7582fcdf0..d058a35c38 100755 --- a/examples/vision/matting/README.md +++ b/examples/vision/matting/README.md @@ -1,11 +1,12 @@ -# 抠图模型 +English | [简体中文](README_CN.md) +# Matting Model -FastDeploy目前支持如下抠图模型部署 +Now FastDeploy supports the deployment of the following matting models -| 模型 | 说明 | 模型格式 | 版本 | +| Model | Description | Model Format | Version | | :--- | :--- | :------- | :--- | -| [ZHKKKe/MODNet](./modnet) | MODNet 系列模型 | ONNX | [CommitID:28165a4](https://github.com/ZHKKKe/MODNet/commit/28165a4) | -| [PeterL1n/RobustVideoMatting](./rvm) | RobustVideoMatting 系列模型 | ONNX | [CommitID:81a1093](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093) | -| [PaddleSeg/PP-Matting](./ppmatting) | PP-Matting 系列模型 | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | -| [PaddleSeg/PP-HumanMatting](./ppmatting) | PP-HumanMatting 系列模型 | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | -| [PaddleSeg/ModNet](./ppmatting) | ModNet 系列模型 | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | +| [ZHKKKe/MODNet](./modnet) | MODNet models | ONNX | [CommitID:28165a4](https://github.com/ZHKKKe/MODNet/commit/28165a4) | +| [PeterL1n/RobustVideoMatting](./rvm) | RobustVideoMatting models | ONNX | [CommitID:81a1093](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093) | +| [PaddleSeg/PP-Matting](./ppmatting) | PP-Matting models | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | +| [PaddleSeg/PP-HumanMatting](./ppmatting) | PP-HumanMatting models | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | +| [PaddleSeg/ModNet](./ppmatting) | ModNet models | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | diff --git a/examples/vision/matting/README_CN.md b/examples/vision/matting/README_CN.md new file mode 100644 index 0000000000..90abbcf739 --- /dev/null +++ b/examples/vision/matting/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# 抠图模型 + +FastDeploy目前支持如下抠图模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +| :--- | :--- | :------- | :--- | +| [ZHKKKe/MODNet](./modnet) | MODNet 系列模型 | ONNX | [CommitID:28165a4](https://github.com/ZHKKKe/MODNet/commit/28165a4) | +| [PeterL1n/RobustVideoMatting](./rvm) | RobustVideoMatting 系列模型 | ONNX | [CommitID:81a1093](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093) | +| [PaddleSeg/PP-Matting](./ppmatting) | PP-Matting 系列模型 | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | +| [PaddleSeg/PP-HumanMatting](./ppmatting) | PP-HumanMatting 系列模型 | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | +| [PaddleSeg/ModNet](./ppmatting) | ModNet 系列模型 | Paddle | [Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) | diff --git a/examples/vision/matting/modnet/README.md b/examples/vision/matting/modnet/README.md index 2edf99b7e5..78219aff94 100644 --- a/examples/vision/matting/modnet/README.md +++ b/examples/vision/matting/modnet/README.md @@ -1,25 +1,26 @@ -# MODNet准备部署模型 +English | [简体中文](README_CN.md) +# MODNet Ready-to-deploy Model - [MODNet](https://github.com/ZHKKKe/MODNet/commit/28165a4) - - (1)[官方库](https://github.com/ZHKKKe/MODNet/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; - - (2)开发者基于自己数据训练的MODNet模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + - (1)The *.pt provided by the [Official Library](https://github.com/ZHKKKe/MODNet/) can be deployed after [Export ONNX Model](#导出ONNX模型); + - (2)As for MODNet model trained on customized data, please follow the operations guidelines in [Export ONNX Model](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B) to complete the deployment. -## 导出ONNX模型 +## Export ONNX Model -访问[MODNet](https://github.com/ZHKKKe/MODNet)官方github库,按照指引下载安装,下载模型文件,利用 `onnx/export_onnx.py` 得到`onnx`格式文件。 +Visit [MODNet](https://github.com/ZHKKKe/MODNet) official github repository, follow the guidelines to download model files, and employ `onnx/export_onnx.py` to get files in `onnx` format. -* 导出onnx格式文件 +* Export files in onnx format ```bash python -m onnx.export_onnx \ --ckpt-path=pretrained/modnet_photographic_portrait_matting.ckpt \ --output-path=pretrained/modnet_photographic_portrait_matting.onnx ``` -## 下载预训练ONNX模型 +## Download Pre-trained ONNX Model -为了方便开发者的测试,下面提供了MODNet导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) -| 模型 | 大小 | 精度 | +For developers' testing, models exported by MODNet are provided below. Developers can download them directly. (The accuracy in the following table is derived from the source official repository) +| Model | Size | Accuracy | |:---------------------------------------------------------------- |:----- |:----- | | [modnet_photographic](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx) | 25MB | - | | [modnet_webcam](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_webcam_portrait_matting.onnx) | 25MB | -| @@ -33,12 +34,12 @@ -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) -## 版本说明 +## Release Note -- 本版本文档和代码基于[MODNet CommitID:28165a4](https://github.com/ZHKKKe/MODNet/commit/28165a4) 编写 +- This tutorial and related code are written based on [MODNet CommitID:28165a4](https://github.com/ZHKKKe/MODNet/commit/28165a4) diff --git a/examples/vision/matting/modnet/README_CN.md b/examples/vision/matting/modnet/README_CN.md new file mode 100644 index 0000000000..d491c04118 --- /dev/null +++ b/examples/vision/matting/modnet/README_CN.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 +# MODNet准备部署模型 + +- [MODNet](https://github.com/ZHKKKe/MODNet/commit/28165a4) + - (1)[官方库](https://github.com/ZHKKKe/MODNet/)中提供的*.pt通过[导出ONNX模型](#导出ONNX模型)操作后,可进行部署; + - (2)开发者基于自己数据训练的MODNet模型,可按照[导出ONNX模型](#%E5%AF%BC%E5%87%BAONNX%E6%A8%A1%E5%9E%8B)后,完成部署。 + +## 导出ONNX模型 + + +访问[MODNet](https://github.com/ZHKKKe/MODNet)官方github库,按照指引下载安装,下载模型文件,利用 `onnx/export_onnx.py` 得到`onnx`格式文件。 + +* 导出onnx格式文件 + ```bash + python -m onnx.export_onnx \ + --ckpt-path=pretrained/modnet_photographic_portrait_matting.ckpt \ + --output-path=pretrained/modnet_photographic_portrait_matting.onnx + ``` + +## 下载预训练ONNX模型 + +为了方便开发者的测试,下面提供了MODNet导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) +| 模型 | 大小 | 精度 | +|:---------------------------------------------------------------- |:----- |:----- | +| [modnet_photographic](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx) | 25MB | - | +| [modnet_webcam](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_webcam_portrait_matting.onnx) | 25MB | -| +| [modnet_photographic_256](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting-256x256.onnx) | 25MB | - | +| [modnet_webcam_256](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_webcam_portrait_matting-256x256.onnx) | 25MB | - | +| [modnet_photographic_512](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting-512x512.onnx) | 25MB | - | +| [modnet_webcam_512](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_webcam_portrait_matting-512x512.onnx) | 25MB | - | +| [modnet_photographic_1024](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting-1024x1024.onnx) | 25MB | - | +| [modnet_webcam_1024](https://bj.bcebos.com/paddlehub/fastdeploy/modnet_webcam_portrait_matting-1024x1024.onnx) | 25MB | -| + + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) + + +## 版本说明 + +- 本版本文档和代码基于[MODNet CommitID:28165a4](https://github.com/ZHKKKe/MODNet/commit/28165a4) 编写 diff --git a/examples/vision/matting/modnet/cpp/README.md b/examples/vision/matting/modnet/cpp/README.md index 25f37c1077..37964404b4 100644 --- a/examples/vision/matting/modnet/cpp/README.md +++ b/examples/vision/matting/modnet/cpp/README.md @@ -1,39 +1,40 @@ -# MODNet C++部署示例 +English | [简体中文](README_CN.md) +# MODNet C++ Deployment Example -本目录下提供`infer.cc`快速完成MODNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of ArcFace on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的MODNet模型文件和测试图片 +# Download the official converted MODNet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU推理 +# CPU inference ./infer_demo modnet_photographic_portrait_matting.onnx matting_input.jpg matting_bgr.jpg 0 -# GPU推理 +# GPU inference ./infer_demo modnet_photographic_portrait_matting.onnx matting_input.jpg matting_bgr.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo modnet_photographic_portrait_matting.onnx matting_input.jpg matting_bgr.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -42,12 +43,12 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## MODNet C++接口 +## MODNet C++ Interface -### MODNet类 +### MODNet Class ```c++ fastdeploy::vision::matting::MODNet( @@ -57,16 +58,16 @@ fastdeploy::vision::matting::MODNet( const ModelFormat& model_format = ModelFormat::ONNX) ``` -MODNet模型加载和初始化,其中model_file为导出的ONNX模型格式。 +MODNet model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Only passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > MODNet::Predict(cv::Mat* im, MattingResult* result, @@ -74,26 +75,26 @@ MODNet模型加载和初始化,其中model_file为导出的ONNX模型格式。 > float nms_iou_threshold = 0.5) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box and confidence of each box. Refer to [Vision Model Prediction Result](../../../../../docs/api/vision_results/) for MattingResult +> > * **conf_threshold**: Filtering threshold of detection box confidence +> > * **nms_iou_threshold**: iou threshold during NMS processing -### 类成员变量 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[256, 256] -> > * **alpha**(vector<float>): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] -> > * **beta**(vector<float>): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] -> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认true +> > * **size**(vector<int>): This parameter changes the size of the resize used during preprocessing, containing two integer elements for [width, height] with default value [256, 256] +> > * **alpha**(vector<float>): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`,alpha defaults to [1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(vector<float>): Preprocess normalized beta, and calculated as `x'=x*alpha+beta`,beta defaults to [-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): Whether to convert BGR to RGB in pre-processing. Default True -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/modnet/cpp/README_CN.md b/examples/vision/matting/modnet/cpp/README_CN.md new file mode 100644 index 0000000000..9073bd2ec4 --- /dev/null +++ b/examples/vision/matting/modnet/cpp/README_CN.md @@ -0,0 +1,100 @@ +[English](README.md) | 简体中文 +# MODNet C++部署示例 + +本目录下提供`infer.cc`快速完成MODNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +#下载官方转换好的MODNet模型文件和测试图片 + +wget https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg + + +# CPU推理 +./infer_demo modnet_photographic_portrait_matting.onnx matting_input.jpg matting_bgr.jpg 0 +# GPU推理 +./infer_demo modnet_photographic_portrait_matting.onnx matting_input.jpg matting_bgr.jpg 1 +# GPU上TensorRT推理 +./infer_demo modnet_photographic_portrait_matting.onnx matting_input.jpg matting_bgr.jpg 2 +``` + +运行完成可视化结果如下图所示 + +
+ + + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## MODNet C++接口 + +### MODNet类 + +```c++ +fastdeploy::vision::matting::MODNet( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +MODNet模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> MODNet::Predict(cv::Mat* im, MattingResult* result, +> float conf_threshold = 0.25, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +### 类成员变量 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + +> > * **size**(vector<int>): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[256, 256] +> > * **alpha**(vector<float>): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(vector<float>): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认true + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/modnet/python/README.md b/examples/vision/matting/modnet/python/README.md index d84d95ac52..44ba8801ed 100755 --- a/examples/vision/matting/modnet/python/README.md +++ b/examples/vision/matting/modnet/python/README.md @@ -1,31 +1,32 @@ -# MODNet Python部署示例 +English | [简体中文](README_CN.md) +# MODNet Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成MODNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of MODNet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/matting/modnet/python/ -#下载modnet模型文件和测试图片 +# Download modnet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU推理 +# CPU inference python infer.py --model modnet_photographic_portrait_matting.onnx --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model modnet_photographic_portrait_matting.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --model modnet_photographic_portrait_matting.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -34,52 +35,51 @@ python infer.py --model modnet_photographic_portrait_matting.onnx --image mattin
-## MODNet Python接口 +## MODNet Python Interface ```python fastdeploy.vision.matting.MODNet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -MODNet模型加载和初始化,其中model_file为导出的ONNX模型格式 +MODNet model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > MODNet.predict(image_data) > ``` > -> 模型预测结口,输入图像直接输出抠图结果。 +> Model prediction interface. Input images and output matting results. > -> **参数** +> **Parameter** > -> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **image_data**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.MattingResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Property +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results +> > * **size**(list[int]): This parameter changes the size of the resize during preprocessing, containing two integer elements for [width, height] with default value [256, 256] +> > * **alpha**(list[float]): Preprocess normalized alpha, and calculated as `x'=x*alpha+beta`. alpha defaults to [1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(list[float]): Preprocess normalized beta, and calculated as `x'=x*alpha+beta`. beta defaults to [-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): Whether to convert BGR to RGB in pre-processing. Default True -> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[256, 256] -> > * **alpha**(list[float]): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] -> > * **beta**(list[float]): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] -> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认True +## Other Documents -## 其它文档 - -- [MODNet 模型介绍](..) -- [MODNet C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [MODNet Model Description](..) +- [MODNet C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/modnet/python/README_CN.md b/examples/vision/matting/modnet/python/README_CN.md new file mode 100644 index 0000000000..066750d252 --- /dev/null +++ b/examples/vision/matting/modnet/python/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# MODNet Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成MODNet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/matting/modnet/python/ + +#下载modnet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg + +# CPU推理 +python infer.py --model modnet_photographic_portrait_matting.onnx --image matting_input.jpg --bg matting_bgr.jpg --device cpu +# GPU推理 +python infer.py --model modnet_photographic_portrait_matting.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model modnet_photographic_portrait_matting.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + +
+ + + + +
+ +## MODNet Python接口 + +```python +fastdeploy.vision.matting.MODNet(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +MODNet模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> MODNet.predict(image_data) +> ``` +> +> 模型预测结口,输入图像直接输出抠图结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[256, 256] +> > * **alpha**(list[float]): 预处理归一化的alpha值,计算公式为`x'=x*alpha+beta`,alpha默认为[1. / 127.5, 1.f / 127.5, 1. / 127.5] +> > * **beta**(list[float]): 预处理归一化的beta值,计算公式为`x'=x*alpha+beta`,beta默认为[-1.f, -1.f, -1.f] +> > * **swap_rb**(bool): 预处理是否将BGR转换成RGB,默认True + + + +## 其它文档 + +- [MODNet 模型介绍](..) +- [MODNet C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md index de5391f032..a2cbdc3464 100644 --- a/examples/vision/matting/ppmatting/README.md +++ b/examples/vision/matting/ppmatting/README.md @@ -1,31 +1,31 @@ -# PP-Matting模型部署 +English | [简体中文](README_CN.md) +# PP-Matting Model Deployment -## 模型版本说明 +## Model Description - [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PP-Matting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [PP-Matting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [PP-HumanMatting models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [ModNet models](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) -## 导出部署模型 +## Export Deployment Model -在部署前,需要先将PP-Matting导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting)(Tips:导出PP-Matting系列模型和PP-HumanMatting系列模型需要设置导出脚本的`--input_shape`参数) +Before deployment, PP-Matting needs to be exported into the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information. (Tips: You need to set the `--input_shape` parameter of the export script when exporting PP-Matting and PP-HumanMatting models) -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了PP-Matting导出的各系列模型,开发者可直接下载使用。 +For developers' testing, models exported by PP-Matting are provided below. Developers can download and use them directly. -其中精度指标来源于PP-Matting中对各模型的介绍(未提供精度数据),详情各参考PP-Matting中的说明。 +The accuracy metric is sourced from the model description in PP-Matting. (Accuracy data are not provided) Refer to the introduction in PP-Matting for more details. - -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | | [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | | [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | @@ -36,7 +36,7 @@ -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/matting/ppmatting/README_CN.md b/examples/vision/matting/ppmatting/README_CN.md new file mode 100644 index 0000000000..a1c9801aa6 --- /dev/null +++ b/examples/vision/matting/ppmatting/README_CN.md @@ -0,0 +1,43 @@ +[English](README.md) | 简体中文 +# PP-Matting模型部署 + +## 模型版本说明 + +- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PP-Matting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + + +## 导出部署模型 + +在部署前,需要先将PP-Matting导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting)(Tips:导出PP-Matting系列模型和PP-HumanMatting系列模型需要设置导出脚本的`--input_shape`参数) + + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PP-Matting导出的各系列模型,开发者可直接下载使用。 + +其中精度指标来源于PP-Matting中对各模型的介绍(未提供精度数据),详情各参考PP-Matting中的说明。 + + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [PP-Matting-512](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz) | 106MB | - | +| [PP-Matting-1024](https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-1024.tgz) | 106MB | - | +| [PP-HumanMatting](https://bj.bcebos.com/paddlehub/fastdeploy/PPHumanMatting.tgz) | 247MB | - | +| [Modnet-ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_ResNet50_vd.tgz) | 355MB | - | +| [Modnet-MobileNetV2](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_MobileNetV2.tgz) | 28MB | - | +| [Modnet-HRNet_w18](https://bj.bcebos.com/paddlehub/fastdeploy/PPModnet_HRNet_w18.tgz) | 51MB | - | + + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/matting/ppmatting/cpp/README.md b/examples/vision/matting/ppmatting/cpp/README.md index 21fd779bee..f8a4088eb4 100755 --- a/examples/vision/matting/ppmatting/cpp/README.md +++ b/examples/vision/matting/ppmatting/cpp/README.md @@ -1,41 +1,41 @@ -# PP-Matting C++部署示例 +English | [简体中文](README_CN.md) +# PP-Matting C++ Deployment Example -本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. +Before deployment, two steps require confirmation -在部署前,需确认以下两个步骤 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以Linux上 PP-Matting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the PP-Matting inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载PP-Matting模型文件和测试图片 +# Download PP-Matting model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz tar -xvf PP-Matting-512.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU推理 +# CPU inference ./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 -# GPU推理 +# GPU inference ./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 -# 昆仑芯XPU推理 +# kunlunxin XPU inference ./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -43,12 +43,12 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PP-Matting C++接口 +## PP-Matting C++ Interface -### PPMatting类 +### PPMatting Class ```c++ fastdeploy::vision::matting::PPMatting( @@ -59,35 +59,35 @@ fastdeploy::vision::matting::PPMatting( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -PP-Matting模型加载和初始化,其中model_file为导出的Paddle模型格式。 +PP-Matting model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > PPMatting::Predict(cv::Mat* im, MattingResult* result) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/cpp/README_CN.md b/examples/vision/matting/ppmatting/cpp/README_CN.md new file mode 100644 index 0000000000..38e2e592a9 --- /dev/null +++ b/examples/vision/matting/ppmatting/cpp/README_CN.md @@ -0,0 +1,94 @@ +[English](README.md) | 简体中文 +# PP-Matting C++部署示例 + +本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上 PP-Matting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载PP-Matting模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg + + +# CPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 +# GPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 +# GPU上TensorRT推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 +# 昆仑芯XPU推理 +./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 +``` + +运行完成可视化结果如下图所示 +
+ + + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PP-Matting C++接口 + +### PPMatting类 + +```c++ +fastdeploy::vision::matting::PPMatting( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PP-Matting模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PPMatting::Predict(cv::Mat* im, MattingResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/python/README.md b/examples/vision/matting/ppmatting/python/README.md index c0791d5d67..ed91d1db26 100755 --- a/examples/vision/matting/ppmatting/python/README.md +++ b/examples/vision/matting/ppmatting/python/README.md @@ -1,80 +1,81 @@ -# PP-Matting Python部署示例 +English | [简体中文](README_CN.md) +# PP-Matting Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishes the deployment of PP-Matting on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/matting/ppmatting/python -# 下载PP-Matting模型文件和测试图片 +# Download PP-Matting model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz tar -xvf PP-Matting-512.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg -# CPU推理 +# CPU inference python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True -# 昆仑芯XPU推理 +# kunlunxin XPU inference python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PP-Matting Python接口 +## PP-Matting Python Interface ```python fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PP-Matting模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) +PP-Matting model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > PPMatting.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.MattingResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. + +### Class Member Variable -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -## 其它文档 +## Other Documents -- [PP-Matting 模型介绍](..) -- [PP-Matting C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-Matting Model Description](..) +- [PP-Matting C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/ppmatting/python/README_CN.md b/examples/vision/matting/ppmatting/python/README_CN.md new file mode 100644 index 0000000000..cdfd7d378a --- /dev/null +++ b/examples/vision/matting/ppmatting/python/README_CN.md @@ -0,0 +1,81 @@ +[English](README.md) | 简体中文 +# PP-Matting Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/matting/ppmatting/python + +# 下载PP-Matting模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz +tar -xvf PP-Matting-512.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg +# CPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu +# GPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True +# 昆仑芯XPU推理 +python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin +``` + +运行完成可视化结果如下图所示 +
+ + + + +
+## PP-Matting Python接口 + +```python +fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PP-Matting模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PPMatting.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + + +## 其它文档 + +- [PP-Matting 模型介绍](..) +- [PP-Matting C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/rvm/README.md b/examples/vision/matting/rvm/README.md index 56d371c5c9..320c52bea3 100755 --- a/examples/vision/matting/rvm/README.md +++ b/examples/vision/matting/rvm/README.md @@ -1,30 +1,31 @@ -# RobustVideoMatting 模型部署 +English | [简体中文](README_CN.md) +# RobustVideoMatting Model Deployment -## 模型版本说明 +## Model Description - [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [RobustVideoMatting 模型](https://github.com/PeterL1n/RobustVideoMatting) +- [RobustVideoMatting model](https://github.com/PeterL1n/RobustVideoMatting) -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了RobustVideoMatting导出的各系列模型,开发者可直接下载使用。 +For developers' testing, models exported by RobustVideoMatting are provided below. Developers can download and use them directly. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:---------------------------------------------------------------- |:----- |:----- | :------ | -| [rvm_mobilenetv3_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx) | 15MB ||exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | -| [rvm_resnet50_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_fp32.onnx) | 103MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | -| [rvm_mobilenetv3_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx) | 15MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | -| [rvm_resnet50_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_trt.onnx) | 103MB | | exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_mobilenetv3_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx) | 15MB | - | +| [rvm_resnet50_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_fp32.onnx) | 103MB | - | +| [rvm_mobilenetv3_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx) | 15MB | - | +| [rvm_resnet50_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_trt.onnx) | 103MB | - | **Note**: -- 如果要使用 TensorRT 进行推理,需要下载后缀为 trt 的 onnx 模型文件 +- If you want to use TensorRT for inference, download onnx model file with the trt suffix is necessary. -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/matting/rvm/README_CN.md b/examples/vision/matting/rvm/README_CN.md new file mode 100644 index 0000000000..bf2b57a1ec --- /dev/null +++ b/examples/vision/matting/rvm/README_CN.md @@ -0,0 +1,31 @@ +[English](README.md) | 简体中文 +# RobustVideoMatting 模型部署 + +## 模型版本说明 + +- [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [RobustVideoMatting 模型](https://github.com/PeterL1n/RobustVideoMatting) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了RobustVideoMatting导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [rvm_mobilenetv3_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx) | 15MB ||exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_resnet50_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_fp32.onnx) | 103MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_mobilenetv3_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx) | 15MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_resnet50_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_trt.onnx) | 103MB | | exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | + +**Note**: +- 如果要使用 TensorRT 进行推理,需要下载后缀为 trt 的 onnx 模型文件 + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/matting/rvm/cpp/README.md b/examples/vision/matting/rvm/cpp/README.md index d8e00400c1..3b9c842cd7 100755 --- a/examples/vision/matting/rvm/cpp/README.md +++ b/examples/vision/matting/rvm/cpp/README.md @@ -1,41 +1,42 @@ -# RobustVideoMatting C++部署示例 +English | [简体中文](README_CN.md) +# RobustVideoMatting C++ Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上 RobustVideoMatting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the RobustVideoMatting inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. -本目录下提供`infer.cc`快速完成RobustVideoMatting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.cc` fast finishes the deployment of RobustVideoMatting on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载RobustVideoMatting模型文件和测试图片以及视频 -## 原版ONNX模型 +# Download RobustVideoMatting model files, test images and videos +## Original ONNX model wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx -## 为加载TRT特殊处理ONNX模型 +## The ONNX model is specially processed for loading TRT wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/video.mp4 -# CPU推理 +# CPU inference ./infer_demo rvm_mobilenetv3_fp32.onnx matting_input.jpg matting_bgr.jpg 0 -# GPU推理 +# GPU inference ./infer_demo rvm_mobilenetv3_fp32.onnx matting_input.jpg matting_bgr.jpg 1 -# TRT推理 +# TRT inference ./infer_demo rvm_mobilenetv3_trt.onnx matting_input.jpg matting_bgr.jpg 2 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -43,10 +44,10 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/video.mp4
-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## RobustVideoMatting C++接口 +## RobustVideoMatting C++ Interface ```c++ fastdeploy::vision::matting::RobustVideoMatting( @@ -56,32 +57,32 @@ fastdeploy::vision::matting::RobustVideoMatting( const ModelFormat& model_format = ModelFormat::ONNX) ``` -RobustVideoMatting模型加载和初始化,其中model_file为导出的ONNX模型格式。 +RobustVideoMatting model loading and initialization, among which model_file is the exported ONNX model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -#### Predict函数 +#### Predict Function > ```c++ > RobustVideoMatting::Predict(cv::Mat* im, MattingResult* result) > ``` > -> 模型预测接口,输入图像直接输出抠图结果。 +> Model prediction interface. Input images and output matting results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 抠图结果, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Matting result. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of MattingResult -## 其它文档 +## Other Documents -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/rvm/cpp/README_CN.md b/examples/vision/matting/rvm/cpp/README_CN.md new file mode 100644 index 0000000000..24e5c71b80 --- /dev/null +++ b/examples/vision/matting/rvm/cpp/README_CN.md @@ -0,0 +1,88 @@ +[English](README.md) | 简体中文 +# RobustVideoMatting C++部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上 RobustVideoMatting 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +本目录下提供`infer.cc`快速完成RobustVideoMatting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载RobustVideoMatting模型文件和测试图片以及视频 +## 原版ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx +## 为加载TRT特殊处理ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/video.mp4 + +# CPU推理 +./infer_demo rvm_mobilenetv3_fp32.onnx matting_input.jpg matting_bgr.jpg 0 +# GPU推理 +./infer_demo rvm_mobilenetv3_fp32.onnx matting_input.jpg matting_bgr.jpg 1 +# TRT推理 +./infer_demo rvm_mobilenetv3_trt.onnx matting_input.jpg matting_bgr.jpg 2 +``` + +运行完成可视化结果如下图所示 +
+ + + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## RobustVideoMatting C++接口 + +```c++ +fastdeploy::vision::matting::RobustVideoMatting( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +RobustVideoMatting模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> RobustVideoMatting::Predict(cv::Mat* im, MattingResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出抠图结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 抠图结果, MattingResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/rvm/export.md b/examples/vision/matting/rvm/export.md index 85167754d8..eeef9d9e46 100755 --- a/examples/vision/matting/rvm/export.md +++ b/examples/vision/matting/rvm/export.md @@ -1,20 +1,21 @@ -# RobustVideoMatting 支持TRT的动态ONNX导出 +English | [简体中文](README_CN.md) +# RobustVideoMatting supports TRT’s dynamic ONNX export -## 环境依赖 +## Environment Dependencies - python >= 3.5 - pytorch 1.12.0 - onnx 1.10.0 - onnxsim 0.4.8 -## 步骤一:拉取 RobustVideoMatting onnx 分支代码 +## Step 1: Pull the RobustVideoMatting onnx branch code ```shell git clone -b onnx https://github.com/PeterL1n/RobustVideoMatting.git cd RobustVideoMatting ``` -## 步骤二:去掉 downsample_ratio 动态输入 +## Step 2: Remove downsample_ratio dynamic input 在```model/model.py```中,将 ```downsample_ratio``` 输入去掉,如下图所示 @@ -49,9 +50,9 @@ def forward(self, src, r1, r2, r3, r4, return [seg, *rec] ``` -## 步骤三:修改导出 ONNX 脚本 +## Step 3: Modify the export ONNX script -修改```export_onnx.py```脚本,去掉```downsample_ratio```输入 +Modify ```export_onnx.py``` script to remove the ```downsample_ratio``` input ```python def export(self): @@ -89,7 +90,7 @@ def export(self): }) ``` -运行下列命令 +Run the following commands ```shell python export_onnx.py \ @@ -102,15 +103,15 @@ python export_onnx.py \ ``` **Note**: -- trt关于多输入ONNX模型的dynamic shape,如果x0和x1的shape不同,不能都以height、width去表示,要以height0、height1去区分,要不然build engine阶段会出错 +- For the dynamic shape of the multi-input ONNX model in trt, if the shapes of x0 and x1 are different, we cannot use height and width but height0 and height1 to differentiate them, otherwise, there will be some mistakes when building engine -## 步骤四:使用onnxsim简化 +## Step 4: Simplify with onnxsim -安装 onnxsim,并简化步骤三导出的 ONNX 模型 +Install onnxsim and simplify the ONNX model exported in step 3 ```shell pip install onnxsim onnxsim rvm_mobilenetv3.onnx rvm_mobilenetv3_trt.onnx ``` -```rvm_mobilenetv3_trt.onnx```即为可运行 TRT 后端的动态 shape 的 ONNX 模型 +```rvm_mobilenetv3_trt.onnx```: The ONNX model in dynamic shape that can run the TRT backend diff --git a/examples/vision/matting/rvm/export_cn.md b/examples/vision/matting/rvm/export_cn.md new file mode 100644 index 0000000000..bf2b57a1ec --- /dev/null +++ b/examples/vision/matting/rvm/export_cn.md @@ -0,0 +1,31 @@ +[English](README.md) | 简体中文 +# RobustVideoMatting 模型部署 + +## 模型版本说明 + +- [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [RobustVideoMatting 模型](https://github.com/PeterL1n/RobustVideoMatting) + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了RobustVideoMatting导出的各系列模型,开发者可直接下载使用。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:---------------------------------------------------------------- |:----- |:----- | :------ | +| [rvm_mobilenetv3_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx) | 15MB ||exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_resnet50_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_fp32.onnx) | 103MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_mobilenetv3_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx) | 15MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | +| [rvm_resnet50_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_trt.onnx) | 103MB | | exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License | + +**Note**: +- 如果要使用 TensorRT 进行推理,需要下载后缀为 trt 的 onnx 模型文件 + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/matting/rvm/python/README.md b/examples/vision/matting/rvm/python/README.md index 5b3676c086..4ab70abc9d 100755 --- a/examples/vision/matting/rvm/python/README.md +++ b/examples/vision/matting/rvm/python/README.md @@ -1,44 +1,45 @@ -# RobustVideoMatting Python部署示例 +English | [简体中文](README_CN.md) +# RobustVideoMatting Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成RobustVideoMatting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of RobustVideoMatting on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/matting/rvm/python -# 下载RobustVideoMatting模型文件和测试图片以及视频 -## 原版ONNX模型 +# Download RobustVideoMatting model files, test images and videos +## Original ONNX Model wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx -## 为加载TRT特殊处理ONNX模型 +## Specially process the ONNX model for loading TRT wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/video.mp4 -# CPU推理 -## 图片 +# CPU inference +## image python infer.py --model rvm_mobilenetv3_fp32.onnx --image matting_input.jpg --bg matting_bgr.jpg --device cpu -## 视频 +## video python infer.py --model rvm_mobilenetv3_fp32.onnx --video video.mp4 --bg matting_bgr.jpg --device cpu -# GPU推理 -## 图片 +# GPU inference +## image python infer.py --model rvm_mobilenetv3_fp32.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu -## 视频 +## video python infer.py --model rvm_mobilenetv3_fp32.onnx --video video.mp4 --bg matting_bgr.jpg --device gpu -# TRT推理 -## 图片 +# TRT inference +## image python infer.py --model rvm_mobilenetv3_trt.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True -## 视频 +## video python infer.py --model rvm_mobilenetv3_trt.onnx --video video.mp4 --bg matting_bgr.jpg --device gpu --use_trt True ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
@@ -48,41 +49,41 @@ python infer.py --model rvm_mobilenetv3_trt.onnx --video video.mp4 --bg matting_
-## RobustVideoMatting Python接口 +## RobustVideoMatting Python Interface ```python fd.vision.matting.RobustVideoMatting(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) ``` -RobustVideoMatting模型加载和初始化,其中model_file为导出的ONNX模型格式 +RobustVideoMatting model loading and initialization, among which model_file is the exported ONNX model format -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为ONNX +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. No need to set when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. ONNX format by default -### predict函数 +### predict function > ```python > RobustVideoMatting.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出抠图结果。 +> Model prediction interface. Input images and output matting results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.MattingResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -## 其它文档 +## Other Documents -- [RobustVideoMatting 模型介绍](..) -- [RobustVideoMatting C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [RobustVideoMatting Model Description](..) +- [RobustVideoMatting C++ Deployment](../cpp) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/matting/rvm/python/README_CN.md b/examples/vision/matting/rvm/python/README_CN.md new file mode 100644 index 0000000000..d70ec52504 --- /dev/null +++ b/examples/vision/matting/rvm/python/README_CN.md @@ -0,0 +1,89 @@ +[English](README.md) | 简体中文 +# RobustVideoMatting Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成RobustVideoMatting在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/matting/rvm/python + +# 下载RobustVideoMatting模型文件和测试图片以及视频 +## 原版ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx +## 为加载TRT特殊处理ONNX模型 +wget https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/video.mp4 + +# CPU推理 +## 图片 +python infer.py --model rvm_mobilenetv3_fp32.onnx --image matting_input.jpg --bg matting_bgr.jpg --device cpu +## 视频 +python infer.py --model rvm_mobilenetv3_fp32.onnx --video video.mp4 --bg matting_bgr.jpg --device cpu +# GPU推理 +## 图片 +python infer.py --model rvm_mobilenetv3_fp32.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu +## 视频 +python infer.py --model rvm_mobilenetv3_fp32.onnx --video video.mp4 --bg matting_bgr.jpg --device gpu +# TRT推理 +## 图片 +python infer.py --model rvm_mobilenetv3_trt.onnx --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True +## 视频 +python infer.py --model rvm_mobilenetv3_trt.onnx --video video.mp4 --bg matting_bgr.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 +
+ + + + + + +
+ +## RobustVideoMatting Python接口 + +```python +fd.vision.matting.RobustVideoMatting(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +RobustVideoMatting模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> RobustVideoMatting.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出抠图结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.MattingResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## 其它文档 + +- [RobustVideoMatting 模型介绍](..) +- [RobustVideoMatting C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv2/android/README.md b/examples/vision/ocr/PP-OCRv2/android/README.md index 4181a93e1b..52edf3a81f 100644 --- a/examples/vision/ocr/PP-OCRv2/android/README.md +++ b/examples/vision/ocr/PP-OCRv2/android/README.md @@ -1,94 +1,95 @@ -# OCR文字识别 Android Demo 使用文档 +English | [简体中文](README_CN.md) +# OCR Text Recognition Android Demo Tutorial -在 Android 上实现实时的OCR文字识别功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 +Real-time OCR text recognition on Android. This demo is easy to use for everyone. For example, you can run your own trained model in the demo. -## 环境准备 +## Prepare the Environment -1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 -2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` +1. Install Android Studio in your local environment. Refer to [Android Studio Official Website](https://developer.android.com/studio) for detailed tutorial. +2. Prepare an Android phone and turn on the USB debug mode. Opening: `Settings -> Find developer options -> Open developer options and USB debug mode` -## 部署步骤 +## Deployment Steps -1. OCR文字识别 Demo 位于 `fastdeploy/examples/vision/ocr/PP-OCRv2/android` 目录 -2. 用 Android Studio 打开 PP-OCRv2/android 工程 -3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) +1. The OCR text recognition Demo is located in the `fastdeploy/examples/vision/ocr/PP-OCRv2/android` +2. Open PP-OCRv2/android project with Android Studio +3. Connect the phone to the computer, turn on USB debug mode and file transfer mode, and connect your phone to Android Studio (allow the phone to install software from USB)

image

-> **注意:** ->> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 +> **Attention:** +>> If you encounter an NDK configuration error during import, compilation or running, open ` File > Project Structure > SDK Location` and change the path of SDK configured by the `Andriod SDK location`. -4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) - 成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 +4. Click the Run button to automatically compile the APP and install it to the phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files. Internet is required). +The final effect is as follows. Figure 1: Install the APP on the phone; Figure 2: The effect after opening the APP. It will automatically recognize and mark the objects in the image; Figure 3: APP setting option. Click setting in the upper right corner and modify your options. -| APP 图标 | APP 效果 | APP设置项 +| APP Icon | APP Effect | APP Settings | --- | --- | --- | | ![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 Java API 说明 +### PP-OCRv2 Java API Description -- 模型初始化 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 包含 DBDetector、Classifier和Recognizer等基础模型,以及pipeline类型。 +- Model initialized API: The initialized API contains two ways: Firstly, initialize directly through the constructor. Secondly, initialize at the appropriate program node by calling the init function. PP-OCR initialization parameters are as follows. + - modelFile: String. Model file path in paddle format, such as model.pdmodel + - paramFile: String. Parameter file path in paddle format, such as model.pdiparams + - labelFile: String. This optional parameter indicates the path of the label file and is used for visualization. such as ppocr_keys_v1.txt, each line containing one label + - option: RuntimeOption. Optional parameter for model initialization. Default runtime options if the parameter is not passed. Different from other models, PP-OCRv2 contains base models such as DBDetector, Classifier, Recognizer and the pipeline type. + ```java -// 构造函数: constructor w/o label file +// Constructor: constructor w/o label file public DBDetector(String modelFile, String paramsFile); public DBDetector(String modelFile, String paramsFile, RuntimeOption option); 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初始化 +public PPOCRv2(); // An empty constructor, which can be initialized by calling init // Constructor w/o classifier public PPOCRv2(DBDetector detModel, Recognizer recModel); public PPOCRv2(DBDetector detModel, Classifier clsModel, Recognizer recModel); ``` -- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +- Model Prediction API: The Model Prediction API contains an API for direct prediction and an API for visualization. In direct prediction, we do not save the image and render the result on Bitmap. Instead, we merely predict the inference result. For prediction and visualization, the results are both predicted and visualized, the visualized images are saved to the specified path, and the visualized results are rendered in Bitmap (Now Bitmap in ARGB8888 format is supported). Afterward, the Bitmap can be displayed on the camera. ```java -// 直接预测:不保存图片以及不渲染结果到Bitmap上 +// Direct prediction: No image saving and no result rendering to Bitmap public OCRResult predict(Bitmap ARGB8888Bitmap); -// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +// Prediction and visualization: Predict and visualize the results, save the visualized image to the specified path, and render the visualized results on Bitmap public OCRResult predict(Bitmap ARGB8888Bitmap, String savedImagePath); -public OCRResult predict(Bitmap ARGB8888Bitmap, boolean rendering); // 只渲染 不保存图片 +public OCRResult predict(Bitmap ARGB8888Bitmap, boolean rendering); // Render without saving images ``` -- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +- Model resource release API: Call release() API to release model resources. Return true for successful release and false for failure; call initialized() to determine whether the model was initialized successfully, with true indicating successful initialization and false indicating failure. ```java -public boolean release(); // 释放native资源 -public boolean initialized(); // 检查是否初始化成功 +public boolean release(); // Release native resources +public boolean initialized(); // Check if initialization was successful ``` -- RuntimeOption设置说明 +- RuntimeOption settings ```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); // 通过字符串形式设置能耗模式 +public void enableLiteFp16(); // Enable fp16 accuracy inference +public void disableLiteFP16(); // Disable fp16 accuracy inference +public void enableLiteInt8(); // Enable int8 accuracy inference for quantification models +public void disableLiteInt8(); // Disable int8 accuracy inference +public void setCpuThreadNum(int threadNum); // Set thread numbers +public void setLitePowerMode(LitePowerMode mode); // Set power mode +public void setLitePowerMode(String modeStr); // Set power mode through character string ``` -- 模型结果OCRResult说明 +- Model 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; // 检测结果是否有效 + public int[][] mBoxes; // The coordinates of all target boxes in a single image. 8 int values represent the 4 coordinate points of the box in the order of bottom left, bottom right, top right and top left + public String[] mText; // Recognized text in multiple text boxes + public float[] mRecScores; // Confidence of the recognized text in the box + public float[] mClsScores; // Confidence of the classification result of the text box + public int[] mClsLabels; // the directional classification of the text box + public boolean mInitialized = false; // Whether the result is valid or not } ``` -其他参考:C++/Python对应的OCRResult说明: [api/vision_results/ocr_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/ocr_result.md) +Refer to [api/vision_results/ocr_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/ocr_result.md) for C++/Python OCRResult -- 模型调用示例1:使用构造函数 +- Model Calling Example 1: Using Constructor ```java import java.nio.ByteBuffer; import android.graphics.Bitmap; @@ -101,7 +102,7 @@ import com.baidu.paddle.fastdeploy.vision.ocr.Classifier; import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector; import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer; -// 模型路径 +// Model path 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"; @@ -109,7 +110,7 @@ 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 +// Set the RuntimeOption RuntimeOption detOption = new RuntimeOption(); RuntimeOption clsOption = new RuntimeOption(); RuntimeOption recOption = new RuntimeOption(); @@ -122,37 +123,37 @@ recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); detOption.enableLiteFp16(); clsOption.enableLiteFp16(); recOption.enableLiteFp16(); -// 初始化模型 +// Initialize the model 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的伪代码 +// Read the image: The following is merely the pseudo code to read the 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); -// 模型推理 +// Model Inference OCRResult result = model.predict(ARGB8888ImageBitmap); -// 释放模型资源 +// Release model resources model.release(); ``` -- 模型调用示例2: 在合适的程序节点,手动调用init +- Model calling example 2: Manually call init at the appropriate program node ```java -// import 同上 ... +// import is as the above ... 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; -// 新建空模型 +// Create an empty model PPOCRv2 model = new PPOCRv2(); -// 模型路径 +// Model path 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"; @@ -160,7 +161,7 @@ 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 +// Set the RuntimeOption RuntimeOption detOption = new RuntimeOption(); RuntimeOption clsOption = new RuntimeOption(); RuntimeOption recOption = new RuntimeOption(); @@ -173,30 +174,30 @@ recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); detOption.enableLiteFp16(); clsOption.enableLiteFp16(); recOption.enableLiteFp16(); -// 使用init函数初始化 +// Use init function for initialization 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读取、模型预测、资源释放 同上 ... +// Bitmap reading, model prediction, and resource release are as above ``` -更详细的用法请参考 [OcrMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java)中的用法 +Refer to [OcrMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java) for more details -## 替换 FastDeploy SDK和模型 -替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models`。 -- 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: - - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +## Replace FastDeploy SDK and Models +It’s simple to replace the FastDeploy prediction library and models. The prediction library is located at `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` represents the version of your prediction library. The models are located at `app/src/main/assets/models` +- Replace the FastDeploy Android SDK: Download or compile the latest FastDeploy Android SDK, unzip and place it in the `app/libs` directory; For detailed configuration, refer to + - [FastDeploy Java SDK in Android](../../../../../java/android/) -- 替换OCR模型的步骤: - - 将您的OCR模型放在 `app/src/main/assets/models` 目录下; - - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +- Steps to replace OCR models: + - Put your OCR model in `app/src/main/assets/models`; + - Modify the default value of the model path in `app/src/main/res/values/strings.xml`. For example, ```xml - + models labels/ppocr_keys_v1.txt ``` -## 更多参考文档 -如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: -- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) -- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) +## More Reference Documents +For more FastDeploy Java API documentes and how to access FastDeploy C++ API via JNI, refer to: +- [FastDeploy Java SDK in Android](../../../../../java/android/) +- [FastDeploy C++ SDK in Android](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/ocr/PP-OCRv2/android/README_CN.md b/examples/vision/ocr/PP-OCRv2/android/README_CN.md new file mode 100644 index 0000000000..4e501ae124 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv2/android/README_CN.md @@ -0,0 +1,203 @@ +[English](README.md) | 简体中文 +# OCR文字识别 Android Demo 使用文档 + +在 Android 上实现实时的OCR文字识别功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 + +## 环境准备 + +1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 +2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` + +## 部署步骤 + +1. OCR文字识别 Demo 位于 `fastdeploy/examples/vision/ocr/PP-OCRv2/android` 目录 +2. 用 Android Studio 打开 PP-OCRv2/android 工程 +3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) + +

+image +

+ +> **注意:** +>> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 + +4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) + 成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 + +| APP 图标 | APP 效果 | APP设置项 + | --- | --- | --- | +| ![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 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 包含 DBDetector、Classifier和Recognizer等基础模型,以及pipeline类型。 +```java +// 构造函数: constructor w/o label file +public DBDetector(String modelFile, String paramsFile); +public DBDetector(String modelFile, String paramsFile, RuntimeOption option); +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); +``` +- 模型预测 API:模型预测API包含直接预测的API以及带可视化功能的API。直接预测是指,不保存图片以及不渲染结果到Bitmap上,仅预测推理结果。预测并且可视化是指,预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap(目前支持ARGB8888格式的Bitmap), 后续可将该Bitmap在camera中进行显示。 +```java +// 直接预测:不保存图片以及不渲染结果到Bitmap上 +public OCRResult predict(Bitmap ARGB8888Bitmap); +// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +public OCRResult predict(Bitmap ARGB8888Bitmap, String savedImagePath); +public OCRResult predict(Bitmap ARGB8888Bitmap, boolean rendering); // 只渲染 不保存图片 +``` +- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +```java +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` 目录下;详细配置文档可参考: + - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) + +- 替换OCR模型的步骤: + - 将您的OCR模型放在 `app/src/main/assets/models` 目录下; + - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +```xml + +models +labels/ppocr_keys_v1.txt +``` + +## 更多参考文档 +如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: +- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/ocr/PP-OCRv2/cpp/README.md b/examples/vision/ocr/PP-OCRv2/cpp/README.md index 9052dd80ec..230b8cf3f4 100755 --- a/examples/vision/ocr/PP-OCRv2/cpp/README.md +++ b/examples/vision/ocr/PP-OCRv2/cpp/README.md @@ -1,25 +1,26 @@ -# PPOCRv2 C++部署示例 +English | [简体中文](README_CN.md) +# PPOCRv2 C++ Deployment Example -本目录下提供`infer.cc`快速完成PPOCRv2在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PPOCRv2 on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ``` mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载模型,图片和字典文件 +# Download model, image, and dictionary files wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar tar -xvf ch_PP-OCRv2_det_infer.tar @@ -33,34 +34,29 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt -# CPU推理 +# CPU inference ./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 0 -# GPU推理 +# GPU inference ./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 2 -# GPU上Paddle-TRT推理 +# Paddle-TRT inference on GPU ./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 3 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 4 -# 华为昇腾推理, 需要使用静态shape的demo, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 -./infer_static_shape_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) - -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## PPOCRv2 C++接口 +## PPOCRv2 C++ Interface -### PPOCRv2类 +### PPOCRv2 Class ``` fastdeploy::pipeline::PPOCRv2(fastdeploy::vision::ocr::DBDetector* det_model, @@ -68,43 +64,43 @@ fastdeploy::pipeline::PPOCRv2(fastdeploy::vision::ocr::DBDetector* det_model, fastdeploy::vision::ocr::Recognizer* rec_model); ``` -PPOCRv2 的初始化,由检测,分类和识别模型串联构成 +The initialization of PPOCRv2, consisting of detection, classification and recognition models -**参数** +**Parameter** -> * **DBDetector**(model): OCR中的检测模型 -> * **Classifier**(model): OCR中的分类模型 -> * **Recognizer**(model): OCR中的识别模型 +> * **DBDetector**(model): Detection model in OCR +> * **Classifier**(model): Classification model in OCR +> * **Recognizer**(model): Recognition model in OCR ``` fastdeploy::pipeline::PPOCRv2(fastdeploy::vision::ocr::DBDetector* det_model, fastdeploy::vision::ocr::Recognizer* rec_model); ``` -PPOCRv2 的初始化,由检测,识别模型串联构成(无分类器) +The initialization of PPOCRv2, consisting of detection and recognition models (No classifier) -**参数** +**Parameter** -> * **DBDetector**(model): OCR中的检测模型 -> * **Recognizer**(model): OCR中的识别模型 +> * **DBDetector**(model): Detection model in OCROCR中的检测模型 +> * **Recognizer**(model): Recognition model in OCR -#### Predict函数 +#### Predict Function > ``` > bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result); > bool Predict(const cv::Mat& img, fastdeploy::vision::OCRResult* result); > ``` > -> 模型预测接口,输入一张图片,返回OCR预测结果 +> Model prediction interface. Input images and output OCR prediction results > -> **参数** +> **Parameter** > -> > * **img**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: OCR预测结果,包括由检测模型输出的检测框位置,分类模型输出的方向分类,以及识别模型输出的识别结果, OCRResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **img**: Input images in HWC or BGR format +> > * **result**: OCR prediction results, including the position of the detection box from the detection model, the classification of the direction from the classification model, and the recognition result from the recognition model. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for OCRResult -## DBDetector C++接口 +## DBDetector C++ Interface -### DBDetector类 +### DBDetector Class ``` fastdeploy::vision::ocr::DBDetector(const std::string& model_file, const std::string& params_file = "", @@ -112,18 +108,18 @@ fastdeploy::vision::ocr::DBDetector(const std::string& model_file, const std::st const ModelFormat& model_format = ModelFormat::PADDLE); ``` -DBDetector模型加载和初始化,其中模型为paddle模型格式。 +DBDetector model loading and initialization. The model is in paddle format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### Classifier类与DBDetector类相同 +### The same applies to Classifier Class -### Recognizer类 +### Recognizer Class ``` Recognizer(const std::string& model_file, const std::string& params_file = "", @@ -131,31 +127,31 @@ DBDetector模型加载和初始化,其中模型为paddle模型格式。 const RuntimeOption& custom_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE); ``` -Recognizer类初始化时,需要在label_path参数中,输入识别模型所需的label文件,其他参数均与DBDetector类相同 +For the initialization of the Recognizer class, users should input the label file required by the recognition model in the label_path parameter. Other parameters are the same as the DBDetector class -**参数** -> * **label_path**(str): 识别模型的label文件路径 +**Parameter** +> * **label_path**(str): The label path of the recognition model -### 类成员变量 -#### DBDetector预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variable +#### DBDetector Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **max_side_len**(int): 检测算法前向时图片长边的最大尺寸,当长边超出这个值时会将长边resize到这个大小,短边等比例缩放,默认为960 -> > * **det_db_thresh**(double): DB模型输出预测图的二值化阈值,默认为0.3 -> > * **det_db_box_thresh**(double): DB模型输出框的阈值,低于此值的预测框会被丢弃,默认为0.6 -> > * **det_db_unclip_ratio**(double): DB模型输出框扩大的比例,默认为1.5 -> > * **det_db_score_mode**(string):DB后处理中计算文本框平均得分的方式,默认为slow,即求polygon区域的平均分数的方式 -> > * **use_dilation**(bool):是否对检测输出的feature map做膨胀处理,默认为Fasle +> > * **max_side_len**(int): The long side’s maximum size of the oriented view before detection. The long side will be resized to this size when exceeding the value. And the short side will be scaled in equal proportion. Default 960 +> > * **det_db_thresh**(double): The binarization threshold of the prediction image from DB models. Default 0.3 +> > * **det_db_box_thresh**(double): The threshold for the output box of DB models, below which the predicted box is discarded. Default 0.6 +> > * **det_db_unclip_ratio**(double): The expansion ratio of the DB model output box. Default 1.5 +> > * **det_db_score_mode**(string): The way to calculate the average score of the text box in DB post-processing. Default slow, which is identical to the calculation of the polygon area’s average score +> > * **use_dilation**(bool): Whether to expand the feature map from the detection. Default False -#### Classifier预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +#### Classifier Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **cls_thresh**(double): 当分类模型输出的得分超过此阈值,输入的图片将被翻转,默认为0.9 +> > * **cls_thresh**(double): The input image will be flipped when the score output by the classification model exceeds this threshold. Default 0.9 -## 其它文档 +## Other Documents -- [PPOCR 系列模型介绍](../../) -- [PPOCRv2 Python部署](../python) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PPOCR Model Description](../../) +- [PPOCRv2 Python Deployment](../python) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv2/cpp/README_CN.md b/examples/vision/ocr/PP-OCRv2/cpp/README_CN.md new file mode 100644 index 0000000000..ec8b0c16b3 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv2/cpp/README_CN.md @@ -0,0 +1,162 @@ +[English](README.md) | 简体中文 +# PPOCRv2 C++部署示例 + +本目录下提供`infer.cc`快速完成PPOCRv2在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +``` +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + + +# 下载模型,图片和字典文件 +wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar +tar -xvf ch_PP-OCRv2_det_infer.tar + +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar +tar -xvf ch_ppocr_mobile_v2.0_cls_infer.tar + +wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar +tar -xvf ch_PP-OCRv2_rec_infer.tar + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt + +# CPU推理 +./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 0 +# GPU推理 +./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 +# GPU上TensorRT推理 +./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 2 +# GPU上Paddle-TRT推理 +./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 3 +# 昆仑芯XPU推理 +./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 4 +# 华为昇腾推理, 需要使用静态shape的demo, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 +./infer_static_shape_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +运行完成可视化结果如下图所示 + + + + +## PPOCRv2 C++接口 + +### PPOCRv2类 + +``` +fastdeploy::pipeline::PPOCRv2(fastdeploy::vision::ocr::DBDetector* det_model, + fastdeploy::vision::ocr::Classifier* cls_model, + fastdeploy::vision::ocr::Recognizer* rec_model); +``` + +PPOCRv2 的初始化,由检测,分类和识别模型串联构成 + +**参数** + +> * **DBDetector**(model): OCR中的检测模型 +> * **Classifier**(model): OCR中的分类模型 +> * **Recognizer**(model): OCR中的识别模型 + +``` +fastdeploy::pipeline::PPOCRv2(fastdeploy::vision::ocr::DBDetector* det_model, + fastdeploy::vision::ocr::Recognizer* rec_model); +``` +PPOCRv2 的初始化,由检测,识别模型串联构成(无分类器) + +**参数** + +> * **DBDetector**(model): OCR中的检测模型 +> * **Recognizer**(model): OCR中的识别模型 + +#### Predict函数 + +> ``` +> bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result); +> bool Predict(const cv::Mat& img, fastdeploy::vision::OCRResult* result); +> ``` +> +> 模型预测接口,输入一张图片,返回OCR预测结果 +> +> **参数** +> +> > * **img**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: OCR预测结果,包括由检测模型输出的检测框位置,分类模型输出的方向分类,以及识别模型输出的识别结果, OCRResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +## DBDetector C++接口 + +### DBDetector类 + +``` +fastdeploy::vision::ocr::DBDetector(const std::string& model_file, const std::string& params_file = "", + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE); +``` + +DBDetector模型加载和初始化,其中模型为paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### Classifier类与DBDetector类相同 + +### Recognizer类 +``` + Recognizer(const std::string& model_file, + const std::string& params_file = "", + const std::string& label_path = "", + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE); +``` +Recognizer类初始化时,需要在label_path参数中,输入识别模型所需的label文件,其他参数均与DBDetector类相同 + +**参数** +> * **label_path**(str): 识别模型的label文件路径 + + +### 类成员变量 +#### DBDetector预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **max_side_len**(int): 检测算法前向时图片长边的最大尺寸,当长边超出这个值时会将长边resize到这个大小,短边等比例缩放,默认为960 +> > * **det_db_thresh**(double): DB模型输出预测图的二值化阈值,默认为0.3 +> > * **det_db_box_thresh**(double): DB模型输出框的阈值,低于此值的预测框会被丢弃,默认为0.6 +> > * **det_db_unclip_ratio**(double): DB模型输出框扩大的比例,默认为1.5 +> > * **det_db_score_mode**(string):DB后处理中计算文本框平均得分的方式,默认为slow,即求polygon区域的平均分数的方式 +> > * **use_dilation**(bool):是否对检测输出的feature map做膨胀处理,默认为Fasle + +#### Classifier预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **cls_thresh**(double): 当分类模型输出的得分超过此阈值,输入的图片将被翻转,默认为0.9 + +## 其它文档 + +- [PPOCR 系列模型介绍](../../) +- [PPOCRv2 Python部署](../python) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv2/python/README.md b/examples/vision/ocr/PP-OCRv2/python/README.md index 1ea95695f3..53316be248 100755 --- a/examples/vision/ocr/PP-OCRv2/python/README.md +++ b/examples/vision/ocr/PP-OCRv2/python/README.md @@ -1,15 +1,16 @@ -# PPOCRv2 Python部署示例 +English | [简体中文](README_CN.md) +# PPOCRv2 Python Deployment Example -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成PPOCRv2在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of PPOCRv2 on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ``` -# 下载模型,图片和字典文件 +# Download model, image, and dictionary files wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar tar -xvf ch_PP-OCRv2_det_infer.tar @@ -24,109 +25,107 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vison/ocr/PP-OCRv2/python/ -# CPU推理 +# CPU inference python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt -# 昆仑芯XPU推理 +# KunlunXin XPU inference python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device kunlunxin -# 华为昇腾推理,需要使用静态shape脚本, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 -python infer_static_shape.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device ascend ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## PPOCRv2 Python接口 +## PPOCRv2 Python Interface ``` fd.vision.ocr.PPOCRv2(det_model=det_model, cls_model=cls_model, rec_model=rec_model) ``` -PPOCRv2的初始化,输入的参数是检测模型,分类模型和识别模型,其中cls_model可选,如无需求,可设置为None +To initialize PPOCRv2, the input parameters correspond to detection model, classification model, and recognition model. Among them, cls_model is optional. It can be set to None if there is no demand -**参数** +**Parameter** -> * **det_model**(model): OCR中的检测模型 -> * **cls_model**(model): OCR中的分类模型 -> * **rec_model**(model): OCR中的识别模型 +> * **det_model**(model): Detection model in OCR +> * **cls_model**(model): Classification model in OCR +> * **rec_model**(model): Recognition model in OCR -### predict函数 +### predict function > ``` > result = ppocr_v2.predict(im) > ``` > -> 模型预测接口,输入是一张图片 +> Model prediction interface. Input one image. > -> **参数** +> **Parameter** > -> > * **im**(np.ndarray): 输入数据,每张图片注意需为HWC,BGR格式 +> > * **im**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.OCRResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return the `fastdeploy.vision.OCRResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for its description. -## DBDetector Python接口 +## DBDetector Python Interface -### DBDetector类 +### DBDetector Class ``` fastdeploy.vision.ocr.DBDetector(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -DBDetector模型加载和初始化,其中模型为paddle模型格式。 +DBDetector model loading and initialization. The model is in paddle format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为PADDLE格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path. Merely passing an empty string when the model is in ONNX format +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. PADDLE format by default -### Classifier类与DBDetector类相同 +### The same applies to the Classifier class -### Recognizer类 +### Recognizer Class ``` fastdeploy.vision.ocr.Recognizer(rec_model_file,rec_params_file,rec_label_file, runtime_option=rec_runtime_option,model_format=ModelFormat.PADDLE) ``` -Recognizer类初始化时,需要在rec_label_file参数中,输入识别模型所需的label文件路径,其他参数均与DBDetector类相同 +To initialize the Recognizer class, users need to input the label file path required by the recognition model in the rec_label_file parameter. Other parameters are the same as those of DBDetector class -**参数** -> * **label_path**(str): 识别模型的label文件路径 +**Parameter** +> * **label_path**(str): The label path of the recognition model -### 类成员变量 +### Class Member Variable -#### DBDetector预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +#### DBDetector Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **max_side_len**(int): 检测算法前向时图片长边的最大尺寸,当长边超出这个值时会将长边resize到这个大小,短边等比例缩放,默认为960 -> > * **det_db_thresh**(double): DB模型输出预测图的二值化阈值,默认为0.3 -> > * **det_db_box_thresh**(double): DB模型输出框的阈值,低于此值的预测框会被丢弃,默认为0.6 -> > * **det_db_unclip_ratio**(double): DB模型输出框扩大的比例,默认为1.5 -> > * **det_db_score_mode**(string):DB后处理中计算文本框平均得分的方式,默认为slow,即求polygon区域的平均分数的方式 -> > * **use_dilation**(bool):是否对检测输出的feature map做膨胀处理,默认为Fasle +> > * **max_side_len**(int): The long side’s maximum size of the oriented view before detection. The long side will be resized to this size when exceeding the value. And the short side will be scaled in equal proportion. Default 960 +> > * **det_db_thresh**(double): The binarization threshold of the prediction image from DB models. Default 0.3 +> > * **det_db_box_thresh**(double): The threshold for the output box of DB models, below which the predicted box is discarded. Default 0.6 +> > * **det_db_unclip_ratio**(double): The expansion ratio of the DB model output box. Default 1.5 +> > * **det_db_score_mode**(string): The way to calculate the average score of the text box in DB post-processing. Default slow, which is identical to the calculation of the polygon area’s average score +> > * **use_dilation**(bool): Whether to expand the feature map from the detection. Default False -#### Classifier预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +#### Classifier Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **cls_thresh**(double): 当分类模型输出的得分超过此阈值,输入的图片将被翻转,默认为0.9 +> > * **cls_thresh**(double): The input image will be flipped when the score output by the classification model exceeds this threshold. Default 0.9 -## 其它文档 +## Other Documents -- [PPOCR 系列模型介绍](../../) -- [PPOCRv2 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PPOCR Model Description](../../) +- [PPOCRv2 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv2/python/README_CN.md b/examples/vision/ocr/PP-OCRv2/python/README_CN.md new file mode 100644 index 0000000000..9eea8ba5c8 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv2/python/README_CN.md @@ -0,0 +1,133 @@ +[English](README.md) | 简体中文 +# PPOCRv2 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PPOCRv2在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +``` + +# 下载模型,图片和字典文件 +wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar +tar -xvf ch_PP-OCRv2_det_infer.tar + +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar +tar -xvf ch_ppocr_mobile_v2.0_cls_infer.tar + +wget https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar +tar -xvf ch_PP-OCRv2_rec_infer.tar + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt + + +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vison/ocr/PP-OCRv2/python/ + +# CPU推理 +python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu +# GPU推理 +python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt +# 昆仑芯XPU推理 +python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device kunlunxin +# 华为昇腾推理,需要使用静态shape脚本, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 +python infer_static_shape.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device ascend +``` + +运行完成可视化结果如下图所示 + + +## PPOCRv2 Python接口 + +``` +fd.vision.ocr.PPOCRv2(det_model=det_model, cls_model=cls_model, rec_model=rec_model) +``` +PPOCRv2的初始化,输入的参数是检测模型,分类模型和识别模型,其中cls_model可选,如无需求,可设置为None + +**参数** + +> * **det_model**(model): OCR中的检测模型 +> * **cls_model**(model): OCR中的分类模型 +> * **rec_model**(model): OCR中的识别模型 + +### predict函数 + +> ``` +> result = ppocr_v2.predict(im) +> ``` +> +> 模型预测接口,输入是一张图片 +> +> **参数** +> +> > * **im**(np.ndarray): 输入数据,每张图片注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.OCRResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + + + +## DBDetector Python接口 + +### DBDetector类 + +``` +fastdeploy.vision.ocr.DBDetector(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +DBDetector模型加载和初始化,其中模型为paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为PADDLE格式 + +### Classifier类与DBDetector类相同 + +### Recognizer类 +``` +fastdeploy.vision.ocr.Recognizer(rec_model_file,rec_params_file,rec_label_file, + runtime_option=rec_runtime_option,model_format=ModelFormat.PADDLE) +``` +Recognizer类初始化时,需要在rec_label_file参数中,输入识别模型所需的label文件路径,其他参数均与DBDetector类相同 + +**参数** +> * **label_path**(str): 识别模型的label文件路径 + + + +### 类成员变量 + +#### DBDetector预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **max_side_len**(int): 检测算法前向时图片长边的最大尺寸,当长边超出这个值时会将长边resize到这个大小,短边等比例缩放,默认为960 +> > * **det_db_thresh**(double): DB模型输出预测图的二值化阈值,默认为0.3 +> > * **det_db_box_thresh**(double): DB模型输出框的阈值,低于此值的预测框会被丢弃,默认为0.6 +> > * **det_db_unclip_ratio**(double): DB模型输出框扩大的比例,默认为1.5 +> > * **det_db_score_mode**(string):DB后处理中计算文本框平均得分的方式,默认为slow,即求polygon区域的平均分数的方式 +> > * **use_dilation**(bool):是否对检测输出的feature map做膨胀处理,默认为Fasle + +#### Classifier预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **cls_thresh**(double): 当分类模型输出的得分超过此阈值,输入的图片将被翻转,默认为0.9 + + + +## 其它文档 + +- [PPOCR 系列模型介绍](../../) +- [PPOCRv2 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv2/serving/README.md b/examples/vision/ocr/PP-OCRv2/serving/README.md index b7a636477d..2049564c9e 100644 --- a/examples/vision/ocr/PP-OCRv2/serving/README.md +++ b/examples/vision/ocr/PP-OCRv2/serving/README.md @@ -1,12 +1,13 @@ -# PP-OCRv2服务化部署示例 +English | [简体中文](README_CN.md) +# PP-OCRv2 Serving Deployment -除了`下载的模型`和`rec前处理的1个参数`以外PP-OCRv2的服务化部署与PP-OCRv3服务化部署全部一样,请参考[PP-OCRv3服务化部署](../../PP-OCRv3/serving)。 +The serving deployment of PP-OCRv2 is identical to that of PP-OCRv3 except for `downloaded models` and `1 parameter for rec pre-processing`. Refer to [PP-OCRv3 serving deployment](../../PP-OCRv3/serving) -## 下载模型 -将下载链接中的`v3`改为`v2`即可。 +## Download models +Change `v3` into `v2` in the download link. -## 修改rec前处理参数 -在[model.py](../../PP-OCRv3/serving/models/det_postprocess/1/model.py#L109)文件**109行添加以下代码**: +## Modify the rec pre-processing parameter +**Add the following code to line 109** in the file [model.py](../../PP-OCRv3/serving/models/det_postprocess/1/model.py#L109): ``` self.rec_preprocessor.cls_image_shape[1] = 32 ``` diff --git a/examples/vision/ocr/PP-OCRv2/serving/README_CN.md b/examples/vision/ocr/PP-OCRv2/serving/README_CN.md new file mode 100644 index 0000000000..f83e8b0b4d --- /dev/null +++ b/examples/vision/ocr/PP-OCRv2/serving/README_CN.md @@ -0,0 +1,13 @@ +[English](README.md) | 简体中文 +# PP-OCRv2服务化部署示例 + +除了`下载的模型`和`rec前处理的1个参数`以外PP-OCRv2的服务化部署与PP-OCRv3服务化部署全部一样,请参考[PP-OCRv3服务化部署](../../PP-OCRv3/serving)。 + +## 下载模型 +将下载链接中的`v3`改为`v2`即可。 + +## 修改rec前处理参数 +在[model.py](../../PP-OCRv3/serving/models/det_postprocess/1/model.py#L109)文件**109行添加以下代码**: +``` +self.rec_preprocessor.cls_image_shape[1] = 32 +``` diff --git a/examples/vision/ocr/PP-OCRv3/android/README.md b/examples/vision/ocr/PP-OCRv3/android/README.md index f4e23ab992..a92fb72246 100644 --- a/examples/vision/ocr/PP-OCRv3/android/README.md +++ b/examples/vision/ocr/PP-OCRv3/android/README.md @@ -1,94 +1,94 @@ -# OCR文字识别 Android Demo 使用文档 +English | [简体中文](README_CN.md) +# OCR Text Recognition Android Demo Tutorial -在 Android 上实现实时的OCR文字识别功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 +Real-time OCR text recognition on Android. This demo is easy to use for everyone. For example, you can run your own trained model in the demo. -## 环境准备 +## Prepare the Environment -1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 -2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` +1. Install Android Studio in your local environment. Refer to [Android Studio Official Website](https://developer.android.com/studio) for detailed tutorial. +2. Prepare an Android phone and turn on the USB debug mode. Opening: `Settings -> Find developer options -> Open developer options and USB debug mode` -## 部署步骤 +## Deployment steps -1. OCR文字识别 Demo 位于 `fastdeploy/examples/vision/ocr/PP-OCRv3/android` 目录 -2. 用 Android Studio 打开 PP-OCRv3/android 工程 -3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) +1. The OCR text recognition Demo is located in the `fastdeploy/examples/vision/ocr/PP-OCRv3/android` +2. Open PP-OCRv2/android project with Android Studio +3. Connect the phone to the computer, turn on USB debug mode and file transfer mode, and connect your phone to Android Studio (allow the phone to install software from USB)

image

-> **注意:** ->> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 +> **Attention:** +>> If you encounter an NDK configuration error during import, compilation or running, open ` File > Project Structure > SDK Location` and change the path of SDK configured by the `Andriod SDK location` -4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) - 成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 +4. Click the Run button to automatically compile the APP and install it to the phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files. Internet is required). +The final effect is as follows. Figure 1: Install the APP on the phone; Figure 2: The effect after opening the APP. It will automatically recognize and mark the objects in the image; Figure 3: APP setting option. Click setting in the upper right corner and modify your options. -| APP 图标 | APP 效果 | APP设置项 +| APP Icon | APP Effect | APP Settings | --- | --- | --- | | ![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-OCRv3 Java API 说明 +### PP-OCRv3 Java API Description -- 模型初始化 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-OCRv3 包含 DBDetector、Classifier和Recognizer等基础模型,以及pipeline类型。 +- Model initialized API: The initialized API contains two ways: Firstly, initialize directly through the constructor. Secondly, initialize at the appropriate program node by calling the init function. PP-OCR initialization parameters are as follows: + - modelFile: String. Model file path in paddle format, such as model.pdmodel + - paramFile: String. Parameter file path in paddle format, such as model.pdiparams + - labelFile: String. This optional parameter indicates the path of the label file and is used for visualization. such as ppocr_keys_v1.txt, each line containing one label + - option: RuntimeOption. Optional parameter for model initialization. Default runtime options if the parameter is not passed. Different from other models, PP-OCRv3 contains base models such as DBDetector, Classifier, Recognizer and the pipeline type. ```java -// 构造函数: constructor w/o label file +// Constructor: constructor w/o label file public DBDetector(String modelFile, String paramsFile); public DBDetector(String modelFile, String paramsFile, RuntimeOption option); 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 PPOCRv3(); // 空构造函数,之后可以调用init初始化 +public PPOCRv3(); // An empty constructor, which can be initialized by calling 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中进行显示。 +- Model Prediction API: The Model Prediction API contains an API for direct prediction and an API for visualization. In direct prediction, we do not save the image and render the result on Bitmap. Instead, we merely predict the inference result. For prediction and visualization, the results are both predicted and visualized, the visualized images are saved to the specified path, and the visualized results are rendered in Bitmap (Now Bitmap in ARGB8888 format is supported). Afterward, the Bitmap can be displayed on the camera. ```java -// 直接预测:不保存图片以及不渲染结果到Bitmap上 +// Direct prediction: No image saving and no result rendering to Bitmap public OCRResult predict(Bitmap ARGB8888Bitmap); -// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +// Prediction and visualization: Predict and visualize the results, save the visualized image to the specified path, and render the visualized results on Bitmap public OCRResult predict(Bitmap ARGB8888Bitmap, String savedImagePath); -public OCRResult predict(Bitmap ARGB8888Bitmap, boolean rendering); // 只渲染 不保存图片 +public OCRResult predict(Bitmap ARGB8888Bitmap, boolean rendering); // Render without saving images ``` -- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +- Model resource release API: Call release() API to release model resources. Return true for successful release and false for failure; call initialized() to determine whether the model was initialized successfully, with true indicating successful initialization and false indicating failure. ```java -public boolean release(); // 释放native资源 -public boolean initialized(); // 检查是否初始化成功 +public boolean release(); // Release native resources +public boolean initialized(); // Check if initialization was successful ``` -- RuntimeOption设置说明 +- RuntimeOption settings ```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); // 通过字符串形式设置能耗模式 +public void enableLiteFp16(); // Enable fp16 accuracy inference +public void disableLiteFP16(); // Disable fp16 accuracy inference +public void enableLiteInt8(); // Enable int8 accuracy inference for quantification models +public void disableLiteInt8(); // Disable int8 accuracy inference +public void setCpuThreadNum(int threadNum); // Set thread numbers +public void setLitePowerMode(LitePowerMode mode); // Set power mode +public void setLitePowerMode(String modeStr); // Set power mode through character string ``` -- 模型结果OCRResult说明 +- Model 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; // 检测结果是否有效 + public int[][] mBoxes; // The coordinates of all target boxes in a single image. 8 int values represent the 4 coordinate points of the box in the order of bottom left, bottom right, top right and top left + public String[] mText; // Recognized text in multiple text boxes + public float[] mRecScores; // Confidence of the recognized text in the box + public float[] mClsScores; // Confidence of the classification result of the text box + public int[] mClsLabels; // Directional classification of the text box + public boolean mInitialized = false; // Whether the result is valid or not } ``` -其他参考:C++/Python对应的OCRResult说明: [api/vision_results/ocr_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/ocr_result.md) +Refer to [api/vision_results/ocr_result.md](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/api/vision_results/ocr_result.md) for C++/Python OCRResult -- 模型调用示例1:使用构造函数 +- Model Calling Example 1: Using Constructor ```java import java.nio.ByteBuffer; import android.graphics.Bitmap; @@ -101,7 +101,7 @@ import com.baidu.paddle.fastdeploy.vision.ocr.Classifier; import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector; import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer; -// 模型路径 +// Model path 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"; @@ -109,7 +109,7 @@ 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 +// Set the RuntimeOption RuntimeOption detOption = new RuntimeOption(); RuntimeOption clsOption = new RuntimeOption(); RuntimeOption recOption = new RuntimeOption(); @@ -122,37 +122,37 @@ recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); detOption.enableLiteFp16(); clsOption.enableLiteFp16(); recOption.enableLiteFp16(); -// 初始化模型 +// Initialize the model 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的伪代码 +// Read the image: The following is merely the pseudo code to read the 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); -// 模型推理 +// Model Inference OCRResult result = model.predict(ARGB8888ImageBitmap); -// 释放模型资源 +// Release model resources model.release(); ``` -- 模型调用示例2: 在合适的程序节点,手动调用init +- Model calling example 2: Manually call init at the appropriate program node ```java -// import 同上 ... +// import is as above... 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; -// 新建空模型 +// Create an empty model PPOCRv3 model = new PPOCRv3(); -// 模型路径 +// Model path 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"; @@ -160,7 +160,7 @@ 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 +// Set the RuntimeOption RuntimeOption detOption = new RuntimeOption(); RuntimeOption clsOption = new RuntimeOption(); RuntimeOption recOption = new RuntimeOption(); @@ -173,30 +173,30 @@ recOption.setLitePowerMode(LitePowerMode.LITE_POWER_HIGH); detOption.enableLiteFp16(); clsOption.enableLiteFp16(); recOption.enableLiteFp16(); -// 使用init函数初始化 +// Use init function for initialization 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读取、模型预测、资源释放 同上 ... +// Bitmap reading, model prediction, and resource release are as above ... ``` -更详细的用法请参考 [OcrMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java)中的用法 +Refer to [OcrMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java) for more details -## 替换 FastDeploy SDK和模型 -替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models`。 -- 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: - - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +## Replace FastDeploy SDK and Models +It’s simple to replace the FastDeploy prediction library and models. The prediction library is located at `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` represents the version of your prediction library. The models are located at `app/src/main/assets/models`. +- Replace the FastDeploy Android SDK: Download or compile the latest FastDeploy Android SDK, unzip and place it in the `app/libs`; For detailed configuration, refer to + - [FastDeploy Java SDK in Android](../../../../../java/android/) -- 替换OCR模型的步骤: - - 将您的OCR模型放在 `app/src/main/assets/models` 目录下; - - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +- Steps to replace OCR models: + - Put your OCR model in `app/src/main/assets/models`; + - Modify the default value of the model path in `app/src/main/res/values/strings.xml`. For example, ```xml - + models labels/ppocr_keys_v1.txt ``` -## 使用量化模型 -如果您使用的是量化格式的模型,只需要使用RuntimeOption的enableLiteInt8()接口设置Int8精度推理即可。 +## Use quantification models +If you're using quantification models, set Int8 accuracy inference using the interface enableLiteInt8() of RuntimeOption. ```java String detModelFile = "ch_ppocrv3_plate_det_quant/inference.pdmodel"; String detParamsFile = "ch_ppocrv3_plate_det_quant/inference.pdiparams"; @@ -205,18 +205,18 @@ String recParamsFile = "ch_ppocrv3_plate_rec_distillation_quant/inference.pdipar String recLabelFilePath = "ppocr_keys_v1.txt"; // ppocr_keys_v1.txt RuntimeOption detOption = new RuntimeOption(); RuntimeOption recOption = new RuntimeOption(); -// 使用Int8精度进行推理 +// Use Int8 accuracy for inference detOption.enableLiteInt8(); recOption.enableLiteInt8(); -// 初始化PP-OCRv3 Pipeline +// Initialize PP-OCRv3 Pipeline PPOCRv3 predictor = new PPOCRv3(); DBDetector detModel = new DBDetector(detModelFile, detParamsFile, detOption); Recognizer recModel = new Recognizer(recModelFile, recParamsFile, recLabelFilePath, recOption); predictor.init(detModel, recModel); ``` -在App中使用,可以参考 [OcrMainActivity.java](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java) 中的用法。 +Refer to [OcrMainActivity.java](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java) for use-pattern in APP. -## 更多参考文档 -如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: -- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) -- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) +## More Reference Documents +For more FastDeploy Java API documentes and how to access FastDeploy C++ API via JNI, refer to: +- [FastDeploy Java SDK in Android](../../../../../java/android/) +- [FastDeploy C++ SDK in Android](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/ocr/PP-OCRv3/android/README_CN.md b/examples/vision/ocr/PP-OCRv3/android/README_CN.md new file mode 100644 index 0000000000..b355119e2b --- /dev/null +++ b/examples/vision/ocr/PP-OCRv3/android/README_CN.md @@ -0,0 +1,223 @@ +[English](README.md) | 简体中文 +# OCR文字识别 Android Demo 使用文档 + +在 Android 上实现实时的OCR文字识别功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 + +## 环境准备 + +1. 在本地环境安装好 Android Studio 工具,详细安装方法请见[Android Stuido 官网](https://developer.android.com/studio)。 +2. 准备一部 Android 手机,并开启 USB 调试模式。开启方法: `手机设置 -> 查找开发者选项 -> 打开开发者选项和 USB 调试模式` + +## 部署步骤 + +1. OCR文字识别 Demo 位于 `fastdeploy/examples/vision/ocr/PP-OCRv3/android` 目录 +2. 用 Android Studio 打开 PP-OCRv3/android 工程 +3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) + +

+image +

+ +> **注意:** +>> 如果您在导入项目、编译或者运行过程中遇到 NDK 配置错误的提示,请打开 ` File > Project Structure > SDK Location`,修改 `Andriod SDK location` 为您本机配置的 SDK 所在路径。 + +4. 点击 Run 按钮,自动编译 APP 并安装到手机。(该过程会自动下载预编译的 FastDeploy Android 库 以及 模型文件,需要联网) + 成功后效果如下,图一:APP 安装到手机;图二: APP 打开后的效果,会自动识别图片中的物体并标记;图三:APP设置选项,点击右上角的设置图片,可以设置不同选项进行体验。 + +| APP 图标 | APP 效果 | APP设置项 + | --- | --- | --- | +| ![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-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-OCRv3 包含 DBDetector、Classifier和Recognizer等基础模型,以及pipeline类型。 +```java +// 构造函数: constructor w/o label file +public DBDetector(String modelFile, String paramsFile); +public DBDetector(String modelFile, String paramsFile, RuntimeOption option); +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 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 +// 直接预测:不保存图片以及不渲染结果到Bitmap上 +public OCRResult predict(Bitmap ARGB8888Bitmap); +// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上 +public OCRResult predict(Bitmap ARGB8888Bitmap, String savedImagePath); +public OCRResult predict(Bitmap ARGB8888Bitmap, boolean rendering); // 只渲染 不保存图片 +``` +- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。 +```java +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` 目录下;详细配置文档可参考: + - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) + +- 替换OCR模型的步骤: + - 将您的OCR模型放在 `app/src/main/assets/models` 目录下; + - 修改 `app/src/main/res/values/strings.xml` 中模型路径的默认值,如: +```xml + +models +labels/ppocr_keys_v1.txt +``` +## 使用量化模型 +如果您使用的是量化格式的模型,只需要使用RuntimeOption的enableLiteInt8()接口设置Int8精度推理即可。 +```java +String detModelFile = "ch_ppocrv3_plate_det_quant/inference.pdmodel"; +String detParamsFile = "ch_ppocrv3_plate_det_quant/inference.pdiparams"; +String recModelFile = "ch_ppocrv3_plate_rec_distillation_quant/inference.pdmodel"; +String recParamsFile = "ch_ppocrv3_plate_rec_distillation_quant/inference.pdiparams"; +String recLabelFilePath = "ppocr_keys_v1.txt"; // ppocr_keys_v1.txt +RuntimeOption detOption = new RuntimeOption(); +RuntimeOption recOption = new RuntimeOption(); +// 使用Int8精度进行推理 +detOption.enableLiteInt8(); +recOption.enableLiteInt8(); +// 初始化PP-OCRv3 Pipeline +PPOCRv3 predictor = new PPOCRv3(); +DBDetector detModel = new DBDetector(detModelFile, detParamsFile, detOption); +Recognizer recModel = new Recognizer(recModelFile, recParamsFile, recLabelFilePath, recOption); +predictor.init(detModel, recModel); +``` +在App中使用,可以参考 [OcrMainActivity.java](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/ocr/OcrMainActivity.java) 中的用法。 + +## 更多参考文档 +如果您想知道更多的FastDeploy Java API文档以及如何通过JNI来接入FastDeploy C++ API感兴趣,可以参考以下内容: +- [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) +- [在 Android 中使用 FastDeploy C++ SDK](../../../../../docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/ocr/PP-OCRv3/cpp/README.md b/examples/vision/ocr/PP-OCRv3/cpp/README.md index 7f557a213b..752c6e184b 100755 --- a/examples/vision/ocr/PP-OCRv3/cpp/README.md +++ b/examples/vision/ocr/PP-OCRv3/cpp/README.md @@ -1,25 +1,26 @@ -# PPOCRv3 C++部署示例 +English | [简体中文](README_CN.md) +# PPOCRv3 C++ Deployment Example -本目录下提供`infer.cc`快速完成PPOCRv3在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PPOCRv3 on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the CPU inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ``` mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载模型,图片和字典文件 +# Download model, image, and dictionary files wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar tar -xvf ch_PP-OCRv3_det_infer.tar @@ -33,34 +34,29 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt -# CPU推理 +# CPU inference ./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 0 -# GPU推理 +# GPU inference ./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 2 -# GPU上Paddle-TRT推理 +# Paddle-TRT inference on GPU ./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 3 -# 昆仑芯XPU推理 +# KunlunXin XPU inference ./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 4 -# 华为昇腾推理,需要使用静态shape的demo, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 -./infer_static_shape_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) - -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## 其它文档 +## Other Documents -- [C++ API查阅](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/) -- [PPOCR 系列模型介绍](../../) -- [PPOCRv3 Python部署](../python) -- [模型预测结果说明](../../../../../docs/cn/faq/how_to_change_backend.md) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [C++ API Reference](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/) +- [PPOCR Model Description](../../) +- [PPOCRv3 Python Deployment](../python) +- [Model Prediction Results](../../../../../docs/cn/faq/how_to_change_backend.md) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv3/cpp/README_CN.md b/examples/vision/ocr/PP-OCRv3/cpp/README_CN.md new file mode 100644 index 0000000000..167d2d9524 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv3/cpp/README_CN.md @@ -0,0 +1,67 @@ +[English](README.md) | 简体中文 +# PPOCRv3 C++部署示例 + +本目录下提供`infer.cc`快速完成PPOCRv3在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +``` +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + + +# 下载模型,图片和字典文件 +wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar +tar -xvf ch_PP-OCRv3_det_infer.tar + +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar +tar -xvf ch_ppocr_mobile_v2.0_cls_infer.tar + +wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar +tar -xvf ch_PP-OCRv3_rec_infer.tar + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt + +# CPU推理 +./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 0 +# GPU推理 +./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 +# GPU上TensorRT推理 +./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 2 +# GPU上Paddle-TRT推理 +./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 3 +# 昆仑芯XPU推理 +./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 4 +# 华为昇腾推理,需要使用静态shape的demo, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 +./infer_static_shape_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +运行完成可视化结果如下图所示 + + + +## 其它文档 + +- [C++ API查阅](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/) +- [PPOCR 系列模型介绍](../../) +- [PPOCRv3 Python部署](../python) +- [模型预测结果说明](../../../../../docs/cn/faq/how_to_change_backend.md) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv3/mini_program/README.md b/examples/vision/ocr/PP-OCRv3/mini_program/README.md index 447a02e725..b80e6acb09 100644 --- a/examples/vision/ocr/PP-OCRv3/mini_program/README.md +++ b/examples/vision/ocr/PP-OCRv3/mini_program/README.md @@ -1,40 +1,40 @@ +English | [简体中文](README_CN.md) +# PP-OCRv3 Wechat Mini-program Deployment Example -# PP-OCRv3 微信小程序部署示例 +This document introduces the deployment of PP-OCRv3 model from PaddleOCR in Wechat mini-program, and the js interface in the @paddle-js-models/ocr npm package. -本节介绍部署PaddleOCR的PP-OCRv3模型在微信小程序中运行,以及@paddle-js-models/ocr npm包中的js接口。 +## Deploy PP-OCRv3 models in Wechat Mini-program -## 微信小程序部署PP-OCRv3模型 +For the deployment of PP-OCRv3 models in Wechat mini-program, refer to [**reference document**](../../../../application/js/mini_program) -PP-OCRv3模型部署到微信小程序[**参考文档**](../../../../application/js/mini_program) - -## PP-OCRv3 js接口 +## PP-OCRv3 js interface ``` import * as ocr from "@paddle-js-models/ocr"; await ocr.init(detConfig, recConfig); const res = await ocr.recognize(img, option, postConfig); ``` -ocr模型加载和初始化,其中模型为Paddle.js模型格式,js模型转换方式参考[文档](../../../../application/js/web_demo/README.md) +ocr model loading and initialization, where the model is in Paddle.js model format. For the conversion of js models, refer to [document](../../../../application/js/web_demo/README.md) -**init函数参数** +**init function parameter** -> * **detConfig**(dict): 文本检测模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_det_infer_js_960/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 -> * **recConfig**(dict)): 文本识别模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_rec_infer_js/model.json', fill: '#000', mean: [0.5, 0.5, 0.5], std: [0.5, 0.5, 0.5]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 +> * **detConfig**(dict): The configuration parameter for text detection model. Default {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_det_infer_js_960/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; Among them, modelPath is the path of the text detection model; fill is the padding value in the image pre-processing; mean and std are the mean and standard deviation in the pre-processing +> * **recConfig**(dict)): The configuration parameter for text recognition model. Default {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_rec_infer_js/model.json', fill: '#000', mean: [0.5, 0.5, 0.5], std: [0.5, 0.5, 0.5]}; Among them, modelPath is the path of the text detection model, fill is the padding value in the image pre-processing, and mean/std are the mean and standard deviation in the pre-processing -**recognize函数参数** +**recognize function parameter** -> * **img**(HTMLImageElement): 输入图像参数,类型为HTMLImageElement。 -> * **option**(dict): 可视化文本检测框的canvas参数,可不用设置。 -> * **postConfig**(dict): 文本检测后处理参数,默认值为:{shape: 960, thresh: 0.3, box_thresh: 0.6, unclip_ratio:1.5}; thresh是输出预测图的二值化阈值;box_thresh是输出框的阈值,低于此值的预测框会被丢弃,unclip_ratio是输出框扩大的比例。 +> * **img**(HTMLImageElement): Enter an image parameter in HTMLImageElement. +> * **option**(dict): The canvas parameter of the visual text detection box. No need to set. +> * **postConfig**(dict): Text detection post-processing parameter. Default: {shape: 960, thresh: 0.3, box_thresh: 0.6, unclip_ratio:1.5}; thresh is the binarization threshold of the output prediction image; box_thresh is the threshold of the output box, below which the prediction box will be discarded; unclip_ratio is the expansion ratio of the output box. -## 其它文档 +## Other Documents -- [PP-OCR 系列模型介绍](../../) -- [PP-OCRv3 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) -- [PP-OCRv3模型web demo文档](../../../../application/js/web_demo/README.md) +- [PP-OCR Model Description](../../) +- [PP-OCRv3 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Web demo document of PP-OCRv3 models](../../../../application/js/web_demo/README.md) diff --git a/examples/vision/ocr/PP-OCRv3/mini_program/README_CN.md b/examples/vision/ocr/PP-OCRv3/mini_program/README_CN.md new file mode 100644 index 0000000000..e3a9691008 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv3/mini_program/README_CN.md @@ -0,0 +1,40 @@ +[English](README.md) | 简体中文 +# PP-OCRv3 微信小程序部署示例 + +本节介绍部署PaddleOCR的PP-OCRv3模型在微信小程序中运行,以及@paddle-js-models/ocr npm包中的js接口。 + + +## 微信小程序部署PP-OCRv3模型 + +PP-OCRv3模型部署到微信小程序[**参考文档**](../../../../application/js/mini_program) + + +## PP-OCRv3 js接口 + +``` +import * as ocr from "@paddle-js-models/ocr"; +await ocr.init(detConfig, recConfig); +const res = await ocr.recognize(img, option, postConfig); +``` +ocr模型加载和初始化,其中模型为Paddle.js模型格式,js模型转换方式参考[文档](../../../../application/js/web_demo/README.md) + +**init函数参数** + +> * **detConfig**(dict): 文本检测模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_det_infer_js_960/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 +> * **recConfig**(dict)): 文本识别模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_rec_infer_js/model.json', fill: '#000', mean: [0.5, 0.5, 0.5], std: [0.5, 0.5, 0.5]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 + + +**recognize函数参数** + +> * **img**(HTMLImageElement): 输入图像参数,类型为HTMLImageElement。 +> * **option**(dict): 可视化文本检测框的canvas参数,可不用设置。 +> * **postConfig**(dict): 文本检测后处理参数,默认值为:{shape: 960, thresh: 0.3, box_thresh: 0.6, unclip_ratio:1.5}; thresh是输出预测图的二值化阈值;box_thresh是输出框的阈值,低于此值的预测框会被丢弃,unclip_ratio是输出框扩大的比例。 + + +## 其它文档 + +- [PP-OCR 系列模型介绍](../../) +- [PP-OCRv3 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-OCRv3模型web demo文档](../../../../application/js/web_demo/README.md) diff --git a/examples/vision/ocr/PP-OCRv3/python/README.md b/examples/vision/ocr/PP-OCRv3/python/README.md index 3fcf372e05..99217ceea0 100755 --- a/examples/vision/ocr/PP-OCRv3/python/README.md +++ b/examples/vision/ocr/PP-OCRv3/python/README.md @@ -1,15 +1,16 @@ -# PPOCRv3 Python部署示例 +English | [简体中文](README_CN.md) +# PPOCRv3 Python Deployment Example -在部署前,需确认以下两个步骤 +Two steps before deployment -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成PPOCRv3在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of PPOCRv3 on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ``` -# 下载模型,图片和字典文件 +# Download model, image, and dictionary files wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar tar xvf ch_PP-OCRv3_det_infer.tar @@ -23,32 +24,32 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt -#下载部署示例代码 +# Download the example code for deployment git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vison/ocr/PP-OCRv3/python/ -# CPU推理 +# CPU inference python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu -# GPU推理 +# GPU inference python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu -# GPU上使用TensorRT推理 +# TensorRT inference on GPU python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt -# 昆仑芯XPU推理 +# KunlunXin XPU inference python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device kunlunxin -# 华为昇腾推理,需要使用静态shape脚本, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 +# HUAWEI Ascend inference requires static shape script. The size of input images should be consistent if you want to continuously predict images. python infer_static_shape.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device ascend ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows -## 其它文档 +## Other Documents -- [Python API文档查阅](https://baidu-paddle.github.io/fastdeploy-api/python/html/) -- [PPOCR 系列模型介绍](../../) -- [PPOCRv3 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Python API reference](https://baidu-paddle.github.io/fastdeploy-api/python/html/) +- [PPOCR Model Description](../../) +- [PPOCRv3 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv3/python/README_CN.md b/examples/vision/ocr/PP-OCRv3/python/README_CN.md new file mode 100644 index 0000000000..845cc91abf --- /dev/null +++ b/examples/vision/ocr/PP-OCRv3/python/README_CN.md @@ -0,0 +1,55 @@ +[English](README.md) | 简体中文 +# PPOCRv3 Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PPOCRv3在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +``` + +# 下载模型,图片和字典文件 +wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar +tar xvf ch_PP-OCRv3_det_infer.tar + +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar +tar -xvf ch_ppocr_mobile_v2.0_cls_infer.tar + +wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar +tar xvf ch_PP-OCRv3_rec_infer.tar + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt + +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vison/ocr/PP-OCRv3/python/ + +# CPU推理 +python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device cpu +# GPU推理 +python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt +# 昆仑芯XPU推理 +python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device kunlunxin +# 华为昇腾推理,需要使用静态shape脚本, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸 +python infer_static_shape.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device ascend +``` + +运行完成可视化结果如下图所示 + + + + + +## 其它文档 + +- [Python API文档查阅](https://baidu-paddle.github.io/fastdeploy-api/python/html/) +- [PPOCR 系列模型介绍](../../) +- [PPOCRv3 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/ocr/PP-OCRv3/serving/README.md b/examples/vision/ocr/PP-OCRv3/serving/README.md index a870b2d19a..1ad4c70090 100755 --- a/examples/vision/ocr/PP-OCRv3/serving/README.md +++ b/examples/vision/ocr/PP-OCRv3/serving/README.md @@ -1,37 +1,37 @@ -# PP-OCR服务化部署示例 +English | [简体中文](README_CN.md) +# PP-OCR Serving Deployment Example -在服务化部署前,需确认 +Before the serving deployment, please confirm -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) +- 1. Refer to [FastDeploy Serving Deployment](../../../../../serving/README_CN.md) for software and hardware environment requirements and image pull commands -## 介绍 -本文介绍了使用FastDeploy搭建OCR文字识别服务的方法. +## Introduction +This document describes how to build an OCR text recognition service with FastDeploy. -服务端必须在docker内启动,而客户端不是必须在docker容器内. +The server must be started in docker, while the client does not need to be in a docker container. -**本文所在路径($PWD)下的models里包含模型的配置和代码(服务端会加载模型和代码以启动服务), 需要将其映射到docker中使用.** +**The models in the path ($PWD) contain the model configuration and code (the server will load the models and code to start the service), which needs to be mapped to docker.** -OCR由det(检测)、cls(分类)和rec(识别)三个模型组成. +OCR consists of det (detection), cls (classification) and rec (recognition) models. -服务化部署串联的示意图如下图所示,其中`pp_ocr`串联了`det_preprocess`、`det_runtime`和`det_postprocess`,`cls_pp`串联了`cls_runtime`和`cls_postprocess`,`rec_pp`串联了`rec_runtime`和`rec_postprocess`. - -特别的是,在`det_postprocess`中会多次调用`cls_pp`和`rec_pp`服务,来实现对检测结果(多个框)进行分类和识别,,最后返回给用户最终的识别结果。 +The diagram of the serving deployment is shown below, where `pp_ocr` connects to `det_preprocess`、`det_runtime` and `det_postprocess`,`cls_pp` connects to `cls_runtime` and `cls_postprocess`,`rec_pp` connects to `rec_runtime` and `rec_postprocess`. +In particular, `cls_pp` and `rec_pp` services are called multiple times in `det_postprocess` to realize the classification and identification of the detection results (multiple boxes), and finally return the identification results to users.



-## 使用 -### 1. 服务端 +## Usage +### 1. Server #### 1.1 Docker ```bash -# 下载仓库代码 +# Download the repository code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/ocr/PP-OCRv3/serving/ -# 下载模型,图片和字典文件 +# Dpwnload model, image, and dictionary files wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar tar xvf ch_PP-OCRv3_det_infer.tar && mv ch_PP-OCRv3_det_infer 1 mv 1/inference.pdiparams 1/model.pdiparams && mv 1/inference.pdmodel 1/model.pdmodel @@ -54,41 +54,41 @@ mv ppocr_keys_v1.txt models/rec_postprocess/1/ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg -# x.y.z为镜像版本号,需参照serving文档替换为数字 +# x.y.z represent the image version. Refer to serving document to replace them with numbers docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 docker run -dit --net=host --name fastdeploy --shm-size="1g" -v $PWD:/ocr_serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash docker exec -it -u root fastdeploy bash ``` -#### 1.2 安装(在docker内) +#### 1.2 Installation (in docker) ```bash ldconfig apt-get install libgl1 ``` -#### 1.3 启动服务端(在docker内) +#### 1.3 Start the server (in docker) ```bash fastdeployserver --model-repository=/ocr_serving/models ``` -参数: - - `model-repository`(required): 整套模型streaming_pp_tts存放的路径. - - `http-port`(optional): HTTP服务的端口号. 默认: `8000`. 本示例中未使用该端口. - - `grpc-port`(optional): GRPC服务的端口号. 默认: `8001`. - - `metrics-port`(optional): 服务端指标的端口号. 默认: `8002`. 本示例中未使用该端口. +Parameter: + - `model-repository`(required): The storage path of the entire model streaming_pp_tts. + - `http-port`(optional): Port number for the HTTP service. Default: `8000`. This port is not used in this example. + - `grpc-port`(optional): Port number for the GRPC service. Default: `8001`. + - `metrics-port`(optional): Port number for the serer metric. Default: `8002`. This port is not used in this example. -### 2. 客户端 -#### 2.1 安装 +### 2. Client +#### 2.1 Installation ```bash pip3 install tritonclient[all] ``` -#### 2.2 发送请求 +#### 2.2 Send Requests ```bash python3 client.py ``` -## 配置修改 +## Configuration Change -当前默认配置在GPU上运行, 如果要在CPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) +The current default configuration runs on GPU. If you want to run it on CPU or other inference engines, please modify the configuration in `models/runtime/config.pbtxt`. Refer to [Configuration Document](../../../../../serving/docs/zh_CN/model_configuration.md) for more information. diff --git a/examples/vision/ocr/PP-OCRv3/serving/README_CN.md b/examples/vision/ocr/PP-OCRv3/serving/README_CN.md new file mode 100644 index 0000000000..3f68e69ff4 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv3/serving/README_CN.md @@ -0,0 +1,95 @@ +[English](README.md) | 简体中文 +# PP-OCR服务化部署示例 + +在服务化部署前,需确认 + +- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) + +## 介绍 +本文介绍了使用FastDeploy搭建OCR文字识别服务的方法. + +服务端必须在docker内启动,而客户端不是必须在docker容器内. + +**本文所在路径($PWD)下的models里包含模型的配置和代码(服务端会加载模型和代码以启动服务), 需要将其映射到docker中使用.** + +OCR由det(检测)、cls(分类)和rec(识别)三个模型组成. + +服务化部署串联的示意图如下图所示,其中`pp_ocr`串联了`det_preprocess`、`det_runtime`和`det_postprocess`,`cls_pp`串联了`cls_runtime`和`cls_postprocess`,`rec_pp`串联了`rec_runtime`和`rec_postprocess`. + +特别的是,在`det_postprocess`中会多次调用`cls_pp`和`rec_pp`服务,来实现对检测结果(多个框)进行分类和识别,,最后返回给用户最终的识别结果。 + +

+
+ +
+

+ +## 使用 +### 1. 服务端 +#### 1.1 Docker +```bash +# 下载仓库代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/ocr/PP-OCRv3/serving/ + +# 下载模型,图片和字典文件 +wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar +tar xvf ch_PP-OCRv3_det_infer.tar && mv ch_PP-OCRv3_det_infer 1 +mv 1/inference.pdiparams 1/model.pdiparams && mv 1/inference.pdmodel 1/model.pdmodel +mv 1 models/det_runtime/ && rm -rf ch_PP-OCRv3_det_infer.tar + +wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar +tar xvf ch_ppocr_mobile_v2.0_cls_infer.tar && mv ch_ppocr_mobile_v2.0_cls_infer 1 +mv 1/inference.pdiparams 1/model.pdiparams && mv 1/inference.pdmodel 1/model.pdmodel +mv 1 models/cls_runtime/ && rm -rf ch_ppocr_mobile_v2.0_cls_infer.tar + +wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar +tar xvf ch_PP-OCRv3_rec_infer.tar && mv ch_PP-OCRv3_rec_infer 1 +mv 1/inference.pdiparams 1/model.pdiparams && mv 1/inference.pdmodel 1/model.pdmodel +mv 1 models/rec_runtime/ && rm -rf ch_PP-OCRv3_rec_infer.tar + +mkdir models/pp_ocr/1 && mkdir models/rec_pp/1 && mkdir models/cls_pp/1 + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_keys_v1.txt +mv ppocr_keys_v1.txt models/rec_postprocess/1/ + +wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/doc/imgs/12.jpg + +# x.y.z为镜像版本号,需参照serving文档替换为数字 +docker pull registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +docker run -dit --net=host --name fastdeploy --shm-size="1g" -v $PWD:/ocr_serving registry.baidubce.com/paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash +docker exec -it -u root fastdeploy bash +``` + +#### 1.2 安装(在docker内) +```bash +ldconfig +apt-get install libgl1 +``` + +#### 1.3 启动服务端(在docker内) +```bash +fastdeployserver --model-repository=/ocr_serving/models +``` + +参数: + - `model-repository`(required): 整套模型streaming_pp_tts存放的路径. + - `http-port`(optional): HTTP服务的端口号. 默认: `8000`. 本示例中未使用该端口. + - `grpc-port`(optional): GRPC服务的端口号. 默认: `8001`. + - `metrics-port`(optional): 服务端指标的端口号. 默认: `8002`. 本示例中未使用该端口. + + +### 2. 客户端 +#### 2.1 安装 +```bash +pip3 install tritonclient[all] +``` + +#### 2.2 发送请求 +```bash +python3 client.py +``` + +## 配置修改 + +当前默认配置在GPU上运行, 如果要在CPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) diff --git a/examples/vision/ocr/PP-OCRv3/web/README.md b/examples/vision/ocr/PP-OCRv3/web/README.md index b13e7547d5..454afa1586 100644 --- a/examples/vision/ocr/PP-OCRv3/web/README.md +++ b/examples/vision/ocr/PP-OCRv3/web/README.md @@ -1,40 +1,39 @@ +English | [简体中文](README_CN.md) +# PP-OCRv3 Frontend Deployment Example -# PP-OCRv3 前端部署示例 +This document introduces the deployment of PaddleOCR's PP-OCRv3 models to run in the browser, and the js interface in the @paddle-js-models/ocr npm package. -本节介绍部署PaddleOCR的PP-OCRv3模型在浏览器中运行,以及@paddle-js-models/ocr npm包中的js接口。 +## Frontend Deployment PP-OCRv3 Model -## 前端部署PP-OCRv3模型 +For PP-OCRv3 model web demo, refer to [**reference document**](../../../../application/js/web_demo/) -PP-OCRv3模型web demo使用[**参考文档**](../../../../application/js/web_demo/) - -## PP-OCRv3 js接口 +## PP-OCRv3 js Interface ``` import * as ocr from "@paddle-js-models/ocr"; await ocr.init(detConfig, recConfig); const res = await ocr.recognize(img, option, postConfig); ``` -ocr模型加载和初始化,其中模型为Paddle.js模型格式,js模型转换方式参考[文档](../../../../application/js/web_demo/README.md) - -**init函数参数** +ocr model loading and initialization, where the model is in Paddle.js model format. For the conversion of js models, refer to [the document](../../../../application/js/web_demo/README.md) -> * **detConfig**(dict): 文本检测模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_det_infer_js_960/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 -> * **recConfig**(dict)): 文本识别模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_rec_infer_js/model.json', fill: '#000', mean: [0.5, 0.5, 0.5], std: [0.5, 0.5, 0.5]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 +**init function parameter** +> * **detConfig**(dict): The configuration parameter for the text detection model. Default {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_det_infer_js_960/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; Among them, modelPath is the path of the text detection model, fill is the padding value in the image pre-processing, and mean/std are the mean and standard deviation in the pre-processing. +> * **recConfig**(dict)): The configuration parameter for the text recognition model. Default {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_rec_infer_js/model.json', fill: '#000', mean: [0.5, 0.5, 0.5], std: [0.5, 0.5, 0.5]}; Among them, modelPath is the path of the text detection model, fill is the padding value in the image pre-processing, and mean/std are the mean and standard deviation in the pre-processing. -**recognize函数参数** -> * **img**(HTMLImageElement): 输入图像参数,类型为HTMLImageElement。 -> * **option**(dict): 可视化文本检测框的canvas参数,可不用设置。 -> * **postConfig**(dict): 文本检测后处理参数,默认值为:{shape: 960, thresh: 0.3, box_thresh: 0.6, unclip_ratio:1.5}; thresh是输出预测图的二值化阈值;box_thresh是输出框的阈值,低于此值的预测框会被丢弃,unclip_ratio是输出框扩大的比例。 +**recognize function parameter** +> * **img**(HTMLImageElement): Enter an image parameter in HTMLImageElement. +> * **option**(dict): The canvas parameter of the visual text detection box. No need to set. +> * **postConfig**(dict): Text detection post-processing parameter. Default: {shape: 960, thresh: 0.3, box_thresh: 0.6, unclip_ratio:1.5}; thresh is the binarization threshold of the output prediction image. box_thresh is the threshold of the output box, below which the prediction box will be discarded. unclip_ratio is the expansion ratio of the output box. -## 其它文档 +## Other Documents -- [PP-OCR 系列模型介绍](../../) -- [PP-OCRv3 C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) -- [PP-OCRv3 微信小程序部署文档](../mini_program/) +- [PP-OCR Model Description](../../) +- [PP-OCRv3 C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-OCRv3 Wechat mini-program deployment document](../mini_program/) diff --git a/examples/vision/ocr/PP-OCRv3/web/README_CN.md b/examples/vision/ocr/PP-OCRv3/web/README_CN.md new file mode 100644 index 0000000000..a383f8c525 --- /dev/null +++ b/examples/vision/ocr/PP-OCRv3/web/README_CN.md @@ -0,0 +1,40 @@ +[English](README.md) | 简体中文 +# PP-OCRv3 前端部署示例 + +本节介绍部署PaddleOCR的PP-OCRv3模型在浏览器中运行,以及@paddle-js-models/ocr npm包中的js接口。 + + +## 前端部署PP-OCRv3模型 + +PP-OCRv3模型web demo使用[**参考文档**](../../../../application/js/web_demo/) + + +## PP-OCRv3 js接口 + +``` +import * as ocr from "@paddle-js-models/ocr"; +await ocr.init(detConfig, recConfig); +const res = await ocr.recognize(img, option, postConfig); +``` +ocr模型加载和初始化,其中模型为Paddle.js模型格式,js模型转换方式参考[文档](../../../../application/js/web_demo/README.md) + +**init函数参数** + +> * **detConfig**(dict): 文本检测模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_det_infer_js_960/model.json', fill: '#fff', mean: [0.485, 0.456, 0.406],std: [0.229, 0.224, 0.225]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 +> * **recConfig**(dict)): 文本识别模型配置参数,默认值为 {modelPath: 'https://js-models.bj.bcebos.com/PaddleOCR/PP-OCRv3/ch_PP-OCRv3_rec_infer_js/model.json', fill: '#000', mean: [0.5, 0.5, 0.5], std: [0.5, 0.5, 0.5]}; 其中,modelPath为文本检测模型路径,fill 为图像预处理padding的值,mean和std分别为预处理的均值和标准差 + + +**recognize函数参数** + +> * **img**(HTMLImageElement): 输入图像参数,类型为HTMLImageElement。 +> * **option**(dict): 可视化文本检测框的canvas参数,可不用设置。 +> * **postConfig**(dict): 文本检测后处理参数,默认值为:{shape: 960, thresh: 0.3, box_thresh: 0.6, unclip_ratio:1.5}; thresh是输出预测图的二值化阈值;box_thresh是输出框的阈值,低于此值的预测框会被丢弃,unclip_ratio是输出框扩大的比例。 + + +## 其它文档 + +- [PP-OCR 系列模型介绍](../../) +- [PP-OCRv3 C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-OCRv3 微信小程序部署文档](../mini_program/) diff --git a/examples/vision/ocr/README.md b/examples/vision/ocr/README.md index 22a72a0bbe..97f0d61460 100644 --- a/examples/vision/ocr/README.md +++ b/examples/vision/ocr/README.md @@ -1,19 +1,20 @@ -# PaddleOCR 模型部署 +English | [简体中文](README_CN.md) +# PaddleOCR Model Deployment -## PaddleOCR为多个模型组合串联任务,包含 -- 文本检测 `DBDetector` -- [可选]方向分类 `Classifer` 用于调整进入文字识别前的图像方向 -- 文字识别 `Recognizer` 用于从图像中识别出文字 +## PaddleOCR contains a series of tasks with multiple models, including +- Text detection `DBDetector` +- [Optional] Direction classification `Classifer` is used to adjust the direction of images before text recognition +- Character recognition `Recognizer` is used to recognize characters from images -根据不同场景, FastDeploy汇总提供如下OCR任务部署, 用户需同时下载3个模型与字典文件(或2个,分类器可选), 完成OCR整个预测流程 +According to different scenarios, FastDeploy provides the following OCR task deployment. Users need to download three models and dictionary files (or two, optional classifier) simultaneously to complete the entire OCR prediction process -### PP-OCR 中英文系列模型 -下表中的模型下载链接由PaddleOCR模型库提供, 详见[PP-OCR系列模型列表](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md) +### PP-OCR Model in English and Chinese Scenarios +The model download links in the following table are provided by PaddleOCR model library. Refer to [PP-OCR Model List](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md) for details -| OCR版本 | 文本框检测 | 方向分类模型 | 文字识别 |字典文件| 说明 | +| OCR version | Text box detection | Direction classification model | Character recognition | Dictionary file | Note | |:----|:----|:----|:----|:----|:--------| -| ch_PP-OCRv3[推荐] |[ch_PP-OCRv3_det](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_PP-OCRv3_rec](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv3系列原始超轻量模型,支持中英文、多语种文本检测 | -| en_PP-OCRv3[推荐] |[en_PP-OCRv3_det](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [en_PP-OCRv3_rec](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_infer.tar) | [en_dict.txt](https://bj.bcebos.com/paddlehub/fastdeploy/en_dict.txt) | OCRv3系列原始超轻量模型,支持英文与数字识别,除检测模型和识别模型的训练数据与中文模型不同以外,无其他区别 | -| ch_PP-OCRv2 |[ch_PP-OCRv2_det](https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_PP-OCRv2_rec](https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2系列原始超轻量模型,支持中英文、多语种文本检测 | -| ch_PP-OCRv2_mobile |[ch_ppocr_mobile_v2.0_det](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_ppocr_mobile_v2.0_rec](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2系列原始超轻量模型,支持中英文、多语种文本检测,比PPOCRv2更加轻量 | -| ch_PP-OCRv2_server |[ch_ppocr_server_v2.0_det](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_ppocr_server_v2.0_rec](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar) |[ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2服务器系列模型, 支持中英文、多语种文本检测,比超轻量模型更大,但效果更好| +| ch_PP-OCRv3[Recommended] |[ch_PP-OCRv3_det](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_PP-OCRv3_rec](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv3 Original Ultra-Lightweight Model supports text detection in Chinese, English and multiple languages | +| en_PP-OCRv3[Recommended] |[en_PP-OCRv3_det](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [en_PP-OCRv3_rec](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_infer.tar) | [en_dict.txt](https://bj.bcebos.com/paddlehub/fastdeploy/en_dict.txt) | OCRv3 Original Ultra-Lightweight Model supports English and digital recognition. Its training data of detection model and recognition model is different from that of Chinese model, and no other differences can be detected | +| ch_PP-OCRv2 |[ch_PP-OCRv2_det](https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_PP-OCRv2_rec](https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2 Original Ultra-Lightweight Model supports text detection in Chinese, English and multiple languages | +| ch_PP-OCRv2_mobile |[ch_ppocr_mobile_v2.0_det](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_ppocr_mobile_v2.0_rec](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2 Original Ultra-Lightweight Model Supports text detection in Chinese, English and multiple languages with lighter weight than PPOCRv2 | +| ch_PP-OCRv2_server |[ch_ppocr_server_v2.0_det](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_ppocr_server_v2.0_rec](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar) |[ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2 Server Model supports text detection in Chinese, English and multiple languages. It has better effects though being larger than the ultra-lightweight model | diff --git a/examples/vision/ocr/README_CN.md b/examples/vision/ocr/README_CN.md new file mode 100644 index 0000000000..9cf63c52d4 --- /dev/null +++ b/examples/vision/ocr/README_CN.md @@ -0,0 +1,20 @@ +[English](README.md) | 简体中文 +# PaddleOCR 模型部署 + +## PaddleOCR为多个模型组合串联任务,包含 +- 文本检测 `DBDetector` +- [可选]方向分类 `Classifer` 用于调整进入文字识别前的图像方向 +- 文字识别 `Recognizer` 用于从图像中识别出文字 + +根据不同场景, FastDeploy汇总提供如下OCR任务部署, 用户需同时下载3个模型与字典文件(或2个,分类器可选), 完成OCR整个预测流程 + +### PP-OCR 中英文系列模型 +下表中的模型下载链接由PaddleOCR模型库提供, 详见[PP-OCR系列模型列表](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/models_list.md) + +| OCR版本 | 文本框检测 | 方向分类模型 | 文字识别 |字典文件| 说明 | +|:----|:----|:----|:----|:----|:--------| +| ch_PP-OCRv3[推荐] |[ch_PP-OCRv3_det](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_PP-OCRv3_rec](https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv3系列原始超轻量模型,支持中英文、多语种文本检测 | +| en_PP-OCRv3[推荐] |[en_PP-OCRv3_det](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [en_PP-OCRv3_rec](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_infer.tar) | [en_dict.txt](https://bj.bcebos.com/paddlehub/fastdeploy/en_dict.txt) | OCRv3系列原始超轻量模型,支持英文与数字识别,除检测模型和识别模型的训练数据与中文模型不同以外,无其他区别 | +| ch_PP-OCRv2 |[ch_PP-OCRv2_det](https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_PP-OCRv2_rec](https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2系列原始超轻量模型,支持中英文、多语种文本检测 | +| ch_PP-OCRv2_mobile |[ch_ppocr_mobile_v2.0_det](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_ppocr_mobile_v2.0_rec](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar) | [ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2系列原始超轻量模型,支持中英文、多语种文本检测,比PPOCRv2更加轻量 | +| ch_PP-OCRv2_server |[ch_ppocr_server_v2.0_det](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_infer.tar) | [ch_ppocr_mobile_v2.0_cls](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar) | [ch_ppocr_server_v2.0_rec](https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar) |[ppocr_keys_v1.txt](https://bj.bcebos.com/paddlehub/fastdeploy/ppocr_keys_v1.txt) | OCRv2服务器系列模型, 支持中英文、多语种文本检测,比超轻量模型更大,但效果更好| diff --git a/examples/vision/segmentation/paddleseg/README.md b/examples/vision/segmentation/paddleseg/README.md index 0b0cda349f..de578cb226 100644 --- a/examples/vision/segmentation/paddleseg/README.md +++ b/examples/vision/segmentation/paddleseg/README.md @@ -1,47 +1,49 @@ -# PaddleSeg 模型部署 +English | [简体中文](README_CN.md) +# PaddleSeg Model Deployment -## 模型版本说明 +## Model Description - [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) -目前FastDeploy支持如下模型的部署 +FastDeploy currently supports the deployment of the following models -- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/unet/README.md) -- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md) -- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/contrib/PP-HumanSeg/README.md) -- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/fcn/README.md) -- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/deeplabv3/README.md) +- [U-Net models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/unet/README.md) +- [PP-LiteSeg models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md) +- [PP-HumanSeg models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/contrib/PP-HumanSeg/README.md) +- [FCN models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/fcn/README.md) +- [DeepLabV3 models](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/deeplabv3/README.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting) +【Attention】For **PP-Matting**、**PP-HumanMatting** and **ModNet** deployment, please refer to [Matting Model Deployment](../../matting) -## 准备PaddleSeg部署模型 +## Prepare PaddleSeg Deployment Model -PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) +For the export of the PaddleSeg model, refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) for more information -**注意** -- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 +**Attention** +- The exported PaddleSeg model contains three files, including `model.pdmodel`、`model.pdiparams` and `deploy.yaml`. FastDeploy will get the pre-processing information for inference from yaml files. -## 下载预训练模型 +## Download Pre-trained Model -为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 -- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` -- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` +For developers' testing, part of the PaddleSeg exported models are provided below. +- without-argmax export mode: **Not specified**`--input_shape`,**specified**`--output_op none` +- with-argmax export mode:**Not specified**`--input_shape`,**specified**`--output_op argmax` -开发者可直接下载使用。 +Developers can download directly. -| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | + +| Model | Parameter Size | Input Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | |:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | | [Unet-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_with_argmax_infer.tgz) \| [Unet-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | | [PP-LiteSeg-B(STDC2)-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz) \| [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 79.04% | 79.52% | 79.85% | -|[PP-HumanSegV1-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -|[PP-HumanSegV2-Lite-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -|[PP-HumanSegV1-Server-with-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2-Lite-with-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | -| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(暂时不支持ONNXRuntime的GPU推理) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | +|[PP-HumanSegV1-Lite-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV1_Lite_with_argmax_infer.tgz) \| [PP-HumanSegV1-Lite-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +|[PP-HumanSegV2-Lite-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Lite-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_with_argmax_infer.tgz) \| [PP-HumanSegV2-Mobile-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +|[PP-HumanSegV1-Server-with-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_with_argmax_infer.tgz) \| [PP-HumanSegV1-Server-without-argmax(General Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2-Lite-with-argmax(Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_with_argmax_infer.tgz) \| [Portait-PP-HumanSegV2-Lite-without-argmax(Portrait Segmentation Model)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [FCN-HRNet-W18-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_with_argmax_infer.tgz) \| [FCN-HRNet-W18-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz)(GPU inference for ONNXRuntime is not supported now) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | | [Deeplabv3-ResNet101-OS8-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_with_argmax_infer.tgz) \| [Deeplabv3-ResNet101-OS8-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/segmentation/paddleseg/README_CN.md b/examples/vision/segmentation/paddleseg/README_CN.md new file mode 100644 index 0000000000..7306a5f4f8 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/README_CN.md @@ -0,0 +1,34 @@ +[English](README.md) | 简体中文 +# 视觉模型部署 + +本目录下提供了各类视觉模型的部署,主要涵盖以下任务类型 + +| 任务类型 | 说明 | 预测结果结构体 | +|:-------------- |:----------------------------------- |:-------------------------------------------------------------------------------- | +| Detection | 目标检测,输入图像,检测图像中物体位置,并返回检测框坐标及类别和置信度 | [DetectionResult](../../docs/api/vision_results/detection_result.md) | +| Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../docs/api/vision_results/segmentation_result.md) | +| Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../docs/api/vision_results/classification_result.md) | +| FaceDetection | 人脸检测,输入图像,检测图像中人脸位置,并返回检测框坐标及人脸关键点 | [FaceDetectionResult](../../docs/api/vision_results/face_detection_result.md) | +| FaceAlignment | 人脸对齐(人脸关键点检测),输入图像,返回人脸关键点 | [FaceAlignmentResult](../../docs/api/vision_results/face_alignment_result.md) | +| KeypointDetection | 关键点检测,输入图像,返回图像中人物行为的各个关键点坐标和置信度 | [KeyPointDetectionResult](../../docs/api/vision_results/keypointdetection_result.md) | +| FaceRecognition | 人脸识别,输入图像,返回可用于相似度计算的人脸特征的embedding | [FaceRecognitionResult](../../docs/api/vision_results/face_recognition_result.md) | +| Matting | 抠图,输入图像,返回图片的前景每个像素点的Alpha值 | [MattingResult](../../docs/api/vision_results/matting_result.md) | +| OCR | 文本框检测,分类,文本框内容识别,输入图像,返回文本框坐标,文本框的方向类别以及框内的文本内容 | [OCRResult](../../docs/api/vision_results/ocr_result.md) | +| MOT | 多目标跟踪,输入图像,检测图像中物体位置,并返回检测框坐标,对象id及类别置信度 | [MOTResult](../../docs/api/vision_results/mot_result.md) | +| HeadPose | 头部姿态估计,返回头部欧拉角 | [HeadPoseResult](../../docs/api/vision_results/headpose_result.md) | + +## FastDeploy API设计 + +视觉模型具有较有统一任务范式,在设计API时(包括C++/Python),FastDeploy将视觉模型的部署拆分为四个步骤 + +- 模型加载 +- 图像预处理 +- 模型推理 +- 推理结果后处理 + +FastDeploy针对飞桨的视觉套件,以及外部热门模型,提供端到端的部署服务,用户只需准备模型,按以下步骤即可完成整个模型的部署 + +- 加载模型 +- 调用`predict`接口 + +FastDeploy在各视觉模型部署时,也支持一键切换后端推理引擎,详情参阅[如何切换模型推理引擎](../../docs/cn/faq/how_to_change_backend.md)。 diff --git a/examples/vision/segmentation/paddleseg/a311d/README.md b/examples/vision/segmentation/paddleseg/a311d/README.md index 3fbf6ed5e0..07870aa590 100755 --- a/examples/vision/segmentation/paddleseg/a311d/README.md +++ b/examples/vision/segmentation/paddleseg/a311d/README.md @@ -1,11 +1,12 @@ -# PP-LiteSeg 量化模型在 A311D 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 A311D 上。 +English | [简体中文](README_CN.md) +# Deployment of PP-LiteSeg Quantification Model on A311D +Now FastDeploy allows deploying PP-LiteSeg quantization model to A311D based on Paddle Lite. -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -在 A311D 上只支持 C++ 的部署。 +Only C++ deployment is supported on A311D. -- [C++部署](cpp) +- [C++ deployment](cpp) diff --git a/examples/vision/segmentation/paddleseg/a311d/README_CN.md b/examples/vision/segmentation/paddleseg/a311d/README_CN.md new file mode 100644 index 0000000000..dad4f39248 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/a311d/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# PP-LiteSeg 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/cpp/README.md b/examples/vision/segmentation/paddleseg/cpp/README.md index 07f9f4c62d..4c5be9f6c1 100755 --- a/examples/vision/segmentation/paddleseg/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/cpp/README.md @@ -1,57 +1,53 @@ -# PaddleSeg C++部署示例 +English | [简体中文](README_CN.md) +# PaddleSeg C++ Deployment Example -本目录下提供`infer.cc`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) +【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) -以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) +Taking the inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.0 or above (x.x.x>=1.0.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载Unet模型文件和测试图片 +# Download Unet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz tar -xvf Unet_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU推理 +# CPU inference ./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU推理 +# GPU inference ./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# GPU上TensorRT推理 +# TensorRT inference on GPU ./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# 昆仑芯XPU推理 +# kunlunxin XPU inference ./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 -# 华为昇腾推理 -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 4 ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows

-以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: -- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) +## PaddleSeg C++ Interface -## PaddleSeg C++接口 - -### PaddleSeg类 +### PaddleSeg Class ```c++ fastdeploy::vision::segmentation::PaddleSegModel( @@ -62,39 +58,39 @@ fastdeploy::vision::segmentation::PaddleSegModel( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 +PaddleSegModel model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: The segmentation result, including the predicted label of the segmentation and the corresponding probability of the label. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of SegmentationResult -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 +> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait, height greater than a width, by setting this parameter to`true` -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 +#### Post-processing Parameter +> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/cpp/README_CN.md new file mode 100644 index 0000000000..df99e324eb --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpp/README_CN.md @@ -0,0 +1,101 @@ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 + +本目录下提供`infer.cc`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载Unet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz +tar -xvf Unet_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + + +# CPU推理 +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 +# GPU推理 +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 +# GPU上TensorRT推理 +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 +# 昆仑芯XPU推理 +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 +# 华为昇腾推理 +./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 4 +``` + +运行完成可视化结果如下图所示 +
+ +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境: +- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md) + +## PaddleSeg C++接口 + +### PaddleSeg类 + +```c++ +fastdeploy::vision::segmentation::PaddleSegModel( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 + +#### 后处理参数 +> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/python/README.md b/examples/vision/segmentation/paddleseg/python/README.md index 02b2e6ab5f..95885a2f2a 100755 --- a/examples/vision/segmentation/paddleseg/python/README.md +++ b/examples/vision/segmentation/paddleseg/python/README.md @@ -1,85 +1,82 @@ -# PaddleSeg Python部署示例 +English | [简体中文](README_CN.md) +# PaddleSeg Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) - -本目录下提供`infer.py`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) +This directory provides examples that `infer.py` fast finishes the deployment of Unet on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/segmentation/paddleseg/python -# 下载Unet模型文件和测试图片 +# Download Unet model files and test images wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz tar -xvf Unet_cityscapes_without_argmax_infer.tgz wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# CPU推理 +# CPU inference python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU推理 +# GPU inference python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True -# 昆仑芯XPU推理 +# kunlunxin XPU inference python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin -# 华为昇腾推理 -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device ascend ``` -运行完成可视化结果如下图所示 +The visualized result after running is as follows
-## PaddleSegModel Python接口 +## PaddleSegModel Python Interface ```python fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) +PaddleSeg model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > PaddleSegModel.predict(input_image) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **input_image**(np.ndarray): Input data in HWC or BGR format -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.SegmentationResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) - -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +> > Return `fastdeploy.vision.SegmentationResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure. -> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -#### 后处理参数 -> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 +> > * **is_vertical_screen**(bool): For PP-HumanSeg models, the input image is portrait with height greater than width by setting this parameter to `true` +#### Post-processing Parameter +> > * **apply_softmax**(bool): The `apply_softmax` parameter is not specified when the model is exported. Set this parameter to `true` to normalize the probability result (score_map) of the predicted output segmentation label (label_map) in softmax -## 其它文档 +## Other Documents -- [PaddleSeg 模型介绍](..) -- [PaddleSeg C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PaddleSeg Model Description](..) +- [PaddleSeg C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/python/README_CN.md b/examples/vision/segmentation/paddleseg/python/README_CN.md new file mode 100644 index 0000000000..61edc5b2b2 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/python/README_CN.md @@ -0,0 +1,86 @@ +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../matting) + +本目录下提供`infer.py`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/python + +# 下载Unet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz +tar -xvf Unet_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# CPU推理 +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu +# GPU推理 +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True +# 昆仑芯XPU推理 +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin +# 华为昇腾推理 +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device ascend +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## PaddleSegModel Python接口 + +```python +fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PaddleSegModel.predict(input_image) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 + +> **返回** +> +> > 返回`fastdeploy.vision.SegmentationResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 + +#### 后处理参数 +> > * **apply_softmax**(bool): 当模型导出时,并未指定`apply_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 + +## 其它文档 + +- [PaddleSeg 模型介绍](..) +- [PaddleSeg C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/segmentation/paddleseg/rv1126/README.md b/examples/vision/segmentation/paddleseg/rv1126/README.md index 61954943c8..dc9755272a 100755 --- a/examples/vision/segmentation/paddleseg/rv1126/README.md +++ b/examples/vision/segmentation/paddleseg/rv1126/README.md @@ -1,11 +1,12 @@ -# PP-LiteSeg 量化模型在 RV1126 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 RV1126 上。 +English | [简体中文](README_CN.md) +# Deployment of PP-LiteSeg Quantification Model on RV1126 +Now FastDeploy allows deploying PP-LiteSeg quantization model to RV1126 based on Paddle Lite. -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) +For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) -## 详细部署文档 +## Detailed Deployment Tutorials -在 RV1126 上只支持 C++ 的部署。 +Only C++ deployment is supported on RV1126. -- [C++部署](cpp) +- [C++ Deployment](cpp) diff --git a/examples/vision/segmentation/paddleseg/rv1126/README_CN.md b/examples/vision/segmentation/paddleseg/rv1126/README_CN.md new file mode 100644 index 0000000000..ce4cbb816c --- /dev/null +++ b/examples/vision/segmentation/paddleseg/rv1126/README_CN.md @@ -0,0 +1,12 @@ +[English](README.md) | 简体中文 +# PP-LiteSeg 量化模型在 RV1126 上的部署 +目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 RV1126 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 RV1126 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/sr/README.md b/examples/vision/sr/README.md index 88f9e77773..b37290f197 100644 --- a/examples/vision/sr/README.md +++ b/examples/vision/sr/README.md @@ -1,9 +1,10 @@ -# sr 模型部署 +English | [简体中文](README_CN.md) +# SR Model Deployment -FastDeploy目前支持如下超分模型部署 +Now FastDeploy supports the deployment of the following SR models -| 模型 | 说明 | 模型格式 | 版本 | +| Model | Description | Model Format | Version | |:-----------------------------------------|:----------------------|:-------|:----------------------------------------------------------------------------------| -| [PaddleGAN/BasicVSR](./basicvsr) | BasicVSR 系列模型 | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | -| [PaddleGAN/EDVR](./edvr) | EDVR 系列模型 | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | -| [PaddleGAN/PP-MSVSR](./ppmsvsr) | PP-MSVSR 系列模型 | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | +| [PaddleGAN/BasicVSR](./basicvsr) | BasicVSR models | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | +| [PaddleGAN/EDVR](./edvr) | EDVR models | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | +| [PaddleGAN/PP-MSVSR](./ppmsvsr) | PP-MSVSR models | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | diff --git a/examples/vision/sr/README_CN.md b/examples/vision/sr/README_CN.md new file mode 100644 index 0000000000..2091e5ed04 --- /dev/null +++ b/examples/vision/sr/README_CN.md @@ -0,0 +1,10 @@ +[English](README.md) | 简体中文 +# sr 模型部署 + +FastDeploy目前支持如下超分模型部署 + +| 模型 | 说明 | 模型格式 | 版本 | +|:-----------------------------------------|:----------------------|:-------|:----------------------------------------------------------------------------------| +| [PaddleGAN/BasicVSR](./basicvsr) | BasicVSR 系列模型 | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | +| [PaddleGAN/EDVR](./edvr) | EDVR 系列模型 | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | +| [PaddleGAN/PP-MSVSR](./ppmsvsr) | PP-MSVSR 系列模型 | paddle | [develop](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) | diff --git a/examples/vision/sr/basicvsr/README.md b/examples/vision/sr/basicvsr/README.md index fc92b84225..91bfc7b814 100644 --- a/examples/vision/sr/basicvsr/README.md +++ b/examples/vision/sr/basicvsr/README.md @@ -1,28 +1,29 @@ -# BasicVSR模型部署 +English | [简体中文](README_CN.md) +# BasicVSR Model Deployment -## 模型版本说明 +## Model Description - [PaddleGAN develop](https://github.com/PaddlePaddle/PaddleGAN) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models - [BasicVSR](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 -## 导出部署模型 +## Export Deployment Model -在部署前,需要先将训练好的BasicVSR导出成部署模型,导出BasicVSR导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 +Before deployment, export the trained BasicVSR to the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) for detailed steps. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:----------------------------------------------------------------------------|:-------|:----- | :------ | | [BasicVSR](https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar) | 30.1MB | - | -**注意**:非常不建议在没有独立显卡的设备上运行该模型 +**Attention**: Running this model on a device without separate graphics card is highly discouraged -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/sr/basicvsr/README_CN.md b/examples/vision/sr/basicvsr/README_CN.md new file mode 100644 index 0000000000..0862c6dd5a --- /dev/null +++ b/examples/vision/sr/basicvsr/README_CN.md @@ -0,0 +1,29 @@ +[English](README.md) | 简体中文 +# BasicVSR模型部署 + +## 模型版本说明 + +- [PaddleGAN develop](https://github.com/PaddlePaddle/PaddleGAN) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [BasicVSR](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 + + +## 导出部署模型 + +在部署前,需要先将训练好的BasicVSR导出成部署模型,导出BasicVSR导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 + + +| 模型 | 参数大小 | 精度 | 备注 | +|:----------------------------------------------------------------------------|:-------|:----- | :------ | +| [BasicVSR](https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar) | 30.1MB | - | + +**注意**:非常不建议在没有独立显卡的设备上运行该模型 + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/sr/basicvsr/cpp/README.md b/examples/vision/sr/basicvsr/cpp/README.md index 802a7ac587..7cb500798c 100644 --- a/examples/vision/sr/basicvsr/cpp/README.md +++ b/examples/vision/sr/basicvsr/cpp/README.md @@ -1,42 +1,42 @@ -# BasicVSR C++部署示例 +English | [简体中文](README_CN.md) +# BasicVSR C++ Deployment Example -本目录下提供`infer.cc`快速完成BasicVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of BasicVSR on CPU/GPU and GPU accelerated by TensorRT. +Before deployment, two steps require confirmation -在部署前,需确认以下两个步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上BasicVSR推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +Taking the BasicVSR inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载BasicVSR模型文件和测试视频 +# Download BasicVSR model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar tar -xvf BasicVSR_reds_x4.tar wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 -# CPU推理 +# CPU inference ./infer_demo BasicVSR_reds_x4 vsr_src.mp4 0 2 -# GPU推理 +# GPU inference ./infer_demo BasicVSR_reds_x4 vsr_src.mp4 1 2 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo BasicVSR_reds_x4 vsr_src.mp4 2 2 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## BasicVSR C++接口 +## BasicVSR C++ Interface -### BasicVSR类 +### BasicVSR Class ```c++ fastdeploy::vision::sr::BasicVSR( @@ -46,28 +46,28 @@ fastdeploy::vision::sr::BasicVSR( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -BasicVSR模型加载和初始化,其中model_file为导出的Paddle模型格式。 +BasicVSR model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > BasicVSR::Predict(std::vector& imgs, std::vector& results) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **imgs**: 输入视频帧序列,注意需为HWC,BGR格式 -> > * **results**: 视频超分结果,超分后的视频帧序列 +> > * **imgs**: Input video frame sequence in HWC or BGR format +> > * **results**: Video SR results: video frame sequence after SR -- [模型介绍](../../) -- [Python部署](../python) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/basicvsr/cpp/README_CN.md b/examples/vision/sr/basicvsr/cpp/README_CN.md new file mode 100644 index 0000000000..ed20764325 --- /dev/null +++ b/examples/vision/sr/basicvsr/cpp/README_CN.md @@ -0,0 +1,74 @@ +[English](README.md) | 简体中文 +# BasicVSR C++部署示例 + +本目录下提供`infer.cc`快速完成BasicVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +以Linux上BasicVSR推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载BasicVSR模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar +tar -xvf BasicVSR_reds_x4.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 + + +# CPU推理 +./infer_demo BasicVSR_reds_x4 vsr_src.mp4 0 2 +# GPU推理 +./infer_demo BasicVSR_reds_x4 vsr_src.mp4 1 2 +# GPU上TensorRT推理 +./infer_demo BasicVSR_reds_x4 vsr_src.mp4 2 2 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## BasicVSR C++接口 + +### BasicVSR类 + +```c++ +fastdeploy::vision::sr::BasicVSR( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +BasicVSR模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> BasicVSR::Predict(std::vector& imgs, std::vector& results) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **imgs**: 输入视频帧序列,注意需为HWC,BGR格式 +> > * **results**: 视频超分结果,超分后的视频帧序列 + +- [模型介绍](../../) +- [Python部署](../python) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/basicvsr/python/README.md b/examples/vision/sr/basicvsr/python/README.md index ac5dd97c64..6597b51927 100644 --- a/examples/vision/sr/basicvsr/python/README.md +++ b/examples/vision/sr/basicvsr/python/README.md @@ -1,61 +1,61 @@ -# BasicVSR Python部署示例 +English | [简体中文](README_CN.md) +# BasicVSR Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成BasicVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishesshes the deployment of BasicVSR on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/sr/basicvsr/python -# 下载BasicVSR模型文件和测试视频 +# Download BasicVSR model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar tar -xvf BasicVSR_reds_x4.tar wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 -# CPU推理 +# CPU inference python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device cpu -# GPU推理 +# GPU inference python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU(Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu --use_trt True ``` -## BasicVSR Python接口 +## BasicVSR Python Interface ```python fd.vision.sr.BasicVSR(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -BasicVSR模型加载和初始化,其中model_file和params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) +YOLOv5Cls model loading and initialization, among which model_file and params_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > BasicVSR.predict(frames) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **frames**(list[np.ndarray]): 输入数据,注意需为HWC,BGR格式, frames为视频帧序列 +> > * **frames**(list[np.ndarray]): Input data in HWC or BGR format. frames are video frame sequences -> **返回** list[np.ndarray] 为超分后的视频帧序列 +> **Return** list[np.ndarray] is the video frame sequence after SR -## 其它文档 +## Other Documents -- [BasicVSR 模型介绍](..) -- [BasicVSR C++部署](../cpp) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [BasicVSR Model Description](..) +- [BasicVSR C++ Deployment](../cpp) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/basicvsr/python/README_CN.md b/examples/vision/sr/basicvsr/python/README_CN.md new file mode 100644 index 0000000000..6c1cf34c22 --- /dev/null +++ b/examples/vision/sr/basicvsr/python/README_CN.md @@ -0,0 +1,62 @@ +[English](README.md) | 简体中文 +# BasicVSR Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成BasicVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/sr/basicvsr/python + +# 下载BasicVSR模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/BasicVSR_reds_x4.tar +tar -xvf BasicVSR_reds_x4.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 +# CPU推理 +python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device cpu +# GPU推理 +python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model BasicVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu --use_trt True +``` + +## BasicVSR Python接口 + +```python +fd.vision.sr.BasicVSR(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +BasicVSR模型加载和初始化,其中model_file和params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> BasicVSR.predict(frames) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **frames**(list[np.ndarray]): 输入数据,注意需为HWC,BGR格式, frames为视频帧序列 + +> **返回** list[np.ndarray] 为超分后的视频帧序列 + + +## 其它文档 + +- [BasicVSR 模型介绍](..) +- [BasicVSR C++部署](../cpp) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/edvr/README.md b/examples/vision/sr/edvr/README.md index 670bad8a14..9e5910cd78 100644 --- a/examples/vision/sr/edvr/README.md +++ b/examples/vision/sr/edvr/README.md @@ -1,28 +1,29 @@ -# EDVR模型部署 +English | [简体中文](README_CN.md) +# EDVR Model Deployment -## 模型版本说明 +## Model Description - [PaddleGAN develop](https://github.com/PaddlePaddle/PaddleGAN) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models - [EDVR](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 -## 导出部署模型 +## Export Deployment Model -在部署前,需要先将训练好的EDVR导出成部署模型,导出EDVR导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 +Before deployment, export the trained EDVR to the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) for detailed steps. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:--------------------------------------------------------------------------------|:-------|:----- | :------ | | [EDVR](https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar) | 14.9MB | - | -**注意**:非常不建议在没有独立显卡的设备上运行该模型 +**Attention**: Running this model on a device without separate graphics card is highly discouraged -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/sr/edvr/README_CN.md b/examples/vision/sr/edvr/README_CN.md new file mode 100644 index 0000000000..88b36c968b --- /dev/null +++ b/examples/vision/sr/edvr/README_CN.md @@ -0,0 +1,29 @@ +[English](README.md) | 简体中文 +# EDVR模型部署 + +## 模型版本说明 + +- [PaddleGAN develop](https://github.com/PaddlePaddle/PaddleGAN) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [EDVR](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 + + +## 导出部署模型 + +在部署前,需要先将训练好的EDVR导出成部署模型,导出EDVR导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 + + +| 模型 | 参数大小 | 精度 | 备注 | +|:--------------------------------------------------------------------------------|:-------|:----- | :------ | +| [EDVR](https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar) | 14.9MB | - | + +**注意**:非常不建议在没有独立显卡的设备上运行该模型 + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/sr/edvr/cpp/README.md b/examples/vision/sr/edvr/cpp/README.md index 54ad66ee11..4068133533 100644 --- a/examples/vision/sr/edvr/cpp/README.md +++ b/examples/vision/sr/edvr/cpp/README.md @@ -1,43 +1,44 @@ -# EDVR C++部署示例 +English | [简体中文](README_CN.md) +# EDVR C++ Deployment Example -本目录下提供`infer.cc`快速完成EDVR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of EDVR on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上EDVR推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the EDVR inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载EDVR模型文件和测试视频 +# Download EDVR model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar tar -xvf EDVR_M_wo_tsa_SRx4.tar wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 -# CPU推理 +# CPU inference ./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 0 5 -# GPU推理 +# GPU inference ./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 1 5 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 2 5 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## EDVR C++接口 +## EDVR C++ Interface -### EDVR类 +### EDVR Class ```c++ fastdeploy::vision::sr::EDVR( @@ -47,28 +48,28 @@ fastdeploy::vision::sr::EDVR( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -EDVR模型加载和初始化,其中model_file为导出的Paddle模型格式。 +EDVR model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > EDVR::Predict(std::vector& imgs, std::vector& results) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **imgs**: 输入视频帧序列,注意需为HWC,BGR格式 -> > * **results**: 视频超分结果,超分后的视频帧序列 +> > * **imgs**: Input video frame sequence in HWC or BGR format +> > * **results**: Video SR results: video frame sequence after SR -- [模型介绍](../../) -- [Python部署](../python) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/edvr/cpp/README_CN.md b/examples/vision/sr/edvr/cpp/README_CN.md new file mode 100644 index 0000000000..b4f173c5a9 --- /dev/null +++ b/examples/vision/sr/edvr/cpp/README_CN.md @@ -0,0 +1,75 @@ +[English](README.md) | 简体中文 +# EDVR C++部署示例 + +本目录下提供`infer.cc`快速完成EDVR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上EDVR推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载EDVR模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar +tar -xvf EDVR_M_wo_tsa_SRx4.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 + + +# CPU推理 +./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 0 5 +# GPU推理 +./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 1 5 +# GPU上TensorRT推理 +./infer_demo EDVR_M_wo_tsa_SRx4 vsr_src.mp4 2 5 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## EDVR C++接口 + +### EDVR类 + +```c++ +fastdeploy::vision::sr::EDVR( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +EDVR模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> EDVR::Predict(std::vector& imgs, std::vector& results) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **imgs**: 输入视频帧序列,注意需为HWC,BGR格式 +> > * **results**: 视频超分结果,超分后的视频帧序列 + +- [模型介绍](../../) +- [Python部署](../python) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/edvr/python/README.md b/examples/vision/sr/edvr/python/README.md index 8875045df1..50ca71c897 100644 --- a/examples/vision/sr/edvr/python/README.md +++ b/examples/vision/sr/edvr/python/README.md @@ -1,61 +1,62 @@ -# EDVR Python部署示例 +English | [简体中文](README_CN.md) +# EDVR Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成EDVR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishes the deployment of EDVR on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/sr/edvr/python -# 下载VSR模型文件和测试视频 +# Download VSR model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar tar -xvf EDVR_M_wo_tsa_SRx4.tar wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 -# CPU推理 +# CPU inference python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device cpu -# GPU推理 +# GPU inference python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device gpu --use_trt True ``` -## EDVR Python接口 +## EDVR Python Interface ```python fd.vision.sr.EDVR(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -EDVR模型加载和初始化,其中model_file和params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) +EDVR model loading and initialization, among which model_file and params_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > EDVR.predict(frames) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **frames**(list[np.ndarray]): 输入数据,注意需为HWC,BGR格式, frames为视频帧序列 +> > * **frames**(list[np.ndarray]): Input data in HWC or BGR format. Frames are video frame sequences. -> **返回** list[np.ndarray] 为超分后的视频帧序列 +> **Return** list[np.ndarray] is the video frame sequence after SR -## 其它文档 +## Other Documents -- [EDVR 模型介绍](..) -- [EDVR C++部署](../cpp) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [EDVR Model Description](..) +- [EDVR C++ Deployment](../cpp) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/edvr/python/README_CN.md b/examples/vision/sr/edvr/python/README_CN.md new file mode 100644 index 0000000000..605ab2fc2e --- /dev/null +++ b/examples/vision/sr/edvr/python/README_CN.md @@ -0,0 +1,62 @@ +[English](README.md) | 简体中文 +# EDVR Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成EDVR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/sr/edvr/python + +# 下载VSR模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/EDVR_M_wo_tsa_SRx4.tar +tar -xvf EDVR_M_wo_tsa_SRx4.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 +# CPU推理 +python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device cpu +# GPU推理 +python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model EDVR_M_wo_tsa_SRx4 --video vsr_src.mp4 --frame_num 5 --device gpu --use_trt True +``` + +## EDVR Python接口 + +```python +fd.vision.sr.EDVR(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +EDVR模型加载和初始化,其中model_file和params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> EDVR.predict(frames) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **frames**(list[np.ndarray]): 输入数据,注意需为HWC,BGR格式, frames为视频帧序列 + +> **返回** list[np.ndarray] 为超分后的视频帧序列 + + +## 其它文档 + +- [EDVR 模型介绍](..) +- [EDVR C++部署](../cpp) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/ppmsvsr/README.md b/examples/vision/sr/ppmsvsr/README.md index a11e8101ed..3719a3744b 100644 --- a/examples/vision/sr/ppmsvsr/README.md +++ b/examples/vision/sr/ppmsvsr/README.md @@ -1,27 +1,28 @@ -# PP-MSVSR模型部署 +English | [简体中文](README_CN.md) +# PP-MSVSR Model Deployment -## 模型版本说明 +## Model Description - [PaddleGAN develop](https://github.com/PaddlePaddle/PaddleGAN) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models - [PP-MSVSR](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 -## 导出部署模型 +## Export Deployment Model -在部署前,需要先将训练好的PP-MSVSR导出成部署模型,导出PP-MSVSR导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 +Before deployment, export the trained PP-MSVSR to the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) for detailed steps. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:----------------------------------------------------------------------------|:------|:----- | :------ | | [PP-MSVSR](https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar) | 8.8MB | - | -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python deployment](python) +- [C++ deployment](cpp) diff --git a/examples/vision/sr/ppmsvsr/README_CN.md b/examples/vision/sr/ppmsvsr/README_CN.md new file mode 100644 index 0000000000..a62411cf41 --- /dev/null +++ b/examples/vision/sr/ppmsvsr/README_CN.md @@ -0,0 +1,28 @@ +[English](README.md) | 简体中文 +# PP-MSVSR模型部署 + +## 模型版本说明 + +- [PaddleGAN develop](https://github.com/PaddlePaddle/PaddleGAN) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PP-MSVSR](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 + + +## 导出部署模型 + +在部署前,需要先将训练好的PP-MSVSR导出成部署模型,导出PP-MSVSR导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md)。 + + +| 模型 | 参数大小 | 精度 | 备注 | +|:----------------------------------------------------------------------------|:------|:----- | :------ | +| [PP-MSVSR](https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar) | 8.8MB | - | + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/sr/ppmsvsr/cpp/README.md b/examples/vision/sr/ppmsvsr/cpp/README.md index 712264a36d..7e1c66a3b6 100644 --- a/examples/vision/sr/ppmsvsr/cpp/README.md +++ b/examples/vision/sr/ppmsvsr/cpp/README.md @@ -1,43 +1,44 @@ -# VSR C++部署示例 +English | [简体中文](README_CN.md) +# VSR C++ Deployment Example -本目录下提供`infer.cc`快速完成PP-MSVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PP-MSVSR on CPU/GPU and GPU accelerated by TensorRT. -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上 PP-MSVSR 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the PP-MSVSR inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the `FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载PP-MSVSR模型文件和测试视频 +# Download PP-MSVSR model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar tar -xvf PP-MSVSR_reds_x4.tar wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 -# CPU推理 +# CPU inference ./infer_demo PP-MSVSR_reds_x4 vsr_src.mp4 0 2 -# GPU推理 +# GPU inference ./infer_demo PP-MSVSR_reds_x4 vsr_src.mp4 1 2 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo PP-MSVSR_reds_x4 vsr_src.mp4 2 2 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PP-MSVSR C++接口 +## PP-MSVSR C++ Interface -### PPMSVSR类 +### PPMSVSR Class ```c++ fastdeploy::vision::sr::PPMSVSR( @@ -47,28 +48,28 @@ fastdeploy::vision::sr::PPMSVSR( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -PP-MSVSR模型加载和初始化,其中model_file为导出的Paddle模型格式。 +PP-MSVSR model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > PPMSVSR::Predict(std::vector& imgs, std::vector& results) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **imgs**: 输入视频帧序列,注意需为HWC,BGR格式 -> > * **results**: 视频超分结果,超分后的视频帧序列 +> > * **imgs**: Input video frame sequences in HWC or BGR format +> > * **results**: Video SR results: video frame sequence after SR -- [模型介绍](../../) -- [Python部署](../python) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/ppmsvsr/cpp/README_CN.md b/examples/vision/sr/ppmsvsr/cpp/README_CN.md new file mode 100644 index 0000000000..4fcff3aea6 --- /dev/null +++ b/examples/vision/sr/ppmsvsr/cpp/README_CN.md @@ -0,0 +1,75 @@ +[English](README.md) | 简体中文 +# VSR C++部署示例 + +本目录下提供`infer.cc`快速完成PP-MSVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上 PP-MSVSR 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载PP-MSVSR模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar +tar -xvf PP-MSVSR_reds_x4.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 + + +# CPU推理 +./infer_demo PP-MSVSR_reds_x4 vsr_src.mp4 0 2 +# GPU推理 +./infer_demo PP-MSVSR_reds_x4 vsr_src.mp4 1 2 +# GPU上TensorRT推理 +./infer_demo PP-MSVSR_reds_x4 vsr_src.mp4 2 2 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PP-MSVSR C++接口 + +### PPMSVSR类 + +```c++ +fastdeploy::vision::sr::PPMSVSR( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PP-MSVSR模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PPMSVSR::Predict(std::vector& imgs, std::vector& results) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **imgs**: 输入视频帧序列,注意需为HWC,BGR格式 +> > * **results**: 视频超分结果,超分后的视频帧序列 + +- [模型介绍](../../) +- [Python部署](../python) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/ppmsvsr/python/README.md b/examples/vision/sr/ppmsvsr/python/README.md index 66eea35f7d..cf4ef5ed16 100644 --- a/examples/vision/sr/ppmsvsr/python/README.md +++ b/examples/vision/sr/ppmsvsr/python/README.md @@ -1,61 +1,61 @@ -# PP-MSVSR Python部署示例 +English | [简体中文](README_CN.md) +# PP-MSVSR Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -本目录下提供`infer.py`快速完成PP-MSVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +This directory provides examples that `infer.py` fast finishes the deployment of PP-MSVSR on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download the deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/sr/ppmsvsr/python -# 下载VSR模型文件和测试视频 +# Download VSR model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar tar -xvf PP-MSVSR_reds_x4.tar wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 -# CPU推理 +# CPU inference python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device cpu -# GPU推理 +# GPU inference python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu --use_trt True ``` -## VSR Python接口 +## VSR Python Interface ```python fd.vision.sr.PPMSVSR(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PP-MSVSR模型加载和初始化,其中model_file和params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) +PP-MSVSR model loading and initialization, among which model_file and params_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > PPMSVSR.predict(frames) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **frames**(list[np.ndarray]): 输入数据,注意需为HWC,BGR格式, frames为视频帧序列 +> > * **frames**(list[np.ndarray]): Input data in HWC or BGR format. Frames are the video frame sequences -> **返回** list[np.ndarray] 为超分后的视频帧序列 +> **Return** list[np.ndarray] is the video frame sequence after SR -## 其它文档 +## Other Documents -- [PP-MSVSR 模型介绍](..) -- [PP-MSVSR C++部署](../cpp) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-MSVSR Model Description](..) +- [PP-MSVSR C++ Deployment](../cpp) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/sr/ppmsvsr/python/README_CN.md b/examples/vision/sr/ppmsvsr/python/README_CN.md new file mode 100644 index 0000000000..ba793011d1 --- /dev/null +++ b/examples/vision/sr/ppmsvsr/python/README_CN.md @@ -0,0 +1,62 @@ +[English](README.md) | 简体中文 +# PP-MSVSR Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PP-MSVSR在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/sr/ppmsvsr/python + +# 下载VSR模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-MSVSR_reds_x4.tar +tar -xvf PP-MSVSR_reds_x4.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/vsr_src.mp4 +# CPU推理 +python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device cpu +# GPU推理 +python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP-MSVSR_reds_x4 --video vsr_src.mp4 --frame_num 2 --device gpu --use_trt True +``` + +## VSR Python接口 + +```python +fd.vision.sr.PPMSVSR(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PP-MSVSR模型加载和初始化,其中model_file和params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleGAN/blob/develop/docs/zh_CN/tutorials/video_super_resolution.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PPMSVSR.predict(frames) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **frames**(list[np.ndarray]): 输入数据,注意需为HWC,BGR格式, frames为视频帧序列 + +> **返回** list[np.ndarray] 为超分后的视频帧序列 + + +## 其它文档 + +- [PP-MSVSR 模型介绍](..) +- [PP-MSVSR C++部署](../cpp) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/tracking/pptracking/README.md b/examples/vision/tracking/pptracking/README.md index 35b9d7173d..e3e5ff9496 100644 --- a/examples/vision/tracking/pptracking/README.md +++ b/examples/vision/tracking/pptracking/README.md @@ -1,35 +1,36 @@ -# PP-Tracking模型部署 +English | [简体中文](README_CN.md) +# PP-Tracking Model Deployment -## 模型版本说明 +## Model Description - [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5) -## 支持模型列表 +## List of Supported Models -目前FastDeploy支持如下模型的部署 +Now FastDeploy supports the deployment of the following models -- [PP-Tracking系列模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/configs/mot) +- [PP-Tracking models](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/configs/mot) -## 导出部署模型 +## Export Deployment Models -在部署前,需要先将训练好的PP-Tracking导出成部署模型,导出PPTracking导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md)。 +Before deployment, the trained PP-Tracking needs to be exported into the deployment model. Refer to [Export Model](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md) for more details. -## 下载预训练模型 +## Download Pre-trained Models -为了方便开发者的测试,下面提供了PP-Tracking行人跟踪垂类模型,开发者可直接下载使用,更多模型参见[PPTracking](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/README_cn.md)。 +For developers' testing, PP-Tracking’s pedestrian tracking pendant model is provided below. Developers can download and use it directly. Refer to [PPTracking](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/README_cn.md) for other models. -| 模型 | 参数大小 | 精度 | 备注 | +| Model | Parameter Size | Accuracy | Note | |:-----------------------------------------------------------------------------------------------------|:-------|:----- | :------ | | [PP-Tracking](https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz) | 51.2MB | - | -**说明** -- 仅支持JDE模型(JDE,FairMOT,MCFairMOT); -- 目前暂不支持SDE模型的部署,待PaddleDetection官方更新SED部署代码后,对SDE模型进行支持。 +**Statement** +- Only JDE models are supported(JDE,FairMOT,MCFairMOT); +- SDE model deployment is not supported at present. Its deployment can be allowed after PaddleDetection officially updates SED deployment code. -## 详细部署文档 +## Detailed Deployment Tutorials -- [Python部署](python) -- [C++部署](cpp) +- [Python Deployment](python) +- [C++ Deployment](cpp) diff --git a/examples/vision/tracking/pptracking/README_CN.md b/examples/vision/tracking/pptracking/README_CN.md new file mode 100644 index 0000000000..6549aee62f --- /dev/null +++ b/examples/vision/tracking/pptracking/README_CN.md @@ -0,0 +1,36 @@ +[English](README.md) | 简体中文 +# PP-Tracking模型部署 + +## 模型版本说明 + +- [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5) + +## 支持模型列表 + +目前FastDeploy支持如下模型的部署 + +- [PP-Tracking系列模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/configs/mot) + + +## 导出部署模型 + +在部署前,需要先将训练好的PP-Tracking导出成部署模型,导出PPTracking导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md)。 + + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PP-Tracking行人跟踪垂类模型,开发者可直接下载使用,更多模型参见[PPTracking](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/README_cn.md)。 + +| 模型 | 参数大小 | 精度 | 备注 | +|:-----------------------------------------------------------------------------------------------------|:-------|:----- | :------ | +| [PP-Tracking](https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz) | 51.2MB | - | + +**说明** +- 仅支持JDE模型(JDE,FairMOT,MCFairMOT); +- 目前暂不支持SDE模型的部署,待PaddleDetection官方更新SED部署代码后,对SDE模型进行支持。 + + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/tracking/pptracking/cpp/README.md b/examples/vision/tracking/pptracking/cpp/README.md index af26e1fff4..189639a4bc 100644 --- a/examples/vision/tracking/pptracking/cpp/README.md +++ b/examples/vision/tracking/pptracking/cpp/README.md @@ -1,43 +1,43 @@ -# PP-Tracking C++部署示例 +English | [简体中文](README_CN.md) +# PP-Tracking C++ Deployment Example -本目录下提供`infer.cc`快速完成PP-Tracking在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +This directory provides examples that `infer.cc` fast finishes the deployment of PP-Tracking on CPU/GPU and GPU accelerated by TensorRT. +Before deployment, two steps require confirmation -在部署前,需确认以下两个步骤 +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -以Linux上 PP-Tracking 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +Taking the PP-Tracking inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 0.7.0 or above (x.x.x>=0.7.0) is required to support this model. ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# Download the FastDeploy precompiled library. Users can choose your appropriate version in the`FastDeploy Precompiled Library` mentioned above wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -# 下载PP-Tracking模型文件和测试视频 +# Download PP-Tracking model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz tar -xvf fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/person.mp4 -# CPU推理 +# CPU inference ./infer_demo fairmot_hrnetv2_w18_dlafpn_30e_576x320 person.mp4 0 -# GPU推理 +# GPU inference ./infer_demo fairmot_hrnetv2_w18_dlafpn_30e_576x320 person.mp4 1 -# GPU上TensorRT推理 +# TensorRT Inference on GPU ./infer_demo fairmot_hrnetv2_w18_dlafpn_30e_576x320 person.mp4 2 ``` -以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: -- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) +The above command works for Linux or MacOS. For SDK use-pattern in Windows, refer to: +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) -## PP-Tracking C++接口 +## PP-Tracking C++ Interface -### PPTracking类 +### PPTracking Class ```c++ fastdeploy::vision::tracking::PPTracking( @@ -48,31 +48,31 @@ fastdeploy::vision::tracking::PPTracking( const ModelFormat& model_format = ModelFormat::PADDLE) ``` -PP-Tracking模型加载和初始化,其中model_file为导出的Paddle模型格式。 +PP-Tracking model loading and initialization, among which model_file is the exported Paddle model format. -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -#### Predict函数 +#### Predict Function > ```c++ > PPTracking::Predict(cv::Mat* im, MOTResult* result) > ``` > -> 模型预测接口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,跟踪id,各个框的置信度,对象类别id,MOTResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **im**: Input images in HWC or BGR format +> > * **result**: Detection results, including detection box, tracking id, confidence of each box, and object class id. Refer to [visual model prediction results](../../../../../docs/api/vision_results/) for the description of MOTResult -- [模型介绍](../../) -- [Python部署](../python) -- [视觉模型预测结果](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [Model Description](../../) +- [Python Deployment](../python) +- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/tracking/pptracking/cpp/README_CN.md b/examples/vision/tracking/pptracking/cpp/README_CN.md new file mode 100644 index 0000000000..bd21ab13ce --- /dev/null +++ b/examples/vision/tracking/pptracking/cpp/README_CN.md @@ -0,0 +1,79 @@ +[English](README.md) | 简体中文 +# PP-Tracking C++部署示例 + +本目录下提供`infer.cc`快速完成PP-Tracking在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上 PP-Tracking 推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz +tar xvf fastdeploy-linux-x64-x.x.x.tgz +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x +make -j + +# 下载PP-Tracking模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz +tar -xvf fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/person.mp4 + + +# CPU推理 +./infer_demo fairmot_hrnetv2_w18_dlafpn_30e_576x320 person.mp4 0 +# GPU推理 +./infer_demo fairmot_hrnetv2_w18_dlafpn_30e_576x320 person.mp4 1 +# GPU上TensorRT推理 +./infer_demo fairmot_hrnetv2_w18_dlafpn_30e_576x320 person.mp4 2 +``` + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## PP-Tracking C++接口 + +### PPTracking类 + +```c++ +fastdeploy::vision::tracking::PPTracking( + const string& model_file, + const string& params_file = "", + const string& config_file, + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) +``` + +PP-Tracking模型加载和初始化,其中model_file为导出的Paddle模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +#### Predict函数 + +> ```c++ +> PPTracking::Predict(cv::Mat* im, MOTResult* result) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,跟踪id,各个框的置信度,对象类别id,MOTResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/tracking/pptracking/python/README.md b/examples/vision/tracking/pptracking/python/README.md index 48f8300c9e..318a75cbea 100644 --- a/examples/vision/tracking/pptracking/python/README.md +++ b/examples/vision/tracking/pptracking/python/README.md @@ -1,70 +1,71 @@ -# PP-Tracking Python部署示例 +English | [简体中文](README_CN.md) +# PP-Tracking Python Deployment Example -在部署前,需确认以下两个步骤 +Before deployment, two steps require confirmation -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -本目录下提供`infer.py`快速完成PP-Tracking在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +This directory provides examples that `infer.py` fast finishesshes the deployment of PP-Tracking on CPU/GPU and GPU accelerated by TensorRT. The script is as follows ```bash -#下载部署示例代码 +# Download deployment example code git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/tracking/pptracking/python -# 下载PP-Tracking模型文件和测试视频 +# Download PP-Tracking model files and test videos wget https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz tar -xvf fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/person.mp4 -# CPU推理 +# CPU inference python infer.py --model fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video person.mp4 --device cpu -# GPU推理 +# GPU inference python infer.py --model fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video person.mp4 --device gpu -# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +# TensorRT inference on GPU (Attention: It is somewhat time-consuming for the operation of model serialization when running TensorRT inference for the first time. Please be patient.) python infer.py --model fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video person.mp4 --device gpu --use_trt True ``` -## PP-Tracking Python接口 +## PP-Tracking Python Interface ```python fd.vision.tracking.PPTracking(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` -PP-Tracking模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md) +PP-Tracking model loading and initialization, among which model_file, params_file, and config_file are the Paddle inference files exported from the training model. Refer to [Model Export](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md) for more information -**参数** +**Parameter** -> * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径 -> * **config_file**(str): 推理部署配置文件 -> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 +> * **model_file**(str): Model file path +> * **params_file**(str): Parameter file path +> * **config_file**(str): Inference deployment configuration file +> * **runtime_option**(RuntimeOption): Backend inference configuration. None by default, which is the default configuration +> * **model_format**(ModelFormat): Model format. Paddle format by default -### predict函数 +### predict function > ```python > PPTracking.predict(frame) > ``` > -> 模型预测结口,输入图像直接输出检测结果。 +> Model prediction interface. Input images and output detection results. > -> **参数** +> **Parameter** > -> > * **frame**(np.ndarray): 输入数据,注意需为HWC,BGR格式,frame为视频帧如:_,frame=cap.read()得到 +> > * **frame**(np.ndarray): Input data in HWC or BGR format. The video frame is obtained through: _,frame=cap.read() -> **返回** +> **Return** > -> > 返回`fastdeploy.vision.MOTResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > Return `fastdeploy.vision.MOTResult` structure. Refer to [Vision Model Prediction Results](../../../../../docs/api/vision_results/) for the description of the structure -### 类成员属性 -#### 预处理参数 -用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 +### Class Member Variable +#### Pre-processing Parameter +Users can modify the following pre-processing parameters to their needs, which affects the final inference and deployment results -## 其它文档 +## Other Documents -- [PP-Tracking 模型介绍](..) -- [PP-Tracking C++部署](../cpp) -- [模型预测结果说明](../../../../../docs/api/vision_results/) -- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md) +- [PP-Tracking Model Description](..) +- [PP-Tracking C++ Deployment](../cpp) +- [Model Prediction Results](../../../../../docs/api/vision_results/) +- [How to switch the model inference backend engine](../../../../../docs/cn/faq/how_to_change_backend.md) diff --git a/examples/vision/tracking/pptracking/python/README_CN.md b/examples/vision/tracking/pptracking/python/README_CN.md new file mode 100644 index 0000000000..6e1d5e89c9 --- /dev/null +++ b/examples/vision/tracking/pptracking/python/README_CN.md @@ -0,0 +1,71 @@ +[English](README.md) | 简体中文 +# PP-Tracking Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成PP-Tracking在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/tracking/pptracking/python + +# 下载PP-Tracking模型文件和测试视频 +wget https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz +tar -xvf fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz +wget https://bj.bcebos.com/paddlehub/fastdeploy/person.mp4 +# CPU推理 +python infer.py --model fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video person.mp4 --device cpu +# GPU推理 +python infer.py --model fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video person.mp4 --device gpu +# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model fairmot_hrnetv2_w18_dlafpn_30e_576x320 --video person.mp4 --device gpu --use_trt True +``` + +## PP-Tracking Python接口 + +```python +fd.vision.tracking.PPTracking(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +``` + +PP-Tracking模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md) + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式 + +### predict函数 + +> ```python +> PPTracking.predict(frame) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **frame**(np.ndarray): 输入数据,注意需为HWC,BGR格式,frame为视频帧如:_,frame=cap.read()得到 + +> **返回** +> +> > 返回`fastdeploy.vision.MOTResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + + + +## 其它文档 + +- [PP-Tracking 模型介绍](..) +- [PP-Tracking C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) +- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)