diff --git a/docs/api/vision_results/face_alignment_result_CN.md b/docs/api/vision_results/face_alignment_result_CN.md index 1697fbfd5..ada0291fa 100644 --- a/docs/api/vision_results/face_alignment_result_CN.md +++ b/docs/api/vision_results/face_alignment_result_CN.md @@ -1,35 +1,27 @@ -简体中文 | [English](face_detection_result.md) -# FaceDetectionResult 人脸检测结果 +[English](face_alignment_result.md) | 简体中文 -FaceDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸检测出来的目标框、人脸landmarks,目标置信度和每张人脸的landmark数量。 +# FaceAlignmentResult 人脸对齐(人脸关键点检测)结果 + +FaceAlignmentResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸landmarks。 ## C++ 定义 -`fastdeploy::vision::FaceDetectionResult` +`fastdeploy::vision::FaceAlignmentResult` ```c++ -struct FaceDetectionResult { - std::vector> boxes; +struct FaceAlignmentResult { std::vector> landmarks; - std::vector scores; - int landmarks_per_face; void Clear(); std::string Str(); }; ``` -- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 -- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 -- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点,其元素个数与`boxes.size()`一致 -- **landmarks_per_face**: 成员变量,表示每个人脸框中的关键点的数量。 +- **landmarks**: 成员变量,表示单张人脸图片检测出来的所有关键点 - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) ## Python 定义 -`fastdeploy.vision.FaceDetectionResult` +`fastdeploy.vision.FaceAlignmentResult` -- **boxes**(list of list(float)): 成员变量,表示单张图片检测出来的所有目标框坐标。boxes是一个list,其每个元素为一个长度为4的list, 表示为一个框,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 -- **scores**(list of float): 成员变量,表示单张图片检测出来的所有目标置信度 -- **landmarks**(list of list(float)): 成员变量,表示单张图片检测出来的所有人脸的关键点 -- **landmarks_per_face**(int): 成员变量,表示每个人脸框中的关键点的数量。 +- **landmarks**(list of list(float)): 成员变量,表示单张人脸图片检测出来的所有关键点 diff --git a/docs/api/vision_results/segmentation_result.md b/docs/api/vision_results/segmentation_result.md index 426d38d1e..0852254ea 100644 --- a/docs/api/vision_results/segmentation_result.md +++ b/docs/api/vision_results/segmentation_result.md @@ -19,7 +19,7 @@ struct SegmentationResult { ``` - **label_map**: Member variable which indicates the segmentation category of each pixel in a single image. `label_map.size()` indicates the number of pixel points of a image. -- **score_map**: Member variable which indicates the predicted segmentation category probability value (specified as `--output_op argmax` when export) corresponding to label_map, or the probability value normalized by softmax (specified as `--output_op softmax` when export, or as `--output_op when exporting the model). none` when export while setting the [class member attribute](../../../examples/vision/segmentation/paddleseg/cpp/) as `apply_softmax=True` during model initialization). +- **score_map**: Member variable which indicates the predicted segmentation category probability value corresponding to the label_map one-to-one, the member variable is not empty only when `--output_op none` is specified when exporting the PaddleSeg model, otherwise the member variable is empty. - **shape**: Member variable which indicates the shape of the output image as H\*W. - **Clear()**: Member function used to clear the results stored in the structure. - **Str()**: Member function used to output the information in the structure as string (for Debug). @@ -29,5 +29,5 @@ struct SegmentationResult { `fastdeploy.vision.SegmentationResult` - **label_map**(list of int): Member variable which indicates the segmentation category of each pixel in a single image. -- **score_map**(list of float): Member variable which indicates the predicted segmentation category probability value (specified as `--output_op argmax` when export) corresponding to label_map, or the probability value normalized by softmax (specified as `--output_op softmax` when export, or as `--output_op when exporting the model). none` when export while setting the [class member attribute](../../../examples/vision/segmentation/paddleseg/cpp/) as `apply_softmax=True` during model initialization). +- **score_map**(list of float): Member variable which indicates the predicted segmentation category probability value corresponding to the label_map one-to-one, the member variable is not empty only when `--output_op none` is specified when exporting the PaddleSeg model, otherwise the member variable is empty. - **shape**(list of int): Member variable which indicates the shape of the output image as H\*W. diff --git a/docs/api/vision_results/segmentation_result_CN.md b/docs/api/vision_results/segmentation_result_CN.md index 5b393c6ea..42b6eaf73 100644 --- a/docs/api/vision_results/segmentation_result_CN.md +++ b/docs/api/vision_results/segmentation_result_CN.md @@ -14,14 +14,16 @@ struct SegmentationResult { std::vector shape; bool contain_score_map = false; void Clear(); + void Free(); std::string Str(); }; ``` - **label_map**: 成员变量,表示单张图片每个像素点的分割类别,`label_map.size()`表示图片像素点的个数 -- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/cpp/)`apply_softmax=True`) +- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值,只有导出PaddleSeg模型时指定`--output_op none`时,该成员变量才不为空,否则该成员变量为空 - **shape**: 成员变量,表示输出图片的shape,为H\*W - **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Free()**: 成员函数,用于清除结构体中存储的结果并释放内存 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) ## Python 定义 @@ -29,5 +31,5 @@ struct SegmentationResult { `fastdeploy.vision.SegmentationResult` - **label_map**(list of int): 成员变量,表示单张图片每个像素点的分割类别 -- **score_map**(list of float): 成员变量,与label_map一一对应的所预测的分割类别概率值(当导出模型时指定`--output_op argmax`)或者经过softmax归一化化后的概率值(当导出模型时指定`--output_op softmax`或者导出模型时指定`--output_op none`同时模型初始化的时候设置模型[类成员属性](../../../examples/vision/segmentation/paddleseg/python/)`apply_softmax=true`) +- **score_map**(list of float): 成员变量,与label_map一一对应的所预测的分割类别概率值,只有导出PaddleSeg模型时指定`--output_op none`时,该成员变量才不为空,否则该成员变量为空 - **shape**(list of int): 成员变量,表示输出图片的shape,为H\*W diff --git a/docs/api_docs/cpp/vision_results_cn.md b/docs/api_docs/cpp/vision_results_cn.md new file mode 100644 index 000000000..73b3b4e6d --- /dev/null +++ b/docs/api_docs/cpp/vision_results_cn.md @@ -0,0 +1,324 @@ +[English](./vision_results_en.md) | 简体中文 + +# 视觉模型预测结果说明 + +## ClassifyResult 图像分类结果 + +ClassifyResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像的分类结果和置信度。 + +### C++ 定义 + +```c++ +fastdeploy::vision::ClassifyResult +``` + +```c++ +struct ClassifyResult { + std::vector label_ids; + std::vector scores; + void Clear(); + std::string Str(); +}; +``` + +- **label_ids**: 成员变量,表示单张图片的分类结果,其个数根据在使用分类模型时传入的topk决定,例如可以返回top 5的分类结果 +- **scores**: 成员变量,表示单张图片在相应分类结果上的置信度,其个数根据在使用分类模型时传入的topk决定,例如可以返回top 5的分类置信度 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## SegmentationResult 图像分割结果 + +SegmentationResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像中每个像素预测出来的分割类别和分割类别的概率值。 + +### C++ 定义 + +```c++ +fastdeploy::vision::SegmentationResult +``` + +```c++ +struct SegmentationResult { + std::vector label_map; + std::vector score_map; + std::vector shape; + bool contain_score_map = false; + void Clear(); + void Free(); + std::string Str(); +}; +``` + +- **label_map**: 成员变量,表示单张图片每个像素点的分割类别,`label_map.size()`表示图片像素点的个数 +- **score_map**: 成员变量,与label_map一一对应的所预测的分割类别概率值,只有导出PaddleSeg模型时指定`--output_op none`时,该成员变量才不为空,否则该成员变量为空 +- **shape**: 成员变量,表示输出图片的shape,为H\*W +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Free()**: 成员函数,用于清除结构体中存储的结果并释放内存 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## DetectionResult 目标检测结果 + +DetectionResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。 + +### C++ 定义 + +```c++ +fastdeploy::vision::DetectionResult +``` + +```c++ +struct DetectionResult { + std::vector> boxes; + std::vector scores; + std::vector label_ids; + std::vector masks; + bool contain_masks = false; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 +- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 +- **label_ids**: 成员变量,表示单张图片检测出来的所有目标类别,其元素个数与`boxes.size()`一致 +- **masks**: 成员变量,表示单张图片检测出来的所有实例mask,其元素个数及shape大小与`boxes`一致 +- **contain_masks**: 成员变量,表示检测结果中是否包含实例mask,实例分割模型的结果此项一般为true. +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +```c++ +fastdeploy::vision::Mask +``` +```c++ +struct Mask { + std::vector data; + std::vector shape; // (H,W) ... + + void Clear(); + std::string Str(); +}; +``` +- **data**: 成员变量,表示检测到的一个mask +- **shape**: 成员变量,表示mask的shape,如 (h,w) +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## FaceAlignmentResult 人脸对齐(人脸关键点检测)结果 + +FaceAlignmentResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸landmarks。 + +### C++ 定义 + +```c++ +fastdeploy::vision::FaceAlignmentResult +``` + +```c++ +struct FaceAlignmentResult { + std::vector> landmarks; + void Clear(); + std::string Str(); +}; +``` + +- **landmarks**: 成员变量,表示单张人脸图片检测出来的所有关键点 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## KeyPointDetectionResult 目标检测结果 + +KeyPointDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像中目标行为的各个关键点坐标和置信度。 + +### C++ 定义 + +```c++ +fastdeploy::vision::KeyPointDetectionResult +``` + +```c++ +struct KeyPointDetectionResult { + std::vector> keypoints; + std::vector scores; + int num_joints = -1; + void Clear(); + std::string Str(); +}; +``` + +- **keypoints**: 成员变量,表示识别到的目标行为的关键点坐标。 + `keypoints.size()= N * J` + - `N`:图片中的目标数量 + - `J`:num_joints(一个目标的关键点数量) +- **scores**: 成员变量,表示识别到的目标行为的关键点坐标的置信度。 + `scores.size()= N * J` + - `N`:图片中的目标数量 + - `J`:num_joints(一个目标的关键点数量) +- **num_joints**: 成员变量,一个目标的关键点数量 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + +## FaceRecognitionResult 人脸识别结果 + +FaceRecognitionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸识别模型对图像特征的embedding。 +### C++ 定义 + +```c++ +fastdeploy::vision::FaceRecognitionResult +``` + +```c++ +struct FaceRecognitionResult { + std::vector embedding; + void Clear(); + std::string Str(); +}; +``` + +- **embedding**: 成员变量,表示人脸识别模型最终的提取的特征embedding,可以用来计算人脸之间的特征相似度。 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + + +## MattingResult 抠图结果 + +MattingResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明模型预测的alpha透明度的值,预测的前景等。 + +### C++ 定义 + +```c++ +fastdeploy::vision::MattingResult +``` + +```c++ +struct MattingResult { + std::vector alpha; + std::vector foreground; + std::vector shape; + bool contain_foreground = false; + void Clear(); + std::string Str(); +}; +``` + +- **alpha**: 是一维向量,为预测的alpha透明度的值,值域为[0.,1.],长度为hxw,h,w为输入图像的高和宽 +- **foreground**: 是一维向量,为预测的前景,值域为[0.,255.],长度为hxwxc,h,w为输入图像的高和宽,c一般为3,foreground不是一定有的,只有模型本身预测了前景,这个属性才会有效 +- **contain_foreground**: 表示预测的结果是否包含前景 +- **shape**: 表示输出结果的shape,当contain_foreground为false,shape只包含(h,w),当contain_foreground为true,shape包含(h,w,c), c一般为3 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## OCRResult OCR预测结果 + +OCRResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明图像检测和识别出来的文本框,文本框方向分类,以及文本框内的文本内容 + +### C++ 定义 + +```c++ +fastdeploy::vision::OCRResult +``` + +```c++ +struct OCRResult { + std::vector> boxes; + std::vector text; + std::vector rec_scores; + std::vector cls_scores; + std::vector cls_labels; + ResultType type = ResultType::OCR; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示单张图内检测出的框的个数,每个框以8个int数值依次表示框的4个坐标点,顺序为左下,右下,右上,左上 +- **text**: 成员变量,表示多个文本框内被识别出来的文本内容,其元素个数与`boxes.size()`一致 +- **rec_scores**: 成员变量,表示文本框内识别出来的文本的置信度,其元素个数与`boxes.size()`一致 +- **cls_scores**: 成员变量,表示文本框的分类结果的置信度,其元素个数与`boxes.size()`一致 +- **cls_labels**: 成员变量,表示文本框的方向分类类别,其元素个数与`boxes.size()`一致 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + +## FaceDetectionResult 人脸检测结果 + +FaceDetectionResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明人脸检测出来的目标框、人脸landmarks,目标置信度和每张人脸的landmark数量。 + +### C++ 定义 + +```c++ +fastdeploy::vision::FaceDetectionResult +``` + +```c++ +struct FaceDetectionResult { + std::vector> boxes; + std::vector> landmarks; + std::vector scores; + int landmarks_per_face; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单张图片检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 +- **scores**: 成员变量,表示单张图片检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 +- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点,其元素个数与`boxes.size()`一致 +- **landmarks_per_face**: 成员变量,表示每个人脸框中的关键点的数量。 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## HeadPoseResult 头部姿态结果 + +HeadPoseResult 代码定义在`fastdeploy/vision/common/result.h`中,用于表明头部姿态结果。 + +### C++ 定义 + +```c++ +fastdeploy::vision::HeadPoseResult +``` + +```c++ +struct HeadPoseResult { + std::vector euler_angles; + void Clear(); + std::string Str(); +}; +``` + +- **euler_angles**: 成员变量,表示单张人脸图片预测的欧拉角,存放的顺序是(yaw, pitch, roll), yaw 代表水平转角,pitch 代表垂直角,roll 代表翻滚角,值域都为 [-90,+90]度 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + + +API:`fastdeploy.vision.HeadPoseResult`, 该结果返回: +- **euler_angles**(list of float): 成员变量,表示单张人脸图片预测的欧拉角,存放的顺序是(yaw, pitch, roll), yaw 代表水平转角,pitch 代表垂直角,roll 代表翻滚角,值域都为 [-90, +90]度 + +## MOTResult 多目标跟踪结果 + +MOTResult代码定义在`fastdeploy/vision/common/result.h`中,用于表明多目标跟踪中的检测出来的目标框、目标跟踪id、目标类别和目标置信度。 + +### C++ 定义 + +```c++ +fastdeploy::vision::MOTResult +``` + +```c++ +struct MOTResult{ + // left top right bottom + std::vector> boxes; + std::vector ids; + std::vector scores; + std::vector class_ids; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: 成员变量,表示单帧画面中检测出来的所有目标框坐标,`boxes.size()`表示框的个数,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 +- **ids**: 成员变量,表示单帧画面中所有目标的id,其元素个数与`boxes.size()`一致 +- **scores**: 成员变量,表示单帧画面检测出来的所有目标置信度,其元素个数与`boxes.size()`一致 +- **class_ids**: 成员变量,表示单帧画面出来的所有目标类别,其元素个数与`boxes.size()`一致 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) diff --git a/docs/api_docs/cpp/vision_results_en.md b/docs/api_docs/cpp/vision_results_en.md new file mode 100644 index 000000000..7feb3793c --- /dev/null +++ b/docs/api_docs/cpp/vision_results_en.md @@ -0,0 +1,290 @@ +English | [简体中文](./vision_results_cn.md) + +# Description of Vision Results + +## Image Classification Result + +The ClassifyResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the classification result and confidence level of the image. + +### C++ Definition + +```c++ +fastdeploy::vision::ClassifyResult +``` + +```c++ +struct ClassifyResult { + std::vector label_ids; + std::vector scores; + void Clear(); + std::string Str(); +}; +``` + +- **label_ids**: Member variable which indicates the classification results of a single image. Its number is determined by the topk passed in when using the classification model, e.g. it can return the top 5 classification results. +- **scores**: Member variable which indicates the confidence level of a single image on the corresponding classification result. Its number is determined by the topk passed in when using the classification model, e.g. it can return the top 5 classification confidence level. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Segmentation Result + +The SegmentationResult code is defined in `fastdeploy/vision/common/result.h`, indicating the segmentation category and the segmentation category probability predicted in each pixel in the image. + +### C++ Definition + +```c++ +fastdeploy::vision::SegmentationResult +``` + +```c++ +struct SegmentationResult { + std::vector label_map; + std::vector score_map; + std::vector shape; + bool contain_score_map = false; + void Clear(); + std::string Str(); +}; +``` + +- **label_map**: Member variable which indicates the segmentation category of each pixel in a single image. `label_map.size()` indicates the number of pixel points of a image. +- **score_map**: Member variable which indicates the predicted segmentation category probability value corresponding to the label_map one-to-one, the member variable is not empty only when `--output_op none` is specified when exporting the PaddleSeg model, otherwise the member variable is empty. +- **shape**: Member variable which indicates the shape of the output image as H\*W. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + +## Target Detection Result + +The DetectionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the target frame, target class and target confidence level detected in the image. + +### C++ Definition + +```c++ +fastdeploy::vision::DetectionResult +``` + +```c++ +struct DetectionResult { + std::vector> boxes; + std::vector scores; + std::vector label_ids; + std::vector masks; + bool contain_masks = false; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: Member variable which indicates the coordinates of all detected target boxes in a single image. `boxes.size()` indicates the number of boxes, each box is represented by 4 float values in order of xmin, ymin, xmax, ymax, i.e. the coordinates of the top left and bottom right corner. +- **scores**: Member variable which indicates the confidence level of all targets detected in a single image, where the number of elements is the same as `boxes.size()`. +- **label_ids**: Member variable which indicates all target categories detected in a single image, where the number of elements is the same as `boxes.size()`. +- **masks**: Member variable which indicates all detected instance masks of a single image, where the number of elements and the shape size are the same as `boxes`. +- **contain_masks**: Member variable which indicates whether the detected result contains instance masks, which is generally true for the instance segmentation model. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + +```c++ +fastdeploy::vision::Mask +``` +```c++ +struct Mask { + std::vector data; + std::vector shape; // (H,W) ... + + void Clear(); + std::string Str(); +}; +``` +- **data**: Member variable which indicates a detected mask. +- **shape**: Member variable which indicates the shape of the mask, e.g. (h,w). +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Face Detection Result + +The FaceDetectionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the target frames, face landmarks, target confidence and the number of landmark per face. + +### C++ Definition + +```c++ +fastdeploy::vision::FaceDetectionResult +``` + +```c++ +struct FaceDetectionResult { + std::vector> boxes; + std::vector> landmarks; + std::vector scores; + int landmarks_per_face; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: Member variable which indicates the coordinates of all detected target boxes in a single image. `boxes.size()` indicates the number of boxes, each box is represented by 4 float values in order of xmin, ymin, xmax, ymax, i.e. the coordinates of the top left and bottom right corner. +- **scores**: Member variable which indicates the confidence level of all targets detected in a single image, where the number of elements is the same as `boxes.size()`. +- **landmarks**: Member variable which indicates the keypoints of all faces detected in a single image, where the number of elements is the same as `boxes.size()`. +- **landmarks_per_face**: Member variable which indicates the number of keypoints in each face box. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Keypoint Detection Result + +The KeyPointDetectionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the coordinates and confidence level of each keypoint of the target's behavior in the image. + +### C++ Definition + +```c++ +fastdeploy::vision::KeyPointDetectionResult +``` + +```c++ +struct KeyPointDetectionResult { + std::vector> keypoints; + std::vector scores; + int num_joints = -1; + void Clear(); + std::string Str(); +}; +``` + +- **keypoints**: Member variable which indicates the coordinates of the identified target behavior keypoint. + ` keypoints.size() = N * J`: + - `N`: the number of targets in the image + - `J`: num_joints (the number of keypoints of a target) +- **scores**: Member variable which indicates the confidence level of the keypoint coordinates of the identified target behavior. + `scores.size() = N * J`: + - `N`: the number of targets in the picture + - `J`:num_joints (the number of keypoints of a target) +- **num_joints**: Member variable which indicates the number of keypoints of a target. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Face Recognition Result + +The FaceRecognitionResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the image features embedding in the face recognition model. +### C++ Definition + +```c++ +fastdeploy::vision::FaceRecognitionResult +``` + +```c++ +struct FaceRecognitionResult { + std::vector embedding; + void Clear(); + std::string Str(); +}; +``` + +- **embedding**: Member variable which indicates the final extracted feature embedding of the face recognition model, and can be used to calculate the facial feature similarity. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + +## Matting Result + +The MattingResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the predicted value of alpha transparency predicted and the predicted foreground, etc. + +### C++ Definition +```c++ +fastdeploy::vision::MattingResult +``` + +```c++ +struct MattingResult { + std::vector alpha; + std::vector foreground; + std::vector shape; + bool contain_foreground = false; + void Clear(); + std::string Str(); +}; +``` + +- **alpha**: It is a one-dimensional vector, indicating the predicted value of alpha transparency. The value range is [0.,1.], and the length is hxw, in which h,w represent the height and the width of the input image seperately. +- **foreground**: It is a one-dimensional vector, indicating the predicted foreground. The value range is [0.,255.], and the length is hxwxc, in which h,w represent the height and the width of the input image, and c is generally 3. This vector is valid only when the model itself predicts the foreground. +- **contain_foreground**: Used to indicate whether the result contains foreground. +- **shape**: Used to indicate the shape of the output. When contain_foreground is false, the shape only contains (h,w), while when contain_foreground is true, the shape contains (h,w,c), in which c is generally 3. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## OCR prediction result + +The OCRResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the text box detected in the image, text box orientation classification, and the text content. + +### C++ Definition + +```c++ +fastdeploy::vision::OCRResult +``` + +```c++ +struct OCRResult { + std::vector> boxes; + std::vector text; + std::vector rec_scores; + std::vector cls_scores; + std::vector cls_labels; + ResultType type = ResultType::OCR; + void Clear(); + std::string Str(); +}; +``` + +- **boxes**: Member variable which indicates the coordinates of all detected target boxes in a single image. `boxes.size()` indicates the number of detected boxes. Each box is represented by 8 int values to indicate the 4 coordinates of the box, in the order of lower left, lower right, upper right, upper left. +- **text**: Member variable which indicates the content of the recognized text in multiple text boxes, where the element number is the same as `boxes.size()`. +- **rec_scores**: Member variable which indicates the confidence level of the recognized text, where the element number is the same as `boxes.size()`. +- **cls_scores**: Member variable which indicates the confidence level of the classification result of the text box, where the element number is the same as `boxes.size()`. +- **cls_labels**: Member variable which indicates the directional category of the textbox, where the element number is the same as `boxes.size()`. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Face Alignment Result + +The FaceAlignmentResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate face landmarks. + +### C++ Definition +```c++ +fastdeploy::vision::FaceAlignmentResult +``` + +```c++ +struct FaceAlignmentResult { + std::vector> landmarks; + void Clear(); + std::string Str(); +}; +``` + +- **landmarks**: Member variable which indicates all the key points detected in a single face image. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). + + +## Head Pose Result + +The HeadPoseResult code is defined in `fastdeploy/vision/common/result.h`, and is used to indicate the head pose result. + +### C++ Definition + +```c++ +fastdeploy::vision::HeadPoseResult +``` + +```c++ +struct HeadPoseResult { + std::vector euler_angles; + void Clear(); + std::string Str(); +}; +``` + +- **euler_angles**: Member variable which indicates the Euler angles predicted for a single face image, stored in the order (yaw, pitch, roll), with yaw representing the horizontal turn angle, pitch representing the vertical angle, and roll representing the roll angle, all with a value range of [-90,+90]. +- **Clear()**: Member function used to clear the results stored in the structure. +- **Str()**: Member function used to output the information in the structure as string (for Debug). diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md index 92f575d8d..c6d5a23bc 100755 --- a/docs/cn/build_and_install/README.md +++ b/docs/cn/build_and_install/README.md @@ -4,6 +4,7 @@ ## FastDeploy预编译库安装 - [FastDeploy预编译库下载安装](download_prebuilt_libraries.md) +>> **注意**:FastDeploy目前只提供部分环境的预编译库,其他环境需要参考下方文档自行编译 ## 自行编译安装 - [NVIDIA GPU部署环境](gpu.md) diff --git a/docs/cn/build_and_install/a311d.md b/docs/cn/build_and_install/a311d.md index 766be6954..7066ca9d5 100755 --- a/docs/cn/build_and_install/a311d.md +++ b/docs/cn/build_and_install/a311d.md @@ -2,6 +2,16 @@ # 晶晨 A311D 部署环境编译安装 +## 导航目录 + +* [简介以及编译选项](#简介以及编译选项) +* [交叉编译环境搭建](#交叉编译环境搭建) +* [基于 Paddle Lite 的 FastDeploy 交叉编译库编译](#基于-paddle-lite-的-fastdeploy-交叉编译库编译) +* [准备设备运行环境](#准备设备运行环境) +* [基于 FastDeploy 在 A311D 上的部署示例](#基于-fastdeploy-在-a311d-上的部署示例) + +## 简介以及编译选项 + FastDeploy 基于 Paddle Lite 后端支持在晶晨 NPU 上进行部署推理。 更多详细的信息请参考:[Paddle Lite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)。 diff --git a/docs/cn/build_and_install/huawei_ascend.md b/docs/cn/build_and_install/huawei_ascend.md index 520b23eab..4e621e305 100644 --- a/docs/cn/build_and_install/huawei_ascend.md +++ b/docs/cn/build_and_install/huawei_ascend.md @@ -1,5 +1,17 @@ # 华为昇腾NPU 部署环境编译准备 +## 导航目录 + +* [简介以及编译选项](#简介以及编译选项) +* [华为昇腾环境准备](#一华为昇腾环境准备) +* [编译环境搭建](#二编译环境搭建) +* [基于 Paddle Lite 的 C++ FastDeploy 库编译](#三基于-paddle-lite-的-c-fastdeploy-库编译) +* [基于 Paddle Lite 的 Python FastDeploy 库编译](#四基于-paddle-lite-的-python-fastdeploy-库编译) +* [昇腾部署时开启FlyCV](#五昇腾部署时开启flycv) +* [昇腾部署Demo参考](#六昇腾部署demo参考) + +## 简介以及编译选项 + FastDeploy基于 Paddle-Lite 后端, 支持在华为昇腾NPU上进行部署推理。 更多详细的信息请参考:[Paddle Lite部署示例](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/demo_guides/huawei_ascend_npu.md)。 @@ -114,7 +126,7 @@ python setup.py bdist_wheel ## 五.昇腾部署时开启FlyCV [FlyCV](https://github.com/PaddlePaddle/FlyCV) 是一款高性能计算机图像处理库, 针对ARM架构做了很多优化, 相比其他图像处理库性能更为出色. FastDeploy现在已经集成FlyCV, 用户可以在支持的硬件平台上使用FlyCV, 实现模型端到端推理性能的加速. -模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FLyCV使用文档](./boost_cv_by_flycv.md). +模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FlyCV使用文档](../faq/boost_cv_by_flycv.md). ## 六.昇腾部署Demo参考 diff --git a/docs/cn/build_and_install/rv1126.md b/docs/cn/build_and_install/rv1126.md index 159ac00e4..090393e1d 100755 --- a/docs/cn/build_and_install/rv1126.md +++ b/docs/cn/build_and_install/rv1126.md @@ -2,6 +2,16 @@ # 瑞芯微 RV1126 部署环境编译安装 +## 导航目录 + +* [简介以及编译选项](#简介以及编译选项) +* [交叉编译环境搭建](#交叉编译环境搭建) +* [基于 Paddle Lite 的 FastDeploy 交叉编译库编译](#基于-paddle-lite-的-fastdeploy-交叉编译库编译) +* [准备设备运行环境](#准备设备运行环境) +* [基于 FastDeploy 在 RV1126 上的部署示例](#基于-fastdeploy-在-rv1126-上的部署示例) + +## 简介以及编译选项 + FastDeploy基于 Paddle Lite 后端支持在瑞芯微(Rockchip)Soc 上进行部署推理。 更多详细的信息请参考:[Paddle Lite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)。 diff --git a/docs/cn/faq/vision_result_related_problems.md b/docs/cn/faq/vision_result_related_problems.md new file mode 100644 index 000000000..0426a2d18 --- /dev/null +++ b/docs/cn/faq/vision_result_related_problems.md @@ -0,0 +1,25 @@ +[English](faq.md)| 简体中文 +# 视觉模型预测结果常见问题 + +## 将视觉模型预测结果转换为numpy格式 + +这里以[SegmentationResult](./segmentation_result_CN.md)为例,展示如何抽取SegmentationResult中的label_map或者score_map来转为numpy格式,同时也可以利用已有数据new SegmentationResult结构体 +``` python +import fastdeploy as fd +import cv2 +import numpy as np + +model = fd.vision.segmentation.PaddleSegModel( + model_file, params_file, config_file) +im = cv2.imread(image) +result = model.predict(im) +# convert label_map and score_map to numpy format +numpy_label_map = np.array(result.label_map) +numpy_score_map = np.array(result.score_map) + +# create SegmentationResult object +result = fd.C.vision.SegmentationResult() +result.label_map = numpy_label_map.tolist() +result.score_map = numpy_score_map.tolist() +``` +>> **注意**: 以上为示例代码,具体请参考[PaddleSeg example](../../../examples/vision/segmentation/paddleseg/) diff --git a/examples/vision/matting/modnet/cpp/infer.cc b/examples/vision/matting/modnet/cpp/infer.cc index aa280eddd..1fef35218 100644 --- a/examples/vision/matting/modnet/cpp/infer.cc +++ b/examples/vision/matting/modnet/cpp/infer.cc @@ -35,7 +35,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -65,7 +65,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -96,7 +96,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; diff --git a/examples/vision/matting/modnet/python/infer.py b/examples/vision/matting/modnet/python/infer.py index 37c749010..0be874271 100644 --- a/examples/vision/matting/modnet/python/infer.py +++ b/examples/vision/matting/modnet/python/infer.py @@ -57,7 +57,7 @@ print(result) # 可视化结果 vis_im = fd.vision.vis_matting_alpha(im, result) vis_im_with_bg = fd.vision.swap_background(im, bg, result) -cv2.imwrite("visualized_result_fg.jpg", vis_im) +cv2.imwrite("visualized_result_fg.png", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( "Visualized result save in ./visualized_result_replaced_bg.jpg and ./visualized_result_fg.jpg" diff --git a/examples/vision/matting/ppmatting/README.md b/examples/vision/matting/ppmatting/README.md index a2cbdc346..2a54d53c7 100644 --- a/examples/vision/matting/ppmatting/README.md +++ b/examples/vision/matting/ppmatting/README.md @@ -1,42 +1,3 @@ -English | [简体中文](README_CN.md) -# PP-Matting Model Deployment +PaddleSeg Matting deployment examples, please refer to [document](../../segmentation/ppmatting/README_CN.md). -## Model Description - -- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -## List of Supported Models - -Now FastDeploy supports the deployment of the following models - -- [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 - -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 - -For developers' testing, models exported by PP-Matting are provided below. Developers can download and use them directly. - -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 | - | -| [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 | - | - - - -## Detailed Deployment Tutorials - -- [Python Deployment](python) -- [C++ Deployment](cpp) +PaddleSeg Matting的部署示例,请参考[文档](../../segmentation/ppmatting/README_CN.md). diff --git a/examples/vision/matting/ppmatting/cpp/README.md b/examples/vision/matting/ppmatting/cpp/README.md deleted file mode 100755 index fbe2c5fae..000000000 --- a/examples/vision/matting/ppmatting/cpp/README.md +++ /dev/null @@ -1,93 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting C++ Deployment Example - -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/en/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/en/build_and_install/download_prebuilt_libraries.md) - -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 -# 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 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 inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 0 -# GPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 1 -# TensorRT inference on GPU -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 2 -# kunlunxin XPU inference -./infer_demo PP-Matting-512 matting_input.jpg matting_bgr.jpg 3 -``` - -The visualized result after running is as follows -
- - - - -
- -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/en/faq/use_sdk_on_windows.md) - -## PP-Matting C++ Interface - -### PPMatting Class - -```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 loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **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 Function - -> ```c++ -> PPMatting::Predict(cv::Mat* im, MattingResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **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 - - -- [Model Description](../../) -- [Python Deployment](../python) -- [Vision Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/en/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 deleted file mode 100644 index 38e2e592a..000000000 --- a/examples/vision/matting/ppmatting/cpp/README_CN.md +++ /dev/null @@ -1,94 +0,0 @@ -[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 deleted file mode 100755 index 09fe0cdc2..000000000 --- a/examples/vision/matting/ppmatting/python/README.md +++ /dev/null @@ -1,81 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-Matting Python Deployment Example - -Before deployment, two steps require confirmation - -- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/en/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 - -# 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 inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu -# GPU inference -python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu -# 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 -# 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 Interface - -```python -fd.vision.matting.PPMatting(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -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): 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 function - -> ```python -> PPMatting.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > 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 Model Description](..) -- [PP-Matting C++ Deployment](../cpp) -- [Model Prediction Results](../../../../../docs/api/vision_results/) -- [How to switch the model inference backend engine](../../../../../docs/en/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 deleted file mode 100644 index cdfd7d378..000000000 --- a/examples/vision/matting/ppmatting/python/README_CN.md +++ /dev/null @@ -1,81 +0,0 @@ -[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/cpp/infer.cc b/examples/vision/matting/rvm/cpp/infer.cc index 9e2a2aa5d..4ca975216 100755 --- a/examples/vision/matting/rvm/cpp/infer.cc +++ b/examples/vision/matting/rvm/cpp/infer.cc @@ -41,7 +41,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im_bak, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -69,7 +69,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im_bak, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -103,7 +103,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file, auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im_bak, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result.jpg " "and ./visualized_result_fg.jpg" << std::endl; diff --git a/examples/vision/matting/rvm/python/infer.py b/examples/vision/matting/rvm/python/infer.py index 0e9eb6b21..b2ade3c0b 100755 --- a/examples/vision/matting/rvm/python/infer.py +++ b/examples/vision/matting/rvm/python/infer.py @@ -105,7 +105,7 @@ if args.image is not None: # 可视化结果 vis_im = fd.vision.vis_matting(im, result) vis_im_with_bg = fd.vision.swap_background(im, bg, result) - cv2.imwrite("visualized_result_fg.jpg", vis_im) + cv2.imwrite("visualized_result_fg.png", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( "Visualized result save in ./visualized_result_replaced_bg.jpg and ./visualized_result_fg.jpg" diff --git a/examples/vision/segmentation/paddleseg/README.md b/examples/vision/segmentation/paddleseg/README.md index de578cb22..c240e41b7 100644 --- a/examples/vision/segmentation/paddleseg/README.md +++ b/examples/vision/segmentation/paddleseg/README.md @@ -1,49 +1,32 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Model Deployment +# PaddleSeg高性能全场景模型部署方案—FastDeploy -## Model Description +## FastDeploy介绍 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +[FastDeploy](https://github.com/PaddlePaddle/FastDeploy)是一款全场景、易用灵活、极致高效的AI推理部署工具,使用FastDeploy可以简单高效的在10+款硬件上对PaddleSeg模型进行快速部署 -FastDeploy currently supports the deployment of the following models +## 支持如下的硬件部署 -- [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) - -【Attention】For **PP-Matting**、**PP-HumanMatting** and **ModNet** deployment, please refer to [Matting Model Deployment](../../matting) - -## Prepare PaddleSeg Deployment Model - -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 - -**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 - -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. +| 硬件支持列表 | | | | +|:----- | :-- | :-- | :-- | +| [NVIDIA GPU](cpu-gpu) | [X86 CPU](cpu-gpu)| [飞腾CPU](cpu-gpu) | [ARM CPU](cpu-gpu) | +| [Intel GPU(独立显卡/集成显卡)](cpu-gpu) | [昆仑](kunlun) | [昇腾](ascend) | [瑞芯微](rockchip) | +| [晶晨](amlogic) | [算能](sophgo) | -| 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(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 +- [Android ARM CPU部署](android) +- [服务化Serving部署](serving) +- [web部署](web) +- [模型自动化压缩工具](quantize) -- [Python Deployment](python) -- [C++ Deployment](cpp) + +## 常见问题 + +遇到问题可查看常见问题集合文档或搜索FastDeploy issues,链接如下: + +[常见问题集合](https://github.com/PaddlePaddle/FastDeploy/tree/develop/docs/cn/faq) + +[FastDeploy issues](https://github.com/PaddlePaddle/FastDeploy/issues) + +若以上方式都无法解决问题,欢迎给FastDeploy提交新的[issue](https://github.com/PaddlePaddle/FastDeploy/issues) diff --git a/examples/vision/segmentation/paddleseg/a311d/README.md b/examples/vision/segmentation/paddleseg/a311d/README.md deleted file mode 100755 index 07870aa59..000000000 --- a/examples/vision/segmentation/paddleseg/a311d/README.md +++ /dev/null @@ -1,12 +0,0 @@ -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. - -For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) - - -## Detailed Deployment Tutorials - -Only C++ deployment is supported on A311D. - -- [C++ deployment](cpp) diff --git a/examples/vision/segmentation/paddleseg/a311d/README_CN.md b/examples/vision/segmentation/paddleseg/a311d/README_CN.md deleted file mode 100644 index dad4f3924..000000000 --- a/examples/vision/segmentation/paddleseg/a311d/README_CN.md +++ /dev/null @@ -1,12 +0,0 @@ -[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/a311d/cpp/README.md b/examples/vision/segmentation/paddleseg/a311d/cpp/README.md deleted file mode 100755 index 0b8467ae4..000000000 --- a/examples/vision/segmentation/paddleseg/a311d/cpp/README.md +++ /dev/null @@ -1,59 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-LiteSeg Quantitative Model C++ Deployment Example - -`infer.cc` in this directory can help you quickly complete the inference acceleration of PP-LiteSeg quantization model deployment on A311D. - -## Deployment Preparations -### FastDeploy Cross-compile Environment Preparations -1. For the software and hardware environment, and the cross-compile environment, please refer to [FastDeploy Cross-compile environment](../../../../../../docs/en/build_and_install/a311d.md#Cross-compilation-environment-construction). - -### Model Preparations -1. You can directly use the quantized model provided by FastDeploy for deployment. -2. You can use one-click automatical compression tool provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) -3. The model requires heterogeneous computation. Please refer to: [Heterogeneous Computation](./../../../../../../docs/en/faq/heterogeneous_computing_on_timvx_npu.md). Since the model is already provided, you can test the heterogeneous file we provide first to verify whether the accuracy meets the requirements. - -For more information, please refer to [Model Quantization](../../quantize/README.md) - -## Deploying the Quantized PP-LiteSeg Segmentation model on A311D -Please follow these steps to complete the deployment of the PP-LiteSeg quantization model on A311D. -1. Cross-compile the FastDeploy library as described in [Cross-compile FastDeploy](../../../../../../docs/en/build_and_install/a311d.md#FastDeploy-cross-compilation-library-compilation-based-on-Paddle-Lite) - -2. Copy the compiled library to the current directory. You can run this line: -```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp -``` - -3. Download the model and example images required for deployment in current path. -```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp -mkdir models && mkdir images -wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz -tar -xvf ppliteseg.tar.gz -cp -r ppliteseg models -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp -r cityscapes_demo.png images -``` - -4. Compile the deployment example. You can run the following lines: -```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp -mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=arm64 .. -make -j8 -make install -# After success, an install folder will be created with a running demo and libraries required for deployment. -``` - -5. Deploy the PP-LiteSeg segmentation model to A311D based on adb. You can run the following lines: -```bash -# Go to the install directory. -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp/build/install/ -# The following line represents: bash run_with_adb.sh, demo needed to run, model path, image path, DEVICE ID. -bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -``` - -The output is: - - - -Please note that the model deployed on A311D needs to be quantized. You can refer to [Model Quantization](../../../../../../docs/en/quantize.md). diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/a311d/cpp/README_CN.md deleted file mode 100644 index a9528e940..000000000 --- a/examples/vision/segmentation/paddleseg/a311d/cpp/README_CN.md +++ /dev/null @@ -1,59 +0,0 @@ -[English](README.md) | 简体中文 -# PP-LiteSeg 量化模型 C++ 部署示例 - -本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在 A311D 上的部署推理加速。 - -## 部署准备 -### FastDeploy 交叉编译环境准备 -1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建) - -### 模型准备 -1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 -2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) -3. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 - -更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) - -## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型 -请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型: -1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) - -2. 将编译后的库拷贝到当前目录,可使用如下命令: -```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp -``` - -3. 在当前路径下载部署所需的模型和示例图片: -```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp -mkdir models && mkdir images -wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz -tar -xvf ppliteseg.tar.gz -cp -r ppliteseg models -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp -r cityscapes_demo.png images -``` - -4. 编译部署示例,可使入如下命令: -```bash -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp -mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=arm64 .. -make -j8 -make install -# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 -``` - -5. 基于 adb 工具部署 PP-LiteSeg 分割模型到晶晨 A311D,可使用如下命令: -```bash -# 进入 install 目录 -cd FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp/build/install/ -# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID -bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -``` - -部署成功后运行结果如下: - - - -需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md new file mode 100644 index 000000000..80a85d8da --- /dev/null +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/README.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 + +# PaddleSeg在晶晨NPU上通过FastDeploy部署模型 + +## PaddleSeg支持部署的晶晨芯片型号 +支持如下芯片的部署 +- Amlogic A311D +- Amlogic C308X +- Amlogic S905D3 + +本示例基于晶晨A311D来介绍如何使用FastDeploy部署PaddleSeg模型 + +晶晨A311D是一款先进的AI应用处理器。PaddleSeg支持通过FastDeploy在A311D上基于Paddle-Lite部署相关Segmentation模型 + +>> **注意**:需要注意的是,芯原(verisilicon)作为 IP 设计厂商,本身并不提供实体SoC产品,而是授权其 IP 给芯片厂商,如:晶晨(Amlogic),瑞芯微(Rockchip)等。因此本文是适用于被芯原授权了 NPU IP 的芯片产品。只要芯片产品没有大副修改芯原的底层库,则该芯片就可以使用本文档作为 Paddle Lite 推理部署的参考和教程。在本文中,晶晨 SoC 中的 NPU 和 瑞芯微 SoC 中的 NPU 统称为芯原 NPU。 + +## 晶晨A311D支持的PaddleSeg模型 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前晶晨A311D所支持的PaddleSeg模型如下: +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) + +## 预导出的量化推理模型 +为了方便开发者的测试,下面提供了PaddleSeg导出的部分量化后的推理模型,开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +**注意** +- PaddleSeg量化模型包含`model.pdmodel`、`model.pdiparams`、`deploy.yaml`和`subgraph.txt`四个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,subgraph.txt是为了异构计算而存储的配置文件 +- 若以上列表中无满足要求的模型,可参考下方教程自行导出适配A311D的模型 + +## PaddleSeg动态图模型导出为A311D支持的INT8模型 +模型导出分为以下两步 +1. PaddleSeg训练的动态图模型导出为推理静态图模型,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) +晶晨A311D仅支持INT8 +2. 将推理模型量化压缩为INT8模型,FastDeploy模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) + +## 详细部署文档 + +目前,A311D上只支持C++的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md new file mode 100644 index 000000000..57a71f86f --- /dev/null +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/README.md @@ -0,0 +1,59 @@ +[English](README.md) | 简体中文 +# PP-LiteSeg 量化模型 C++ 部署示例 + +本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-LiteSeg 量化模型在晶晨 A311D 上的部署推理加速。 + +## 部署准备 +### FastDeploy 交叉编译环境准备 +软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +### 模型准备 +1. 用户可以直接使用由[FastDeploy 提供的量化模型](../README_CN.md#晶晨a311d支持的paddleseg模型)进行部署。 +2. 若FastDeploy没有提供满足要求的量化模型,用户可以参考[PaddleSeg动态图模型导出为A311D支持的INT8模型](../README_CN.md#paddleseg动态图模型导出为a311d支持的int8模型)自行导出或训练量化模型 +3. 若上述导出或训练的模型出现精度下降或者报错,则需要使用异构计算,使得模型算子部分跑在A311D的ARM CPU上进行调试以及精度验证,其中异构计算所需的文件是subgraph.txt。具体关于异构计算可参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md)。 + +## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型 +请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型: + +1. 将编译后的库拷贝到当前目录,可使用如下命令: +```bash +cp -r FastDeploy/build/fastdeploy-timvx/ path/to/paddleseg/amlogic/a311d/cpp +``` + +2. 在当前路径下载部署所需的模型和示例图片: +```bash +cd path/to/paddleseg/amlogic/a311d/cpp +mkdir models && mkdir images +wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz +tar -xvf ppliteseg.tar.gz +cp -r ppliteseg models +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png +cp -r cityscapes_demo.png images +``` + +3. 编译部署示例,可使入如下命令: +```bash +cd path/to/paddleseg/amlogic/a311d/cpp +mkdir build && cd build +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=arm64 .. +make -j8 +make install +# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 +``` + +4. 基于 adb 工具部署 PP-LiteSeg 分割模型到晶晨 A311D,可使用如下命令: +```bash +# 进入 install 目录 +cd path/to/paddleseg/amlogic/a311d/cpp/build/install/ +cp ../../run_with_adb.sh . +# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID +bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID +``` + +部署成功后运行结果如下: + + + +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/infer.cc old mode 100755 new mode 100644 similarity index 95% rename from examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/infer.cc index 38f5f7168..4d2eb3f29 --- a/examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/infer.cc @@ -24,13 +24,13 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file) { auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; auto subgraph_file = model_dir + sep + "subgraph.txt"; - fastdeploy::vision::EnableFlyCV(); + fastdeploy::vision::EnableFlyCV(); fastdeploy::RuntimeOption option; option.UseTimVX(); option.SetLiteSubgraphPartitionPath(subgraph_file); - + auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file,option); + model_file, params_file, config_file, option); assert(model.Initialized()); diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh b/examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/run_with_adb.sh similarity index 100% rename from examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh rename to examples/vision/segmentation/paddleseg/amlogic/a311d/cpp/run_with_adb.sh diff --git a/examples/vision/segmentation/paddleseg/android/README.md b/examples/vision/segmentation/paddleseg/android/README.md index 0d845f2a0..ad363015b 100644 --- a/examples/vision/segmentation/paddleseg/android/README.md +++ b/examples/vision/segmentation/paddleseg/android/README.md @@ -1,5 +1,5 @@ English | [简体中文](README_CN.md) -# PaddleSeg Android Demo for Target Detection +# PaddleSeg Android Demo for Image Segmentation For real-time portrait segmentation on Android, this demo has good ease of use and openness. You can run your own training model in the demo. @@ -10,7 +10,7 @@ For real-time portrait segmentation on Android, this demo has good ease of use a ## Deployment Steps -1. Target detection PaddleSeg Demo is located in `fastdeploy/examples/vision/segmentation/paddleseg/android` directory. +1. Image Segmentation PaddleSeg Demo is located in `fastdeploy/examples/vision/segmentation/paddleseg/android` directory. 2. Please use Android Studio to open paddleseg/android project. 3. Connect your phone to your computer, turn on USB debugging and file transfer mode, and connect your own mobile device on Android Studio (your phone needs to be enabled to allow software installation from USB). @@ -19,7 +19,7 @@ For real-time portrait segmentation on Android, this demo has good ease of use a

> **Notes:** ->> If you encounter an NDK configuration error during importing, compiling or running the program, please open ` File > Project Structure > SDK Location` and change `Andriod SDK location` to your locally configured SDK path. +>> If you encounter an NDK configuration error during importing, compiling or running the program, please open ` File > Project Structure > SDK Location` and change `Andriod SDK location` to your locally configured SDK path. 4. Click the Run button to automatically compile the APP and install it to your phone. (The process will automatically download the pre-compiled FastDeploy Android library and model files, internet connection required.) The success interface is as follows. Figure 1: Install APP on phone; Figure 2: The opening interface, it will automatically recognize the person in the picture and draw the mask; Figure 3: APP setting options, click setting in the upper right corner, and you can set different options. @@ -159,11 +159,11 @@ model.init(modelFile, paramFile, configFile, option); For details, please refer to [SegmentationMainActivity](./app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationMainActivity.java). ## Replace FastDeploy SDK and model - Steps to replace the FastDeploy prediction libraries and model are very simple. The location of the prediction library is `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` indicates the version of the prediction library you are currently using. The location of the model is, `app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`. + Steps to replace the FastDeploy prediction libraries and model are very simple. The location of the prediction library is `app/libs/fastdeploy-android-sdk-xxx.aar`, where `xxx` indicates the version of the prediction library you are currently using. The location of the model is, `app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`. - Replace FastDeploy Android SDK: Download or compile the latest FastDeploy Android SDK, unzip it and put it in the `app/libs` directory. For details please refer to: - - [Use FastDeploy Java SDK on Android](../../../../../java/android/) + - [Use FastDeploy Java SDK on Android](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) -- Steps for replacing the PaddleSeg model. +- Steps for replacing the PaddleSeg model. - Put your PaddleSeg model in `app/src/main/assets/models`; - Modify the model path in `app/src/main/res/values/strings.xml`, such as: ```xml @@ -173,5 +173,5 @@ For details, please refer to [SegmentationMainActivity](./app/src/main/java/com/ ## Other Documenets If you are interested in more FastDeploy Java API documents and how to access the FastDeploy C++ API via JNI, you can refer to the following: -- [Use FastDeploy Java SDK on Android](../../../../../java/android/) -- [Use FastDeploy C++ SDK on Android](../../../../../docs/en/faq/use_cpp_sdk_on_android.md) +- [Use FastDeploy Java SDK on Android](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) +- [Use FastDeploy C++ SDK on Android](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/segmentation/paddleseg/android/README_CN.md b/examples/vision/segmentation/paddleseg/android/README_CN.md index eb683bdfa..1414e8ae9 100644 --- a/examples/vision/segmentation/paddleseg/android/README_CN.md +++ b/examples/vision/segmentation/paddleseg/android/README_CN.md @@ -1,5 +1,5 @@ [English](README.md) | 简体中文 -# 目标检测 PaddleSeg Android Demo 使用文档 +# 图像分割 PaddleSeg Android Demo 使用文档 在 Android 上实现实时的人像分割功能,此 Demo 有很好的的易用性和开放性,如在 Demo 中跑自己训练好的模型等。 @@ -10,7 +10,7 @@ ## 部署步骤 -1. 目标检测 PaddleSeg Demo 位于 `fastdeploy/examples/vision/segmentation/paddleseg/android` 目录 +1. 图像分割 PaddleSeg Demo 位于 `path/to/paddleseg/android` 目录 2. 用 Android Studio 打开 paddleseg/android 工程 3. 手机连接电脑,打开 USB 调试和文件传输模式,并在 Android Studio 上连接自己的手机设备(手机需要开启允许从 USB 安装软件权限) @@ -161,7 +161,7 @@ model.init(modelFile, paramFile, configFile, option); ## 替换 FastDeploy SDK和模型 替换FastDeploy预测库和模型的步骤非常简单。预测库所在的位置为 `app/libs/fastdeploy-android-sdk-xxx.aar`,其中 `xxx` 表示当前您使用的预测库版本号。模型所在的位置为,`app/src/main/assets/models/portrait_pp_humansegv2_lite_256x144_inference_model`。 - 替换FastDeploy Android SDK: 下载或编译最新的FastDeploy Android SDK,解压缩后放在 `app/libs` 目录下;详细配置文档可参考: - - [在 Android 中使用 FastDeploy Java SDK](../../../../../java/android/) + - [在 Android 中使用 FastDeploy Java SDK](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) - 替换PaddleSeg模型的步骤: - 将您的PaddleSeg模型放在 `app/src/main/assets/models` 目录下; @@ -173,5 +173,5 @@ model.init(modelFile, paramFile, configFile, option); ## 更多参考文档 如果您想知道更多的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) +- [在 Android 中使用 FastDeploy Java SDK](https://github.com/PaddlePaddle/FastDeploy/tree/develop/java/android) +- [在 Android 中使用 FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_cpp_sdk_on_android.md) diff --git a/examples/vision/segmentation/paddleseg/ascend/README.md b/examples/vision/segmentation/paddleseg/ascend/README.md new file mode 100644 index 000000000..05f4d8348 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/README.md @@ -0,0 +1,51 @@ +[English](README.md) | 简体中文 + +# PaddleSeg利用FastDeploy在华为昇腾上部署模型 + +PaddleSeg支持通过FastDeploy在华为昇腾上部署Segmentation相关模型 + +## 支持的PaddleSeg模型 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前FastDeploy支持如下模型的部署 + +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) + +>>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../ppmatting/)下载对应模型,部署过程与此文档一致 + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 预导出的推理模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [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% | +| [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% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/matting/ppmatting/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/ascend/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/matting/ppmatting/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/ascend/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/ascend/cpp/README.md b/examples/vision/segmentation/paddleseg/ascend/cpp/README.md new file mode 100644 index 000000000..cfa01c663 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/README.md @@ -0,0 +1,38 @@ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 + +本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 + +## 华为昇腾NPU编译FastDeploy环境准备 +在部署前,需自行编译基于华为昇腾NPU的预测库,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../ppmatting/)下载 + +```bash +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp + +mkdir build +cd build +# 使用编译完成的FastDeploy库编译infer_demo +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend +make -j + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# 华为昇腾推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/infer.cc b/examples/vision/segmentation/paddleseg/ascend/cpp/infer.cc similarity index 55% rename from examples/vision/segmentation/paddleseg/quantize/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/ascend/cpp/infer.cc index 158a30263..cf98dae4e 100644 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/ascend/cpp/infer.cc @@ -13,25 +13,28 @@ // limitations under the License. #include "fastdeploy/vision.h" + #ifdef WIN32 const char sep = '\\'; #else const char sep = '/'; #endif -void InitAndInfer(const std::string& model_dir, const std::string& image_file, - const fastdeploy::RuntimeOption& option) { +void AscendInfer(const std::string& model_dir, const std::string& image_file) { auto model_file = model_dir + sep + "model.pdmodel"; auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; - + auto option = fastdeploy::RuntimeOption(); + option.UseAscend(); auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file,option); + model_file, params_file, config_file, option); - assert(model.Initialized()); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::SegmentationResult res; if (!model.Predict(im, &res)) { @@ -40,37 +43,20 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, } std::cout << res.Str() << std::endl; - + auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } - int main(int argc, char* argv[]) { - if (argc < 4) { - std::cout << "Usage: infer_demo path/to/quant_model " - "path/to/image " - "run_option, " - "e.g ./infer_demo ./ResNet50_vd_quant ./test.jpeg 0" - << std::endl; - std::cout << "The data type of run_option is int, 0: run on cpu with ORT " - "backend; 1: run " - "on gpu with TensorRT backend. " - << std::endl; + if (argc < 3) { + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppseg_model_dir ./test.jpeg" + << std::endl; return -1; } - fastdeploy::RuntimeOption option; - int flag = std::atoi(argv[3]); - - if (flag == 0) { - option.UseCpu(); - option.UseOrtBackend(); - } else if (flag == 1) { - option.UseCpu(); - option.UsePaddleInferBackend(); - } - - std::string model_dir = argv[1]; - std::string test_image = argv[2]; - InitAndInfer(model_dir, test_image, option); + AscendInfer(argv[1], argv[2]); return 0; -} \ No newline at end of file +} diff --git a/examples/vision/segmentation/paddleseg/ascend/python/README.md b/examples/vision/segmentation/paddleseg/ascend/python/README.md new file mode 100644 index 000000000..ee11ea7b9 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/python/README.md @@ -0,0 +1,36 @@ +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 + +本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 + +## 华为昇腾NPU编译FastDeploy wheel包环境准备 +在部署前,需自行编译基于华为昇腾NPU的FastDeploy python wheel包并安装,参考文档[华为昇腾NPU部署环境编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../ppmatting)下载 + + +```bash +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# 华为昇腾推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/ascend/python/infer.py b/examples/vision/segmentation/paddleseg/ascend/python/infer.py new file mode 100755 index 000000000..180f30e80 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/ascend/python/infer.py @@ -0,0 +1,34 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model", required=True, help="Path of PaddleSeg model.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + return parser.parse_args() + + +runtime_option = fd.RuntimeOption() +runtime_option.use_ascend() + +# 配置runtime,加载模型 +model_file = os.path.join(args.model, "model.pdmodel") +params_file = os.path.join(args.model, "model.pdiparams") +config_file = os.path.join(args.model, "deploy.yaml") +model = fd.vision.segmentation.PaddleSegModel( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片分割结果 +im = cv2.imread(args.image) +result = model.predict(im) +print(result) + +# 可视化结果 +vis_im = fd.vision.vis_segmentation(im, result, weight=0.5) +cv2.imwrite("vis_img.png", vis_im) diff --git a/examples/vision/segmentation/paddleseg/cpp/README.md b/examples/vision/segmentation/paddleseg/cpp/README.md deleted file mode 100755 index 572e38078..000000000 --- a/examples/vision/segmentation/paddleseg/cpp/README.md +++ /dev/null @@ -1,98 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example - -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. 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) - -【Attention】For the deployment of **PP-Matting**、**PP-HumanMatting** and **ModNet**, refer to [Matting Model Deployment](../../../matting) - -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 -# 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 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 inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 0 -# GPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 1 -# TensorRT inference on GPU -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2 -# kunlunxin XPU inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3 -# Huawei Ascend Inference -./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 4 -``` - -The visualized result after running is as follows -
- -
- -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) - -## PaddleSeg C++ Interface - -### PaddleSeg Class - -```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 loading and initialization, among which model_file is the exported Paddle model format. - -**Parameter** - -> * **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 Function - -> ```c++ -> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **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): For PP-HumanSeg models, the input image is portrait, height greater than a 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) - -- [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 deleted file mode 100644 index df99e324e..000000000 --- a/examples/vision/segmentation/paddleseg/cpp/README_CN.md +++ /dev/null @@ -1,101 +0,0 @@ -[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/README_CN.md b/examples/vision/segmentation/paddleseg/cpu-gpu/README.md similarity index 78% rename from examples/vision/segmentation/paddleseg/README_CN.md rename to examples/vision/segmentation/paddleseg/cpu-gpu/README.md index 0b0cda349..b126e9ddb 100644 --- a/examples/vision/segmentation/paddleseg/README_CN.md +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/README.md @@ -1,27 +1,32 @@ -# PaddleSeg 模型部署 +[English](README.md) | 简体中文 + +# PaddleSeg模型高性能全场景部署方案-FastDeploy + +PaddleSeg支持利用FastDeploy在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)硬件上部署Segmentation模型 ## 模型版本说明 -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 -目前FastDeploy支持如下模型的部署 +目前FastDeploy支持如下模型的部署 -- [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系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../matting) +>>**注意** 如部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../ppmatting) ## 准备PaddleSeg部署模型 - PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) **注意** - PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 -## 下载预训练模型 +## 预导出的推理模型 为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 - without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` @@ -40,6 +45,7 @@ PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.co | [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% | | [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% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | ## 详细部署文档 diff --git a/examples/vision/segmentation/paddleseg/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/paddleseg/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/cpu-gpu/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md new file mode 100644 index 000000000..2c1f54e9a --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/README.md @@ -0,0 +1,59 @@ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 + +本目录下提供`infer.cc`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过Paddle-TensorRT加速部署的示例。 + +## 部署环境准备 + +在部署前,需确认软硬件环境,同时下载预编译部署库,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) + +>> **注意** 如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../ppmatting) + +以Linux上推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.0以上(x.x.x>=1.0.0) + +```bash +#下载部署示例代码 +cd path/to/paddleseg/cpp-gpu/cpp + +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-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + + +# CPU推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 0 +# GPU推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 1 +# GPU上Paddle-TensorRT推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png 2 +``` + +运行完成可视化结果如下图所示 +
+ +
+ +> **注意:** +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/use_sdk_on_windows.md) + +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) + +## 常见问题 +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/segmentation/paddleseg/cpp/infer.cc b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc old mode 100755 new mode 100644 similarity index 65% rename from examples/vision/segmentation/paddleseg/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc index ae97c0406..af79d3204 --- a/examples/vision/segmentation/paddleseg/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/cpp/infer.cc @@ -48,34 +48,6 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file) { std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void KunlunXinInfer(const std::string& model_dir, const std::string& image_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - auto option = fastdeploy::RuntimeOption(); - option.UseKunlunXin(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file, option); - - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - - fastdeploy::vision::SegmentationResult res; - if (!model.Predict(im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - - std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; -} - void GpuInfer(const std::string& model_dir, const std::string& image_file) { auto model_file = model_dir + sep + "model.pdmodel"; auto params_file = model_dir + sep + "model.pdiparams"; @@ -113,35 +85,14 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file) { auto option = fastdeploy::RuntimeOption(); option.UseGpu(); option.UseTrtBackend(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file, option); + // If use original Tensorrt, not Paddle-TensorRT, + // comment the following two lines + option.EnablePaddleToTrt(); + option.EnablePaddleTrtCollectShape(); + option.SetTrtInputShape("x", {1, 3, 256, 256}, {1, 3, 1024, 1024}, + {1, 3, 2048, 2048}) - if (!model.Initialized()) { - std::cerr << "Failed to initialize." << std::endl; - return; - } - - auto im = cv::imread(image_file); - - fastdeploy::vision::SegmentationResult res; - if (!model.Predict(im, &res)) { - std::cerr << "Failed to predict." << std::endl; - return; - } - - std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; -} - -void AscendInfer(const std::string& model_dir, const std::string& image_file) { - auto model_file = model_dir + sep + "model.pdmodel"; - auto params_file = model_dir + sep + "model.pdiparams"; - auto config_file = model_dir + sep + "deploy.yaml"; - auto option = fastdeploy::RuntimeOption(); - option.UseAscend(); - auto model = fastdeploy::vision::segmentation::PaddleSegModel( + auto model = fastdeploy::vision::segmentation::PaddleSegModel( model_file, params_file, config_file, option); if (!model.Initialized()) { @@ -170,7 +121,8 @@ int main(int argc, char* argv[]) { "e.g ./infer_model ./ppseg_model_dir ./test.jpeg 0" << std::endl; std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " - "with gpu; 2: run with gpu and use tensorrt backend; 3: run with kunlunxin." + "with gpu; 2: run with gpu and use tensorrt backend; 3: run " + "with kunlunxin." << std::endl; return -1; } @@ -181,10 +133,6 @@ int main(int argc, char* argv[]) { GpuInfer(argv[1], argv[2]); } else if (std::atoi(argv[3]) == 2) { TrtInfer(argv[1], argv[2]); - } else if (std::atoi(argv[3]) == 3) { - KunlunXinInfer(argv[1], argv[2]); - } else if (std::atoi(argv[3]) == 4) { - AscendInfer(argv[1], argv[2]); } return 0; } diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md new file mode 100644 index 000000000..12d7c7eb1 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/README.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 +本目录下提供`infer.py`快速完成PP-LiteSeg在CPU/GPU,以及GPU上通过Paddle-TensorRT加速部署的示例。执行如下脚本即可完成 + +## 部署环境准备 + +在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) + +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../ppmatting) + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/cpu-gpu/python + +# 下载Unet模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# CPU推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu +# GPU推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu +# GPU上使用Paddle-TensorRT推理 (注意:Paddle-TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/segmentation/paddleseg/python/infer.py b/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py similarity index 89% rename from examples/vision/segmentation/paddleseg/python/infer.py rename to examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py index 6862330ed..d90f6eb4c 100755 --- a/examples/vision/segmentation/paddleseg/python/infer.py +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/python/infer.py @@ -30,14 +30,12 @@ def build_option(args): if args.device.lower() == "gpu": option.use_gpu() - if args.device.lower() == "kunlunxin": - option.use_kunlunxin() - - if args.device.lower() == "ascend": - option.use_ascend() - if args.use_trt: option.use_trt_backend() + # If use original Tensorrt, not Paddle-TensorRT, + # comment the following two lines + option.enable_paddle_to_trt() + option.enable_paddle_trt_collect_shape() option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024], [1, 3, 2048, 2048]) return option diff --git a/examples/vision/segmentation/paddleseg/kunlun/README.md b/examples/vision/segmentation/paddleseg/kunlun/README.md new file mode 100644 index 000000000..305ce688c --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/README.md @@ -0,0 +1,63 @@ +[English](README.md) | 简体中文 + +# PaddleSeg利用FastDeploy在昆仑芯上部署模型 + +## PaddleSeg支持部署的昆仑芯的芯片型号 +支持如下芯片的部署 +- 昆仑 818-100(推理芯片) +- 昆仑 818-300(训练芯片) + +支持如下芯片的设备 +- K100/K200 昆仑 AI 加速卡 +- R200 昆仑芯 AI 加速卡 + + +PaddleSeg支持利用FastDeploy在昆仑芯片上部署Segmentation模型 + +## 模型版本说明 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前FastDeploy支持如下模型的部署 + +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) + +>>**注意** 若需要在华为昇腾上部署**PP-Matting**、**PP-HumanMatting**请从[Matting模型部署](../../ppmating/)下载对应模型,部署过程与此文档一致 + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 预导出的推理模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入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% | +| [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% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | + +## 详细部署文档 + +- [Python部署](python) +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt similarity index 91% rename from examples/vision/segmentation/paddleseg/quantize/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt index fea1a2888..93540a7e8 100644 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/CMakeLists.txt +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/CMakeLists.txt @@ -1,5 +1,5 @@ PROJECT(infer_demo C CXX) -CMAKE_MINIMUM_REQUIRED (VERSION 3.12) +CMAKE_MINIMUM_REQUIRED (VERSION 3.10) # 指定下载解压后的fastdeploy库路径 option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md b/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md new file mode 100644 index 000000000..b85e3874e --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/README.md @@ -0,0 +1,39 @@ +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 + +本目录下提供`infer.cc`快速完成PP-LiteSeg在华为昇腾上部署的示例。 + +## 昆仑芯XPU编译FastDeploy环境准备 +在部署前,需自行编译基于昆仑芯XPU的预测库,参考文档[昆仑芯XPU部署环境编译安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../matting)下载 + +```bash +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp + +mkdir build +cd build +# 使用编译完成的FastDeploy库编译infer_demo +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-ascend +make -j + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# 华为昇腾推理 +./infer_demo PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer cityscapes_demo.png +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## 快速链接 +how_to_change_backend.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) diff --git a/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc b/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc new file mode 100644 index 000000000..c695cd732 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/cpp/infer.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "fastdeploy/vision.h" + +#ifdef WIN32 +const char sep = '\\'; +#else +const char sep = '/'; +#endif + +void KunlunXinInfer(const std::string& model_dir, + const std::string& image_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto config_file = model_dir + sep + "deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseKunlunXin(); + auto model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file, option); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::SegmentationResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + std::cout << res.Str() << std::endl; + auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppseg_model_dir ./test.jpeg" + << std::endl; + return -1; + } + KunlunXinInfer(argv[1], argv[2]); + return 0; +} diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/README.md b/examples/vision/segmentation/paddleseg/kunlun/python/README.md new file mode 100644 index 000000000..aee36bffe --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/python/README.md @@ -0,0 +1,37 @@ +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 + +本目录下提供`infer.py`快速完成PP-LiteSeg在华为昇腾上部署的示例。 + +## 昆仑XPU编译FastDeploy wheel包环境准备 + +在部署前,需自行编译基于昆仑XPU的FastDeploy python wheel包并安装,参考文档[昆仑芯XPU部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) + +>>**注意** **PP-Matting**、**PP-HumanMatting**的模型,请从[Matting模型部署](../../../ppmatting)下载 + + +```bash +#下载部署示例代码 +cd path/to/paddleseg/ascend/cpp + +# 下载PP-LiteSeg模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +# 华为昇腾推理 +python infer.py --model PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer --image cityscapes_demo.png +``` + +运行完成可视化结果如下图所示 +
+ +
+ +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/kunlun/python/infer.py b/examples/vision/segmentation/paddleseg/kunlun/python/infer.py new file mode 100755 index 000000000..bfbde415f --- /dev/null +++ b/examples/vision/segmentation/paddleseg/kunlun/python/infer.py @@ -0,0 +1,34 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model", required=True, help="Path of PaddleSeg model.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + return parser.parse_args() + + +runtime_option = fd.RuntimeOption() +runtime_option.use_kunlunxin() + +# 配置runtime,加载模型 +model_file = os.path.join(args.model, "model.pdmodel") +params_file = os.path.join(args.model, "model.pdiparams") +config_file = os.path.join(args.model, "deploy.yaml") +model = fd.vision.segmentation.PaddleSegModel( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片分割结果 +im = cv2.imread(args.image) +result = model.predict(im) +print(result) + +# 可视化结果 +vis_im = fd.vision.vis_segmentation(im, result, weight=0.5) +cv2.imwrite("vis_img.png", vis_im) diff --git a/examples/vision/segmentation/paddleseg/python/README.md b/examples/vision/segmentation/paddleseg/python/README.md deleted file mode 100755 index 95885a2f2..000000000 --- a/examples/vision/segmentation/paddleseg/python/README.md +++ /dev/null @@ -1,82 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Python Deployment Example - -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. Install FastDeploy Python whl package. Refer to [FastDeploy Python Installation](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - -【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 - -# 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 inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu -# GPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu -# 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 -# kunlunxin XPU inference -python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin -``` - -The visualized result after running is as follows -
- -
- -## PaddleSegModel Python Interface - -```python -fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) -``` - -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): 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 function - -> ```python -> PaddleSegModel.predict(input_image) -> ``` -> -> Model prediction interface. Input images and output detection results. -> -> **Parameter** -> -> > * **input_image**(np.ndarray): Input data in HWC or BGR format - -> **Return** -> -> > Return `fastdeploy.vision.SegmentationResult` 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 - -> > * **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 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 deleted file mode 100644 index 61edc5b2b..000000000 --- a/examples/vision/segmentation/paddleseg/python/README_CN.md +++ /dev/null @@ -1,86 +0,0 @@ -[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/quantize/README.md b/examples/vision/segmentation/paddleseg/quantize/README.md old mode 100755 new mode 100644 index ab0fa77fc..632772247 --- a/examples/vision/segmentation/paddleseg/quantize/README.md +++ b/examples/vision/segmentation/paddleseg/quantize/README.md @@ -1,37 +1,27 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Quantized Model Deployment -FastDeploy already supports the deployment of quantitative models and provides a tool to automatically compress model with just one click. -You can use the one-click automatical model compression tool to quantify and deploy the models, or directly download the quantified models provided by FastDeploy for deployment. +[English](README.md) | 简体中文 +# PaddleSeg 量化模型部署 +FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. +用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. -## FastDeploy One-Click Automation Model Compression Tool -FastDeploy provides an one-click automatical model compression tool that can quantify a model simply by entering configuration file. -For details, please refer to [one-click automatical compression tool](../../../../../tools/common_tools/auto_compression/). -Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder. +## FastDeploy一键模型自动化压缩工具 +FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. +详细教程请见: [一键模型自动化压缩工具](https://github.com/PaddlePaddle/FastDeploy/tree/develop/tools/common_tools/auto_compression) +>> **注意**: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 -## Download the Quantized PaddleSeg Model -You can also directly download the quantized models in the following table for deployment (click model name to download). +## 量化完成的PaddleSeg模型 +用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) -Note: -- Runtime latency is the inference latency of the model on various Runtimes, including CPU->GPU data copy, GPU inference, and GPU->CPU data copy time. It does not include the respective pre and post processing time of the models. -- The end-to-end latency is the latency of the model in the actual inference scenario, including the pre and post processing of the model. -- The measured latencies are averaged over 1000 inferences, in milliseconds. -- INT8 + FP16 is to enable the FP16 inference option for Runtime while inferring the INT8 quantization model. -- INT8 + FP16 + PM is the option to use Pinned Memory while inferring INT8 quantization model and turning on FP16, which can speed up the GPU->CPU data copy speed. -- The maximum speedup ratio is obtained by dividing the FP32 latency by the fastest INT8 inference latency. -- The strategy is quantitative distillation training, using a small number of unlabeled data sets to train the quantitative model, and verify the accuracy on the full validation set, INT8 accuracy does not represent the highest INT8 accuracy. -- The CPU is Intel(R) Xeon(R) Gold 6271C with a fixed CPU thread count of 1 in all tests. The GPU is Tesla T4, TensorRT version 8.4.15. +| 模型 | 量化方式 | +|:----- | :-- | +| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) |量化蒸馏训练 | -#### Runtime Benchmark -| Model |Inference Backends | Hardware | FP32 Runtime Latency | INT8 Runtime Latency | INT8 + FP16 Runtime Latency | INT8+FP16+PM Runtime Latency | Max Speedup | FP32 mIoU | INT8 mIoU | Method | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 1138.04| 602.62 |None|None | 1.89 |77.37 | 71.62 |Quantaware Distillation Training | +量化后模型的Benchmark比较,请参考[量化模型 Benchmark](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/quantize.md) -#### End to End Benchmark -| Model |Inference Backends | Hardware | FP32 End2End Latency | INT8 End2End Latency | INT8 + FP16 End2End Latency | INT8+FP16+PM End2End Latency | Max Speedup | FP32 mIoU | INT8 mIoU | Method | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 4726.65| 4134.91|None|None | 1.14 |77.37 | 71.62 |Quantaware Distillation Training| +## 支持部署量化模型的硬件 +FastDeploy 量化模型部署的过程大致都与FP32模型类似,只是模型量化与非量化的区别,如果硬件在量化模型部署过程有特殊处理,也会在文档中特别标明,因此量化模型部署可以参考如下硬件的链接 -## Detailed Deployment Documents - -- [Python Deployment](python) -- [C++ Deployment](cpp) +| 硬件支持列表 | | | | +|:----- | :-- | :-- | :-- | +| [NVIDIA GPU](cpu-gpu) | [X86 CPU](cpu-gpu)| [飞腾CPU](cpu-gpu) | [ARM CPU](cpu-gpu) | +| [Intel GPU(独立显卡/集成显卡)](cpu-gpu) | [昆仑](kunlun) | [昇腾](ascend) | [瑞芯微](rockchip) | +| [晶晨](amlogic) | [算能](sophgo) | diff --git a/examples/vision/segmentation/paddleseg/quantize/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/README_CN.md deleted file mode 100644 index a35f1d99d..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/README_CN.md +++ /dev/null @@ -1,37 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 量化模型部署 -FastDeploy已支持部署量化模型,并提供一键模型自动化压缩的工具. -用户可以使用一键模型自动化压缩工具,自行对模型量化后部署, 也可以直接下载FastDeploy提供的量化模型进行部署. - -## FastDeploy一键模型自动化压缩工具 -FastDeploy 提供了一键模型自动化压缩工具, 能够简单地通过输入一个配置文件, 对模型进行量化. -详细教程请见: [一键模型自动化压缩工具](../../../../../tools/common_tools/auto_compression/) -注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。 - -## 下载量化完成的PaddleSeg模型 -用户也可以直接下载下表中的量化模型进行部署.(点击模型名字即可下载) - -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 mIoU | INT8 mIoU | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 1138.04| 602.62 |None|None | 1.89 |77.37 | 71.62 |量化蒸馏训练 | - -#### 端到端 Benchmark -| 模型 |推理后端 |部署硬件 | FP32 End2End时延 | INT8 End2End时延 | INT8 + FP16 End2End时延 | INT8+FP16+PM End2End时延 | 最大加速比 | FP32 mIoU | INT8 mIoU | 量化方式 | -| ------------------- | -----------------|-----------| -------- |-------- |-------- | --------- |-------- |----- |----- |----- | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT_new.tar) | Paddle Inference | CPU | 4726.65| 4134.91|None|None | 1.14 |77.37 | 71.62 |量化蒸馏训练 | - -## 详细部署文档 - -- [Python部署](python) -- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/README.md b/examples/vision/segmentation/paddleseg/quantize/cpp/README.md deleted file mode 100755 index 9eb7c9146..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/README.md +++ /dev/null @@ -1,32 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Quantitative Model C++ Deployment Example - `infer.cc` in this directory can help you quickly complete the inference acceleration of PaddleSeg quantization model deployment on CPU. - -## Deployment Preparations -### FastDeploy Environment Preparations -- 1. For the software and hardware requirements, please refer to [FastDeploy Environment Requirements](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md). -- 2. For the installation of FastDeploy Python whl package, please refer to [FastDeploy Python Installation](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md). - -### Quantized Model Preparations -- 1. You can directly use the quantized model provided by FastDeploy for deployment. -- 2. You can use [one-click automatical compression tool](../../../../../../tools/common_tools/auto_compression/) provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) - -## Take the Quantized PP_LiteSeg_T_STDC1_cityscapes Model as an example for Deployment -Run the following commands in this directory to compile and deploy the quantized model. FastDeploy version 0.7.0 or higher is required (x.x.x>=0.7.0). -```bash -mkdir build -cd build -# Download pre-compiled FastDeploy libraries. You can choose the appropriate version from `pre-compiled FastDeploy libraries` 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 PP_LiteSeg_T_STDC1_cityscapes quantized model and test images provided by FastDeloy. -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# Use Paddle-Inference inference quantization model on CPU. -./infer_demo PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ cityscapes_demo.png 1 -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md deleted file mode 100644 index c4cde0b1f..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/cpp/README_CN.md +++ /dev/null @@ -1,32 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 量化模型 C++部署示例 -本目录下提供的`infer.cc`,可以帮助用户快速完成PaddleSeg量化模型在CPU上的部署推理加速. - -## 部署准备 -### FastDeploy环境准备 -- 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. 用户可以直接使用由FastDeploy提供的量化模型进行部署. -- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) - -## 以量化后的PP_LiteSeg_T_STDC1_cityscapes模型为例, 进行部署 -在本目录执行如下命令即可完成编译,以及量化模型部署.支持此模型需保证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 - -# 下载FastDeloy提供的PP_LiteSeg_T_STDC1_cityscapes量化模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 在CPU上使用Paddle-Inference推理量化模型 -./infer_demo PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ cityscapes_demo.png 1 -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/python/README.md b/examples/vision/segmentation/paddleseg/quantize/python/README.md deleted file mode 100755 index 5607e1a80..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/python/README.md +++ /dev/null @@ -1,29 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Quantitative Model Python Deployment Example - `infer.py` in this directory can help you quickly complete the inference acceleration of PaddleSeg quantization model deployment on CPU/GPU. - -## Deployment Preparations -### FastDeploy Environment Preparations -- 1. For the software and hardware requirements, please refer to [FastDeploy Environment Requirements](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) -- 2. For the installation of FastDeploy Python whl package, please refer to [FastDeploy Python Installation](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) - -### Quantized Model Preparations -- 1. You can directly use the quantized model provided by FastDeploy for deployment. -- 2. You can use [one-click automatical compression tool](../../../../../../tools/common_tools/auto_compression/) provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) - - -## Take the Quantized PP_LiteSeg_T_STDC1_cityscapes Model as an example for Deployment -```bash -# Download sample deployment code. -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/segmentation/paddleseg/quantize/python - -# Download the PP_LiteSeg_T_STDC1_cityscapes quantized model and test images provided by FastDeloy. -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# Use Paddle-Inference inference quantization model on CPU. -python infer.py --model PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT --image cityscapes_demo.png --device cpu --backend paddle - -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/python/README_CN.md b/examples/vision/segmentation/paddleseg/quantize/python/README_CN.md deleted file mode 100644 index 1975a84fe..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/python/README_CN.md +++ /dev/null @@ -1,29 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 量化模型 Python部署示例 -本目录下提供的`infer.py`,可以帮助用户快速完成PaddleSeg量化模型在CPU/GPU上的部署推理加速. - -## 部署准备 -### FastDeploy环境准备 -- 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. 用户可以直接使用由FastDeploy提供的量化模型进行部署. -- 2. 用户可以使用FastDeploy提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的deploy.yaml文件, 自行量化的模型文件夹内不包含此yaml文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) - - -## 以量化后的PP_LiteSeg_T_STDC1_cityscapes模型为例, 进行部署 -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/segmentation/paddleseg/quantize/python - -# 下载FastDeloy提供的PP_LiteSeg_T_STDC1_cityscapes量化模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -tar -xvf PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_PTQ.tar -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 在CPU上使用Paddle-Inference推理量化模型 -python infer.py --model PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer_QAT --image cityscapes_demo.png --device cpu --backend paddle - -``` diff --git a/examples/vision/segmentation/paddleseg/quantize/python/infer.py b/examples/vision/segmentation/paddleseg/quantize/python/infer.py deleted file mode 100644 index 85a875c1e..000000000 --- a/examples/vision/segmentation/paddleseg/quantize/python/infer.py +++ /dev/null @@ -1,76 +0,0 @@ -import fastdeploy as fd -import cv2 -import os - - -def parse_arguments(): - import argparse - import ast - parser = argparse.ArgumentParser() - parser.add_argument( - "--model", required=True, help="Path of PaddleSeg model.") - parser.add_argument( - "--image", required=True, help="Path of test image file.") - parser.add_argument( - "--device", - type=str, - default='cpu', - help="Type of inference device, support 'cpu' or 'gpu'.") - parser.add_argument( - "--backend", - type=str, - default="default", - help="Type of inference backend, support ort/trt/paddle/openvino, default 'openvino' for cpu, 'tensorrt' for gpu" - ) - parser.add_argument( - "--device_id", - type=int, - default=0, - help="Define which GPU card used to run model.") - parser.add_argument( - "--cpu_thread_num", - type=int, - default=9, - help="Number of threads while inference on CPU.") - return parser.parse_args() - - -def build_option(args): - option = fd.RuntimeOption() - if args.device.lower() == "gpu": - option.use_gpu(0) - - option.set_cpu_thread_num(args.cpu_thread_num) - - if args.backend.lower() == "trt": - assert args.device.lower( - ) == "gpu", "TensorRT backend require inferences on device GPU." - option.use_trt_backend() - option.set_trt_cache_file(os.path.join(args.model, "model.trt")) - option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024], - [1, 3, 2048, 2048]) - elif args.backend.lower() == "ort": - option.use_ort_backend() - elif args.backend.lower() == "paddle": - option.use_paddle_infer_backend() - elif args.backend.lower() == "openvino": - assert args.device.lower( - ) == "cpu", "OpenVINO backend require inference on device CPU." - option.use_openvino_backend() - return option - - -args = parse_arguments() - -# 配置runtime,加载模型 -runtime_option = build_option(args) -model_file = os.path.join(args.model, "model.pdmodel") -params_file = os.path.join(args.model, "model.pdiparams") -config_file = os.path.join(args.model, "deploy.yaml") -model = fd.vision.segmentation.PaddleSegModel( - model_file, params_file, config_file, runtime_option=runtime_option) - -# 预测图片检测结果 -im = cv2.imread(args.image) -result = model.predict(im) -print(result) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/README.md b/examples/vision/segmentation/paddleseg/rknpu2/README.md deleted file mode 100644 index 40606fee0..000000000 --- a/examples/vision/segmentation/paddleseg/rknpu2/README.md +++ /dev/null @@ -1,34 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Model Deployment - -## Model Version - -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) - -Currently FastDeploy using RKNPU2 to infer PPSeg supports the following model deployments: - -| Model | Parameter File Size | Input Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------------------------------------------------------------------------------------|:-------|:---------|:-------|:------------|:---------------| -| [Unet-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | -| [PP-HumanSegV1-Lite(Universal portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -| [PP-HumanSegV2-Lite(Universal portrait segmentation model)](https://bj.bcebos.com/paddle2onnx/libs/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile(Universal portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -| [PP-HumanSegV1-Server(Universal portrait segmentation model)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2_Lite(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](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | -| [Deeplabv3-ResNet101-OS8-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | - -## Prepare PaddleSeg Deployment Model and Conversion Model -RKNPU needs to convert the Paddle model to RKNN model before deploying, the steps are as follows: -* For the conversion of Paddle dynamic diagram model to ONNX model, please refer to [PaddleSeg Model Export](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/contrib/PP-HumanSeg). -* For the process of converting ONNX model to RKNN model, please refer to [Conversion document](../../../../../docs/en/faq/rknpu2/export.md). - -## An example of Model Conversion - -* [PPHumanSeg](./pp_humanseg_EN.md) - -## Detailed Deployment Document -- [Overall RKNN Deployment Guidance](../../../../../docs/en/faq/rknpu2/rknpu2.md) -- [Deploy with C++](cpp) -- [Deploy with Python](python) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/README_CN.md b/examples/vision/segmentation/paddleseg/rknpu2/README_CN.md deleted file mode 100644 index 7d10f82f2..000000000 --- a/examples/vision/segmentation/paddleseg/rknpu2/README_CN.md +++ /dev/null @@ -1,34 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg 模型部署 - -## 模型版本说明 - -- [PaddleSeg develop](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) - -目前FastDeploy使用RKNPU2推理PPSeg支持如下模型的部署: - -| 模型 | 参数文件大小 | 输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | -|:---------------------------------------------------------------------------------------------------------------------------------------------|:-------|:---------|:-------|:------------|:---------------| -| [Unet-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | -| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | -| [PP-HumanSegV1-Lite(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | -| [PP-HumanSegV2-Lite(通用人像分割模型)](https://bj.bcebos.com/paddle2onnx/libs/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | -| [PP-HumanSegV2-Mobile(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | -| [PP-HumanSegV1-Server(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | -| [Portait-PP-HumanSegV2_Lite(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | -| [FCN-HRNet-W18-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | -| [Deeplabv3-ResNet101-OS8-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | - -## 准备PaddleSeg部署模型以及转换模型 -RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: -* Paddle动态图模型转换为ONNX模型,请参考[PaddleSeg模型导出说明](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/contrib/PP-HumanSeg) -* ONNX模型转换RKNN模型的过程,请参考[转换文档](../../../../../docs/cn/faq/rknpu2/export.md)进行转换。 - -## 模型转换example - -* [PPHumanSeg](./pp_humanseg.md) - -## 详细部署文档 -- [RKNN总体部署教程](../../../../../docs/cn/faq/rknpu2/rknpu2.md) -- [C++部署](cpp) -- [Python部署](python) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README.md b/examples/vision/segmentation/paddleseg/rknpu2/cpp/README.md deleted file mode 100644 index 48c4646e2..000000000 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README.md +++ /dev/null @@ -1,73 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Deployment Examples for C++ - -This directory demonstrates the deployment of PaddleSeg series models on RKNPU2. The following deployment process takes PHumanSeg as an example. - -Before deployment, the following two steps need to be confirmed: - -1. Hardware and software environment meets the requirements. -2. Download the pre-compiled deployment repository or compile the FastDeploy repository from scratch according to the development environment. - -For the above steps, please refer to [How to Build RKNPU2 Deployment Environment](../../../../../../docs/en/build_and_install/rknpu2.md). - -## Generate Basic Directory Files - -The routine consists of the following parts: -```text -. -├── CMakeLists.txt -├── build # Compile Folder -├── image # Folder for images -├── infer_cpu_npu.cc -├── infer_cpu_npu.h -├── main.cc -├── model # Folder for models -└── thirdpartys # Folder for sdk -``` - -First, please build a directory structure -```bash -mkdir build -mkdir images -mkdir model -mkdir thirdpartys -``` - -## Compile - -### Compile and Copy SDK to folder thirdpartys - -Please refer to [How to Build RKNPU2 Deployment Environment](../../../../../../docs/en/build_and_install/rknpu2.md) to compile SDK.After compiling, the fastdeploy-0.0.3 directory will be created in the build directory, please move it to the thirdpartys directory. - -### Copy model and configuration files to folder Model -In the process of Paddle dynamic map model -> Paddle static map model -> ONNX mdoel, ONNX file and the corresponding yaml configuration file will be generated. Please move the configuration file to the folder model. -After converting to RKNN, the model file also needs to be copied to folder model. Run the following command to download and use (the model file is RK3588. RK3568 needs to be [reconverted to PPSeg RKNN model](../README.md)). - -### Prepare Test Images to folder image -```bash -wget https://paddleseg.bj.bcebos.com/dygraph/pp_humanseg_v2/images.zip -unzip -qo images.zip -``` - -### Compile example - -```bash -cd build -cmake .. -make -j8 -make install -``` - -## Running Routines - -```bash -cd ./build/install -./rknpu_test model/Portrait_PP_HumanSegV2_Lite_256x144_infer/ images/portrait_heng.jpg -``` - -## Notes -The input requirement for the model on RKNPU is to use NHWC format, and image normalization will be embedded into the model when converting the RKNN model, so we need to call DisableNormalizeAndPermute(C++) or disable_normalize_and_permute(Python) first when deploying with FastDeploy to disable normalization and data format conversion in the preprocessing stage. - -- [Model Description](../../) -- [Python Deployment](../python) -- [Convert PPSeg and RKNN model](../README.md) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/README.md b/examples/vision/segmentation/paddleseg/rknpu2/python/README.md deleted file mode 100644 index f5b99400f..000000000 --- a/examples/vision/segmentation/paddleseg/rknpu2/python/README.md +++ /dev/null @@ -1,36 +0,0 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Deployment Examples for Python - -Before deployment, the following step need to be confirmed: - -- 1. Hardware and software environment meets the requirements, please refer to [Environment Requirements for FastDeploy](../../../../../../docs/en/build_and_install/rknpu2.md). - -【Note】If you are deploying **PP-Matting**, **PP-HumanMatting** or **ModNet**, please refer to [Matting Model Deployment](../../../../matting/). - -This directory provides `infer.py` for a quick example of PPHumanseg deployment on RKNPU. This can be done by running the following script. - -```bash -# Download the deploying demo code. -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/python - -# Download images. -wget https://paddleseg.bj.bcebos.com/dygraph/pp_humanseg_v2/images.zip -unzip images.zip - -# Inference. -python3 infer.py --model_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn \ - --config_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/deploy.yaml \ - --image images/portrait_heng.jpg -``` - - -## Notes -The input requirement for the model on RKNPU is to use NHWC format, and image normalization will be embedded into the model when converting the RKNN model, so we need to call DisableNormalizeAndPermute(C++) or disable_normalize_and_permute(Python) first when deploying with FastDeploy to disable normalization and data format conversion in the preprocessing stage. - -## Other Documents - -- [PaddleSeg Model Description](..) -- [PaddleSeg C++ Deployment](../cpp) -- [Description of the prediction](../../../../../../docs/api/vision_results/) -- [Convert PPSeg and RKNN model](../README.md) diff --git a/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md new file mode 100644 index 000000000..a536630e3 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/README.md @@ -0,0 +1,65 @@ +[English](README.md) | 简体中文 + +# PaddleSeg利用FastDeploy基于RKNPU2部署Segmentation模型 + +RKNPU2 提供了一个高性能接口来访问 Rockchip NPU,支持如下硬件的部署 +- RK3566/RK3568 +- RK3588/RK3588S +- RV1103/RV1106 + +本示例基于 RV3588 来介绍如何使用 FastDeploy 部署 PaddleSeg 模型 + +## 模型版本说明 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前FastDeploy使用RKNPU2推理PaddleSeg支持如下模型的部署: +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) + +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 + +## 下载预训练模型 + +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` + +开发者可直接下载使用。 + +| 模型 | 参数文件大小 | 输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:----------------|:-------|:---------|:-------|:------------|:---------------| +| [Unet-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz) | 52MB | 1024x512 | 65.00% | 66.02% | 66.89% | +| [PP-LiteSeg-T(STDC1)-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_T_STDC1_cityscapes_without_argmax_infer.tgz) | 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +| [PP-HumanSegV1-Lite(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +| [PP-HumanSegV2-Lite(通用人像分割模型)](https://bj.bcebos.com/paddle2onnx/libs/PP_HumanSegV2_Lite_192x192_infer.tgz) | 12MB | 192x192 | 92.52% | - | - | +| [PP-HumanSegV2-Mobile(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV2_Mobile_192x192_infer.tgz) | 29MB | 192x192 | 93.13% | - | - | +| [PP-HumanSegV1-Server(通用人像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [Portait-PP-HumanSegV2_Lite(肖像分割模型)](https://bj.bcebos.com/paddlehub/fastdeploy/Portrait_PP_HumanSegV2_Lite_256x144_infer.tgz) | 3.6M | 256x144 | 96.63% | - | - | +| [FCN-HRNet-W18-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/FCN_HRNet_W18_cityscapes_without_argmax_infer.tgz) | 37MB | 1024x512 | 78.97% | 79.49% | 79.74% | +| [Deeplabv3-ResNet101-OS8-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet101_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | + +## 准备PaddleSeg部署模型以及转换模型 +RKNPU部署模型前需要将Paddle模型转换成RKNN模型,具体步骤如下: +* PaddleSeg训练模型导出为推理模型,请参考[PaddleSeg模型导出说明](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md),也可以使用上表中的FastDeploy的预导出模型 +* Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) +* ONNX模型转换RKNN模型的过程,请参考[转换文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/export.md)进行转换。 + +上述步骤可参考以下具体示例 + +## 模型转换示例 + +* [PP-HumanSeg](./pp_humanseg.md) + +## 详细部署文档 +- [RKNN总体部署教程](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) +- [C++部署](cpp) +- [Python部署](python) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/CMakeLists.txt similarity index 96% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/CMakeLists.txt index 28161a83d..7fc1f6e22 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/CMakeLists.txt +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/CMakeLists.txt @@ -33,4 +33,4 @@ file(GLOB PADDLETOONNX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddle2 install(PROGRAMS ${PADDLETOONNX_LIBS} DESTINATION lib) file(GLOB RKNPU2_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/rknpu2_runtime/RK3588/lib/*) -install(PROGRAMS ${RKNPU2_LIBS} DESTINATION lib) \ No newline at end of file +install(PROGRAMS ${RKNPU2_LIBS} DESTINATION lib) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md similarity index 75% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md index 309d5f26c..b6d4c18bf 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/README.md @@ -8,7 +8,7 @@ 1. 软硬件环境满足要求 2. 根据开发环境,下载预编译部署库或者从头编译FastDeploy仓库 -以上步骤请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)实现 +以上步骤请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)实现 ## 生成基本目录文件 @@ -37,7 +37,7 @@ mkdir thirdpartys ### 编译并拷贝SDK到thirdpartys文件夹 -请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录,请移动它至thirdpartys目录下. +请参考[RK2代NPU部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-x-x-x目录,请移动它至thirdpartys目录下. ### 拷贝模型文件,以及配置文件至model文件夹 在Paddle动态图模型 -> Paddle静态图模型 -> ONNX模型的过程中,将生成ONNX文件以及对应的yaml配置文件,请将配置文件存放到model文件夹内。 @@ -66,8 +66,11 @@ cd ./build/install ``` ## 注意事项 -RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换。 +RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换 -- [模型介绍](../../) +## 快速链接 +- [FastDeploy部署PaddleSeg模型概览](../../) - [Python部署](../python) - [转换PPSeg RKNN模型文档](../README.md) +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/infer.cc similarity index 87% rename from examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/infer.cc index f80d3fc8f..b501fc899 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/cpp/infer.cc @@ -16,7 +16,8 @@ #include "fastdeploy/vision.h" void ONNXInfer(const std::string& model_dir, const std::string& image_file) { - std::string model_file = model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer.onnx"; + std::string model_file = + model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer.onnx"; std::string params_file; std::string config_file = model_dir + "/deploy.yaml"; auto option = fastdeploy::RuntimeOption(); @@ -43,13 +44,12 @@ void ONNXInfer(const std::string& model_dir, const std::string& image_file) { tc.PrintInfo("PPSeg in ONNX"); cv::imwrite("infer_onnx.jpg", vis_im); - std::cout - << "Visualized result saved in ./infer_onnx.jpg" - << std::endl; + std::cout << "Visualized result saved in ./infer_onnx.jpg" << std::endl; } void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) { - std::string model_file = model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn"; + std::string model_file = + model_dir + "/Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588.rknn"; std::string params_file; std::string config_file = model_dir + "/deploy.yaml"; auto option = fastdeploy::RuntimeOption(); @@ -78,9 +78,7 @@ void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) { tc.PrintInfo("PPSeg in RKNPU2"); cv::imwrite("infer_rknn.jpg", vis_im); - std::cout - << "Visualized result saved in ./infer_rknn.jpg" - << std::endl; + std::cout << "Visualized result saved in ./infer_rknn.jpg" << std::endl; } int main(int argc, char* argv[]) { @@ -93,7 +91,6 @@ int main(int argc, char* argv[]) { } RKNPU2Infer(argv[1], argv[2]); -// ONNXInfer(argv[1], argv[2]); + // ONNXInfer(argv[1], argv[2]); return 0; } - diff --git a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md similarity index 96% rename from examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md index 2b14f6b9d..ede1656df 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg.md @@ -1,8 +1,8 @@ [English](pp_humanseg_EN.md) | 简体中文 -# PPHumanSeg模型部署 +# PP-HumanSeg模型转换示例 ## 转换模型 -下面以Portait-PP-HumanSegV2_Lite(肖像分割模型)为例子,教大家如何转换PPSeg模型到RKNN模型。 +下面以Portait-PP-HumanSegV2_Lite(肖像分割模型)为例子,教大家如何转换PaddleSeg模型到RKNN模型。 ```bash # 下载Paddle2ONNX仓库 @@ -78,4 +78,4 @@ Deploy: - 144 type: Resize - type: Normalize -``` \ No newline at end of file +``` diff --git a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg_EN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg_EN.md similarity index 99% rename from examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg_EN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg_EN.md index 6870d32c7..312b9f7ae 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/pp_humanseg_EN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/pp_humanseg_EN.md @@ -78,4 +78,4 @@ Deploy: - 144 type: Resize - type: Normalize -``` \ No newline at end of file +``` diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md similarity index 66% rename from examples/vision/segmentation/paddleseg/rknpu2/python/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md index b897dc369..7524b6c60 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/python/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/README.md @@ -3,9 +3,9 @@ 在部署前,需确认以下步骤 -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/rknpu2.md) +- 1. 软硬件环境满足要求,RKNPU2环境部署等参考[FastDeploy环境要求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/rknpu2/rknpu2.md) -【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../matting/) +【注意】如你部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../../../../matting/) 本目录下提供`infer.py`快速完成PPHumanseg在RKNPU上部署的示例。执行如下脚本即可完成 @@ -28,9 +28,11 @@ python3 infer.py --model_file ./Portrait_PP_HumanSegV2_Lite_256x144_infer/Portra ## 注意事项 RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时,需要先调用DisableNormalizeAndPermute(C++)或`disable_normalize_and_permute(Python),在预处理阶段禁用归一化以及数据格式的转换。 -## 其它文档 +## 快速链接 -- [PaddleSeg 模型介绍](..) +- [FastDeploy部署PaddleSeg模型概览](..) - [PaddleSeg C++部署](../cpp) -- [模型预测结果说明](../../../../../../docs/api/vision_results/) -- [转换PPSeg RKNN模型文档](../README.md) +- [转换PaddleSeg模型至RKNN模型文档](../README_CN.md#准备paddleseg部署模型以及转换模型) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py b/examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/infer.py similarity index 100% rename from examples/vision/segmentation/paddleseg/rknpu2/python/infer.py rename to examples/vision/segmentation/paddleseg/rockchip/rknpu2/python/infer.py diff --git a/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md new file mode 100644 index 000000000..e03960f09 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/README.md @@ -0,0 +1,45 @@ +[English](README.md) | 简体中文 +# PaddleSeg在瑞芯微NPU上通过FastDeploy部署模型 + +## PaddleSeg支持部署的瑞芯微的芯片型号 +支持如下芯片的部署 +- Rockchip RV1109 +- Rockchip RV1126 +- Rockchip RK1808 + +>> **注意**:需要注意的是,芯原(verisilicon)作为 IP 设计厂商,本身并不提供实体SoC产品,而是授权其 IP 给芯片厂商,如:晶晨(Amlogic),瑞芯微(Rockchip)等。因此本文是适用于被芯原授权了 NPU IP 的芯片产品。只要芯片产品没有大副修改芯原的底层库,则该芯片就可以使用本文档作为 Paddle Lite 推理部署的参考和教程。在本文中,晶晨 SoC 中的 NPU 和 瑞芯微 SoC 中的 NPU 统称为芯原 NPU。 +瑞芯微 RV1126 是一款编解码芯片,专门面相人工智能的机器视觉领域。 + +本示例基于RV1126来介绍如何使用FastDeploy部署PaddleSeg模型 + +PaddleSeg支持通过FastDeploy在RV1126上基于Paddle-Lite部署相关Segmentation模型 + +## 瑞芯微 RV1126支持的PaddleSeg模型 + +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 + +目前瑞芯微 RV1126 的 NPU 支持的量化模型如下: +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) + +## 预导出的量化推理模型 +为了方便开发者的测试,下面提供了PaddleSeg导出的部分量化后的推理模型,开发者可直接下载使用。 + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | +**注意** +- PaddleSeg量化模型包含`model.pdmodel`、`model.pdiparams`、`deploy.yaml`和`subgraph.txt`四个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,subgraph.txt是为了异构计算而存储的配置文件 +- 若以上列表中无满足要求的模型,可参考下方教程自行导出适配A311D的模型 + +## PaddleSeg动态图模型导出为RV1126支持的INT8模型 +模型导出分为以下两步 +1. PaddleSeg训练的动态图模型导出为推理静态图模型,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) +瑞芯微RV1126仅支持INT8 +2. 将推理模型量化压缩为INT8模型,FastDeploy模型量化的方法及一键自动化压缩工具可以参考[模型量化](../../../quantize/README.md) + +## 详细部署文档 + +目前,瑞芯微 RV1126 上只支持C++的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/CMakeLists.txt similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/CMakeLists.txt rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/CMakeLists.txt diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md similarity index 53% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/README_CN.md rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md index 15c1f273e..aacad9ab1 100644 --- a/examples/vision/segmentation/paddleseg/rv1126/cpp/README_CN.md +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/README.md @@ -5,22 +5,20 @@ ## 部署准备 ### FastDeploy 交叉编译环境准备 -1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建) +软硬件环境满足要求,以及交叉编译环境的准备,请参考:[瑞芯微RV1126部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#自行编译安装) ### 模型准备 -1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 -2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.) -3. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。 - -更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) +1. 用户可以直接使用由[FastDeploy 提供的量化模型](../README_CN.md#瑞芯微-rv1126-支持的paddleseg模型)进行部署。 +2. 若FastDeploy没有提供满足要求的量化模型,用户可以参考[PaddleSeg动态图模型导出为RV1126支持的INT8模型](../README_CN.md#paddleseg动态图模型导出为rv1126支持的int8模型)自行导出或训练量化模型 +3. 若上述导出或训练的模型出现精度下降或者报错,则需要使用异构计算,使得模型算子部分跑在RV1126的ARM CPU上进行调试以及精度验证,其中异构计算所需的文件是subgraph.txt。具体关于异构计算可参考:[异构计算](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md)。 ## 在 RV1126 上部署量化后的 PP-LiteSeg 分割模型 请按照以下步骤完成在 RV1126 上部署 PP-LiteSeg 量化模型: -1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/rv1126.md#基于-paddlelite-的-fastdeploy-交叉编译库编译) +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/a311d.md#基于-paddle-lite-的-fastdeploy-交叉编译库编译) 2. 将编译后的库拷贝到当前目录,可使用如下命令: ```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp +cp -r FastDeploy/build/fastdeploy-timvx/ path/to/paddleseg/rockchip/rv1126/cpp ``` 3. 在当前路径下载部署所需的模型和示例图片: @@ -45,7 +43,8 @@ make install 5. 基于 adb 工具部署 PP-LiteSeg 分割模型到 Rockchip RV1126,可使用如下命令: ```bash # 进入 install 目录 -cd FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp/build/install/ +cd path/to/paddleseg/rockchip/rv1126/cpp/build/install/ +cp ../../run_with_adb.sh . # 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID ``` @@ -54,4 +53,7 @@ bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -需要特别注意的是,在 RV1126 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) + +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/infer.cc old mode 100755 new mode 100644 similarity index 95% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/infer.cc index d9f7c3311..513a03a01 --- a/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/infer.cc @@ -24,13 +24,13 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file) { auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; auto subgraph_file = model_dir + sep + "subgraph.txt"; - fastdeploy::vision::EnableFlyCV(); + fastdeploy::vision::EnableFlyCV(); fastdeploy::RuntimeOption option; option.UseTimVX(); option.SetLiteSubgraphPartitionPath(subgraph_file); - + auto model = fastdeploy::vision::segmentation::PaddleSegModel( - model_file, params_file, config_file,option); + model_file, params_file, config_file, option); assert(model.Initialized()); diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/run_with_adb.sh b/examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/run_with_adb.sh similarity index 100% rename from examples/vision/segmentation/paddleseg/rv1126/cpp/run_with_adb.sh rename to examples/vision/segmentation/paddleseg/rockchip/rv1126/cpp/run_with_adb.sh diff --git a/examples/vision/segmentation/paddleseg/rv1126/README.md b/examples/vision/segmentation/paddleseg/rv1126/README.md deleted file mode 100755 index dc9755272..000000000 --- a/examples/vision/segmentation/paddleseg/rv1126/README.md +++ /dev/null @@ -1,12 +0,0 @@ -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. - -For model quantization and download of quantized models, refer to [Model Quantization](../quantize/README.md) - - -## Detailed Deployment Tutorials - -Only C++ deployment is supported on RV1126. - -- [C++ Deployment](cpp) diff --git a/examples/vision/segmentation/paddleseg/rv1126/README_CN.md b/examples/vision/segmentation/paddleseg/rv1126/README_CN.md deleted file mode 100644 index ce4cbb816..000000000 --- a/examples/vision/segmentation/paddleseg/rv1126/README_CN.md +++ /dev/null @@ -1,12 +0,0 @@ -[English](README.md) | 简体中文 -# PP-LiteSeg 量化模型在 RV1126 上的部署 -目前 FastDeploy 已经支持基于 Paddle Lite 部署 PP-LiteSeg 量化模型到 RV1126 上。 - -模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) - - -## 详细部署文档 - -在 RV1126 上只支持 C++ 的部署。 - -- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md b/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md deleted file mode 100755 index 0022e6840..000000000 --- a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md +++ /dev/null @@ -1,57 +0,0 @@ -English | [简体中文](README_CN.md) -# PP-LiteSeg Quantitative Model C++ Deployment Example - -`infer.cc` in this directory can help you quickly complete the inference acceleration of PP-LiteSeg quantization model deployment on RV1126. - -## Deployment Preparations -### FastDeploy Cross-compile Environment Preparations -1. For the software and hardware environment, and the cross-compile environment, please refer to [Preparations for FastDeploy Cross-compile environment](../../../../../../docs/en/build_and_install/rv1126.md#Cross-compilation-environment-construction). - -### Model Preparations -1. You can directly use the quantized model provided by FastDeploy for deployment. -2. You can use one-click automatical compression tool provided by FastDeploy to quantize model by yourself, and use the generated quantized model for deployment.(Note: The quantized classification model still needs the deploy.yaml file in the FP32 model folder. Self-quantized model folder does not contain this yaml file, you can copy it from the FP32 model folder to the quantized model folder.) -3. The model requires heterogeneous computation. Please refer to: [Heterogeneous Computation](./../../../../../../docs/en/faq/heterogeneous_computing_on_timvx_npu.md). Since the model is already provided, you can test the heterogeneous file we provide first to verify whether the accuracy meets the requirements. - -For more information, please refer to [Model Quantization](../../quantize/README.md). - -## Deploying the Quantized PP-LiteSeg Segmentation model on RV1126 -Please follow these steps to complete the deployment of the PP-LiteSeg quantization model on RV1126. -1. Cross-compile the FastDeploy library as described in [Cross-compile FastDeploy](../../../../../../docs/en/build_and_install/rv1126.md#FastDeploy-cross-compilation-library-compilation-based-on-Paddle-Lite). - -2. Copy the compiled library to the current directory. You can run this line: -```bash -cp -r FastDeploy/build/fastdeploy-timvx/ FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp -``` - -3. Download the model and example images required for deployment in current path. -```bash -mkdir models && mkdir images -wget https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz -tar -xvf ppliteseg.tar.gz -cp -r ppliteseg models -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp -r cityscapes_demo.png images -``` - -4. Compile the deployment example. You can run the following lines: -```bash -mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-timvx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-timvx -DTARGET_ABI=armhf .. -make -j8 -make install -# After success, an install folder will be created with a running demo and libraries required for deployment. -``` - -5. Deploy the PP-LiteSeg segmentation model to Rockchip RV1126 based on adb. You can run the following lines: -```bash -# Go to the install directory. -cd FastDeploy/examples/vision/segmentation/paddleseg/rv1126/cpp/build/install/ -# The following line represents: bash run_with_adb.sh, demo needed to run, model path, image path, DEVICE ID. -bash run_with_adb.sh infer_demo ppliteseg cityscapes_demo.png $DEVICE_ID -``` - -The output is: - - - -Please note that the model deployed on RV1126 needs to be quantized. You can refer to [Model Quantization](../../../../../../docs/en/quantize.md). diff --git a/examples/vision/segmentation/paddleseg/serving/README.md b/examples/vision/segmentation/paddleseg/serving/README.md index a451e8730..00074183d 100644 --- a/examples/vision/segmentation/paddleseg/serving/README.md +++ b/examples/vision/segmentation/paddleseg/serving/README.md @@ -1,62 +1,54 @@ -English | [简体中文](README_CN.md) -# PaddleSegmentation Serving Deployment Demo +[English](README.md) | 简体中文 +# PaddleSeg 使用 FastDeploy 服务化部署 Segmentation 模型 +## FastDeploy 服务化部署介绍 +在线推理作为企业或个人线上部署模型的最后一环,是工业界必不可少的环节,其中最重要的就是服务化推理框架。FastDeploy 目前提供两种服务化部署方式:simple_serving和fastdeploy_serving +- simple_serving:适用于只需要通过http等调用AI推理任务,没有高并发需求的场景。simple_serving基于Flask框架具有简单高效的特点,可以快速验证线上部署模型的可行性 +- fastdeploy_serving:适用于高并发、高吞吐量请求的场景。基于Triton Inference Server框架,是一套可用于实际生产的完备且性能卓越的服务化部署框架 -## Launch Serving +## 模型版本说明 -```bash -# Download demo code -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/serving +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 -#Download PP_LiteSeg model file -wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz -tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz +目前FastDeploy支持如下模型的部署 -# Move the model files to models/infer/1 -mv yolov5s.onnx models/infer/1/ +- [U-Net系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/unet/README.md) +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) +- [PP-HumanSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/PP-HumanSeg/README.md) +- [FCN系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/fcn/README.md) +- [DeepLabV3系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/deeplabv3/README.md) +- [SegFormer系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/segformer/README.md) -# Pull fastdeploy image, x.y.z is FastDeploy version, example 1.0.2. -docker pull paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 +>>**注意** 如部署的为**PP-Matting**、**PP-HumanMatting**以及**ModNet**请参考[Matting模型部署](../../ppmatting) -# Run the docker. The docker name is fd_serving, and the current directory is mounted as the docker's /serving directory -nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/serving paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 bash +## 准备PaddleSeg部署模型 +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) -# 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=/serving/models --backend-config=python,shm-default-byte-size=10485760 -``` +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 -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 -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 -``` +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型 +- without-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op none` +- with-argmax导出方式为:**不指定**`--input_shape`,**指定**`--output_op argmax` -## Client Requests +开发者可直接下载使用。 -Execute the following command in the physical machine to send a grpc request and output the result +| 模型 | 参数文件大小 |输入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% | +| [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% | +| [SegFormer_B0-cityscapes-with-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-with-argmax.tgz) \| [SegFormer_B0-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/SegFormer_B0-cityscapes-without-argmax.tgz) | 15MB | 1024x1024 | 76.73% | 77.16% | - | -``` -#Download test images -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png +## 详细部署文档 -#Installing client-side dependencies -python3 -m pip install tritonclient\[all\] - -# Send requests -python3 paddleseg_grpc_client.py -``` - -When the request is sent successfully, the results are returned in json format and printed out: - -``` - -``` - -## 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/EN/model_configuration-en.md) to modify the configs in `models/runtime/config.pbtxt`. +- [fastdeploy serving](fastdeploy_serving) +- [simple serving](simple_serving) diff --git a/examples/vision/segmentation/paddleseg/serving/models/preprocess/1/deploy.yaml b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/deploy.yaml similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/preprocess/1/deploy.yaml rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer/deploy.yaml diff --git a/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md new file mode 100644 index 000000000..120b3994a --- /dev/null +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README.md @@ -0,0 +1,68 @@ +English | [简体中文](README_CN.md) +# PaddleSeg Serving Deployment Demo + +The PaddleSeg serving deployment Demo is built with FastDeploy Serving. FastDeploy Serving is a service-oriented deployment framework suitable for high-concurrency and high-throughput requests encapsulated based on the Triton Inference Server framework. It is a complete and high-performance service-oriented deployment framework that can be used in actual production. If you don’t need high-concurrency and high-throughput scenarios, and just want to quickly test the feasibility of online deployment of the model, please refer to [fastdeploy_serving](../simple_serving/) + +## Environment + +Before serving deployment, it is necessary to confirm the hardware and software environment requirements of the service image and the image pull command, please refer to [FastDeploy service deployment](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README.md) + +## Launch Serving + +```bash +# Download demo code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/segmentation/paddleseg/serving + +#Download PP_LiteSeg model file +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz +tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz + +# Move the model files to models/infer/1 +mv yolov5s.onnx models/infer/1/ + +# Pull fastdeploy image, x.y.z is FastDeploy version, example 1.0.2. +docker pull paddlepaddle/fastdeploy:x.y.z-gpu-cuda11.4-trt8.4-21.10 + +# Run the docker. The docker name is fd_serving, and the current directory is mounted as the docker's /serving directory +nvidia-docker run -it --net=host --name fd_serving -v `pwd`/:/serving 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=/serving/models --backend-config=python,shm-default-byte-size=10485760 +``` + +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 +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 +``` + +## Client Requests + +Execute the following command in the physical machine to send a grpc request and output the result + +``` +#Download test images +wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png + +#Installing client-side dependencies +python3 -m pip install tritonclient\[all\] + +# Send requests +python3 paddleseg_grpc_client.py +``` + +When the request is sent successfully, the results are returned in json format and printed out: + +``` + +``` + +## 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/EN/model_configuration-en.md) to modify the configs in `models/runtime/config.pbtxt`. diff --git a/examples/vision/segmentation/paddleseg/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md similarity index 53% rename from examples/vision/segmentation/paddleseg/serving/README_CN.md rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md index 676272f2e..a07a773e5 100644 --- a/examples/vision/segmentation/paddleseg/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/README_CN.md @@ -1,9 +1,10 @@ [English](README.md) | 简体中文 -# PaddleSegmentation 服务化部署示例 +# PaddleSeg 服务化部署示例 -在服务化部署前,需确认 +PaddleSeg 服务化部署示例是利用FastDeploy Serving搭建的服务化部署示例。FastDeploy Serving是基于Triton Inference Server框架封装的适用于高并发、高吞吐量请求的服务化部署框架,是一套可用于实际生产的完备且性能卓越的服务化部署框架。如没有高并发,高吞吐场景的需求,只想快速检验模型线上部署的可行性,请参考[fastdeploy_serving](../simple_serving/) -- 1. 服务化镜像的软硬件环境要求和镜像拉取命令请参考[FastDeploy服务化部署](../../../../../serving/README_CN.md) +## 部署环境准备 +在服务化部署前,需确认服务化镜像的软硬件环境要求和镜像拉取命令,请参考[FastDeploy服务化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/README_CN.md) ## 启动服务 @@ -11,9 +12,9 @@ ```bash #下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/serving +cd FastDeploy/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving -#下载yolov5模型文件 +#下载PP-LiteSeg模型文件 wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz @@ -60,9 +61,27 @@ python3 paddleseg_grpc_client.py 发送请求成功后,会返回json格式的检测结果并打印输出: ``` +tm: name: "INPUT" +datatype: "UINT8" +shape: -1 +shape: -1 +shape: -1 +shape: 3 +output_name: SEG_RESULT +Only print the first 20 labels in label_map of SEG_RESULT +{'label_map': [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 'score_map': [], 'shape': [1024, 2048], 'contain_score_map': False} ``` ## 配置修改 -当前默认配置在CPU上运行ONNXRuntime引擎, 如果要在GPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](../../../../../serving/docs/zh_CN/model_configuration.md) +当前默认配置在CPU上运行ONNXRuntime引擎, 如果要在GPU或其他推理引擎上运行。 需要修改`models/runtime/config.pbtxt`中配置,详情请参考[配置文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/model_configuration.md) + +## 更多部署方式 +- [使用 VisualDL 进行 Serving 可视化部署](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/vdl_management.md) + +## 常见问题 +- [如何编写客户端 HTTP/GRPC 请求](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/client.md) +- [如何编译服务化部署镜像](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/compile.md) +- [服务化部署原理及动态Batch介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/demo.md) +- [模型仓库介绍](https://github.com/PaddlePaddle/FastDeploy/blob/develop/serving/docs/zh_CN/model_repository.md) diff --git a/examples/vision/segmentation/paddleseg/serving/models/paddleseg/1/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/1/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/paddleseg/1/README.md rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/1/README.md diff --git a/examples/vision/segmentation/paddleseg/serving/models/paddleseg/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/paddleseg/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/paddleseg/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/models/postprocess/1/model.py b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/1/model.py similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/postprocess/1/model.py rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/1/model.py diff --git a/examples/vision/segmentation/paddleseg/serving/models/postprocess/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/postprocess/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/postprocess/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/models/preprocess/1/model.py b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/1/model.py similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/preprocess/1/model.py rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/1/model.py diff --git a/examples/vision/segmentation/paddleseg/serving/models/preprocess/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/preprocess/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/preprocess/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/models/runtime/1/README.md b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/1/README.md similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/runtime/1/README.md rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/1/README.md diff --git a/examples/vision/segmentation/paddleseg/serving/models/runtime/config.pbtxt b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/config.pbtxt similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/models/runtime/config.pbtxt rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/models/runtime/config.pbtxt diff --git a/examples/vision/segmentation/paddleseg/serving/paddleseg_grpc_client.py b/examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/paddleseg_grpc_client.py similarity index 100% rename from examples/vision/segmentation/paddleseg/serving/paddleseg_grpc_client.py rename to examples/vision/segmentation/paddleseg/serving/fastdeploy_serving/paddleseg_grpc_client.py diff --git a/examples/vision/segmentation/paddleseg/python/serving/README.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md similarity index 62% rename from examples/vision/segmentation/paddleseg/python/serving/README.md rename to examples/vision/segmentation/paddleseg/serving/simple_serving/README.md index da41a3a00..ea8223ecc 100644 --- a/examples/vision/segmentation/paddleseg/python/serving/README.md +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README.md @@ -1,11 +1,12 @@ English | [简体中文](README_CN.md) -# PaddleSegmentation Python Simple Serving Demo +# PaddleSeg Python Simple Serving Demo +PaddleSeg Python Simple serving is an example of serving deployment built by FastDeploy based on the Flask framework that can quickly verify the feasibility of online model deployment. It completes AI inference tasks based on http requests, and is suitable for simple scenarios without concurrent inference task. For high concurrency and high throughput scenarios, please refer to [fastdeploy_serving](../fastdeploy_serving/) ## Environment -- 1. Prepare environment and install FastDeploy Python whl, refer to [download_prebuilt_libraries](../../../../../../docs/en/build_and_install/download_prebuilt_libraries.md) +- 1. Prepare environment and install FastDeploy Python whl, refer to [download_prebuilt_libraries](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/en/build_and_install#install-prebuilt-fastdeploy) Server: ```bash diff --git a/examples/vision/segmentation/paddleseg/python/serving/README_CN.md b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md similarity index 54% rename from examples/vision/segmentation/paddleseg/python/serving/README_CN.md rename to examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md index 3f382c904..afc1325dc 100644 --- a/examples/vision/segmentation/paddleseg/python/serving/README_CN.md +++ b/examples/vision/segmentation/paddleseg/serving/simple_serving/README_CN.md @@ -1,11 +1,12 @@ 简体中文 | [English](README.md) -# PaddleSegmentation Python轻量服务化部署示例 +# PaddleSeg Python轻量服务化部署示例 -在部署前,需确认以下两个步骤 +PaddleSeg Python轻量服务化部署是FastDeploy基于Flask框架搭建的可快速验证线上模型部署可行性的服务化部署示例,基于http请求完成AI推理任务,适用于无并发推理的简单场景,如有高并发,高吞吐场景的需求请参考[fastdeploy_serving](../fastdeploy_serving/) -- 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) +## 部署环境准备 + +在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#FastDeploy预编译库安装) 服务端: ```bash @@ -13,7 +14,7 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/examples/vision/segmentation/paddleseg/python/serving -# 下载PP_LiteSeg模型文件 +# 下载PP-LiteSeg模型文件 wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz tar -xvf PP_LiteSeg_B_STDC2_cityscapes_with_argmax_infer.tgz @@ -24,10 +25,6 @@ fastdeploy simple_serving --app server:app 客户端: ```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/detection/paddledetection/python/serving - # 下载测试图片 wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg diff --git a/examples/vision/segmentation/paddleseg/python/serving/client.py b/examples/vision/segmentation/paddleseg/serving/simple_serving/client.py similarity index 100% rename from examples/vision/segmentation/paddleseg/python/serving/client.py rename to examples/vision/segmentation/paddleseg/serving/simple_serving/client.py diff --git a/examples/vision/segmentation/paddleseg/python/serving/server.py b/examples/vision/segmentation/paddleseg/serving/simple_serving/server.py similarity index 100% rename from examples/vision/segmentation/paddleseg/python/serving/server.py rename to examples/vision/segmentation/paddleseg/serving/simple_serving/server.py diff --git a/examples/vision/segmentation/paddleseg/sophgo/README.md b/examples/vision/segmentation/paddleseg/sophgo/README.md index 85a4360fa..67f636486 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/README.md @@ -1,34 +1,61 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg在算能(Sophgo)硬件上通过FastDeploy部署模型 -## Supporting Model List +## PaddleSeg支持部署的Sophgo的芯片型号 +支持如下芯片的部署 +- Sophgo 1684X -- PP-LiteSeg deployment models are from [PaddleSeg PP-LiteSeg series model](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md). +PaddleSeg支持通过FastDeploy在算能TPU上部署相关Segmentation模型 -## PP-LiteSeg Model Deployment and Conversion Preparations +## 算能硬件支持的PaddleSeg模型 -Befor SOPHGO-TPU model deployment, you should first convert Paddle model to bmodel model. Specific steps are as follows: -- Download Paddle model: [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz). -- Convert Paddle model to ONNX model. Please refer to [Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX). -- For the process of converting ONNX model to bmodel, please refer to [TPU-MLIR](https://github.com/sophgo/tpu-mlir). +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg) +>> **注意**:支持PaddleSeg高于2.6版本的Segmentation模型 -## Model Converting Example +目前算能TPU支持的模型如下: +- [PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/configs/pp_liteseg/README.md) -Here we take [PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) as an example to show you how to convert Paddle model to SOPHGO-TPU model. +## 预导出的推理模型 -### Download PP-LiteSeg-B(STDC2)-cityscapes-without-argmax, and convert it to ONNX +为了方便开发者的测试,下面提供了PaddleSeg导出的部分推理模型,开发者可直接下载使用。 + +PaddleSeg训练模型导出为推理模型,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/develop/docs/model_export_cn.md) + +| 模型 | 参数文件大小 |输入Shape | mIoU | mIoU (flip) | mIoU (ms+flip) | +|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | :----- | +| [PP-LiteSeg-T(STDC1)-cityscapes-without-argmax](https://bj.bcebos.com/fastdeploy/models/rk1/ppliteseg.tar.gz)| 31MB | 1024x512 | 77.04% | 77.73% | 77.46% | + +## 将PaddleSeg推理模型转换为bmodel模型步骤 + +SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下: +- 下载Paddle模型[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) +- Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) +- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir) + +## bmode模型转换example + +下面以[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz)为例,教大家如何转换Paddle模型到SOPHGO-TPU支持的bmodel模型 + +### 下载PP-LiteSeg-B(STDC2)-cityscapes-without-argmax模型,并转换为ONNX模型 ```shell -https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz +# 下载Paddle2ONNX仓库 +git clone https://github.com/PaddlePaddle/Paddle2ONNX + +# 下载Paddle静态图模型并为Paddle静态图模型固定输入shape +## 进入为Paddle静态图模型固定输入shape的目录 +cd Paddle2ONNX/tools/paddle + +wget https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -# Modify the input shape of PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer model from dynamic input to constant input. +# 修改PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer模型的输入shape,由动态输入变成固定输入 python paddle_infer_shape.py --model_dir PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer \ --model_filename model.pdmodel \ --params_filename model.pdiparams \ --save_dir pp_liteseg_fix \ --input_shape_dict="{'x':[1,3,512,512]}" -# Convert constant input Paddle model to ONNX model. +#将固定输入的Paddle模型转换成ONNX模型 paddle2onnx --model_dir pp_liteseg_fix \ --model_filename model.pdmodel \ --params_filename model.pdiparams \ @@ -36,32 +63,32 @@ paddle2onnx --model_dir pp_liteseg_fix \ --enable_dev_version True ``` -### Export bmodel +### 导出bmodel模型 -Take converting BM1684x model to bmodel as an example. You need to download [TPU-MLIR](https://github.com/sophgo/tpu-mlir) project. For the process of installation, please refer to [TPU-MLIR Document](https://github.com/sophgo/tpu-mlir/blob/master/README.md). -### 1. Installation +以转换BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 +#### 1. 安装 ``` shell docker pull sophgo/tpuc_dev:latest -# myname1234 is just an example, you can customize your own name. +# myname1234是一个示例,也可以设置其他名字 docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest source ./envsetup.sh ./build.sh ``` -### 2. Convert ONNX model to bmodel +#### 2. ONNX模型转换为bmodel模型 ``` shell mkdir pp_liteseg && cd pp_liteseg -# Put the test image in this file, and put the converted pp_liteseg.onnx into this folder. +#在该文件中放入测试图片,同时将上一步转换的pp_liteseg.onnx放入该文件夹中 cp -rf ${REGRESSION_PATH}/dataset/COCO2017 . cp -rf ${REGRESSION_PATH}/image . -# Put in the onnx model file pp_liteseg.onnx. +#放入onnx模型文件pp_liteseg.onnx mkdir workspace && cd workspace -# Convert ONNX model to mlir model, the parameter --output_names can be viewed via NETRON. +#将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看 model_transform.py \ --model_name pp_liteseg \ --model_def ../pp_liteseg.onnx \ @@ -75,7 +102,7 @@ model_transform.py \ --test_result pp_liteseg_top_outputs.npz \ --mlir pp_liteseg.mlir -# Convert mlir model to BM1684x F32 bmodel. +#将mlir模型转换为BM1684x的F32 bmodel模型 model_deploy.py \ --mlir pp_liteseg.mlir \ --quantize F32 \ @@ -84,7 +111,8 @@ model_deploy.py \ --test_reference pp_liteseg_top_outputs.npz \ --model pp_liteseg_1684x_f32.bmodel ``` -The final bmodel, pp_liteseg_1684x_f32.bmodel, can run on BM1684x. If you want to further accelerate the model, you can convert ONNX model to INT8 bmodel. For details, please refer to [TPU-MLIR Document](https://github.com/sophgo/tpu-mlir/blob/master/README.md). +最终获得可以在BM1684x上能够运行的bmodel模型pp_liteseg_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 -## Other Documents -- [Cpp Deployment](./cpp) +## 快速链接 +- [Cpp部署](./cpp) +- [Python部署](./python) diff --git a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/README_CN.md deleted file mode 100644 index 5961d2e94..000000000 --- a/examples/vision/segmentation/paddleseg/sophgo/README_CN.md +++ /dev/null @@ -1,90 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -## 支持模型列表 - -- PP-LiteSeg部署模型实现来自[PaddleSeg PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md) - -## 准备PP-LiteSeg部署模型以及转换模型 - -SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下: -- 下载Paddle模型[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz) -- Paddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX) -- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir) - -## 模型转换example - -下面以[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz)为例子,教大家如何转换Paddle模型到SOPHGO-TPU模型 - -### 下载PP-LiteSeg-B(STDC2)-cityscapes-without-argmax模型,并转换为ONNX模型 -```shell -https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz -tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz - -# 修改PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer模型的输入shape,由动态输入变成固定输入 -python paddle_infer_shape.py --model_dir PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer \ - --model_filename model.pdmodel \ - --params_filename model.pdiparams \ - --save_dir pp_liteseg_fix \ - --input_shape_dict="{'x':[1,3,512,512]}" - -#将固定输入的Paddle模型转换成ONNX模型 -paddle2onnx --model_dir pp_liteseg_fix \ - --model_filename model.pdmodel \ - --params_filename model.pdiparams \ - --save_file pp_liteseg.onnx \ - --enable_dev_version True -``` - -### 导出bmodel模型 - -以转换BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 -### 1. 安装 -``` shell -docker pull sophgo/tpuc_dev:latest - -# myname1234是一个示例,也可以设置其他名字 -docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest - -source ./envsetup.sh -./build.sh -``` - -### 2. ONNX模型转换为bmodel模型 -``` shell -mkdir pp_liteseg && cd pp_liteseg - -#在该文件中放入测试图片,同时将上一步转换的pp_liteseg.onnx放入该文件夹中 -cp -rf ${REGRESSION_PATH}/dataset/COCO2017 . -cp -rf ${REGRESSION_PATH}/image . -#放入onnx模型文件pp_liteseg.onnx - -mkdir workspace && cd workspace - -#将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看 -model_transform.py \ - --model_name pp_liteseg \ - --model_def ../pp_liteseg.onnx \ - --input_shapes [[1,3,512,512]] \ - --mean 0.0,0.0,0.0 \ - --scale 0.0039216,0.0039216,0.0039216 \ - --keep_aspect_ratio \ - --pixel_format rgb \ - --output_names bilinear_interp_v2_6.tmp_0 \ - --test_input ../image/dog.jpg \ - --test_result pp_liteseg_top_outputs.npz \ - --mlir pp_liteseg.mlir - -#将mlir模型转换为BM1684x的F32 bmodel模型 -model_deploy.py \ - --mlir pp_liteseg.mlir \ - --quantize F32 \ - --chip bm1684x \ - --test_input pp_liteseg_in_f32.npz \ - --test_reference pp_liteseg_top_outputs.npz \ - --model pp_liteseg_1684x_f32.bmodel -``` -最终获得可以在BM1684x上能够运行的bmodel模型pp_liteseg_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。 - -## 其他链接 -- [Cpp部署](./cpp) diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md b/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md index eae65d559..3f33c398c 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md @@ -1,57 +1,56 @@ -English | [简体中文](README_CN.md) -# PaddleSeg C++ Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg C++部署示例 -`infer.cc` in this directory provides a quick example of accelerated deployment of the pp_liteseg model on SOPHGO BM1684x. +本目录下提供`infer.cc`快速完成PP-LiteSeg在SOPHGO BM1684x板子上加速部署的示例。 -Before deployment, the following two steps need to be confirmed: +## 算能硬件编译FastDeploy环境准备 +在部署前,需自行编译基于算能硬件的预测库,参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境) -1. Hardware and software environment meets the requirements. -2. Compile the FastDeploy repository from scratch according to the development environment. +## 生成基本目录文件 -For the above steps, please refer to [How to Build SOPHGO Deployment Environment](../../../../../../docs/en/build_and_install/sophgo.md). - -## Generate Basic Directory Files - -The routine consists of the following parts: +该例程由以下几个部分组成 ```text . ├── CMakeLists.txt -├── build # Compile Folder -├── image # Folder for images +├── fastdeploy-sophgo # 编译文件夹 +├── image # 存放图片的文件夹 ├── infer.cc -└── model # Folder for models +└── model # 存放模型文件的文件夹 ``` -## Compile +## 编译 -### Compile and Copy SDK to folder thirdpartys +### 编译FastDeploy -Please refer to [How to Build SOPHGO Deployment Environment](../../../../../../docs/en/build_and_install/sophgo.md) to compile SDK.After compiling, the fastdeploy-0.0.3 directory will be created in the build directory. +请参考[SOPHGO部署库编译](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/sophgo.md)编译SDK,编译完成后,将在build目录下生成fastdeploy-sophgo目录。拷贝fastdeploy-sophgo至当前目录 -### Copy model and configuration files to folder Model -Convert Paddle model to SOPHGO bmodel model. For the conversion steps, please refer to [Document](../README.md). -Please copy the converted SOPHGO bmodel to folder model. +### 拷贝模型文件,以及配置文件至model文件夹 +将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README_CN.md#将paddleseg推理模型转换为bmodel模型步骤) -### Prepare Test Images to folder image +将转换后的SOPHGO bmodel模型文件拷贝至model中 + +### 准备测试图片至image文件夹 ```bash wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png cp cityscapes_demo.png ./images ``` -### Compile example +### 编译example ```bash cd build -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3 +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-sophgo make ``` -## Running Routines +## 运行例程 ```bash ./infer_demo model images/cityscapes_demo.png ``` - -- [Model Description](../../) -- [Model Conversion](../) +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) +- [模型转换](../README_CN.md#将paddleseg推理模型转换为bmodel模型步骤) diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md deleted file mode 100644 index 6360a2907..000000000 --- a/examples/vision/segmentation/paddleseg/sophgo/cpp/README_CN.md +++ /dev/null @@ -1,57 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg C++部署示例 - -本目录下提供`infer.cc`快速完成pp_liteseg模型在SOPHGO BM1684x板子上加速部署的示例。 - -在部署前,需确认以下两个步骤: - -1. 软硬件环境满足要求 -2. 根据开发环境,从头编译FastDeploy仓库 - -以上步骤请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)实现 - -## 生成基本目录文件 - -该例程由以下几个部分组成 -```text -. -├── CMakeLists.txt -├── build # 编译文件夹 -├── image # 存放图片的文件夹 -├── infer.cc -└── model # 存放模型文件的文件夹 -``` - -## 编译 - -### 编译并拷贝SDK到thirdpartys文件夹 - -请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录. - -### 拷贝模型文件,以及配置文件至model文件夹 -将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md) -将转换后的SOPHGO bmodel模型文件拷贝至model中 - -### 准备测试图片至image文件夹 -```bash -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -cp cityscapes_demo.png ./images -``` - -### 编译example - -```bash -cd build -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3 -make -``` - -## 运行例程 - -```bash -./infer_demo model images/cityscapes_demo.png -``` - - -- [模型介绍](../../) -- [模型转换](../) diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/README.md b/examples/vision/segmentation/paddleseg/sophgo/python/README.md index 5aba6590f..e646d6a90 100644 --- a/examples/vision/segmentation/paddleseg/sophgo/python/README.md +++ b/examples/vision/segmentation/paddleseg/sophgo/python/README.md @@ -1,27 +1,33 @@ -English | [简体中文](README_CN.md) -# PaddleSeg Python Deployment Example +[English](README.md) | 简体中文 +# PaddleSeg Python部署示例 -Before deployment, the following step need to be confirmed: +## 算能硬件编译FastDeploy wheel包环境准备 -- 1. Hardware and software environment meets the requirements. Please refer to [FastDeploy Environment Requirement](../../../../../../docs/en/build_and_install/sophgo.md). +在部署前,需自行编译基于算能硬件的FastDeploy python wheel包并安装,参考文档[算能硬件部署环境](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install#算能硬件部署环境) -`infer.py` in this directory provides a quick example of deployment of the pp_liteseg model on SOPHGO TPU. Please run the following script: +本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 ```bash -# Download the sample deployment code. +# 下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/sophgo/python +cd path/to/paddleseg/sophgo/python -# Download images. +# 下载图片 wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png -# Inference. +# PaddleSeg模型转换为bmodel模型 +将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README_CN.md#将paddleseg推理模型转换为bmodel模型步骤) + +# 推理 python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png -# The returned result. -The result is saved as sophgo_img.png. +# 运行完成后返回结果如下所示 +运行结果保存在sophgo_img.png中 ``` -## Other Documents -- [pp_liteseg C++ Deployment](../cpp) -- [Converting pp_liteseg SOPHGO model](../README.md) +## 快速链接 +- [pp_liteseg C++部署](../cpp) +- [转换 pp_liteseg SOPHGO模型文档](../README_CN.md#导出bmodel模型) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md b/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md deleted file mode 100644 index 9cafb1dc9..000000000 --- a/examples/vision/segmentation/paddleseg/sophgo/python/README_CN.md +++ /dev/null @@ -1,27 +0,0 @@ -[English](README.md) | 简体中文 -# PaddleSeg Python部署示例 - -在部署前,需确认以下步骤 - -- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md) - -本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成 - -```bash -# 下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd FastDeploy/examples/vision/segmentation/paddleseg/sophgo/python - -# 下载图片 -wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png - -# 推理 -python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png - -# 运行完成后返回结果如下所示 -运行结果保存在sophgo_img.png中 -``` - -## 其它文档 -- [pp_liteseg C++部署](../cpp) -- [转换 pp_liteseg SOPHGO模型文档](../README.md) diff --git a/examples/vision/segmentation/paddleseg/web/README_CN.md b/examples/vision/segmentation/paddleseg/web/README_CN.md index 81664eee3..2847da0be 100644 --- a/examples/vision/segmentation/paddleseg/web/README_CN.md +++ b/examples/vision/segmentation/paddleseg/web/README_CN.md @@ -8,7 +8,7 @@ ## 前端部署PP-Humanseg v1模型 -PP-Humanseg v1模型web demo部署及使用参考[文档](../../../../application/js/web_demo/README.md) +PP-Humanseg v1模型web demo部署及使用参考[文档](https://github.com/PaddlePaddle/FastDeploy/blob/develop/examples/application/js/README_CN.md) ## PP-Humanseg v1 js接口 diff --git a/examples/vision/segmentation/ppmatting/README.md b/examples/vision/segmentation/ppmatting/README.md new file mode 100644 index 000000000..b3dd9cc80 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/README.md @@ -0,0 +1,22 @@ +# PaddleSeg高性能全场景模型部署方案—FastDeploy + +## FastDeploy介绍 + +[FastDeploy](https://github.com/PaddlePaddle/FastDeploy)是一款全场景、易用灵活、极致高效的AI推理部署工具,使用FastDeploy可以简单高效的在10+款硬件上对PaddleSeg Matting模型进行快速部署 + +## 支持如下的硬件部署 + +| 硬件支持列表 | | | | +|:----- | :-- | :-- | :-- | +| [NVIDIA GPU](cpu-gpu) | [X86 CPU](cpu-gpu)| [飞腾CPU](cpu-gpu) | [ARM CPU](cpu-gpu) | +| [Intel GPU(独立显卡/集成显卡)](cpu-gpu) | [昆仑](cpu-gpu) | [昇腾](cpu-gpu) | + +## 常见问题 + +遇到问题可查看常见问题集合文档或搜索FastDeploy issues,链接如下: + +[常见问题集合](https://github.com/PaddlePaddle/FastDeploy/tree/develop/docs/cn/faq) + +[FastDeploy issues](https://github.com/PaddlePaddle/FastDeploy/issues) + +若以上方式都无法解决问题,欢迎给FastDeploy提交新的[issue](https://github.com/PaddlePaddle/FastDeploy/issues) diff --git a/examples/vision/segmentation/ppmatting/ascend/README.md b/examples/vision/segmentation/ppmatting/ascend/README.md new file mode 120000 index 000000000..3ed44e130 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/ascend/README.md @@ -0,0 +1 @@ +../cpu-gpu/README.md \ No newline at end of file diff --git a/examples/vision/matting/ppmatting/README_CN.md b/examples/vision/segmentation/ppmatting/cpu-gpu/README.md similarity index 56% rename from examples/vision/matting/ppmatting/README_CN.md rename to examples/vision/segmentation/ppmatting/cpu-gpu/README.md index a1c9801aa..e590ac42c 100644 --- a/examples/vision/matting/ppmatting/README_CN.md +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/README.md @@ -1,30 +1,32 @@ -[English](README.md) | 简体中文 -# PP-Matting模型部署 +# PaddleSeg Matting模型高性能全场景部署方案-FastDeploy + +PaddleSeg通过[FastDeploy](https://github.com/PaddlePaddle/FastDeploy)支持在NVIDIA GPU、X86 CPU、飞腾CPU、ARM CPU、Intel GPU(独立显卡/集成显卡)、昆仑芯、华为昇腾硬件上部署Matting模型 ## 模型版本说明 -- [PP-Matting Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting) - -## 支持模型列表 +- [PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg/tree/develop) +>> **注意**:支持PaddleSeg高于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/develop/Matting) +- [PP-HumanMatting系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) +- [ModNet系列模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) -## 导出部署模型 +## 准备PaddleSeg部署模型 +在部署前,需要先将Matting模型导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/develop/Matting) -在部署前,需要先将PP-Matting导出成部署模型,导出步骤参考文档[导出模型](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6/Matting)(Tips:导出PP-Matting系列模型和PP-HumanMatting系列模型需要设置导出脚本的`--input_shape`参数) +**注意** +- PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息 - -## 下载预训练模型 +## 预导出的推理模型 为了方便开发者的测试,下面提供了PP-Matting导出的各系列模型,开发者可直接下载使用。 其中精度指标来源于PP-Matting中对各模型的介绍(未提供精度数据),详情各参考PP-Matting中的说明。 +>> **注意**`deploy.yaml`文件记录导出模型的`input_shape`以及预处理信息,若不满足要求,用户可重新导出相关模型 | 模型 | 参数大小 | 精度 | 备注 | |:---------------------------------------------------------------- |:----- |:----- | :------ | @@ -35,8 +37,6 @@ | [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) diff --git a/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/CMakeLists.txt b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/CMakeLists.txt new file mode 100644 index 000000000..93540a7e8 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +PROJECT(infer_demo C CXX) +CMAKE_MINIMUM_REQUIRED (VERSION 3.10) + +# 指定下载解压后的fastdeploy库路径 +option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") + +include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) + +# 添加FastDeploy依赖头文件 +include_directories(${FASTDEPLOY_INCS}) + +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md new file mode 100644 index 000000000..b88b79942 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/README.md @@ -0,0 +1,60 @@ +[English](README.md) | 简体中文 +# PP-Matting C++部署示例 + +本目录下提供`infer.cc`快速完成PP-Matting在CPU/GPU、昆仑芯、华为昇腾以及GPU上通过Paddle-TensorRT加速部署的示例。 + +在部署前,需确认软硬件环境,同时下载预编译部署库,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install) + +>> **注意** 只有CPU、GPU提供预编译库,华为昇腾以及昆仑芯需要参考以上文档自行编译部署环境 + +以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 + +# 下载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 +``` +>> ***注意** 以上示例未提供华为昇腾的示例,在编译好昇腾部署环境后,只需改造一行代码,将示例文件中KunlunXinInfer方法的`option.UseKunlunXin()`为`option.UseAscend()`就可以完成在华为昇腾上的推理部署 + +运行完成可视化结果如下图所示 +
+ + + + +
+ +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## 快速链接 +- [PaddleSeg C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/namespacefastdeploy_1_1vision_1_1segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](../../) +- [Python部署](../python) + +## 常见问题 +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/matting/ppmatting/cpp/infer.cc b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc old mode 100755 new mode 100644 similarity index 87% rename from examples/vision/matting/ppmatting/cpp/infer.cc rename to examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc index d86122477..9f1e69d5e --- a/examples/vision/matting/ppmatting/cpp/infer.cc +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/cpp/infer.cc @@ -42,17 +42,16 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file, return; } auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; } void KunlunXinInfer(const std::string& model_dir, const std::string& image_file, - const std::string& background_file) { + const std::string& background_file) { auto model_file = model_dir + sep + "model.pdmodel"; auto params_file = model_dir + sep + "model.pdiparams"; auto config_file = model_dir + sep + "deploy.yaml"; @@ -73,10 +72,9 @@ void KunlunXinInfer(const std::string& model_dir, const std::string& image_file, return; } auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -106,10 +104,9 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file, return; } auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); - cv::imwrite("visualized_result.png", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); + cv::imwrite("visualized_result.jpg", vis_im_with_bg); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.png" << std::endl; @@ -124,6 +121,10 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, auto option = fastdeploy::RuntimeOption(); option.UseGpu(); option.UseTrtBackend(); + // If use original Tensorrt, not Paddle-TensorRT, + // comment the following two lines + option.EnablePaddleToTrt(); + option.EnablePaddleTrtCollectShape(); option.SetTrtInputShape("img", {1, 3, 512, 512}); auto model = fastdeploy::vision::matting::PPMatting(model_file, params_file, config_file, option); @@ -140,10 +141,9 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, return; } auto vis_im = fastdeploy::vision::VisMatting(im, res); - auto vis_im_with_bg = - fastdeploy::vision::SwapBackground(im, bg, res); + auto vis_im_with_bg = fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); - cv::imwrite("visualized_result_fg.jpg", vis_im); + cv::imwrite("visualized_result_fg.png", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " "and ./visualized_result_fg.jpg" << std::endl; @@ -156,7 +156,8 @@ int main(int argc, char* argv[]) { "e.g ./infer_model ./PP-Matting-512 ./test.jpg ./test_bg.jpg 0" << std::endl; std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " - "with gpu; 2: run with gpu and use tensorrt backend, 3: run with kunlunxin." + "with gpu; 2: run with gpu and use tensorrt backend, 3: run " + "with kunlunxin." << std::endl; return -1; } diff --git a/examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md b/examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md new file mode 100644 index 000000000..2adb2458a --- /dev/null +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/python/README.md @@ -0,0 +1,52 @@ +[English](README.md) | 简体中文 +# PP-Matting Python部署示例 + +本目录下提供`infer.py`快速完成PP-Matting在CPU/GPU、昆仑芯、华为昇腾,以及GPU上通过Paddle-TensorRT加速部署的示例。执行如下脚本即可完成 + +## 部署环境准备 + +在部署前,需确认软硬件环境,同时下载预编译python wheel 包,参考文档[FastDeploy预编译库安装](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install) +>> **注意** 只有CPU、GPU提供预编译库,华为昇腾以及昆仑芯需要参考以上文档自行编译部署环境 + + +```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 +``` +>> ***注意** 以上示例未提供华为昇腾的示例,在编译好昇腾部署环境后,只需改造一行代码,将示例文件中的`option.use_kunlunxin()`为`option.use_ascend()`就可以完成在华为昇腾上的推理部署 + +运行完成可视化结果如下图所示 +
+ + + + +
+ +## 快速链接 +- [PaddleSeg python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/semantic_segmentation.html) +- [FastDeploy部署PaddleSeg模型概览](..) +- [PaddleSeg C++部署](../cpp) + +## 常见问题 +- [如何将模型预测结果SegmentationResult转为numpy格式](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/vision_result_related_problems.md) +- [如何切换模型推理后端引擎](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/faq/how_to_change_backend.md) +- [Intel GPU(独立显卡/集成显卡)的使用](https://github.com/PaddlePaddle/FastDeploy/blob/develop/tutorials/intel_gpu/README.md) +- [编译CPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/cpu.md) +- [编译GPU部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/gpu.md) +- [编译Jetson部署库](https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/build_and_install/jetson.md) diff --git a/examples/vision/matting/ppmatting/python/infer.py b/examples/vision/segmentation/ppmatting/cpu-gpu/python/infer.py similarity index 91% rename from examples/vision/matting/ppmatting/python/infer.py rename to examples/vision/segmentation/ppmatting/cpu-gpu/python/infer.py index 668d617ef..a6150ff0e 100755 --- a/examples/vision/matting/ppmatting/python/infer.py +++ b/examples/vision/segmentation/ppmatting/cpu-gpu/python/infer.py @@ -38,6 +38,10 @@ def build_option(args): if args.use_trt: option.use_trt_backend() + # If use original Tensorrt, not Paddle-TensorRT, + # comment the following two lines + option.enable_paddle_to_trt() + option.enable_paddle_trt_collect_shape() option.set_trt_input_shape("img", [1, 3, 512, 512]) if args.device.lower() == "kunlunxin": diff --git a/examples/vision/segmentation/ppmatting/kunlun/README.md b/examples/vision/segmentation/ppmatting/kunlun/README.md new file mode 120000 index 000000000..3ed44e130 --- /dev/null +++ b/examples/vision/segmentation/ppmatting/kunlun/README.md @@ -0,0 +1 @@ +../cpu-gpu/README.md \ No newline at end of file