diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in index 082fa30f30b..ccd1039be29 100644 --- a/FastDeploy.cmake.in +++ b/FastDeploy.cmake.in @@ -95,6 +95,10 @@ endif() if (ENABLE_TEXT) # Add dependency libs later + find_library(FASTER_TOKENIZER_LIB core_tokenizers ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/faster_tokenizer/lib NO_DEFAULT_PATH) + list(APPEND FASTDEPLOY_LIBS ${FASTER_TOKENIZER_LIB}) + list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/faster_tokenizer/include) + list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/faster_tokenizer/third_party/include) endif() if(ENABLE_PADDLE_FRONTEND) diff --git a/README.md b/README.md index 5619db16009..8046fe0cba9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# ⚡️FastDeploy +![⚡️FastDeploy](docs/logo/fastdeploy-opaque.png)

------------------------------------------------------------------------------------------- -

@@ -19,147 +17,196 @@ **⚡️FastDeploy**是一款**简单易用**的推理部署工具箱。覆盖业界主流**优质预训练模型**并提供**开箱即用**的开发体验,包括图像分类、目标检测、图像分割、人脸检测、人体关键点识别、文字识别等多任务,满足开发者**多场景**,**多硬件**、**多平台**的快速部署需求。 ## 发版历史 -- [v0.2.0] 2022.08.18 全面开源服务端部署代码,支持40+视觉模型在CPU/GPU,以及通过GPU TensorRT加速部署 - -## 服务端模型 - -| 任务场景 | 模型 | CPU | NVIDIA GPU | TensorRT | -| -------- | ------------------------------------------------------------ | ------- | ---------- | ------------------- | -| 图像分类 | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | √ | √ | √ | -| | [PaddleClas/PPLCNet](./examples/vision/classification/paddleclas) | √ | √ | √ | -| | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | √ | √ | √ | -| | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | √ | √ | √ | -| | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | √ | √ | √ | -| | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | √ | √ | √ | -| | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | √ | √ | √ | -| 目标检测 | [PaddleDetection/PPYOLOE](./examples/vision/detection/paddledetection) | √ | √ | √ | -| | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | √ | √ | √ | -| | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | √ | √ | √ | -| | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | √ | √ | √ | -| | [PaddleDetection/PPYOLO](./examples/vision/detection/paddledetection) | √ | √ | - | -| | [PaddleDetection/PPYOLOv2](./examples/vision/detection/paddledetection) | √ | √ | - | -| | [PaddleDetection/FasterRCNN](./examples/vision/detection/paddledetection) | √ | √ | - | -| | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | √ | √ | √ | - -## 快速开始 - -#### 安装FastDeploy Python - -用户根据开发环境选择安装版本,更多安装环境参考[安装文档](docs/quick_start/install.md). - -``` +- [v0.2.0] 2022.08.18 全面开源服务端部署代码,支持40+视觉模型在CPU/GPU,以及通过TensorRT加速部署 + +## 内容目录 +* [服务端模型列表](#fastdeploy-server-models) +* [服务端快速开始](#fastdeploy-quick-start) + * [快速安装](#fastdeploy-quick-start) + * [Python预测示例](#fastdeploy-quick-start-python) + * [C++预测示例](#fastdeploy-quick-start-cpp) +* [轻量化SDK快速实现端侧AI推理部署](#fastdeploy-edge-sdk) + * [边缘侧部署](#fastdeploy-edge-sdk-arm-linux) + * [移动端部署](#fastdeploy-edge-sdk-ios-android) + * [自定义模型部署](#fastdeploy-edge-sdk-custom) +* [社区交流](#fastdeploy-community) +* [Acknowledge](#fastdeploy-acknowledge) +* [License](#fastdeploy-license) +## 1. 服务端模型列表 🔥🔥🔥 + +

+ +符号说明: (1) ✅: 已经支持; (2) ❔: 计划未来支持; (3) ❌: 暂不支持; (4) contrib: 外部模型 +| 任务场景 | 模型 | API | Linux | Linux | Windows | Windows | MacOS | MacOS | Linux | +| :--------: | :--------: | :--------: | :--------: | :--------: | :--------: | :--------: | :--------: | :--------: | :--------: | +| --- | --- | --- | X86 CPU | NVIDIA GPU | Intel CPU | NVIDIA GPU | Intel CPU | Arm CPU | NVIDIA Jetson | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PPLCNet](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PPLCNetv2](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PPHGNet](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/SwinTransformer](./examples/vision/classification/paddleclas) | [Python](./examples/vision/classification/paddleclas/python)/[C++](./examples/vision/classification/paddleclas/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/PPYOLOE](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/PPYOLO](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/PPYOLOv2](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [PaddleDetection/FasterRCNN](./examples/vision/detection/paddledetection) | [Python](./examples/vision/detection/paddledetection/python)/[C++](./examples/vision/detection/paddledetection/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/YOLOX](./examples/vision/detection/yolox) | [Python](./examples/vision/detection/yolox/python)/[C++](./examples/vision/detection/yolox/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/YOLOv7](./examples/vision/detection/yolov7) | [Python](./examples/vision/detection/yolov7/python)/[C++](./examples/vision/detection/yolov7/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/YOLOv6](./examples/vision/detection/yolov6) | [Python](./examples/vision/detection/yolov6/python)/[C++](./examples/vision/detection/yolov6/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/YOLOv5](./examples/vision/detection/yolov5) | [Python](./examples/vision/detection/yolov5/python)/[C++](./examples/vision/detection/yolov5/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/YOLOR](./examples/vision/detection/yolor) | [Python](./examples/vision/detection/yolor/python)/[C++](./examples/vision/detection/yolor/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | [Python](./examples/vision/detection/scaledyolov4/python)/[C++](./examples/vision/detection/scaledyolov4/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/YOLOv5Lite](./examples/vision/detection/yolov5lite) | [Python](./examples/vision/detection/yolov5lite/python)/[C++](./examples/vision/detection/yolov5lite/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [Contrib/NanoDetPlus](./examples/vision/detection/nanodet_plus) | [Python](./examples/vision/detection/nanodet_plus/python)/[C++](./examples/vision/detection/nanodet_plus/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PPLiteSeg](./examples/vision/segmentation/paddleseg) | [Python](./examples/vision/segmentation/paddleseg/python)/[C++](./examples/vision/segmentation/paddleseg/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PPHumanSegLite](./examples/vision/segmentation/paddleseg) | [Python](./examples/vision/segmentation/paddleseg/python)/[C++](./examples/vision/segmentation/paddleseg/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | [Python](./examples/vision/segmentation/paddleseg/python)/[C++](./examples/vision/segmentation/paddleseg/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PPHumanSegServer](./examples/vision/segmentation/paddleseg) | [Python](./examples/vision/segmentation/paddleseg/python)/[C++](./examples/vision/segmentation/paddleseg/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | [Python](./examples/vision/segmentation/paddleseg/python)/[C++](./examples/vision/segmentation/paddleseg/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | [Python](./examples/vision/segmentation/paddleseg/python)/[C++](./examples/vision/segmentation/paddleseg/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Contrib/RetinaFace](./examples/vision/facedet/retinaface) | [Python](./examples/vision/facedet/retinaface/python)/[C++](./examples/vision/facedet/retinaface/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Contrib/UltraFace](./examples/vision/facedet/utltraface) | [ Python](./examples/vision/facedet/utltraface/python)/[C++](./examples/vision/facedet/utltraface/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Contrib/YOLOv5Face](./examples/vision/facedet/yolov5face) | [Python](./examples/vision/facedet/yolov5face/python)/[C++](./examples/vision/facedet/yolov5face/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Contrib/SCRFD](./examples/vision/facedet/scrfd) | [Python](./examples/vision/facedet/scrfd/python)/[C++](./examples/vision/facedet/scrfd/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [Contrib/ArcFace](./examples/vision/faceid/insightface) | [Python](./examples/vision/faceid/insightface/python)/[C++](./examples/vision/faceid/insightface/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [Contrib/CosFace](./examples/vision/faceid/insightface) | [Python](./examples/vision/faceid/insightface/python)/[C++](./examples/vision/faceid/insightface/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [Contrib/PartialFC](./examples/vision/faceid/insightface) | [Python](./examples/vision/faceid/insightface/python)/[C++](./examples/vision/faceid/insightface/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [Contrib/VPL](./examples/vision/faceid/insightface) | [Python](./examples/vision/faceid/insightface/python)/[C++](./examples/vision/faceid/insightface/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [Contrib/MODNet](./examples/vision/matting/modnet) | [Python](./examples/vision/matting/modnet/python)/[C++](./examples/vision/matting/modnet/cpp) | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | + + +## 2. 服务端快速开始 +
+ +
+💡 快速安装 FastDeploy Python/C++ 库 + +用户根据自己的python版本选择安装对应的wheel包,详细的wheel目录请参考 [python安装文档](docs/compile/prebuilt_wheels.md) . + +```bash pip install https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_python-0.2.0-cp38-cp38-manylinux1_x86_64.whl ``` - -准备目标检测模型和测试图片 +或获取C++预编译库,更多可用的预编译库请参考 [C++预编译库下载](docs/compile/prebuilt_libraries.md) +```bash +wget https://bj.bcebos.com/paddlehub/fastdeploy/cpp/fastdeploy-linux-x64-0.2.0.tgz ``` +准备目标检测模型和测试图片 +```bash wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz tar xvf ppyoloe_crn_l_300e_coco.tgz wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg ``` +
-加载模型预测 -``` -import fastdeploy.vision as vis -import cv2 +### 2.1 Python预测示例 +
-model = vis.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", - "ppyoloe_crn_l_300e_coco/model.pdiparams", - "ppyoloe_crn_l_300e_coco/infer_cfg.yml") +```python +import cv2 +import fastdeploy.vision as vision +model = vision.detection.PPYOLOE("model.pdmodel", "model.pdiparams", "infer_cfg.yml") im = cv2.imread("000000014439.jpg") result = model.predict(im.copy()) print(result) -vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) +vis_im = vision.vis_detection(im, result, score_threshold=0.5) cv2.imwrite("vis_image.jpg", vis_im) ``` +### 2.2 C++预测示例 +
-预测完成,可视化结果保存至`vis_image.jpg`,同时输出检测结果如下 -``` -DetectionResult: [xmin, ymin, xmax, ymax, score, label_id] -415.047363,89.311523, 506.009613, 283.863129, 0.950423, 0 -163.665710,81.914894, 198.585342, 166.760880, 0.896433, 0 -581.788635,113.027596, 612.623474, 198.521713, 0.842597, 0 -267.217224,89.777321, 298.796051, 169.361496, 0.837951, 0 -104.465599,45.482410, 127.688835, 93.533875, 0.773348, 0 -... -``` - -## 更多服务端部署示例 +```C++ +#include "fastdeploy/vision.h" -FastDeploy提供了大量部署示例供开发者参考,支持模型在CPU、GPU以及TensorRT的部署 +int main(int argc, char* argv[]) { + namespace vision = fastdeploy::vision; + auto model = vision::detection::PPYOLOE("model.pdmodel", "model.pdiparams", "infer_cfg.yml"); + auto im = cv::imread("000000014439.jpg"); -- [PaddleDetection模型部署](examples/vision/detection/paddledetection) -- [PaddleClas模型部署](examples/vision/classification/paddleclas) -- [PaddleSeg模型部署](examples/vision/segmentation/paddleseg) -- [YOLOv7部署](examples/vision/detection/yolov7) -- [YOLOv6部署](examples/vision/detection/yolov6) -- [YOLOv5部署](examples/vision/detection/yolov5) -- [人脸检测模型部署](examples/vision/facedet) -- [更多视觉模型部署示例...](examples/vision) + vision::DetectionResult res; + model.Predict(&im, &res) -### 📱轻量化SDK快速实现端侧AI推理部署 + auto vis_im = vision::Visualize::VisDetection(im, res, 0.5); + cv::imwrite("vis_image.jpg", vis_im); +} +``` +更多部署案例请参考[视觉模型部署示例](examples/vision) . +## 3. 轻量化SDK快速实现端侧AI推理部署 📱 +
| 任务场景 | 模型 | 大小(MB) | 边缘端 | 移动端 | 移动端 | -| ------------------ | ---------------------------- | --------------------- | --------------------- | ---------------------- | --------------------- | -| ---- | --- | --- | Linux | Android | iOS | -| ----- | ---- | --- | ARM CPU | ARM CPU | ARM CPU | -| Classfication | PP-LCNet | 11.9 | ✅ | ✅ | ✅ | -| | PP-LCNetv2 | 26.6 | ✅ | ✅ | ✅ | -| | EfficientNet | 31.4 | ✅ | ✅ | ✅ | -| | GhostNet | 20.8 | ✅ | ✅ | ✅ | -| | MobileNetV1 | 17 | ✅ | ✅ | ✅ | -| | MobileNetV2 | 14.2 | ✅ | ✅ | ✅ | -| | MobileNetV3 | 22 | ✅ | ✅ | ✅ | -| | ShuffleNetV2 | 9.2 | ✅ | ✅ | ✅ | -| | SqueezeNetV1.1 | 5 | ✅ | ✅ | ✅ | -| | Inceptionv3 | 95.5 | ✅ | ✅ | ✅ | -| | PP-HGNet | 59 | ✅ | ✅ | ✅ | -| | SwinTransformer_224_win7 | 352.7 | ✅ | ✅ | ✅ | -| Detection | PP-PicoDet_s_320_coco | 4.1 | ✅ | ✅ | ✅ | -| | PP-PicoDet_s_320_lcnet | 4.9 | ✅ | ✅ | ✅ | -| | CenterNet | 4.8 | ✅ | ✅ | ✅ | -| | YOLOv3_MobileNetV3 | 94.6 | ✅ | ✅ | ✅ | -| | PP-YOLO_tiny_650e_coco | 4.4 | ✅ | ✅ | ✅ | -| | SSD_MobileNetV1_300_120e_voc | 23.3 | ✅ | ✅ | ✅ | -| | PP-YOLO_ResNet50vd | 188.5 | ✅ | ✅ | ✅ | -| | PP-YOLOv2_ResNet50vd | 218.7 | ✅ | ✅ | ✅ | -| | PP-YOLO_crn_l_300e_coco | 209.1 | ✅ | ✅ | ✅ | -| | YOLOv5s | 29.3 | ✅ | ✅ | ✅ | -| Face Detection | BlazeFace | 1.5 | ✅ | ✅ | ✅ | -| Face Localisation | RetinaFace | 1.7 | ✅ | ❌ | ❌ | -| Keypoint Detection | PP-TinyPose | 5.5 | ✅ | ✅ | ✅ | -| Segmentation | PP-LiteSeg(STDC1) | 32.2 | ✅ | ✅ | ✅ | -| | PP-HumanSeg-Lite | 0.556 | ✅ | ✅ | ✅ | -| | HRNet-w18 | 38.7 | ✅ | ✅ | ✅ | -| | PP-HumanSeg-Server | 107.2 | ✅ | ✅ | ✅ | -| | Unet | 53.7 | ❌ | ✅ | ❌ | -| OCR | PP-OCRv1 | 2.3+4.4 | ✅ | ✅ | ✅ | -| | PP-OCRv2 | 2.3+4.4 | ✅ | ✅ | ✅ | -| | PP-OCRv3 | 2.4+10.6 | ✅ | ✅ | ✅ | -| | PP-OCRv3-tiny | 2.4+10.7 | ✅ | ✅ | ✅ | - - -#### 边缘侧部署 - -- ARM Linux 系统 +| :--------: | :--------: | :--------: | :--------: | :--------: | :--------: | +| --- | --- | --- | Linux | Android | iOS | +| --- | --- | --- | ARM CPU | ARM CPU | ARM CPU | +| Classification | PP-LCNet | 11.9 | ✅ | ✅ | ✅ | +| Classification | PP-LCNetv2 | 26.6 | ✅ | ✅ | ✅ | +| Classification | EfficientNet | 31.4 | ✅ | ✅ | ✅ | +| Classification | GhostNet | 20.8 | ✅ | ✅ | ✅ | +| Classification | MobileNetV1 | 17 | ✅ | ✅ | ✅ | +| Classification | MobileNetV2 | 14.2 | ✅ | ✅ | ✅ | +| Classification | MobileNetV3 | 22 | ✅ | ✅ | ✅ | +| Classification | ShuffleNetV2 | 9.2 | ✅ | ✅ | ✅ | +| Classification | SqueezeNetV1.1 | 5 | ✅ | ✅ | ✅ | +| Classification | Inceptionv3 | 95.5 | ✅ | ✅ | ✅ | +| Classification | PP-HGNet | 59 | ✅ | ✅ | ✅ | +| Classification | SwinTransformer_224_win7 | 352.7 | ✅ | ✅ | ✅ | +| Detection | PP-PicoDet_s_320_coco | 4.1 | ✅ | ✅ | ✅ | +| Detection | PP-PicoDet_s_320_lcnet | 4.9 | ✅ | ✅ | ✅ | +| Detection | CenterNet | 4.8 | ✅ | ✅ | ✅ | +| Detection | YOLOv3_MobileNetV3 | 94.6 | ✅ | ✅ | ✅ | +| Detection | PP-YOLO_tiny_650e_coco | 4.4 | ✅ | ✅ | ✅ | +| Detection | SSD_MobileNetV1_300_120e_voc | 23.3 | ✅ | ✅ | ✅ | +| Detection | PP-YOLO_ResNet50vd | 188.5 | ✅ | ✅ | ✅ | +| Detection | PP-YOLOv2_ResNet50vd | 218.7 | ✅ | ✅ | ✅ | +| Detection | PP-YOLO_crn_l_300e_coco | 209.1 | ✅ | ✅ | ✅ | +| Detection | YOLOv5s | 29.3 | ✅ | ✅ | ✅ | +| FaceDetection | BlazeFace | 1.5 | ✅ | ✅ | ✅ | +| FaceDetection | RetinaFace | 1.7 | ✅ | ❌ | ❌ | +| KeypointsDetection | PP-TinyPose | 5.5 | ✅ | ✅ | ✅ | +| Segmentation | PP-LiteSeg(STDC1) | 32.2 | ✅ | ✅ | ✅ | +| Segmentation | PP-HumanSeg-Lite | 0.556 | ✅ | ✅ | ✅ | +| Segmentation | HRNet-w18 | 38.7 | ✅ | ✅ | ✅ | +| Segmentation | PP-HumanSeg-Server | 107.2 | ✅ | ✅ | ✅ | +| Segmentation | Unet | 53.7 | ❌ | ✅ | ❌ | +| OCR | PP-OCRv1 | 2.3+4.4 | ✅ | ✅ | ✅ | +| OCR | PP-OCRv2 | 2.3+4.4 | ✅ | ✅ | ✅ | +| OCR | PP-OCRv3 | 2.4+10.6 | ✅ | ✅ | ✅ | +| OCR | PP-OCRv3-tiny | 2.4+10.7 | ✅ | ✅ | ✅ | + +### 3.1 边缘侧部署 +
+ +- ARM Linux 系统 - [C++ Inference部署(含视频流)](./docs/ARM-Linux-CPP-SDK-Inference.md) - [C++ 服务化部署](./docs/ARM-Linux-CPP-SDK-Serving.md) - [Python Inference部署](./docs/ARM-Linux-Python-SDK-Inference.md) - [Python 服务化部署](./docs/ARM-Linux-Python-SDK-Serving.md) -#### 移动端部署 +### 3.2 移动端部署 +
- [iOS 系统部署](./docs/iOS-SDK.md) - [Android 系统部署](./docs/Android-SDK.md) -#### 自定义模型部署 +### 3.3 自定义模型部署 +
- [快速实现个性化模型替换](./docs/Replace-Model-With-Anther-One.md) -## 社区交流 +## 4. 社区交流 +
- **加入社区👬:** 微信扫描二维码后,填写问卷加入交流群,与开发者共同讨论推理部署痛点问题 @@ -167,11 +214,13 @@ FastDeploy提供了大量部署示例供开发者参考,支持模型在CPU、G -## Acknowledge +## 5. Acknowledge +
本项目中SDK生成和下载使用了[EasyEdge](https://ai.baidu.com/easyedge/app/openSource)中的免费开放能力,再次表示感谢。 -## License +## 6. License +
FastDeploy遵循[Apache-2.0开源协议](./LICENSE)。 diff --git a/csrc/fastdeploy/core/config.h.in b/csrc/fastdeploy/core/config.h.in index 7713925867a..b29113f1fdb 100644 --- a/csrc/fastdeploy/core/config.h.in +++ b/csrc/fastdeploy/core/config.h.in @@ -45,6 +45,10 @@ #cmakedefine ENABLE_VISION #endif +#ifndef ENABLE_TEXT +#cmakedefine ENABLE_TEXT +#endif + #ifndef ENABLE_OPENCV_CUDA #cmakedefine ENABLE_OPENCV_CUDA #endif @@ -52,3 +56,7 @@ #ifndef ENABLE_VISION_VISUALIZE #cmakedefine ENABLE_VISION_VISUALIZE #endif + +#ifndef ENABLE_FDTENSOR_FUNC +#cmakedefine ENABLE_FDTENSOR_FUNC +#endif diff --git a/csrc/fastdeploy/vision/segmentation/ppseg/model.cc b/csrc/fastdeploy/vision/segmentation/ppseg/model.cc index be5c241f7d3..9604d665c13 100644 --- a/csrc/fastdeploy/vision/segmentation/ppseg/model.cc +++ b/csrc/fastdeploy/vision/segmentation/ppseg/model.cc @@ -14,7 +14,7 @@ PaddleSegModel::PaddleSegModel(const std::string& model_file, const Frontend& model_format) { config_file_ = config_file; valid_cpu_backends = {Backend::PDINFER, Backend::ORT}; - valid_gpu_backends = {Backend::PDINFER, Backend::ORT}; + valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT}; runtime_option = custom_option; runtime_option.model_format = model_format; runtime_option.model_file = model_file; diff --git a/docs/api/vision_results/README.md b/docs/api/vision_results/README.md index 844388cca86..64ea4fc671b 100644 --- a/docs/api/vision_results/README.md +++ b/docs/api/vision_results/README.md @@ -6,5 +6,6 @@ FastDeploy根据视觉模型的任务类型,定义了不同的结构体(`csrcs | :----- | :--- | :---- | :------- | | ClassificationResult | [C++/Python文档](./classification_result.md) | 图像分类返回结果 | ResNet50、MobileNetV3等 | | DetectionResult | [C++/Python文档](./detection_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 | -| FaceDetectionResult | [C++/Python文档](./face_detection_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 | -| MattingResult | [C++/Python文档](./matting_result.md) | 目标检测返回结果 | PPYOLOE、YOLOv7系列模型等 | +| FaceDetectionResult | [C++/Python文档](./face_detection_result.md) | 目标检测返回结果 | SCRFD、RetinaFace系列模型等 | +| FaceRecognitionResult | [C++/Python文档](./face_recognition_result.md) | 目标检测返回结果 | ArcFace、CosFace系列模型等 | +| MattingResult | [C++/Python文档](./matting_result.md) | 目标检测返回结果 | MODNet系列模型等 | diff --git a/docs/api/vision_results/classification_result.md b/docs/api/vision_results/classification_result.md index 113db39608a..bf94d0ff159 100644 --- a/docs/api/vision_results/classification_result.md +++ b/docs/api/vision_results/classification_result.md @@ -2,7 +2,7 @@ ClassifyResult代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像的分类结果和置信度。 -## C++ 结构体 +## C++ 定义 `fastdeploy::vision::ClassifyResult` @@ -20,7 +20,7 @@ struct ClassifyResult { - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) -## Python结构体 +## Python 定义 `fastdeploy.vision.ClassifyResult` diff --git a/docs/api/vision_results/detection_result.md b/docs/api/vision_results/detection_result.md index e44a27b34c3..a702d49899f 100644 --- a/docs/api/vision_results/detection_result.md +++ b/docs/api/vision_results/detection_result.md @@ -2,7 +2,7 @@ DetectionResult代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。 -## C++ 结构体 +## C++ 定义 `fastdeploy::vision::DetectionResult` @@ -22,10 +22,10 @@ struct DetectionResult { - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) -## Python结构体 +## Python 定义 `fastdeploy.vision.DetectionResult` - **boxes**(list of list(float)): 成员变量,表示单张图片检测出来的所有目标框坐标。boxes是一个list,其每个元素为一个长度为4的list, 表示为一个框,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 - **scores**(list of float): 成员变量,表示单张图片检测出来的所有目标置信度 -- **label_ids(list of int): 成员变量,表示单张图片检测出来的所有目标类别 +- **label_ids**(list of int): 成员变量,表示单张图片检测出来的所有目标类别 diff --git a/docs/api/vision_results/face_detection_result.md b/docs/api/vision_results/face_detection_result.md index 6c9c09f0073..30029a7f0fa 100644 --- a/docs/api/vision_results/face_detection_result.md +++ b/docs/api/vision_results/face_detection_result.md @@ -1,8 +1,8 @@ # FaceDetectionResult 人脸检测结果 -FaceDetectionResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。 +FaceDetectionResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明人脸检测出来的目标框、人脸landmarks,目标置信度和每张人脸的landmark数量。 -## C++ 结构体 +## C++ 定义 `fastdeploy::vision::FaceDetectionResult` @@ -11,7 +11,6 @@ struct FaceDetectionResult { std::vector> boxes; std::vector> landmarks; std::vector scores; - ResultType type = ResultType::FACE_DETECTION; int landmarks_per_face; void Clear(); std::string Str(); @@ -25,10 +24,12 @@ struct FaceDetectionResult { - **Clear()**: 成员函数,用于清除结构体中存储的结果 - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) -## Python结构体 +## Python 定义 `fastdeploy.vision.FaceDetectionResult` - **boxes**(list of list(float)): 成员变量,表示单张图片检测出来的所有目标框坐标。boxes是一个list,其每个元素为一个长度为4的list, 表示为一个框,每个框以4个float数值依次表示xmin, ymin, xmax, ymax, 即左上角和右下角坐标 - **scores**(list of float): 成员变量,表示单张图片检测出来的所有目标置信度 -- **landmarks**: 成员变量,表示单张图片检测出来的所有人脸的关键点 +- **landmarks**(list of list(float)): 成员变量,表示单张图片检测出来的所有人脸的关键点 +- **landmarks_per_face**(int): 成员变量,表示每个人脸框中的关键点的数量。 + diff --git a/docs/api/vision_results/face_recognition_result.md b/docs/api/vision_results/face_recognition_result.md new file mode 100644 index 00000000000..54d6eabb145 --- /dev/null +++ b/docs/api/vision_results/face_recognition_result.md @@ -0,0 +1,24 @@ +# FaceRecognitionResult 人脸识别结果 + +FaceRecognitionResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明人脸识别模型对图像特征的embedding。 +## C++ 定义 + +`fastdeploy::vision::FaceRecognitionResult` + +``` +struct FaceRecognitionResult { + std::vector embedding; + void Clear(); + std::string Str(); +}; +``` + +- **embedding**: 成员变量,表示人脸识别模型最终的提取的特征embedding,可以用来计算人脸之间的特征相似度。 +- **Clear()**: 成员函数,用于清除结构体中存储的结果 +- **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) + +## Python 定义 + +`fastdeploy.vision.FaceRecognitionResult` + +- **embedding**(list of float): 成员变量,表示人脸识别模型最终提取的特征embedding,可以用来计算人脸之间的特征相似度。 diff --git a/docs/api/vision_results/matting_result.md b/docs/api/vision_results/matting_result.md index 3418400ecaa..5a61365c268 100644 --- a/docs/api/vision_results/matting_result.md +++ b/docs/api/vision_results/matting_result.md @@ -1,15 +1,15 @@ # MattingResult 抠图结果 -MattingResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明图像检测出来的目标框、目标类别和目标置信度。 +MattingResult 代码定义在`csrcs/fastdeploy/vision/common/result.h`中,用于表明模型预测的alpha透明度的值,预测的前景等。 -## C++ 结构体 +## C++ 定义 `fastdeploy::vision::MattingResult` ``` struct MattingResult { - std::vector alpha; // h x w - std::vector foreground; // h x w x c (c=3 default) + std::vector alpha; + std::vector foreground; std::vector shape; bool contain_foreground = false; void Clear(); @@ -25,11 +25,11 @@ struct MattingResult { - **Str()**: 成员函数,将结构体中的信息以字符串形式输出(用于Debug) -## Python结构体 +## Python 定义 `fastdeploy.vision.MattingResult` -- **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 +- **alpha**(list of float): 是一维向量,为预测的alpha透明度的值,值域为[0.,1.],长度为hxw,h,w为输入图像的高和宽 +- **foreground**(list of float): 是一维向量,为预测的前景,值域为[0.,255.],长度为hxwxc,h,w为输入图像的高和宽,c一般为3,foreground不是一定有的,只有模型本身预测了前景,这个属性才会有效 +- **contain_foreground**(bool): 表示预测的结果是否包含前景 +- **shape**(list of int): 表示输出结果的shape,当contain_foreground为false,shape只包含(h,w),当contain_foreground为true,shape包含(h,w,c), c一般为3 diff --git a/docs/compile/prebuilt_libraries.md b/docs/compile/prebuilt_libraries.md index 6cec3721acd..905eb6d5295 100644 --- a/docs/compile/prebuilt_libraries.md +++ b/docs/compile/prebuilt_libraries.md @@ -1,4 +1,4 @@ -# FastDeploy 预编编译Python Wheel包 +# FastDeploy 预编译 C++ 库 FastDeploy提供了在Windows/Linux/Mac上的预先编译CPP部署库,开发者可以直接下载后使用,也可以自行编译代码。 @@ -19,17 +19,17 @@ FastDeploy提供了在Windows/Linux/Mac上的预先编译CPP部署库,开发 ### Windows 10 x64平台 -| 部署库下载地址 | 硬件 | -| :------------- | :--- | -| [comming...] | CPU | -| [comming...] | CPU/GPU | +| 部署库下载地址 | 硬件 | 说明 | +| :------------- | :--- | :--- | +| [fastdeploy-win-x64-0.2.0](https://bj.bcebos.com/paddlehub/fastdeploy/cpp/fastdeploy-win-x64-0.2.0.zip) | CPU | Visual Studio 16 2019 编译产出 | +| [fastdeploy-win-x64-gpu-0.2.0](https://bj.bcebos.com/paddlehub/fastdeploy/cpp/fastdeploy-win-x64-gpu-0.2.0.zip) | CPU/GPU | Visual Studio 16 2019,cuda 11.2, cudnn 8.2编译产出 | ### Linux aarch64平台 | 安装包 | 硬件 | | :---- | :-- | | [comming...] | CPU | -| [comming...] | Jetson | +| [comming...] | Jetson | ### Mac OSX平台 diff --git a/docs/compile/prebuilt_wheels.md b/docs/compile/prebuilt_wheels.md index 14ba7d40044..e3ada892e11 100644 --- a/docs/compile/prebuilt_wheels.md +++ b/docs/compile/prebuilt_wheels.md @@ -38,15 +38,20 @@ python -m pip install fastdeploy_python-0.2.0-cp38-cp38-manylinux1_x86_64.whl | CPU 安装包 | 硬件 | Python版本 | | :---- | :-- | :------ | -| [comming...] | CPU | 3.8 | -| [comming...] | CPU | 3.9 | +| [fastdeploy_python-0.2.0-cp38-cp38-win_amd64.whl](https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_python-0.2.0-cp38-cp38-win_amd64.whl) | CPU | 3.8 | +| [fastdeploy_python-0.2.0-cp39-cp39-win_amd64.whl](https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_python-0.2.0-cp39-cp39-win_amd64.whl) | CPU | 3.9 | + +| GPU 安装包 | 硬件 | Python版本 | +| :---- | :-- | :------ | +| [fastdeploy_gpu_python-0.2.0-cp38-cp38-win_amd64.whl](https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_gpu_python-0.2.0-cp38-cp38-win_amd64.whl) | CPU/GPU | 3.8 | +| [fastdeploy_gpu_python-0.2.0-cp39-cp39-win_amd64.whl](https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_gpu_python-0.2.0-cp39-cp39-win_amd64.whl) | CPU/GPU | 3.9 | ### Linux aarch64平台 | 安装包 | 硬件 | Python版本 | | :---- | :-- | :------ | | [comming...] | CPU | 3.7 | -| [comming...] | CPU | 3.8 | +| [comming...] | CPU | 3.8 | | [comming...] | CPU | 3.9 | ### Mac OSX平台 diff --git a/docs/logo/fastdeploy-opaque.png b/docs/logo/fastdeploy-opaque.png new file mode 100644 index 00000000000..16289dcf555 Binary files /dev/null and b/docs/logo/fastdeploy-opaque.png differ diff --git a/examples/text/information_extraction/ernie/cpp/CMakeLists.txt b/examples/text/information_extraction/ernie/cpp/CMakeLists.txt new file mode 100644 index 00000000000..1189820cb79 --- /dev/null +++ b/examples/text/information_extraction/ernie/cpp/CMakeLists.txt @@ -0,0 +1,25 @@ +# 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. + +PROJECT(infer_demo C CXX) +CMAKE_MINIMUM_REQUIRED (VERSION 3.12) + +option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") + +include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) + +include_directories(${FASTDEPLOY_INCS}) + +add_executable(infer_ernie_demo ${PROJECT_SOURCE_DIR}/infer.cc) +target_link_libraries(infer_ernie_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/text/information_extraction/ernie/cpp/infer.cc b/examples/text/information_extraction/ernie/cpp/infer.cc new file mode 100644 index 00000000000..7f3b9318664 --- /dev/null +++ b/examples/text/information_extraction/ernie/cpp/infer.cc @@ -0,0 +1,182 @@ +// 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 +#include + +#include "fastdeploy/function/reduce.h" +#include "fastdeploy/function/softmax.h" +#include "fastdeploy/text.h" +#include "tokenizers/ernie_faster_tokenizer.h" + +using namespace paddlenlp; + +void LoadTransitionFromFile(const std::string& file, + std::vector* transitions, int* num_tags) { + std::ifstream fin(file); + std::string curr_transition; + float transition; + int i = 0; + while (fin) { + std::getline(fin, curr_transition); + std::istringstream iss(curr_transition); + while (iss) { + iss >> transition; + transitions->push_back(transition); + } + if (curr_transition != "") { + ++i; + } + } + *num_tags = i; +} + +template +void ViterbiDecode(const fastdeploy::FDTensor& slot_logits, + const fastdeploy::FDTensor& trans, + fastdeploy::FDTensor* best_path) { + int batch_size = slot_logits.shape[0]; + int seq_len = slot_logits.shape[1]; + int num_tags = slot_logits.shape[2]; + best_path->Allocate({batch_size, seq_len}, fastdeploy::FDDataType::INT64); + + const T* slot_logits_ptr = reinterpret_cast(slot_logits.Data()); + const T* trans_ptr = reinterpret_cast(trans.Data()); + int64_t* best_path_ptr = reinterpret_cast(best_path->Data()); + std::vector scores(num_tags); + std::copy(slot_logits_ptr, slot_logits_ptr + num_tags, scores.begin()); + std::vector> M(num_tags, std::vector(num_tags)); + for (int b = 0; b < batch_size; ++b) { + std::vector> paths; + const T* curr_slot_logits_ptr = slot_logits_ptr + b * seq_len * num_tags; + int64_t* curr_best_path_ptr = best_path_ptr + b * seq_len; + for (int t = 1; t < seq_len; t++) { + for (size_t i = 0; i < num_tags; i++) { + for (size_t j = 0; j < num_tags; j++) { + auto trans_idx = i * num_tags * num_tags + j * num_tags; + auto slot_logit_idx = t * num_tags + j; + M[i][j] = scores[i] + trans_ptr[trans_idx] + + curr_slot_logits_ptr[slot_logit_idx]; + } + } + std::vector idxs; + for (size_t i = 0; i < num_tags; i++) { + T max = 0.0f; + int idx = 0; + for (size_t j = 0; j < num_tags; j++) { + if (M[j][i] > max) { + max = M[j][i]; + idx = j; + } + } + scores[i] = max; + idxs.push_back(idx); + } + paths.push_back(idxs); + } + int scores_max_index = 0; + float scores_max = 0.0f; + for (size_t i = 0; i < scores.size(); i++) { + if (scores[i] > scores_max) { + scores_max = scores[i]; + scores_max_index = i; + } + } + curr_best_path_ptr[seq_len - 1] = scores_max_index; + for (int i = seq_len - 2; i >= 0; i--) { + int index = curr_best_path_ptr[i + 1]; + curr_best_path_ptr[i] = paths[i][index]; + } + } +} + +int main() { + // 1. Define a ernie faster tokenizer + faster_tokenizer::tokenizers_impl::ErnieFasterTokenizer tokenizer( + "ernie_vocab.txt"); + std::vector strings_list = { + "导航去科技园二号楼", "屏幕亮度为我减小一点吧"}; + std::vector encodings; + tokenizer.EncodeBatchStrings(strings_list, &encodings); + size_t batch_size = strings_list.size(); + size_t seq_len = encodings[0].GetLen(); + for (auto&& encoding : encodings) { + std::cout << encoding.DebugString() << std::endl; + } + // 2. Initialize runtime + fastdeploy::RuntimeOption runtime_option; + runtime_option.SetModelPath("nano_static/model.pdmodel", + "nano_static/model.pdiparams"); + fastdeploy::Runtime runtime; + runtime.Init(runtime_option); + + // 3. Construct input vector + // 3.1 Convert encodings to input_ids, token_type_ids + std::vector input_ids, token_type_ids; + for (int i = 0; i < encodings.size(); ++i) { + auto&& curr_input_ids = encodings[i].GetIds(); + auto&& curr_type_ids = encodings[i].GetTypeIds(); + input_ids.insert(input_ids.end(), curr_input_ids.begin(), + curr_input_ids.end()); + token_type_ids.insert(token_type_ids.end(), curr_type_ids.begin(), + curr_type_ids.end()); + } + // 3.2 Set data to input vector + std::vector inputs(runtime.NumInputs()); + void* inputs_ptrs[] = {input_ids.data(), token_type_ids.data()}; + for (int i = 0; i < runtime.NumInputs(); ++i) { + inputs[i].SetExternalData({batch_size, seq_len}, + fastdeploy::FDDataType::INT64, inputs_ptrs[i]); + inputs[i].name = runtime.GetInputInfo(i).name; + } + + // 4. Infer + std::vector outputs(runtime.NumOutputs()); + runtime.Infer(inputs, &outputs); + + // 5. Postprocess + fastdeploy::FDTensor domain_probs, intent_probs; + fastdeploy::Softmax(outputs[0], &domain_probs); + fastdeploy::Softmax(outputs[1], &intent_probs); + + fastdeploy::FDTensor domain_max_probs, intent_max_probs; + fastdeploy::Max(domain_probs, &domain_max_probs, {-1}, true); + fastdeploy::Max(intent_probs, &intent_max_probs, {-1}, true); + + std::vector transition; + int num_tags; + LoadTransitionFromFile("joint_transition.txt", &transition, &num_tags); + fastdeploy::FDTensor trans; + trans.SetExternalData({num_tags, num_tags}, fastdeploy::FDDataType::FP32, + transition.data()); + + fastdeploy::FDTensor best_path; + ViterbiDecode(outputs[2], trans, &best_path); + // 6. Print result + domain_max_probs.PrintInfo(); + intent_max_probs.PrintInfo(); + + batch_size = best_path.shape[0]; + seq_len = best_path.shape[1]; + const int64_t* best_path_ptr = + reinterpret_cast(best_path.Data()); + for (int i = 0; i < batch_size; ++i) { + std::cout << "best_path[" << i << "] = "; + for (int j = 0; j < seq_len; ++j) { + std::cout << best_path_ptr[i * seq_len + j] << ", "; + } + std::cout << std::endl; + } + best_path.PrintInfo(); + return 0; +} diff --git a/examples/vision/README.md b/examples/vision/README.md index 9f05d2d7f6d..d95a315d798 100644 --- a/examples/vision/README.md +++ b/examples/vision/README.md @@ -8,6 +8,7 @@ | Segmentation | 语义分割,输入图像,给出图像中每个像素的分类及置信度 | [SegmentationResult](../../docs/api/vision_results/segmentation_result.md) | | Classification | 图像分类,输入图像,给出图像的分类结果和置信度 | [ClassifyResult](../../docs/api/vision_results/classification_result.md) | | FaceDetection | 人脸检测,输入图像,检测图像中人脸位置,并返回检测框坐标及人脸关键点 | [FaceDetectionResult](../../docs/api/vision_results/face_detection_result.md) | +| FaceRecognition | 人脸识别,输入图像,返回可用于相似度计算的人脸特征的embedding | [FaceRecognitionResult](../../docs/api/vision_results/face_recognition_result.md) | | Matting | 抠图,输入图像,返回图片的前景每个像素点的Alpha值 | [MattingResult](../../docs/api/vision_results/matting_result.md) | ## FastDeploy API设计 diff --git a/examples/vision/classification/paddleclas/README.md b/examples/vision/classification/paddleclas/README.md index 1f837761645..9a62f07f0ba 100644 --- a/examples/vision/classification/paddleclas/README.md +++ b/examples/vision/classification/paddleclas/README.md @@ -21,7 +21,7 @@ PaddleClas模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) -注意:PaddleClas导出的模型仅包含`inference.pdmodel`和`inference.pdiparams`两个文档,但为了满足部署的需求,同时也需准备其提供的通用[inference_cls.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/deploy/configs/inference_cls.yaml)文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,开发者可直接下载此文件使用。但需根据自己的需求修改yaml文件中的配置参数,具体可比照PaddleClas模型训练[config](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4/ppcls/configs/ImageNet)中的infer部分的配置信息进行修改。 +注意:PaddleClas导出的模型仅包含`inference.pdmodel`和`inference.pdiparams`两个文件,但为了满足部署的需求,同时也需准备其提供的通用[inference_cls.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/deploy/configs/inference_cls.yaml)文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,开发者可直接下载此文件使用。但需根据自己的需求修改yaml文件中的配置参数,具体可比照PaddleClas模型训练[config](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4/ppcls/configs/ImageNet)中的infer部分的配置信息进行修改。 ## 下载预训练模型 diff --git a/examples/vision/classification/paddleclas/python/README.md b/examples/vision/classification/paddleclas/python/README.md index c6bb35d2ee5..77ad787973f 100644 --- a/examples/vision/classification/paddleclas/python/README.md +++ b/examples/vision/classification/paddleclas/python/README.md @@ -8,22 +8,21 @@ 本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 ``` +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/classification/paddleclas/python + # 下载ResNet50_vd模型文件和测试图片 wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz tar -xvf ResNet50_vd_infer.tgz wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg - -#下载部署示例代码 -git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/classification/paddleclas/python - # CPU推理 -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu --topk 1 # GPU推理 -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --topk 1 # GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 ``` 运行完成后返回结果如下所示 diff --git a/examples/vision/detection/paddledetection/cpp/README.md b/examples/vision/detection/paddledetection/cpp/README.md index 4ed39929b85..64e2dc99734 100644 --- a/examples/vision/detection/paddledetection/cpp/README.md +++ b/examples/vision/detection/paddledetection/cpp/README.md @@ -15,7 +15,7 @@ wget https://bj.bcebos.com/paddlehub/fastdeploy/libs/0.2.0/fastdeploy-linux-x64- tar xvf fastdeploy-linux-x64-gpu-0.2.0.tgz cd fastdeploy-linux-x64-gpu-0.2.0/examples/vision/detection/paddledetection mkdir build && cd build -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/../../../../../../fastdeploy-linux-x64-gpu-0.2.0 +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/../../../../../../../fastdeploy-linux-x64-gpu-0.2.0 make -j # 下载PPYOLOE模型文件和测试图片 diff --git a/examples/vision/segmentation/paddleseg/README.md b/examples/vision/segmentation/paddleseg/README.md index 1f837761645..413e10b8a2c 100644 --- a/examples/vision/segmentation/paddleseg/README.md +++ b/examples/vision/segmentation/paddleseg/README.md @@ -1,54 +1,36 @@ -# PaddleClas 模型部署 +# PaddleSeg 模型部署 ## 模型版本说明 -- [PaddleClas Release/2.4](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4) +- [PaddleSeg Release/2.6](https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.6) 目前FastDeploy支持如下模型的部署 -- [PP-LCNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNet.md) -- [PP-LCNetV2系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-LCNetV2.md) -- [EfficientNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/EfficientNet_and_ResNeXt101_wsl.md) -- [GhostNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) -- [MobileNet系列模型(包含v1,v2,v3)](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) -- [ShuffleNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Mobile.md) -- [SqueezeNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Others.md) -- [Inception系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/Inception.md) -- [PP-HGNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/PP-HGNet.md) -- [ResNet系列模型(包含vd系列)](https://github.com/PaddlePaddle/PaddleClas/blob/develop/docs/zh_CN/models/ResNet_and_vd.md) +- [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) -## 准备PaddleClas部署模型 +## 准备PaddleSeg部署模型 -PaddleClas模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) +PaddleSeg模型导出,请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) -注意:PaddleClas导出的模型仅包含`inference.pdmodel`和`inference.pdiparams`两个文档,但为了满足部署的需求,同时也需准备其提供的通用[inference_cls.yaml](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/deploy/configs/inference_cls.yaml)文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息,开发者可直接下载此文件使用。但需根据自己的需求修改yaml文件中的配置参数,具体可比照PaddleClas模型训练[config](https://github.com/PaddlePaddle/PaddleClas/tree/release/2.4/ppcls/configs/ImageNet)中的infer部分的配置信息进行修改。 +注意:在使用PaddleSeg模型导出时,可指定`--input_shape`参数,若预测输入图片尺寸并不固定,建议使用默认值即不指定该参数。PaddleSeg导出的模型包含`model.pdmodel`、`model.pdiparams`和`deploy.yaml`三个文件,FastDeploy会从yaml文件中获取模型在推理时需要的预处理信息。 ## 下载预训练模型 -为了方便开发者的测试,下面提供了PaddleClas导出的部分模型(含inference_cls.yaml文件),开发者可直接下载使用。 - -| 模型 | 参数文件大小 |输入Shape | Top1 | Top5 | -|:---------------------------------------------------------------- |:----- |:----- | :----- | :----- | -| [PPLCNet_x1_0](https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNet_x1_0_infer.tgz) | 12MB | 224x224 |71.32% | 90.03% | -| [PPLCNetV2_base](https://bj.bcebos.com/paddlehub/fastdeploy/PPLCNetV2_base_infer.tgz) | 26MB | 224x224 |77.04% | 93.27% | -| [EfficientNetB7](https://bj.bcebos.com/paddlehub/fastdeploy/EfficientNetB7_infer.tgz) | 255MB | 600x600 | 84.3% | 96.9% | -| [EfficientNetB0_small](https://bj.bcebos.com/paddlehub/fastdeploy/EfficientNetB0_small_infer.tgz)| 18MB | 224x224 | 75.8% | 75.8% | -| [GhostNet_x1_3_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/GhostNet_x1_3_ssld_infer.tgz) | 29MB | 224x224 | 75.7% | 92.5% | -| [GhostNet_x0_5_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/GhostNet_x0_5_infer.tgz) | 10MB | 224x224 | 66.8% | 86.9% | -| [MobileNetV1_x0_25](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_x0_25_infer.tgz) | 1.9MB | 224x224 | 51.4% | 75.5% | -| [MobileNetV1_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV1_ssld_infer.tgz) | 17MB | 224x224 | 77.9% | 93.9% | -| [MobileNetV2_x0_25](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV2_x0_25_infer.tgz) | 5.9MB | 224x224 | 53.2% | 76.5% | -| [MobileNetV2_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV2_ssld_infer.tgz) | 14MB | 224x224 | 76.74% | 93.39% | -| [MobileNetV3_small_x0_35_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV3_small_x0_35_ssld_infer.tgz) | 6.4MB | 224x224 | 55.55% | 77.71% | -| [MobileNetV3_large_x1_0_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/MobileNetV3_large_x1_0_ssld_infer.tgz) | 22MB | 224x224 | 78.96% | 94.48% | -| [ShuffleNetV2_x0_25](https://bj.bcebos.com/paddlehub/fastdeploy/ShuffleNetV2_x0_25_infer.tgz) | 2.4MB | 224x224 | 49.9% | 73.79% | -| [ShuffleNetV2_x2_0](https://bj.bcebos.com/paddlehub/fastdeploy/ShuffleNetV2_x2_0_infer.tgz) | 29MB | 224x224 | 73.15% | 91.2% | -| [SqueezeNet1_1](https://bj.bcebos.com/paddlehub/fastdeploy/SqueezeNet1_1_infer.tgz) | 4.8MB | 224x224 | 60.1% | 81.9% | -| [InceptionV3](https://bj.bcebos.com/paddlehub/fastdeploy/InceptionV3_infer.tgz) | 92MB | 299x299 | 79.14% | 94.59% | -| [PPHGNet_tiny_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_tiny_ssld_infer.tgz) | 57MB | 224x224 | 81.95% | 96.12% | -| [PPHGNet_base_ssld](https://bj.bcebos.com/paddlehub/fastdeploy/PPHGNet_base_ssld_infer.tgz) | 274MB | 224x224 | 85.0% | 97.35% | -| [ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz) | 98MB | 224x224 | 79.12% | 94.44% | +为了方便开发者的测试,下面提供了PaddleSeg导出的部分模型(导出方式为:**不指定**`input_shape`和`with_softmax`,**指定**`without_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 |73.10% | 73.89% | - | +| [PP-HumanSegV1-Lite](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Lite_infer.tgz) | 543KB | 192x192 | 86.2% | - | - | +| [PP-HumanSegV1-Server](https://bj.bcebos.com/paddlehub/fastdeploy/PP_HumanSegV1_Server_infer.tgz) | 103MB | 512x512 | 96.47% | - | - | +| [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-ResNet50-OS8-cityscapes](https://bj.bcebos.com/paddlehub/fastdeploy/Deeplabv3_ResNet50_OS8_cityscapes_without_argmax_infer.tgz) | 150MB | 1024x512 | 79.90% | 80.22% | 80.47% | ## 详细部署文档 diff --git a/examples/vision/segmentation/paddleseg/cpp/README.md b/examples/vision/segmentation/paddleseg/cpp/README.md index 302f3f74f36..8e5a9627b16 100644 --- a/examples/vision/segmentation/paddleseg/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/cpp/README.md @@ -1,6 +1,6 @@ -# YOLOv7 C++部署示例 +# PaddleSeg C++部署示例 -本目录下提供`infer.cc`快速完成YOLOv7在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +本目录下提供`infer.cc`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 在部署前,需确认以下两个步骤 @@ -12,51 +12,58 @@ ``` mkdir build cd build -wget https://xxx.tgz -tar xvf fastdeploy-linux-x64-0.2.0.tgz -cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-0.2.0 +wget https://bj.bcebos.com/paddlehub/fastdeploy/libs/0.2.0/fastdeploy-linux-x64-gpu-0.2.0.tgz +tar xvf fastdeploy-linux-x64-gpu-0.2.0.tgz +cd fastdeploy-linux-x64-gpu-0.2.0/examples/vision/segmentation/paddleseg/cpp/build +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/../../../../../../../fastdeploy-linux-x64-gpu-0.2.0 make -j -#下载官方转换好的yolov7模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx -wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000087038.jpg +# 下载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 yolov7.onnx 000000087038.jpg 0 +./infer_demo Unet_cityscapes_without_argmax_infer infer.cc cityscapes_demo.png 0 # GPU推理 -./infer_demo yolov7.onnx 000000087038.jpg 1 +./infer_demo Unet_cityscapes_without_argmax_infer infer.cc cityscapes_demo.png 1 # GPU上TensorRT推理 -./infer_demo yolov7.onnx 000000087038.jpg 2 +./infer_demo Unet_cityscapes_without_argmax_infer infer.cc cityscapes_demo.png 2 ``` -## YOLOv7 C++接口 +运行完成可视化结果如下图所示 +
+ +
-### YOLOv7类 +## PaddleSeg C++接口 + +### PaddleSeg类 ``` -fastdeploy::vision::detection::YOLOv7( +fastdeploy::vision::segmentation::PaddleSegModel( const string& model_file, const string& params_file = "", + const string& config_file, const RuntimeOption& runtime_option = RuntimeOption(), - const Frontend& model_format = Frontend::ONNX) + const Frontend& model_format = Frontend::PADDLE) ``` -YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。 +PaddleSegModel模型加载和初始化,其中model_file为导出的Paddle模型格式。 **参数** > * **model_file**(str): 模型文件路径 -> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **params_file**(str): 参数文件路径 +> * **config_file**(str): 推理部署配置文件 > * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 -> * **model_format**(Frontend): 模型格式,默认为ONNX格式 +> * **model_format**(Frontend): 模型格式,默认为Paddle格式 #### Predict函数 > ``` -> YOLOv7::Predict(cv::Mat* im, DetectionResult* result, -> float conf_threshold = 0.25, -> float nms_iou_threshold = 0.5) +> PaddleSegModel::Predict(cv::Mat* im, DetectionResult* result) > ``` > > 模型预测接口,输入图像直接输出检测结果。 @@ -64,13 +71,16 @@ YOLOv7模型加载和初始化,其中model_file为导出的ONNX模型格式。 > **参数** > > > * **im**: 输入图像,注意需为HWC,BGR格式 -> > * **result**: 检测结果,包括检测框,各个框的置信度, DetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) -> > * **conf_threshold**: 检测框置信度过滤阈值 -> > * **nms_iou_threshold**: NMS处理过程中iou阈值 +> > * **result**: 分割结果,包括分割预测的标签以及标签对应的概率值, SegmentationResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 -### 类成员变量 +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`True`表明输入图片是竖屏,即height大于width的图片 -> > * **size**(vector): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +#### 后处理参数 +> > * **with_softmax**(bool): 当模型导出时,并未指定`with_softmax`参数,可通过此设置此参数为`True`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 - [模型介绍](../../) - [Python部署](../python) diff --git a/examples/vision/segmentation/paddleseg/cpp/infer.cc b/examples/vision/segmentation/paddleseg/cpp/infer.cc index bd07ba988da..1f20ea9c87f 100644 --- a/examples/vision/segmentation/paddleseg/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/cpp/infer.cc @@ -14,34 +14,45 @@ #include "fastdeploy/vision.h" -void CpuInfer(const std::string& model_file, const std::string& params_file, - const std::string& config_file, const std::string& image_file) { - auto option = fastdeploy::RuntimeOption(); - option.UseCpu() auto model = - fastdeploy::vision::classification::PaddleClasModel( - model_file, params_file, config_file, option); +#ifdef WIN32 +const char sep = '\\'; +#else +const char sep = '/'; +#endif + +void CpuInfer(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 model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file); if (!model.Initialized()) { std::cerr << "Failed to initialize." << std::endl; return; } auto im = cv::imread(image_file); + auto im_bak = im.clone(); - fastdeploy::vision::ClassifyResult res; + fastdeploy::vision::SegmentationResult res; if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - // print res - res.Str(); + auto vis_im = fastdeploy::vision::Visualize::VisSegmentation(im_bak, res); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void GpuInfer(const std::string& model_file, const std::string& params_file, - const std::string& config_file, const std::string& image_file) { +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"; + auto config_file = model_dir + sep + "deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); option.UseGpu(); - auto model = fastdeploy::vision::classification::PaddleClasModel( + auto model = fastdeploy::vision::segmentation::PaddleSegModel( model_file, params_file, config_file, option); if (!model.Initialized()) { std::cerr << "Failed to initialize." << std::endl; @@ -49,25 +60,30 @@ void GpuInfer(const std::string& model_file, const std::string& params_file, } auto im = cv::imread(image_file); + auto im_bak = im.clone(); - fastdeploy::vision::ClassifyResult res; + fastdeploy::vision::SegmentationResult res; if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - // print res - res.Str(); + auto vis_im = fastdeploy::vision::Visualize::VisSegmentation(im_bak, res); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } -void TrtInfer(const std::string& model_file, const std::string& params_file, - const std::string& config_file, const std::string& image_file) { +void TrtInfer(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.UseGpu(); option.UseTrtBackend(); - option.SetTrtInputShape("inputs", [ 1, 3, 224, 224 ], [ 1, 3, 224, 224 ], - [ 1, 3, 224, 224 ]); - auto model = fastdeploy::vision::classification::PaddleClasModel( + option.SetTrtInputShape("x", {1, 3, 256, 256}, {1, 3, 1024, 1024}, + {1, 3, 2048, 2048}); + auto model = fastdeploy::vision::segmentation::PaddleSegModel( model_file, params_file, config_file, option); if (!model.Initialized()) { std::cerr << "Failed to initialize." << std::endl; @@ -75,40 +91,37 @@ void TrtInfer(const std::string& model_file, const std::string& params_file, } auto im = cv::imread(image_file); + auto im_bak = im.clone(); - fastdeploy::vision::ClassifyResult res; + fastdeploy::vision::SegmentationResult res; if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - // print res - res.Str(); + auto vis_im = fastdeploy::vision::Visualize::VisSegmentation(im_bak, res); + 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/model path/to/image run_option, " - "e.g ./infer_demo ./ResNet50_vd ./test.jpeg 0" - << std::endl; + std::cout + << "Usage: infer_demo path/to/model_dir path/to/image run_option, " + "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." << std::endl; return -1; } - std::string model_file = - argv[1] + "/" + "model.pdmodel" std::string params_file = - argv[1] + "/" + "model.pdiparams" std::string config_file = - argv[1] + "/" + "inference_cls.yaml" std::string image_file = - argv[2] if (std::atoi(argv[3]) == 0) { - CpuInfer(model_file, params_file, config_file, image_file); - } - else if (std::atoi(argv[3]) == 1) { - GpuInfer(model_file, params_file, config_file, image_file); - } - else if (std::atoi(argv[3]) == 2) { - TrtInfer(model_file, params_file, config_file, image_file); + if (std::atoi(argv[3]) == 0) { + CpuInfer(argv[1], argv[2]); + } else if (std::atoi(argv[3]) == 1) { + GpuInfer(argv[1], argv[2]); + } else if (std::atoi(argv[3]) == 2) { + TrtInfer(argv[1], argv[2]); } return 0; } diff --git a/examples/vision/segmentation/paddleseg/python/README.md b/examples/vision/segmentation/paddleseg/python/README.md index 1259c150992..a4456488491 100644 --- a/examples/vision/segmentation/paddleseg/python/README.md +++ b/examples/vision/segmentation/paddleseg/python/README.md @@ -1,46 +1,43 @@ -# PaddleClas模型 Python部署示例 +# PaddleSeg Python部署示例 在部署前,需确认以下两个步骤 - 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/quick_start/requirements.md) - 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/quick_start/install.md) -本目录下提供`infer.py`快速完成ResNet50_vd在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 +本目录下提供`infer.py`快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 ``` -# 下载ResNet50_vd模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz -tar -xvf ResNet50_vd_infer.tgz -wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg - - #下载部署示例代码 git clone https://github.com/PaddlePaddle/FastDeploy.git -cd examples/vision/classification/paddleclas/python +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 ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device cpu +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu # GPU推理 -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu # GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) -python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True +python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True ``` -运行完成后返回结果如下所示 -``` -ClassifyResult( -label_ids: 153, -scores: 0.686229, -) -``` +运行完成可视化结果如下图所示 +
+ +
-## PaddleClasModel Python接口 +## PaddleSegModel Python接口 ``` -fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=None, model_format=Frontend.PADDLE) +fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=Frontend.PADDLE) ``` -PaddleClas模型加载和初始化,其中model_file, params_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/inference_deployment/export_model.md#2-%E5%88%86%E7%B1%BB%E6%A8%A1%E5%9E%8B%E5%AF%BC%E5%87%BA) +PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明[模型导出](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/docs/model_export_cn.md) **参数** @@ -53,7 +50,7 @@ PaddleClas模型加载和初始化,其中model_file, params_file为训练模 ### predict函数 > ``` -> PaddleClasModel.predict(input_image, topk=1) +> PaddleSegModel.predict(input_image) > ``` > > 模型预测结口,输入图像直接输出检测结果。 @@ -61,15 +58,22 @@ PaddleClas模型加载和初始化,其中model_file, params_file为训练模 > **参数** > > > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式 -> > * **topk**(int):返回预测概率最高的topk个分类结果 > **返回** > -> > 返回`fastdeploy.vision.ClassifyResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > 返回`fastdeploy.vision.SegmentationResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **is_vertical_screen**(bool): PP-HumanSeg系列模型通过设置此参数为`true`表明输入图片是竖屏,即height大于width的图片 +#### 后处理参数 +> > * **with_softmax**(bool): 当模型导出时,并未指定`with_softmax`参数,可通过此设置此参数为`true`,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理 ## 其它文档 -- [PaddleClas 模型介绍](..) -- [PaddleClas C++部署](../cpp) +- [PaddleSeg 模型介绍](..) +- [PaddleSeg C++部署](../cpp) - [模型预测结果说明](../../../../../docs/api/vision_results/) diff --git a/examples/vision/segmentation/paddleseg/python/infer.py b/examples/vision/segmentation/paddleseg/python/infer.py index 88c272bcac7..28903e92957 100644 --- a/examples/vision/segmentation/paddleseg/python/infer.py +++ b/examples/vision/segmentation/paddleseg/python/infer.py @@ -8,11 +8,9 @@ def parse_arguments(): import ast parser = argparse.ArgumentParser() parser.add_argument( - "--model", required=True, help="Path of PaddleClas model.") + "--model", required=True, help="Path of PaddleSeg model.") parser.add_argument( "--image", type=str, required=True, help="Path of test image file.") - parser.add_argument( - "--topk", type=int, default=1, help="Return topk results.") parser.add_argument( "--device", type=str, @@ -43,14 +41,17 @@ def build_option(args): # 配置runtime,加载模型 runtime_option = build_option(args) -model_file = os.path.join(args.model, "inference.pdmodel") -params_file = os.path.join(args.model, "inference.pdiparams") -config_file = os.path.join(args.model, "inference_cls.yaml") -#model = fd.vision.classification.PaddleClasModel(model_file, params_file, config_file, runtime_option=runtime_option) -model = fd.vision.classification.ResNet50vd( +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, args.topk) +result = model.predict(im) print(result) + +# 可视化结果 +vis_im = fd.vision.visualize.vis_segmentation(im, result) +cv2.imwrite("vis_img.png", vis_im) diff --git a/fastdeploy/vision/segmentation/ppseg/__init__.py b/fastdeploy/vision/segmentation/ppseg/__init__.py index 9d3cfaf4d78..bc516351d0e 100644 --- a/fastdeploy/vision/segmentation/ppseg/__init__.py +++ b/fastdeploy/vision/segmentation/ppseg/__init__.py @@ -23,9 +23,9 @@ def __init__(self, model_file, params_file, config_file, - backend_option=None, + runtime_option=None, model_format=Frontend.PADDLE): - super(Model, self).__init__(backend_option) + super(PaddleSegModel, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "PaddleSeg only support model format of Frontend.Paddle now." self._model = C.vision.segmentation.PaddleSegModel(