diff --git a/.github/ISSUE_TEMPLATE/报告issue.md b/.github/ISSUE_TEMPLATE/报告issue.md index 34085055f..be93cd251 100644 --- a/.github/ISSUE_TEMPLATE/报告issue.md +++ b/.github/ISSUE_TEMPLATE/报告issue.md @@ -7,9 +7,16 @@ assignees: '' --- +********************************************* +开源不易,工程师每天有大量研发工作,请直接按此issue模版进行提问 + +这会大大减少工程师与你确认使用环境,编译过程中的基础信息时间 +********************************************* + ## 环境 -- FastDeploy版本: 说明具体的版本,如fastdeploy-linux-gpu-0.8.0或自行编译的develop代码(附上自行编译的方式,及cmake时print的编译选项截图) +- FastDeploy版本: 说明具体的版本,如fastdeploy-linux-gpu-0.8.0 +- 如果您是自行编译的FastDeploy,请说明您的编译方式(参数命令) - 系统平台: Linux x64(Ubuntu 18.04) / Windows x64(Windows10) / Mac OSX arm(12.0) / Mac OSX intel(12.0) - 硬件: 说明具体硬件型号,如 Nvidia GPU 3080TI, CUDA 11.2 CUDNN 8.3 - 编译语言: C++ / Python(3.7或3.8等) @@ -23,3 +30,10 @@ assignees: '' - - 先执行`examples`下的部署示例,包括使用examples提供的模型,确认是否可以正确执行 - - 如若`examples`下的代码可以运行,但自己的模型,或自己的代码不能运行 - - - 提供自己的代码使用方式或自己的模型,供工程师快速定位问题 + + +********************************************* +开源不易,工程师每天有大量研发工作,请直接按此issue模版进行提问 + +这会大大减少工程师与你确认使用环境,编译过程中的基础信息时间 +********************************************* diff --git a/CMakeLists.txt b/CMakeLists.txt index dda90278f..ab23efc3d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ if(NOT MSVC) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1) endif(NOT MSVC) -if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT ENABLE_TIMVX)) +if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND (NOT WITH_TIMVX)) include(${PROJECT_SOURCE_DIR}/cmake/patchelf.cmake) endif() @@ -67,6 +67,8 @@ option(ENABLE_FLYCV "Whether to enable flycv to boost image preprocess." OFF) option(ENABLE_TIMVX "Whether to compile for TIMVX deploy." OFF) option(WITH_CANN "Whether to compile for Huawei Ascend deploy with CANN." OFF) option(WITH_CANN_PY "Whether to compile for Huawei Ascend deploy with CANN using python." OFF) +option(WITH_TIMVX "Whether to compile for TIMVX deploy." OFF) +option(WITH_XPU "Whether to compile for KunlunXin XPU deploy." OFF) option(WITH_TESTING "Whether to compile with unittest." OFF) ############################# Options for Android cross compiling ######################### option(WITH_OPENCV_STATIC "Use OpenCV static lib for Android." OFF) @@ -140,14 +142,19 @@ set(HEAD_DIR "${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}") include_directories(${HEAD_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -if (ENABLE_TIMVX) +if (WITH_TIMVX) include(${PROJECT_SOURCE_DIR}/cmake/timvx.cmake) endif() if (WITH_CANN) if(NOT ${ENABLE_LITE_BACKEND}) - message(WARNING "While compiling with -DWITH_CANN=ON, will force to set -DENABLE_LITE_BACKEND=ON") - set(ENABLE_LITE_BACKEND ON) + set(ENABLE_LITE_BACKEND ON) + endif() + if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + message(FATAL_ERROR "Huawei Ascend NPU is supported on Linux aarch64 platform for now.") + endif() + if(NOT PADDLELITE_URL) + set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_1121.tgz") endif() endif() @@ -156,17 +163,34 @@ if (WITH_CANN_PY) if(NOT ${ENABLE_LITE_BACKEND}) set(ENABLE_LITE_BACKEND ON) endif() + if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + message(FATAL_ERROR "Huawei Ascend NPU is supported on Linux aarch64 platform for now.") + endif() + if(NOT PADDLELITE_URL) + set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_python_1207.tgz") + endif() execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/paddlelite/lib COMMAND sh -c "xargs ${PATCHELF_EXE} --set-rpath '$ORIGIN'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/paddlelite/lib RESULT_VARIABLE result OUTPUT_VARIABLE curr_out ERROR_VARIABLE curr_out) if(ret EQUAL "1") - message(FATAL_ERROR "Failed to patchelf tensorrt libraries.") + message(FATAL_ERROR "Failed to patchelf CANN libraries.") endif() message(STATUS "result:${result} out:${curr_out}") endif() +if (WITH_XPU) + if(NOT ENABLE_LITE_BACKEND) + set(ENABLE_LITE_BACKEND ON) + endif() + if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") + message(FATAL_ERROR "XPU is only supported on Linux x64 platform") + endif() + if(NOT PADDLELITE_URL) + set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-x64-xpu-20221215.tgz") + endif() +endif() if(ANDROID OR IOS) if(ENABLE_ORT_BACKEND) @@ -373,14 +397,20 @@ if(ENABLE_TRT_BACKEND) endif() if(NOT BUILD_ON_JETSON) if(NOT TRT_DIRECTORY) - message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must define -DTRT_DIRECTORY, e.g -DTRT_DIRECTORY=/Downloads/TensorRT-8.4") + set(TRT_INC_DIR /usr/include/x86_64-linux-gnu/) + set(TRT_LIB_DIR /usr/lib/x86_64-linux-gnu/) endif() endif() - set(TRT_INC_DIR /usr/include/aarch64-linux-gnu/) - set(TRT_LIB_DIR /usr/lib/aarch64-linux-gnu/) - if(NOT BUILD_ON_JETSON) - set(TRT_INC_DIR ${TRT_DIRECTORY}/include) - set(TRT_LIB_DIR ${TRT_DIRECTORY}/lib) + if(BUILD_ON_JETSON) + set(TRT_INC_DIR /usr/include/aarch64-linux-gnu/) + set(TRT_LIB_DIR /usr/lib/aarch64-linux-gnu/) + else() + set(TRT_INC_DIR /usr/include/x86_64-linux-gnu/) + set(TRT_LIB_DIR /usr/lib/x86_64-linux-gnu/) + if(TRT_DIRECTORY) + set(TRT_INC_DIR ${TRT_DIRECTORY}/include) + set(TRT_LIB_DIR ${TRT_DIRECTORY}/lib) + endif() endif() add_definitions(-DENABLE_TRT_BACKEND) @@ -393,7 +423,7 @@ if(ENABLE_TRT_BACKEND) list(APPEND DEPEND_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB}) list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_OP_CUDA_KERNEL_SRCS}) - if(NOT BUILD_ON_JETSON) + if(NOT BUILD_ON_JETSON AND TRT_DIRECTORY) if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt") endif() @@ -614,7 +644,6 @@ install( DESTINATION ${CMAKE_INSTALL_PREFIX} ) - install( DIRECTORY ${PROJECT_SOURCE_DIR}/examples DESTINATION ${CMAKE_INSTALL_PREFIX} diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in index fd0ea847a..17f83eb69 100755 --- a/FastDeploy.cmake.in +++ b/FastDeploy.cmake.in @@ -27,6 +27,7 @@ set(OPENCV_DIRECTORY "@OPENCV_DIRECTORY@") set(ORT_DIRECTORY "@ORT_DIRECTORY@") set(OPENVINO_DIRECTORY "@OPENVINO_DIRECTORY@") set(RKNN2_TARGET_SOC "@RKNN2_TARGET_SOC@") +set(WITH_XPU @WITH_XPU@) set(FASTDEPLOY_LIBS "") set(FASTDEPLOY_INCS "") @@ -140,13 +141,19 @@ if(WITH_GPU) if (ENABLE_TRT_BACKEND) if(BUILD_ON_JETSON) - find_library(TRT_INFER_LIB nvinfer /usr/include/aarch64-linux-gnu/) - find_library(TRT_ONNX_LIB nvonnxparser /usr/include/aarch64-linux-gnu/) - find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/include/aarch64-linux-gnu/) + find_library(TRT_INFER_LIB nvinfer /usr/lib/aarch64-linux-gnu/) + find_library(TRT_ONNX_LIB nvonnxparser /usr/lib/aarch64-linux-gnu/) + find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/lib/aarch64-linux-gnu/) else() - find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH) - find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH) - find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH) + if(TRT_DIRECTORY) + find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH) + find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH) + find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH) + else() + find_library(TRT_INFER_LIB nvinfer /usr/lib/x86_64-linux-gnu/) + find_library(TRT_ONNX_LIB nvonnxparser /usr/lib/x86_64-linux-gnu/) + find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/lib/x86_64-linux-gnu/) + endif() endif() list(APPEND FASTDEPLOY_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB}) endif() @@ -237,6 +244,10 @@ if(ENABLE_PADDLE_FRONTEND) list(APPEND FASTDEPLOY_LIBS ${PADDLE2ONNX_LIB}) endif() +if(WITH_XPU) + list(APPEND FASTDEPLOY_LIBS -lpthread -lrt -ldl) +endif() + remove_duplicate_libraries(FASTDEPLOY_LIBS) # Print compiler information @@ -270,6 +281,7 @@ message(STATUS " ENABLE_VISION : ${ENABLE_VISION}") message(STATUS " ENABLE_TEXT : ${ENABLE_TEXT}") if(WITH_GPU) message(STATUS " CUDA_DIRECTORY : ${CUDA_DIRECTORY}") + message(STATUS " TRT_DIRECTORY : ${TRT_DIRECTORY}") endif() if(OPENCV_DIRECTORY) message(STATUS " OPENCV_DIRECTORY : ${OPENCV_DIRECTORY}") diff --git a/README.md b/README.md index b1dd06cd5..e8f014f6f 120000 --- a/README.md +++ b/README.md @@ -1 +1 @@ -README_EN.md +README_CN.md diff --git a/README_CN.md b/README_CN.md index 8814215fe..9cb3ecf6c 100755 --- a/README_CN.md +++ b/README_CN.md @@ -1,4 +1,4 @@ -[English](README_EN.md) | 简体中文 +[English](README_EN.md) | 简体中文 | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md) ![⚡️FastDeploy](https://user-images.githubusercontent.com/31974251/185771818-5d4423cd-c94c-4a49-9894-bc7a8d1c29d0.png) @@ -36,16 +36,15 @@ | | | |

**input** :早上好今天是2020
/10/29,最低温度是-3°C。

**output**: [](https://paddlespeech.bj.bcebos.com/Parakeet/docs/demos/parakeet_espnet_fs2_pwg_demo/tn_g2p/parakeet/001.wav)

| -## **社区交流** +## 📣 最新消息 -* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas - -* **微信**:扫描二维码,填写问卷加入技术社区,与社区开发者探讨部署的痛点与方案 +- **💥直播预告:2022.12.12 ~ 2022.12.30日每晚20:30,联合十家硬件厂商伙伴,推出部署月《产业级AI模型部署全攻略》**。微信扫描下方二维码,关注公众号并填写问卷后进入官方交流群,与行业精英共同探讨AI部署话题。
- +
+ ## 目录 * **🖥️ 服务器端部署** @@ -118,7 +117,7 @@ model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", "ppyoloe_crn_l_300e_coco/model.pdiparams", "ppyoloe_crn_l_300e_coco/infer_cfg.yml") im = cv2.imread("000000014439.jpg") -result = model.predict(im.copy()) +result = model.predict(im) print(result) vis_im = vision.vis_detection(im, result, score_threshold=0.5) @@ -163,9 +162,9 @@ int main(int argc, char* argv[]) { auto im = cv::imread("000000014439.jpg"); vision::DetectionResult res; - model.Predict(&im, &res); + model.Predict(im, &res); - auto vis_im = vision::Visualize::VisDetection(im, res, 0.5); + auto vis_im = vision::VisDetection(im, res, 0.5); cv::imwrite("vis_image.jpg", vis_im); return 0; } @@ -187,75 +186,75 @@ int main(int argc, char* argv[]) { -| 任务场景 | 模型 | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | -|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:| -| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | 飞腾D2000 aarch64 | NVIDIA Jetson | Graphcore IPU | Serving | -| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | | -| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | -| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ | +| 任务场景 | 模型 | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | Linux | +|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:|:-------:| +| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | 飞腾D2000 aarch64 | NVIDIA Jetson | Graphcore IPU | KunlunXin XPU | Serving | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ? | ❔ |❔ | +| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ |❔ | +| FaceAlign | [Single430/FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |❔ | +| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ |❔ | +| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ |❔ | +| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | | +| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | ✅ | +| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- |❔ | ✅ | @@ -322,6 +321,16 @@ int main(int argc, char* argv[]) { +## **社区交流** + +* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas + +* **微信**:扫描二维码,填写问卷加入技术社区,与社区开发者探讨部署的痛点与方案 + +
+ +
+
diff --git a/README_EN.md b/README_EN.md index 1157caa7d..d6f5d1405 100755 --- a/README_EN.md +++ b/README_EN.md @@ -1,4 +1,5 @@ -English | [简体中文](README_CN.md) +English | [简体中文](README_CN.md) | [हिन्दी](./docs/docs_i18n/README_हिन्दी.md) | [日本語](./docs/docs_i18n/README_日本語.md) | [한국인](./docs/docs_i18n/README_한국어.md) | [Pу́сский язы́к](./docs/docs_i18n/README_Ру́сский_язы́к.md) + ![⚡️FastDeploy](https://user-images.githubusercontent.com/31974251/185771818-5d4423cd-c94c-4a49-9894-bc7a8d1c29d0.png) @@ -36,15 +37,15 @@ Including image classification, object detection, image segmentation, face detec | [**Pose Estimation**](examples/vision/keypointdetection) | [**Behavior Recognition**](https://github.com/PaddlePaddle/FastDeploy/issues/6) | [**NLP**](examples/text) | [**Speech**](examples/audio/pp-tts) | | | | |

**input**:Life was like a box
of chocolates, you never
know what you're
gonna get.

**output**: [](https://paddlespeech.bj.bcebos.com/Parakeet/docs/demos/tacotron2_ljspeech_waveflow_samples_0.2/sentence_1.wav)

| -## 👬 Community - - **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas. - - **WeChat**:Scan the QR code below using WeChat, follow the PaddlePaddle official account and fill out the questionnaire to join the WeChat group. +## 📣 Recent updates +- 💥 **Live Preview: Dec 12 - Dec 30, China Standard Time, 20:30,** FastDeploy has joined hands with ten hardware vendor partners to launch the deployment month `The Complete Guide to Deploying Industrial Grade AI Models`. + - Scan the QR code below using WeChat, follow the PaddlePaddle official account and fill out the questionnaire to join the WeChat group -
- -
+
+ +
## Contents @@ -185,75 +186,75 @@ Notes: ✅: already supported; ❔: to be supported in the future; N/A: Not Ava -| Task | Model | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | -|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:------------------------:|:------------------------:|:------------------------:|:-----------------------:|:---------------------:|:--------------------------:| :----------------: |:---------------------------:|:---------------------------:|:-------:| -| --- | --- | X86 CPU | NVIDIA GPU | Intel CPU | NVIDIA GPU | Intel CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | Serving | -| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | -| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | | -| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | -| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ | +| Task | Model | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | Linux | +|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:------------------------:|:------------------------:|:------------------------:|:-----------------------:|:---------------------:|:--------------------------:| :----------------: |:---------------------------:|:---------------------------:|:-------:|:-------:| +| --- | --- | X86 CPU | NVIDIA GPU | Intel CPU | NVIDIA GPU | Intel CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | KunlunXin XPU |Serving | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | +| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ✅ | ❔ | +| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | +| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | +| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | | +| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | ✅ | +| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ❔ | ✅ | @@ -318,6 +319,16 @@ Notes: ✅: already supported; ❔: to be supported in the future; N/A: Not Ava | OCR | [PaddleOCR/PP-OCRv3](./examples/application/js/web_demo/src/pages/cv/ocr) | ✅ | + +## 👬 Community + + - **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas. + + - **WeChat**:Scan the QR code below using WeChat, follow the PaddlePaddle official account and fill out the questionnaire to join the WeChat group. + +
+ +
## Acknowledge diff --git a/benchmark/benchmark_ppocr.py b/benchmark/benchmark_ppocr.py index 885f9a5a5..2de86be68 100644 --- a/benchmark/benchmark_ppocr.py +++ b/benchmark/benchmark_ppocr.py @@ -92,6 +92,7 @@ def build_option(args): elif backend in ["trt", "paddle_trt"]: option.use_trt_backend() if backend == "paddle_trt": + option.enable_paddle_trt_collect_shape() option.enable_paddle_to_trt() if enable_trt_fp16: option.enable_trt_fp16() @@ -267,7 +268,6 @@ if __name__ == '__main__': f.writelines("===={}====: \n".format(os.path.split(file_path)[-1][:-4])) try: - rec_option = option if "OCRv2" in args.model_dir: det_option = option if args.backend in ["trt", "paddle_trt"]: @@ -293,16 +293,19 @@ if __name__ == '__main__': model = fd.vision.ocr.PPOCRv2( det_model=det_model, cls_model=cls_model, rec_model=rec_model) elif "OCRv3" in args.model_dir: + det_option = option if args.backend in ["trt", "paddle_trt"]: det_option.set_trt_input_shape( "x", [1, 3, 64, 64], [1, 3, 640, 640], [1, 3, 960, 960]) det_model = fd.vision.ocr.DBDetector( det_model_file, det_params_file, runtime_option=det_option) + cls_option = option if args.backend in ["trt", "paddle_trt"]: cls_option.set_trt_input_shape( "x", [1, 3, 48, 10], [10, 3, 48, 320], [64, 3, 48, 1024]) cls_model = fd.vision.ocr.Classifier( cls_model_file, cls_params_file, runtime_option=cls_option) + rec_option = option if args.backend in ["trt", "paddle_trt"]: rec_option.set_trt_input_shape( "x", [1, 3, 48, 10], [10, 3, 48, 320], [64, 3, 48, 2304]) diff --git a/benchmark/convert_info.py b/benchmark/convert_info.py index 338a0cec5..e5942e1f7 100644 --- a/benchmark/convert_info.py +++ b/benchmark/convert_info.py @@ -70,10 +70,8 @@ for i in range(line_nums): cpu_rss_mb_list = cpu_rss_mb_ori.split(".") cpu_rss_mb = cpu_rss_mb_list[0] + "." + cpu_rss_mb_list[1][:2] if "gpu_rss_mb" in lines[i + 4]: - gpu_rss_mb_ori = lines[i + 4].split(": ")[1] - # two decimal places - gpu_rss_mb_list = gpu_rss_mb_ori.split(".") - gpu_rss_mb = gpu_rss_mb_list[0] + "." + gpu_rss_mb_list[1][:2] + gpu_rss_mb_ori = lines[i + 4].split(": ")[1].strip() + gpu_rss_mb = str(gpu_rss_mb_ori) + ".0" if "ort_cpu_1" in lines[i]: ort_cpu_thread1[ model_name] = runtime + "\t" + end2end + "\t" + cpu_rss_mb @@ -111,7 +109,7 @@ for i in range(line_nums): f2 = open("struct_cpu_" + domain + ".txt", "w") f2.writelines( - "model_name\tthread_nums\tort_run\tort_end2end\tcpu_rss_mb\tov_run\tov_end2end\tcpu_rss_mb\tpaddle_run\tpaddle_end2end\tcpu_rss_mb\n" + "model_name\tthread_nums\tort_run\tort_end2end\tcpu_mem\tov_run\tov_end2end\tcpu_mem\tpaddle_run\tpaddle_end2end\tcpu_mem\n" ) for model_name in model_name_set: lines1 = model_name + '\t1\t' @@ -148,7 +146,7 @@ f2.close() f3 = open("struct_gpu_" + domain + ".txt", "w") f3.writelines( - "model_name\tort_run\tort_end2end\tgpu_rss_mb\tpaddle_run\tpaddle_end2end\tgpu_rss_mb\tpaddle_trt_run\tpaddle_trt_end2end\tgpu_rss_mb\tpaddle_trt_fp16_run\tpaddle_trt_fp16_end2end\tgpu_rss_mb\ttrt_run\ttrt_end2end\tgpu_rss_mb\ttrt_fp16_run\ttrt_fp16_end2end\tgpu_rss_mb\n" + "model_name\tort_run\tort_end2end\tgpu_mem\tpaddle_run\tpaddle_end2end\tgpu_mem\tpaddle_trt_run\tpaddle_trt_end2end\tgpu_mem\tpaddle_trt_fp16_run\tpaddle_trt_fp16_end2end\tgpu_mem\ttrt_run\ttrt_end2end\tgpu_mem\ttrt_fp16_run\ttrt_fp16_end2end\tgpu_mem\n" ) for model_name in model_name_set: lines1 = model_name + '\t' diff --git a/cmake/gflags.cmake b/cmake/gflags.cmake index 08d5e49c8..37ee2c4de 100644 --- a/cmake/gflags.cmake +++ b/cmake/gflags.cmake @@ -14,9 +14,6 @@ INCLUDE(ExternalProject) -if(NOT GIT_URL) - SET(GIT_URL "https://github.com") -endif() if(THIRD_PARTY_PATH) SET(GFLAGS_PREFIX_DIR ${THIRD_PARTY_PATH}/gflags) SET(GFLAGS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/gflags) @@ -26,8 +23,16 @@ else() SET(GFLAGS_INSTALL_DIR ${FASTDEPLOY_INSTALL_DIR}/installed_fastdeploy/cmake/gflags) endif() SET(GFLAGS_INCLUDE_DIR "${GFLAGS_INSTALL_DIR}/include" CACHE PATH "gflags include directory." FORCE) -set(GFLAGS_REPOSITORY ${GIT_URL}/gflags/gflags.git) -set(GFLAGS_TAG "v2.2.2") +set(GFLAGS_SOURCE_FILE ${GFLAGS_PREFIX_DIR}/src/gflags.tgz CACHE PATH "gflags source file." FORCE) + +set(GFLAGS_URL_PREFIX "https://bj.bcebos.com/fastdeploy/third_libs") +set(GFLAGS_URL ${GFLAGS_URL_PREFIX}/gflags.tgz) +set(GFLAGS_CACHE_FILE ${CMAKE_CURRENT_LIST_DIR}/gflags.tgz) +if(EXISTS ${GFLAGS_CACHE_FILE}) + set(GFLAGS_URL ${GFLAGS_CACHE_FILE} CACHE PATH "gflags cache file." FORCE) + set(GFLAGS_SOURCE_FILE ${GFLAGS_CACHE_FILE} CACHE PATH "gflags source file." FORCE) +endif() + IF(WIN32) set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/gflags_static.lib" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE) ELSE(WIN32) @@ -40,45 +45,41 @@ INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR}) if(ANDROID) ExternalProject_Add( - extern_gflags - ${EXTERNAL_PROJECT_LOG_ARGS} - ${SHALLOW_CLONE} - GIT_REPOSITORY ${GFLAGS_REPOSITORY} - GIT_TAG ${GFLAGS_TAG} - PREFIX ${GFLAGS_PREFIX_DIR} - UPDATE_COMMAND "" - BUILD_COMMAND ${BUILD_COMMAND} - INSTALL_COMMAND ${INSTALL_COMMAND} - CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_NDK=${ANDROID_NDK} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_STL=c++_static - -DANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} - -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} - -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} - -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE} - -DBUILD_STATIC_LIBS=ON - -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DBUILD_TESTING=OFF - -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} - ${EXTERNAL_OPTIONAL_ARGS} - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${GFLAGS_INSTALL_DIR} - -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON - -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} - BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES} - ) + extern_gflags + ${EXTERNAL_PROJECT_LOG_ARGS} + URL ${GFLAGS_URL} + PREFIX ${GFLAGS_PREFIX_DIR} + UPDATE_COMMAND "" + BUILD_COMMAND ${BUILD_COMMAND} + INSTALL_COMMAND ${INSTALL_COMMAND} + CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_NDK=${ANDROID_NDK} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_STL=c++_static + -DANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN} + -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} + -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} + -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} + -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG} + -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE} + -DBUILD_STATIC_LIBS=ON + -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DBUILD_TESTING=OFF + -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} + ${EXTERNAL_OPTIONAL_ARGS} + CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${GFLAGS_INSTALL_DIR} + -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON + -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE} + BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES} +) else() ExternalProject_Add( extern_gflags ${EXTERNAL_PROJECT_LOG_ARGS} - ${SHALLOW_CLONE} - GIT_REPOSITORY ${GFLAGS_REPOSITORY} - GIT_TAG ${GFLAGS_TAG} + URL ${GFLAGS_URL} PREFIX ${GFLAGS_PREFIX_DIR} UPDATE_COMMAND "" BUILD_COMMAND ${BUILD_COMMAND} @@ -107,11 +108,16 @@ ADD_LIBRARY(gflags STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARIES}) ADD_DEPENDENCIES(gflags extern_gflags) +if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) + list(APPEND GFLAGS_LIBRARIES pthread) +endif() + # On Windows (including MinGW), the Shlwapi library is used by gflags if available. if (WIN32) include(CheckIncludeFileCXX) check_include_file_cxx("shlwapi.h" HAVE_SHLWAPI) if (HAVE_SHLWAPI) set_property(GLOBAL PROPERTY OS_DEPENDENCY_MODULES shlwapi.lib) + list(APPEND GFLAGS_LIBRARIES shlwapi.lib) endif(HAVE_SHLWAPI) endif (WIN32) diff --git a/cmake/opencv.cmake b/cmake/opencv.cmake index 87f8c8bcd..fd2ecabe4 100755 --- a/cmake/opencv.cmake +++ b/cmake/opencv.cmake @@ -41,12 +41,6 @@ elseif(IOS) else() if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") set(OPENCV_FILENAME "opencv-linux-aarch64-3.4.14") - else() - if(ENABLE_TIMVX) - set(OPENCV_FILENAME "opencv-armv7hf") - else() - set(OPENCV_FILENAME "opencv-linux-x64-3.4.16") - endif() endif() if(ENABLE_OPENCV_CUDA) if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") @@ -56,15 +50,20 @@ else() endif() endif() +if(NOT OPENCV_FILENAME) + set(OPENCV_FILENAME "opencv-linux-x64-3.4.16") +endif() + set(OPENCV_INSTALL_DIR ${THIRD_PARTY_PATH}/install/) if(ANDROID) set(OPENCV_URL_PREFIX "https://bj.bcebos.com/fastdeploy/third_libs") -elseif(ENABLE_TIMVX) - set(OPENCV_URL_PREFIX "https://bj.bcebos.com/fastdeploy/test") else() # TODO: use fastdeploy/third_libs instead. set(OPENCV_URL_PREFIX "https://bj.bcebos.com/paddle2onnx/libs") endif() -set(OPENCV_URL ${OPENCV_URL_PREFIX}/${OPENCV_FILENAME}${COMPRESSED_SUFFIX}) +if(NOT OPENCV_URL) + set(OPENCV_URL ${OPENCV_URL_PREFIX}/${OPENCV_FILENAME}${COMPRESSED_SUFFIX}) +endif() + if(BUILD_ON_JETSON) if(EXISTS /usr/lib/aarch64-linux-gnu/cmake/opencv4/) @@ -186,9 +185,8 @@ else() endif() file(RENAME ${THIRD_PARTY_PATH}/install/${OPENCV_FILENAME}/ ${THIRD_PARTY_PATH}/install/opencv) set(OPENCV_FILENAME opencv) - set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/${OPENCV_FILENAME}) - if(ENABLE_TIMVX) - set(OpenCV_DIR ${OpenCV_DIR}/lib/cmake/opencv4) + if(NOT OpenCV_DIR) + set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/${OPENCV_FILENAME}) endif() if (WIN32) set(OpenCV_DIR ${OpenCV_DIR}/build) diff --git a/cmake/paddle_inference.cmake b/cmake/paddle_inference.cmake index f1b5ee6c7..3ab45454a 100644 --- a/cmake/paddle_inference.cmake +++ b/cmake/paddle_inference.cmake @@ -13,6 +13,8 @@ # limitations under the License. include(ExternalProject) +option(PADDLEINFERENCE_DIRECTORY "Directory of Paddle Inference library" OFF) + set(PADDLEINFERENCE_PROJECT "extern_paddle_inference") set(PADDLEINFERENCE_PREFIX_DIR ${THIRD_PARTY_PATH}/paddle_inference) set(PADDLEINFERENCE_SOURCE_DIR @@ -27,6 +29,10 @@ set(PADDLEINFERENCE_LIB_DIR set(CMAKE_BUILD_RPATH "${CMAKE_BUILD_RPATH}" "${PADDLEINFERENCE_LIB_DIR}") +if(PADDLEINFERENCE_DIRECTORY) + set(PADDLEINFERENCE_INC_DIR ${PADDLEINFERENCE_DIRECTORY}/paddle/include) +endif() + include_directories(${PADDLEINFERENCE_INC_DIR}) if(WIN32) set(PADDLEINFERENCE_COMPILE_LIB @@ -47,50 +53,59 @@ else() endif(WIN32) -set(PADDLEINFERENCE_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/") -set(PADDLEINFERENCE_VERSION "2.4-dev3") -if(WIN32) - if (WITH_GPU) - set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.zip") - else() - set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-${PADDLEINFERENCE_VERSION}.zip") - endif() -elseif(APPLE) - if(CURRENT_OSX_ARCH MATCHES "arm64") - message(FATAL_ERROR "Paddle Backend doesn't support Mac OSX with Arm64 now.") - set(PADDLEINFERENCE_FILE "paddle_inference-osx-arm64-${PADDLEINFERENCE_VERSION}.tgz") - else() - set(PADDLEINFERENCE_FILE "paddle_inference-osx-x86_64-${PADDLEINFERENCE_VERSION}.tgz") +if(PADDLEINFERENCE_DIRECTORY) + if(EXISTS "${THIRD_PARTY_PATH}/install/paddle_inference") + file(REMOVE_RECURSE "${THIRD_PARTY_PATH}/install/paddle_inference") endif() + find_package(Python COMPONENTS Interpreter Development REQUIRED) + message(STATUS "Copying ${PADDLEINFERENCE_DIRECTORY} to ${THIRD_PARTY_PATH}/install/paddle_inference ...") + execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/copy_directory.py ${PADDLEINFERENCE_DIRECTORY} ${THIRD_PARTY_PATH}/install/paddle_inference) else() - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") - message(FATAL_ERROR "Paddle Backend doesn't support linux aarch64 now.") - set(PADDLEINFERENCE_FILE "paddle_inference-linux-aarch64-${PADDLEINFERENCE_VERSION}.tgz") - else() - set(PADDLEINFERENCE_FILE "paddle_inference-linux-x64-${PADDLEINFERENCE_VERSION}.tgz") - if(WITH_GPU) - set(PADDLEINFERENCE_FILE "paddle_inference-linux-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.tgz") + set(PADDLEINFERENCE_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/") + set(PADDLEINFERENCE_VERSION "2.4-dev3") + if(WIN32) + if (WITH_GPU) + set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.zip") + else() + set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-${PADDLEINFERENCE_VERSION}.zip") endif() - if (WITH_IPU) - set(PADDLEINFERENCE_VERSION "2.4-dev1") - set(PADDLEINFERENCE_FILE "paddle_inference-linux-x64-ipu-${PADDLEINFERENCE_VERSION}.tgz") + elseif(APPLE) + if(CURRENT_OSX_ARCH MATCHES "arm64") + message(FATAL_ERROR "Paddle Backend doesn't support Mac OSX with Arm64 now.") + set(PADDLEINFERENCE_FILE "paddle_inference-osx-arm64-${PADDLEINFERENCE_VERSION}.tgz") + else() + set(PADDLEINFERENCE_FILE "paddle_inference-osx-x86_64-${PADDLEINFERENCE_VERSION}.tgz") + endif() + else() + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + message(FATAL_ERROR "Paddle Backend doesn't support linux aarch64 now.") + set(PADDLEINFERENCE_FILE "paddle_inference-linux-aarch64-${PADDLEINFERENCE_VERSION}.tgz") + else() + set(PADDLEINFERENCE_FILE "paddle_inference-linux-x64-${PADDLEINFERENCE_VERSION}.tgz") + if(WITH_GPU) + set(PADDLEINFERENCE_FILE "paddle_inference-linux-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.tgz") + endif() + if (WITH_IPU) + set(PADDLEINFERENCE_VERSION "2.4-dev1") + set(PADDLEINFERENCE_FILE "paddle_inference-linux-x64-ipu-${PADDLEINFERENCE_VERSION}.tgz") + endif() endif() endif() -endif() -set(PADDLEINFERENCE_URL "${PADDLEINFERENCE_URL_BASE}${PADDLEINFERENCE_FILE}") - -ExternalProject_Add( - ${PADDLEINFERENCE_PROJECT} - ${EXTERNAL_PROJECT_LOG_ARGS} - URL ${PADDLEINFERENCE_URL} - PREFIX ${PADDLEINFERENCE_PREFIX_DIR} - DOWNLOAD_NO_PROGRESS 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - UPDATE_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} -E copy_directory ${PADDLEINFERENCE_SOURCE_DIR} ${PADDLEINFERENCE_INSTALL_DIR} - BUILD_BYPRODUCTS ${PADDLEINFERENCE_COMPILE_LIB}) + set(PADDLEINFERENCE_URL "${PADDLEINFERENCE_URL_BASE}${PADDLEINFERENCE_FILE}") + + ExternalProject_Add( + ${PADDLEINFERENCE_PROJECT} + ${EXTERNAL_PROJECT_LOG_ARGS} + URL ${PADDLEINFERENCE_URL} + PREFIX ${PADDLEINFERENCE_PREFIX_DIR} + DOWNLOAD_NO_PROGRESS 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + UPDATE_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} -E copy_directory ${PADDLEINFERENCE_SOURCE_DIR} ${PADDLEINFERENCE_INSTALL_DIR} + BUILD_BYPRODUCTS ${PADDLEINFERENCE_COMPILE_LIB}) +endif(PADDLEINFERENCE_DIRECTORY) if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) add_custom_target(patchelf_paddle_inference ALL COMMAND bash -c "PATCHELF_EXE=${PATCHELF_EXE} python ${PROJECT_SOURCE_DIR}/scripts/patch_paddle_inference.py ${PADDLEINFERENCE_INSTALL_DIR}/paddle/lib/libpaddle_inference.so" DEPENDS ${LIBRARY_NAME}) diff --git a/cmake/paddlelite.cmake b/cmake/paddlelite.cmake index 62b4020d5..74525b7a9 100755 --- a/cmake/paddlelite.cmake +++ b/cmake/paddlelite.cmake @@ -49,28 +49,20 @@ if(ANDROID) endif() endif() -if(WIN32 OR APPLE OR IOS) - message(FATAL_ERROR "Doesn't support windows/mac/ios platform with backend Paddle Lite now.") -elseif(ANDROID) - set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-android-${ANDROID_ABI}-latest.tgz") - if(ANDROID_ABI MATCHES "arm64-v8a") - set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-android-${ANDROID_ABI}-fp16-latest.tgz") - endif() -else() # Linux - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") - if(WITH_CANN) - set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_1121.tgz") - elseif(WITH_CANN_PY) - set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_python_1207.tgz") +if(NOT PADDLELITE_URL) + if(WIN32 OR APPLE OR IOS) + message(FATAL_ERROR "Doesn't support windows/mac/ios platform with backend Paddle Lite now.") + elseif(ANDROID) + set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-android-${ANDROID_ABI}-latest-dev.tgz") + if(ANDROID_ABI MATCHES "arm64-v8a") + set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-android-${ANDROID_ABI}-fp16-latest-dev.tgz") + endif() + else() # Linux + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-linux-arm64-20221209.tgz") else() - set(PADDLELITE_URL "${PADDLELITE_URL_PREFIX}/lite-linux-arm64-20220920.tgz") - endif() - else() - if(ENABLE_TIMVX) - set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_armhf_1130.tgz") - else() - message(FATAL_ERROR "Only support Linux aarch64 or ENABLE_TIMVX now, x64 is not supported with backend Paddle Lite.") - endif() + message(FATAL_ERROR "Only support Linux aarch64 now, x64 is not supported with backend Paddle Lite.") + endif() endif() endif() diff --git a/cmake/summary.cmake b/cmake/summary.cmake index d4604195a..88233e629 100755 --- a/cmake/summary.cmake +++ b/cmake/summary.cmake @@ -38,7 +38,9 @@ function(fastdeploy_summary) message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}") message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}") message(STATUS " WITH_CANN : ${WITH_CANN}") - message(STATUS " WITH_CANN_PY : ${WITH_CANN_PY}") + message(STATUS " WITH_CANN_PY : ${WITH_CANN_PY}") + message(STATUS " WITH_TIMVX : ${WITH_TIMVX}") + message(STATUS " WITH_XPU : ${WITH_XPU}") if(ENABLE_ORT_BACKEND) message(STATUS " ONNXRuntime version : ${ONNXRUNTIME_VERSION}") endif() diff --git a/cmake/timvx.cmake b/cmake/timvx.cmake index c6a7d54d2..973face96 100755 --- a/cmake/timvx.cmake +++ b/cmake/timvx.cmake @@ -1,54 +1,45 @@ -if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) - set(CMAKE_SYSTEM_NAME Linux) - set(CMAKE_SYSTEM_PROCESSOR arm) - set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") - set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") - set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}" ) - set(CMAKE_BUILD_TYPE MinSizeRel) -else() - if(NOT ${ENABLE_LITE_BACKEND}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_LITE_BACKEND=ON") - set(ENABLE_LITE_BACKEND ON) - endif() - if(${ENABLE_PADDLE_FRONTEND}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_FRONTEND=OFF") - set(ENABLE_PADDLE_FRONTEND OFF) - endif() - if(${ENABLE_ORT_BACKEND}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_ORT_BACKEND=OFF") - set(ENABLE_ORT_BACKEND OFF) - endif() - if(${ENABLE_PADDLE_BACKEND}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_BACKEND=OFF") - set(ENABLE_PADDLE_BACKEND OFF) - endif() - if(${ENABLE_OPENVINO_BACKEND}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENVINO_BACKEND=OFF") - set(ENABLE_OPENVINO_BACKEND OFF) - endif() - if(${ENABLE_TRT_BACKEND}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TRT_BACKEND=OFF") - set(ENABLE_TRT_BACKEND OFF) - endif() - if(${WITH_GPU}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DWITH_GPU=OFF") - set(WITH_GPU OFF) - endif() - - if(${ENABLE_OPENCV_CUDA}) - message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENCV_CUDA=OFF") - set(ENABLE_OPENCV_CUDA OFF) - endif() - - if(${ENABLE_TEXT}) - set(ENABLE_TEXT OFF CACHE BOOL "Force ENABLE_TEXT OFF" FORCE) - message(STATUS "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TEXT=OFF") - endif() - if (DEFINED CMAKE_INSTALL_PREFIX) - install(FILES ${PROJECT_SOURCE_DIR}/cmake/timvx.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) - endif() +if(NOT ${ENABLE_LITE_BACKEND}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_LITE_BACKEND=ON") + set(ENABLE_LITE_BACKEND ON) +endif() +if(${ENABLE_PADDLE_FRONTEND}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_FRONTEND=OFF") + set(ENABLE_PADDLE_FRONTEND OFF) +endif() +if(${ENABLE_ORT_BACKEND}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_ORT_BACKEND=OFF") + set(ENABLE_ORT_BACKEND OFF) +endif() +if(${ENABLE_PADDLE_BACKEND}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_PADDLE_BACKEND=OFF") + set(ENABLE_PADDLE_BACKEND OFF) +endif() +if(${ENABLE_OPENVINO_BACKEND}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENVINO_BACKEND=OFF") + set(ENABLE_OPENVINO_BACKEND OFF) +endif() +if(${ENABLE_TRT_BACKEND}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TRT_BACKEND=OFF") + set(ENABLE_TRT_BACKEND OFF) endif() +if(${WITH_GPU}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DWITH_GPU=OFF") + set(WITH_GPU OFF) +endif() + +if(${ENABLE_OPENCV_CUDA}) + message(WARNING "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_OPENCV_CUDA=OFF") + set(ENABLE_OPENCV_CUDA OFF) +endif() + +if(${ENABLE_TEXT}) + set(ENABLE_TEXT OFF CACHE BOOL "Force ENABLE_TEXT OFF" FORCE) + message(STATUS "While compiling with -DWITH_TIMVX=ON, will force to set -DENABLE_TEXT=OFF") +endif() + +install(FILES ${PROJECT_SOURCE_DIR}/cmake/timvx.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) +install(FILES ${PROJECT_SOURCE_DIR}/cmake/toolchain.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}) + diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake new file mode 100755 index 000000000..4b3485748 --- /dev/null +++ b/cmake/toolchain.cmake @@ -0,0 +1,38 @@ +if (DEFINED TARGET_ABI) + set(CMAKE_SYSTEM_NAME Linux) + set(CMAKE_BUILD_TYPE MinSizeRel) + if(${TARGET_ABI} MATCHES "armhf") + set(CMAKE_SYSTEM_PROCESSOR arm) + set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") + set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") + set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}" ) + set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-armv7hf-4.6.0.tgz") + set(OPENCV_FILENAME "opencv-linux-armv7hf-4.6.0") + if(WITH_TIMVX) + set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-armhf-timvx-1130.tgz") + else() + message(STATUS "PADDLELITE_URL will be configured if WITH_TIMVX=ON.") + endif() + set(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}/third_libs) + set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/opencv/lib/cmake/opencv4) + elseif(${TARGET_ABI} MATCHES "arm64") + set(CMAKE_SYSTEM_PROCESSOR aarch64) + set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc") + set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++") + set(CMAKE_CXX_FLAGS "-march=armv8-a ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-march=armv8-a ${CMAKE_C_FLAGS}") + set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-aarch64-4.6.0.tgz") + set(OPENCV_FILENAME "opencv-linux-aarch64-4.6.0") + if(WITH_TIMVX) + set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-aarch64-timvx-20221209.tgz") + else() + set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-arm64-20221209.tgz") + endif() + set(THIRD_PARTY_PATH ${CMAKE_CURRENT_BINARY_DIR}/third_libs) + set(OpenCV_DIR ${THIRD_PARTY_PATH}/install/opencv/lib/cmake/opencv4) + else() + message(FATAL_ERROR "When cross-compiling, please set the -DTARGET_ABI to arm64 or armhf.") + endif() +endif() + diff --git a/docs/README_CN.md b/docs/README_CN.md old mode 100644 new mode 100755 index 5fb8b2127..ec0267f45 --- a/docs/README_CN.md +++ b/docs/README_CN.md @@ -8,6 +8,7 @@ - [GPU部署环境编译安装](cn/build_and_install/gpu.md) - [CPU部署环境编译安装](cn/build_and_install/cpu.md) - [IPU部署环境编译安装](cn/build_and_install/ipu.md) +- [昆仑芯XPU部署环境编译安装](cn/build_and_install/xpu.md) - [Jetson部署环境编译安装](cn/build_and_install/jetson.md) - [Android平台部署环境编译安装](cn/build_and_install/android.md) - [服务化部署镜像编译安装](../serving/docs/zh_CN/compile.md) @@ -19,7 +20,7 @@ - [Runtime Python使用示例](cn/quick_start/runtime/python.md) - [Runtime C++使用示例](cn/quick_start/runtime/cpp.md) -## API文档(进行中) +## API文档 - [Python API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/python/html/) - [C++ API文档](https://www.paddlepaddle.org.cn/fastdeploy-api-doc/cpp/html/) diff --git a/docs/README_EN.md b/docs/README_EN.md old mode 100644 new mode 100755 index c4f9adfa3..ed257c59b --- a/docs/README_EN.md +++ b/docs/README_EN.md @@ -8,6 +8,7 @@ - [Build and Install FastDeploy Library on GPU Platform](en/build_and_install/gpu.md) - [Build and Install FastDeploy Library on CPU Platform](en/build_and_install/cpu.md) - [Build and Install FastDeploy Library on IPU Platform](en/build_and_install/ipu.md) +- [Build and Install FastDeploy Library on KunlunXin XPU Platform](en/build_and_install/xpu.md) - [Build and Install FastDeploy Library on Nvidia Jetson Platform](en/build_and_install/jetson.md) - [Build and Install FastDeploy Library on Android Platform](en/build_and_install/android.md) - [Build and Install FastDeploy Serving Deployment Image](../serving/docs/EN/compile-en.md) @@ -19,10 +20,10 @@ - [A Quick Start on Runtime Python](en/quick_start/runtime/python.md) - [A Quick Start on Runtime C++](en/quick_start/runtime/cpp.md) -## API +## API - [Python API](https://baidu-paddle.github.io/fastdeploy-api/python/html/) -- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/) +- [C++ API](https://baidu-paddle.github.io/fastdeploy-api/cpp/html/) - [Android Java API](../java/android) ## Performance Optimization diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md index 0698eca4d..374b083f9 100755 --- a/docs/cn/build_and_install/README.md +++ b/docs/cn/build_and_install/README.md @@ -12,6 +12,8 @@ - [Jetson部署环境](jetson.md) - [Android平台部署环境](android.md) - [瑞芯微RV1126部署环境](rv1126.md) +- [晶晨A311D部署环境](a311d.md) +- [昆仑芯XPU部署环境](xpu.md) ## FastDeploy编译选项说明 @@ -19,11 +21,14 @@ | 选项 | 说明 | |:------------------------|:--------------------------------------------------------------------------| | ENABLE_ORT_BACKEND | 默认OFF, 是否编译集成ONNX Runtime后端(CPU/GPU上推荐打开) | -| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) | -| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) | +| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) | +| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) | | ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) | -| WITH_CANN | 默认OFF,当在华为昇腾NPU上部署时, 需要设置为ON | +| WITH_CANN | 默认OFF,当在华为昇腾NPU上部署时, 需要设置为ON | +| WITH_CANN_PY | 默认OFF,当在华为昇腾NPU上,并使用Python部署时, 需要设置为ON | | ENABLE_TIMVX | 默认OFF,需要在RV1126/RV1109上部署时,需设置为ON | +| WITH_XPU | 默认OFF,当在昆仑芯XPU上部署时,需设置为ON | +| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON | | ENABLE_TRT_BACKEND | 默认OFF,是否编译集成TensorRT后端(GPU上推荐打开) | | ENABLE_OPENVINO_BACKEND | 默认OFF,是否编译集成OpenVINO后端(CPU上推荐打开) | | ENABLE_VISION | 默认OFF,是否编译集成视觉模型的部署模块 | diff --git a/docs/cn/build_and_install/a311d.md b/docs/cn/build_and_install/a311d.md new file mode 100755 index 000000000..20dde7046 --- /dev/null +++ b/docs/cn/build_and_install/a311d.md @@ -0,0 +1,108 @@ +# 晶晨 A311D 部署环境编译安装 + +FastDeploy 基于 Paddle-Lite 后端支持在晶晨 NPU 上进行部署推理。 +更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html)。 + +本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 交叉编译库。 + +相关编译选项说明如下: +|编译选项|默认值|说明|备注| +|:---|:---|:---|:---| +|ENABLE_LITE_BACKEND|OFF|编译A311D部署库时需要设置为ON| - | +|WITH_TIMVX|OFF|编译A311D部署库时需要设置为ON| - | +|TARGET_ABI|NONE|编译RK库时需要设置为arm64| - | + +更多编译选项请参考[FastDeploy编译选项说明](./README.md) + +## 交叉编译环境搭建 + +### 宿主机环境需求 +- os:Ubuntu == 16.04 +- cmake: version >= 3.10.0 + +### 环境搭建 +可以进入 FastDeploy/tools/timvx 目录,使用如下命令一键安装: +```bash +cd FastDeploy/tools/timvx +bash install.sh +``` +也可以按照如下命令安装: +```bash + # 1. Install basic software +apt update +apt-get install -y --no-install-recommends \ + gcc g++ git make wget python unzip + +# 2. Install arm gcc toolchains +apt-get install -y --no-install-recommends \ + g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \ + g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + +# 3. Install cmake 3.10 or above +wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \ + tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \ + mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \ + ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \ + ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake +``` + +## 基于 PaddleLite 的 FastDeploy 交叉编译库编译 +搭建好交叉编译环境之后,编译命令如下: +```bash +# Download the latest source code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy +mkdir build && cd build + +# CMake configuration with A311D toolchain +cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \ + -DWITH_TIMVX=ON \ + -DTARGET_ABI=arm64 \ + -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \ + -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启 + -Wno-dev .. + +# Build FastDeploy A311D C++ SDK +make -j8 +make install +``` +编译完成之后,会生成 fastdeploy-tmivx 目录,表示基于 PadddleLite TIM-VX 的 FastDeploy 库编译完成。 + +## 准备设备运行环境 +部署前要保证晶晨 Linux Kernel NPU 驱动 galcore.so 版本及所适用的芯片型号与依赖库保持一致,在部署前,请登录开发板,并通过命令行输入以下命令查询 NPU 驱动版本,晶晨建议的驱动版本为:6.4.4.3 +```bash +dmesg | grep Galcore +``` + +如果当前版本不符合上述,请用户仔细阅读以下内容,以保证底层 NPU 驱动环境正确。 + +有两种方式可以修改当前的 NPU 驱动版本: +1. 手动替换 NPU 驱动版本。(推荐) +2. 刷机,刷取 NPU 驱动版本符合要求的固件。 + +### 手动替换 NPU 驱动版本 +1. 使用如下命令下载解压 PaddleLite demo,其中提供了现成的驱动文件 +```bash +wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz +tar -xf PaddleLite-generic-demo.tar.gz +``` +2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本, +3. 将 `PaddleLite-generic-demo/libs/PaddleLite/linux/arm64/lib/verisilicon_timvx/viv_sdk_6_4_4_3/lib/a311d/4.9.113` 路径下的 `galcore.ko` 上传至开发板。 + +4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。 +5. 在开发板中输入 `dmesg | grep Galcore` 查询 NPU 驱动版本,确定为:6.4.4.3 + +### 刷机 +根据具体的开发板型号,向开发板卖家或官网客服索要 6.4.4.3 版本 NPU 驱动对应的固件和刷机方法。 + +更多细节请参考:[PaddleLite准备设备环境](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing) + +## 基于 FastDeploy 在 A311D 上的部署示例 +1. A311D 上部署 PaddleClas 分类模型请参考:[PaddleClas 分类模型在 A311D 上的 C++ 部署示例](../../../examples/vision/classification/paddleclas/a311d/README.md) + +2. A311D 上部署 PPYOLOE 检测模型请参考:[PPYOLOE 检测模型在 A311D 上的 C++ 部署示例](../../../examples/vision/detection/paddledetection/a311d/README.md) + +3. A311D 上部署 YOLOv5 检测模型请参考:[YOLOv5 检测模型在 A311D 上的 C++ 部署示例](../../../examples/vision/detection/yolov5/a311d/README.md) + +4. A311D 上部署 PP-LiteSeg 分割模型请参考:[PP-LiteSeg 分割模型在 A311D 上的 C++ 部署示例](../../../examples/vision/segmentation/paddleseg/a311d/README.md) diff --git a/docs/cn/build_and_install/cpu.md b/docs/cn/build_and_install/cpu.md index c6fb2a893..b0057e677 100644 --- a/docs/cn/build_and_install/cpu.md +++ b/docs/cn/build_and_install/cpu.md @@ -27,6 +27,11 @@ Linux上编译需满足 - gcc/g++ >= 5.4(推荐8.2) - cmake >= 3.18.0 +此外更推荐开发者自行安装,编译时通过`-DOPENCV_DIRECTORY`来指定环境中的OpenCV(如若不指定-DOPENCV_DIRECTORY,会自动下载FastDeploy提供的预编译的OpenCV,但在**Linux平台**无法支持Video的读取,以及imshow等可视化界面功能) +``` +sudo apt-get install libopencv-dev +``` + ```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy @@ -36,6 +41,7 @@ cmake .. -DENABLE_ORT_BACKEND=ON \ -DENABLE_OPENVINO_BACKEND=ON \ -DCMAKE_INSTALL_PREFIX=${PWD}/compiled_fastdeploy_sdk \ -DENABLE_VISION=ON \ + -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \ -DENABLE_TEXT=ON make -j12 make install @@ -90,6 +96,8 @@ export ENABLE_PADDLE_BACKEND=ON export ENABLE_OPENVINO_BACKEND=ON export ENABLE_VISION=ON export ENABLE_TEXT=ON +# OPENCV_DIRECTORY可选,不指定会自动下载FastDeploy提供的预编译OpenCV库 +export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 python setup.py build python setup.py bdist_wheel diff --git a/docs/cn/build_and_install/download_prebuilt_libraries.md b/docs/cn/build_and_install/download_prebuilt_libraries.md index 2f48c2c06..3ec302801 100755 --- a/docs/cn/build_and_install/download_prebuilt_libraries.md +++ b/docs/cn/build_and_install/download_prebuilt_libraries.md @@ -20,7 +20,7 @@ FastDeploy提供各平台预编译库,供开发者直接下载安装使用。 ### Python安装 -Release版本(当前最新1.0.0)安装 +Release版本(当前最新1.0.1)安装 ```bash pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html ``` @@ -41,8 +41,8 @@ Release版本 | 平台 | 文件 | 说明 | | :--- | :--- | :---- | -| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.0.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2编译产出 | -| Windows x64 | [fastdeploy-win-x64-gpu-1.0.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.0.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2编译产出 | +| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.1.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2编译产出 | +| Windows x64 | [fastdeploy-win-x64-gpu-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.1.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2编译产出 | Develop版本(Nightly build) @@ -63,7 +63,7 @@ Develop版本(Nightly build) ### Python安装 -Release版本(当前最新1.0.0)安装 +Release版本(当前最新1.0.1)安装 ```bash pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html ``` @@ -79,11 +79,11 @@ Release版本 | 平台 | 文件 | 说明 | | :--- | :--- | :---- | -| Linux x64 | [fastdeploy-linux-x64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.0.tgz) | g++ 8.2编译产出 | -| Windows x64 | [fastdeploy-win-x64-1.0.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.0.zip) | Visual Studio 16 2019编译产出 | -| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.0.tgz) | clang++ 10.0.0编译产出| -| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.0.tgz) | clang++ 13.0.0编译产出 | -| Linux aarch64 | [fastdeploy-osx-arm64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.0.tgz) | gcc 6.3编译产出 | +| Linux x64 | [fastdeploy-linux-x64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.1.tgz) | g++ 8.2编译产出 | +| Windows x64 | [fastdeploy-win-x64-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.1.zip) | Visual Studio 16 2019编译产出 | +| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.1.tgz) | clang++ 10.0.0编译产出| +| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.1.tgz) | clang++ 13.0.0编译产出 | +| Linux aarch64 | [fastdeploy-linux-aarch64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.1.tgz) | gcc 6.3编译产出 | | Android armv7&v8 | [fastdeploy-android-1.0.0-shared.tgz](https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-1.0.0-shared.tgz) | NDK 25及clang++编译产出, 支持arm64-v8a及armeabi-v7a | ## Java SDK安装 diff --git a/docs/cn/build_and_install/gpu.md b/docs/cn/build_and_install/gpu.md index 3d6aba116..1e9a0d26f 100644 --- a/docs/cn/build_and_install/gpu.md +++ b/docs/cn/build_and_install/gpu.md @@ -33,6 +33,11 @@ Linux上编译需满足 - cuda >= 11.2 - cudnn >= 8.2 +此外更推荐开发者自行安装,编译时通过`-DOPENCV_DIRECTORY`来指定环境中的OpenCV(如若不指定-DOPENCV_DIRECTORY,会自动下载FastDeploy提供的预编译的OpenCV,但在**Linux平台**无法支持Video的读取,以及imshow等可视化界面功能) +``` +sudo apt-get install libopencv-dev +``` + ```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy @@ -46,6 +51,7 @@ cmake .. -DENABLE_ORT_BACKEND=ON \ -DCUDA_DIRECTORY=/usr/local/cuda \ -DCMAKE_INSTALL_PREFIX=${PWD}/compiled_fastdeploy_sdk \ -DENABLE_VISION=ON \ + -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \ -DENABLE_TEXT=ON make -j12 make install @@ -115,6 +121,8 @@ export ENABLE_TRT_BACKEND=ON export WITH_GPU=ON export TRT_DIRECTORY=/Paddle/TensorRT-8.4.1.5 export CUDA_DIRECTORY=/usr/local/cuda +# OPENCV_DIRECTORY可选,不指定会在编译过程下载FastDeploy预编译的OpenCV库 +export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \ python setup.py build python setup.py bdist_wheel diff --git a/docs/cn/build_and_install/jetson.md b/docs/cn/build_and_install/jetson.md index f60aa280c..07ab53a61 100644 --- a/docs/cn/build_and_install/jetson.md +++ b/docs/cn/build_and_install/jetson.md @@ -1,7 +1,7 @@ # Jetson部署库编译 -FastDeploy当前在Jetson仅支持ONNX Runtime CPU和TensorRT GPU两种后端推理 +FastDeploy当前在Jetson仅支持ONNX Runtime CPU和TensorRT GPU/Paddle Inference三种后端推理 ## C++ SDK编译安装 @@ -10,12 +10,17 @@ FastDeploy当前在Jetson仅支持ONNX Runtime CPU和TensorRT GPU两种后端推 - cmake >= 3.10.0 - jetpack >= 4.6.1 + +如果需要集成Paddle Inference后端,在[Paddle Inference预编译库](https://www.paddlepaddle.org.cn/inference/v2.4/guides/install/download_lib.html#c)页面根据开发环境选择对应的Jetpack C++包下载,并解压。 + ```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build cmake .. -DBUILD_ON_JETSON=ON \ -DENABLE_VISION=ON \ + -DENABLE_PADDLE_BACKEND=ON \ # 可选项,如若不需要Paddle Inference后端,可关闭 + -DPADDLEINFERENCE_DIRECTORY=/Download/paddle_inference_jetson \ -DCMAKE_INSTALL_PREFIX=${PWD}/installed_fastdeploy make -j8 make install @@ -34,6 +39,8 @@ make install Python打包依赖`wheel`,编译前请先执行`pip install wheel` +如果需要集成Paddle Inference后端,在[Paddle Inference预编译库](https://www.paddlepaddle.org.cn/inference/v2.4/guides/install/download_lib.html#c)页面根据开发环境选择对应的Jetpack C++包下载,并解压。 + 所有编译选项通过环境变量导入 ```bash @@ -42,6 +49,10 @@ cd FastDeploy/python export BUILD_ON_JETSON=ON export ENABLE_VISION=ON +# ENABLE_PADDLE_BACKEND & PADDLEINFERENCE_DIRECTORY为可选项 +export ENABLE_PADDLE_BACKEND=ON +export PADDLEINFERENCE_DIRECTORY=/Download/paddle_inference_jetson + python setup.py build python setup.py bdist_wheel ``` diff --git a/docs/cn/build_and_install/rv1126.md b/docs/cn/build_and_install/rv1126.md index f3cd4ed6a..f3643f070 100755 --- a/docs/cn/build_and_install/rv1126.md +++ b/docs/cn/build_and_install/rv1126.md @@ -8,8 +8,9 @@ FastDeploy基于 Paddle-Lite 后端支持在瑞芯微(Rockchip)Soc 上进行 相关编译选项说明如下: |编译选项|默认值|说明|备注| |:---|:---|:---|:---| -|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - | -|ENABLE_TIMVX|OFF|编译RK库时需要设置为ON| - | +|ENABLE_LITE_BACKEND|OFF|编译RK库时需要设置为ON| - | +|WITH_TIMVX|OFF|编译RK库时需要设置为ON| - | +|TARGET_ABI|NONE|编译RK库时需要设置为armhf| - | 更多编译选项请参考[FastDeploy编译选项说明](./README.md) @@ -20,6 +21,12 @@ FastDeploy基于 Paddle-Lite 后端支持在瑞芯微(Rockchip)Soc 上进行 - cmake: version >= 3.10.0 ### 环境搭建 +可以进入 FastDeploy/tools/timvx 目录,使用如下命令一键安装: +```bash +cd FastDeploy/tools/timvx +bash install.sh +``` +也可以按照如下命令安装: ```bash # 1. Install basic software apt update @@ -49,8 +56,9 @@ cd FastDeploy mkdir build && cd build # CMake configuration with RK toolchain -cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/timvx.cmake \ - -DENABLE_TIMVX=ON \ +cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \ + -DWITH_TIMVX=ON \ + -DTARGET_ABI=armhf \ -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \ -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启 -Wno-dev .. @@ -79,7 +87,7 @@ dmesg | grep Galcore wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz tar -xf PaddleLite-generic-demo.tar.gz ``` -2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本, +2. 使用 `uname -a` 查看 `Linux Kernel` 版本,确定为 `Linux` 系统 4.19.111 版本 3. 将 `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` 路径下的 `galcore.ko` 上传至开发板。 4. 登录开发板,命令行输入 `sudo rmmod galcore` 来卸载原始驱动,输入 `sudo insmod galcore.ko` 来加载传上设备的驱动。(是否需要 sudo 根据开发板实际情况,部分 adb 链接的设备请提前 adb root)。此步骤如果操作失败,请跳转至方法 2。 diff --git a/docs/cn/build_and_install/xpu.md b/docs/cn/build_and_install/xpu.md new file mode 100755 index 000000000..014eb804d --- /dev/null +++ b/docs/cn/build_and_install/xpu.md @@ -0,0 +1,75 @@ +# 昆仑芯 XPU 部署环境编译安装 + +FastDeploy 基于 Paddle-Lite 后端支持在昆仑芯 XPU 上进行部署推理。 +更多详细的信息请参考:[PaddleLite部署示例](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。 + +本文档介绍如何编译基于 PaddleLite 的 C++ FastDeploy 编译库。 + +相关编译选项说明如下: +|编译选项|默认值|说明|备注| +|:---|:---|:---|:---| +| WITH_XPU| OFF | 需要在XPU上部署时需要设置为ON | - | +| ENABLE_ORT_BACKEND | OFF | 是否编译集成ONNX Runtime后端 | - | +| ENABLE_PADDLE_BACKEND | OFF | 是否编译集成Paddle Inference后端 | - | +| ENABLE_OPENVINO_BACKEND | OFF | 是否编译集成OpenVINO后端 | - | +| ENABLE_VISION | OFF | 是否编译集成视觉模型的部署模块 | - | +| ENABLE_TEXT | OFF | 是否编译集成文本NLP模型的部署模块 | - | + +第三方库依赖指定(不设定如下参数,会自动下载预编译库) +| 选项 | 说明 | +| :---------------------- | :--------------------------------------------------------------------------------------------- | +| ORT_DIRECTORY | 当开启ONNX Runtime后端时,用于指定用户本地的ONNX Runtime库路径;如果不指定,编译过程会自动下载ONNX Runtime库 | +| OPENCV_DIRECTORY | 当ENABLE_VISION=ON时,用于指定用户本地的OpenCV库路径;如果不指定,编译过程会自动下载OpenCV库 | +| OPENVINO_DIRECTORY | 当开启OpenVINO后端时, 用于指定用户本地的OpenVINO库路径;如果不指定,编译过程会自动下载OpenVINO库 | +更多编译选项请参考[FastDeploy编译选项说明](./README.md) + +## 基于 PaddleLite 的 C++ FastDeploy 库编译 +- OS: Linux +- gcc/g++: version >= 8.2 +- cmake: version >= 3.15 +此外更推荐开发者自行安装,编译时通过`-DOPENCV_DIRECTORY`来指定环境中的OpenCV(如若不指定-DOPENCV_DIRECTORY,会自动下载FastDeploy提供的预编译的OpenCV,但在**Linux平台**无法支持Video的读取,以及imshow等可视化界面功能) +``` +sudo apt-get install libopencv-dev +``` +编译命令如下: +```bash +# Download the latest source code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy +mkdir build && cd build + +# CMake configuration with KunlunXin xpu toolchain +cmake -DWITH_XPU=ON \ + -DWITH_GPU=OFF \ # 不编译 GPU + -DENABLE_ORT_BACKEND=ON \ # 可选择开启 ORT 后端 + -DENABLE_PADDLE_BACKEND=ON \ # 可选择开启 Paddle 后端 + -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \ + -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启 + -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \ + .. + +# Build FastDeploy KunlunXin XPU C++ SDK +make -j8 +make install +``` +编译完成之后,会生成 fastdeploy-xpu 目录,表示基于 PadddleLite 的 FastDeploy 库编译完成。 + +## Python 编译 +编译命令如下: +```bash +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/python +export WITH_XPU=ON +export WITH_GPU=OFF +export ENABLE_ORT_BACKEND=ON +export ENABLE_PADDLE_BACKEND=ON +export ENABLE_VISION=ON +# OPENCV_DIRECTORY可选,不指定会自动下载FastDeploy提供的预编译OpenCV库 +export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 + +python setup.py build +python setup.py bdist_wheel +``` +编译完成即会在 `FastDeploy/python/dist` 目录下生成编译后的 `wheel` 包,直接 pip install 即可 + +编译过程中,如若修改编译参数,为避免带来缓存影响,可删除 `FastDeploy/python` 目录下的 `build` 和 `.setuptools-cmake-build` 两个子目录后再重新编译 diff --git a/docs/cn/faq/rknpu2/rknpu2.md b/docs/cn/faq/rknpu2/rknpu2.md index c488f311c..c3a424af4 100644 --- a/docs/cn/faq/rknpu2/rknpu2.md +++ b/docs/cn/faq/rknpu2/rknpu2.md @@ -14,19 +14,19 @@ ONNX模型不能直接调用RK芯片中的NPU进行运算,需要把ONNX模型 | 任务场景 | 模型 | 模型版本(表示已经测试的版本) | ARM CPU/RKNN速度(ms) | |------------------|-------------------|-------------------------------|--------------------| -| Detection | Picodet | Picodet-s | 599/136 | +| Detection | Picodet | Picodet-s | 162/112 | +| Detection | RKYOLOV5 | YOLOV5-S-Relu(int8) | -/57 | | Segmentation | Unet | Unet-cityscapes | -/- | -| Segmentation | PP-LiteSeg | PP_LiteSeg_T_STDC1_cityscapes | 6634/5598 | -| Segmentation | PP-HumanSegV2Lite | portrait | 456/266 | -| Segmentation | PP-HumanSegV2Lite | human | 496/256 | -| Face Detection | SCRFD | SCRFD-2.5G-kps-640 | 963/142 | +| Segmentation | PP-LiteSeg | PP_LiteSeg_T_STDC1_cityscapes | -/- | +| Segmentation | PP-HumanSegV2Lite | portrait | 53/50 | +| Segmentation | PP-HumanSegV2Lite | human | 53/50 | +| Face Detection | SCRFD | SCRFD-2.5G-kps-640 | 112/108 | ## TODO 以下为TODO计划,表示还正在准备支持,但是还存在问题或还可以改进的模型。 | 任务场景 | 模型 | 模型版本(表示已经测试的版本) | ARM CPU/RKNN速度(ms) | |------------------|---------|---------------------|--------------------| -| Detection | Picodet | Picodet-s(int8) | -/- | | Detection | PPYOLOE | PPYOLOE(int8) | -/- | | Detection | YOLOv5 | YOLOv5-s_v6.2(int8) | -/- | | Face Recognition | ArcFace | ArcFace_r18 | 600/3 | diff --git a/docs/cn/faq/use_sdk_on_linux.md b/docs/cn/faq/use_sdk_on_linux.md index aba472ecc..0ceb5ca0c 100644 --- a/docs/cn/faq/use_sdk_on_linux.md +++ b/docs/cn/faq/use_sdk_on_linux.md @@ -1,3 +1,6 @@ +[English](../../en/faq/use_sdk_on_linux.md) | 中文 + + # Linux上C++部署 1. 编译完成运行,提示找不到.so文件 @@ -10,4 +13,4 @@ source /Downloads/fastdeploy-linux-x64-1.0.0/fastdeploy_init.sh ``` -再重新执行即可。 注意此命令执行后仅在当前的命令环境中生效(切换一个新的终端窗口,或关闭窗口重新打开后会无效),如若需要在系统中持续生效,可将这些环境变量加入到`~/.bashrc`文件中。 \ No newline at end of file +再重新执行即可。 注意此命令执行后仅在当前的命令环境中生效(切换一个新的终端窗口,或关闭窗口重新打开后会无效),如若需要在系统中持续生效,可将这些环境变量加入到`~/.bashrc`文件中。 diff --git a/docs/cn/faq/use_sdk_on_windows.md b/docs/cn/faq/use_sdk_on_windows.md index 7209d50bb..0683e8d04 100644 --- a/docs/cn/faq/use_sdk_on_windows.md +++ b/docs/cn/faq/use_sdk_on_windows.md @@ -1,3 +1,5 @@ +[English](../../en/faq/use_sdk_on_windows.md) | 中文 + # 在 Windows 使用 FastDeploy C++ SDK ## 目录 diff --git a/docs/docs_i18n/README_Pу́сский язы́к.md b/docs/docs_i18n/README_Pу́сский язы́к.md new file mode 100644 index 000000000..29045dd45 --- /dev/null +++ b/docs/docs_i18n/README_Pу́сский язы́к.md @@ -0,0 +1,334 @@ +[English](../../README_EN.md) | [简体中文](../../README_CN.md) | [हिन्दी](./README_हिन्दी.md) | [日本語](./README_日本語.md) | [한국인](./README_한국어.md) | Pу́сский язы́к + +![⚡️FastDeploy](https://user-images.githubusercontent.com/31974251/185771818-5d4423cd-c94c-4a49-9894-bc7a8d1c29d0.png) + +

+ +

+ + + + + + + + +

+ +

+ Установка + | + Использование документации + | + API документация + | + Журнал обновления +

+ +**⚡️FastDeploy**- это**всесценарный**,**простой в использовании и гибкий**,**чрезвычайно эффективный**инструмент развертывания выводов ИИ. Он обеспечивает 📦**из коробки**опыт развертывания с поддержкой более 🔥150+ **текстовых**,**зрительных**, **речевых** и **кросс-модальных** моделей и 🔚 **сквозной** оптимизацией производительности вывода. Сюда входят классификация изображений, обнаружение объектов, сегментация изображений, обнаружение лиц, распознавание лиц, обнаружение ключевых точек, распознавание ключей, OCR, NLP, TTS и другие задачи для удовлетворения потребностей разработчиков с **многосценическими, многоаппаратными, многоплатформенными** промышленными развертываниями. +| [Image Classification](examples/vision/classification) | [Object Detection](examples/vision/detection) | [Semantic Segmentation](examples/vision/segmentation/paddleseg) | [Potrait Segmentation](examples/vision/segmentation/paddleseg) | +|:----------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| +| | | | | +| [**Image Matting**](examples/vision/matting) | [**Real-Time Matting**](examples/vision/matting) | [**OCR**](examples/vision/ocr) | [**Face Alignment**](examples/vision/facealign) | +| | | | | +| [**Pose Estimation**](examples/vision/keypointdetection) | [**Behavior Recognition**](https://github.com/PaddlePaddle/FastDeploy/issues/6) | [**NLP**](examples/text) | [**Speech**](examples/audio/pp-tts) | +| | | |

**input** :早上好今天是2020
/10/29,最低温度是-3°C。

**output**: [](https://paddlespeech.bj.bcebos.com/Parakeet/docs/demos/parakeet_espnet_fs2_pwg_demo/tn_g2p/parakeet/001.wav)

| + + +## **Обмен сообществами** + +* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas + +* **WeChat**: Отсканируйте QR-код и заполните анкету, чтобы присоединиться к техническому сообществу и обсудить болевые точки развертывания и решения с разработчиками сообщества + +
+ +
+ +## Каталог + +* **🖥️Развертывание на стороне сервера** + + * [Python SDK Quick Start](#fastdeploy-quick-start-python) + * [C++ SDK Quick Start](#fastdeploy-quick-start-cpp) + * [Список поддержки моделей на стороне сервера](#fastdeploy-server-models) + +* **📲 Мобильные и конечные развертывания** + + * [Список поддержки конечных моделей](#fastdeploy-edge-models) + +* **🌐 Развертывание веб и апплетов** + + * [Список поддержки веб-моделей](#fastdeploy-web-models) +* [Acknowledge](#fastdeploy-acknowledge) +* [License](#fastdeploy-license) + +## 🖥️ Развертывание на стороне сервера + +
+ +
+ + Быстрый старт Python SDK (нажмите для получения подробной информации)
+ +#### Быстрая установка + +##### Предварительные зависимости + +- CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6 +- OS: Linux x86_64/macOS/Windows 10 + +##### Установка версии GPU + +```bash +pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +##### [установка Conda (рекомендуется)](docs/cn/build_and_install/download_prebuilt_libraries.md) + +```bash +conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2 +``` + +##### Установка CPU процессора + +```bash +pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +#### Пример умозаключения в Python + +* Подготовка модели и изображений + +```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 +``` + +* Проверка результатов вывода + +```python +# GPU/TensorRT Справочник по развертыванию examples/vision/detection/paddledetection/python +import cv2 +import fastdeploy.vision as vision + +model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml") +im = cv2.imread("000000014439.jpg") +result = model.predict(im.copy()) +print(result) + +vis_im = vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("vis_image.jpg", vis_im) + +``` + +
+ +
+ +
+ + C++ SDK Quick Start (нажмите для получения подробной информации)
+ + +#### Установка + +Обратитесь к документации [C++ prebuilt libraries download](docs/cn/build_and_install/download_prebuilt_libraries.md) + +#### Пример вывода в C++ + +* Подготовка моделей и фотографий + +```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 +``` + +* Результаты рассуждений при тестировании + +```C++ +// GPU/TensorRT Ссылка на развертывание examples/vision/detection/paddledetection/cpp +#include "fastdeploy/vision.h" + +int main(int argc, char* argv[]) { + namespace vision = fastdeploy::vision; + auto model = vision::detection::PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml"); + auto im = cv::imread("000000014439.jpg"); + + vision::DetectionResult res; + model.Predict(&im, &res); + + auto vis_im = vision::Visualize::VisDetection(im, res, 0.5); + cv::imwrite("vis_image.jpg", vis_im); + return 0; +} +``` + +
+ +Дополнительные примеры развертывания см. в разделе [Примеры развертывания модели] (examples). + +
+ +### Список поддержки моделей на стороне сервера🔥🔥🔥🔥🔥 + +Описание символов: (1) ✅: Уже поддерживается; (2) ❔:Текущий; (3) N/A:В настоящее время не поддерживается;
+ +
Список поддержки моделей на стороне сервера (нажмите, чтобы уменьшить)
+ +
+ +
+ +| Сценарии миссий | Модели | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | +|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:| +| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | Serving | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | | +| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | +| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ | + + +
+ +
+ +## 📲 Мобильное и конечное развертывание 🔥🔥🔥🔥 + +
+ +### Список поддержки конечных моделей +
Список поддержки конечных моделей (нажмите, чтобы уменьшить)
+ +
+ +
+ +| Сценарии миссий | Модели | Размер(MB) | Linux | Android | Linux | Linux | Linux | Linux | Linux | TBD... | +|:------------------:|:-----------------------------------------------------------------------------------------:|:--------:|:-------:|:-------:|:-------:|:-----------------------:|:------------------------------:|:---------------------------:|:--------------------------------:|:-------:| +| --- | --- | --- | ARM CPU | ARM CPU | Rockchip-NPU
RK3568/RK3588 | Rockchip-NPU
RV1109/RV1126/RK1808 | Amlogic-NPU
A311D/S905D/C308X | NXP-NPU
i.MX 8M Plus | TBD...| | +| Classification | [PaddleClas/ResNet50](examples/vision/classification/paddleclas) | 98 | ✅ | ✅ | ❔ | ✅ | | | | +| Classification | [PaddleClas/PP-LCNet](examples/vision/classification/paddleclas) | 11.9 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-LCNetv2](examples/vision/classification/paddleclas) | 26.6 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/EfficientNet](examples/vision/classification/paddleclas) | 31.4 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/GhostNet](examples/vision/classification/paddleclas) | 20.8 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV1](examples/vision/classification/paddleclas) | 17 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV2](examples/vision/classification/paddleclas) | 14.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV3](examples/vision/classification/paddleclas) | 22 | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -- | +| Classification | [PaddleClas/ShuffleNetV2](examples/vision/classification/paddleclas) | 9.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/SqueezeNetV1.1](examples/vision/classification/paddleclas) | 5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/Inceptionv3](examples/vision/classification/paddleclas) | 95.5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-HGNet](examples/vision/classification/paddleclas) | 59 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Detection | [PaddleDetection/PP-PicoDet_s_320_coco_lcnet](examples/vision/detection/paddledetection) | 4.9 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -- | +| Face Detection | [deepinsight/SCRFD](./examples/vision/facedet/scrfd) | 2.5 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Keypoint Detection | [PaddleDetection/PP-TinyPose](examples/vision/keypointdetection/tiny_pose) | 5.5 | ✅ | ✅ | ❔ | ❔ | ❔ | ❔ | -- | +| Segmentation | [PaddleSeg/PP-LiteSeg(STDC1)](examples/vision/segmentation/paddleseg) | 32.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg-Lite](examples/vision/segmentation/paddleseg) | 0.556 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/HRNet-w18](examples/vision/segmentation/paddleseg) | 38.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg](examples/vision/segmentation/paddleseg) | 107.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Unet](examples/vision/segmentation/paddleseg) | 53.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Deeplabv3](examples/vision/segmentation/paddleseg) | 150 | ❔ | ✅ | ✅ | | | | | +| OCR | [PaddleOCR/PP-OCRv2](examples/vision/ocr/PP-OCRv2) | 2.3+4.4 | ✅ | ✅ | ❔ | -- | -- | -- | -- | +| OCR | [PaddleOCR/PP-OCRv3](examples/vision/ocr/PP-OCRv3) | 2.4+10.6 | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | -- | + + +
+ +## 🌐 🌐 Развертывание веб и апплетов + +
+ +
Список поддержки развертывания веб-приложений и апплетов (нажмите, чтобы уменьшить)
+ +| Сценарии миссий | Модели | [web_demo](examples/application/js/web_demo) | +|:------------------:|:-------------------------------------------------------------------------------------------:|:--------------------------------------------:| +| --- | --- | [Paddle.js](examples/application/js) | +| Detection | [FaceDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Detection | [ScrewDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Segmentation | [PaddleSeg/HumanSeg](./examples/application/js/web_demo/src/pages/cv/segmentation/HumanSeg) | ✅ | +| Object Recognition | [GestureRecognition](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| Object Recognition | [ItemIdentification](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/application/js/web_demo/src/pages/cv/ocr) | ✅ | + +
+ + +
+ +## Acknowledge + +Для создания и загрузки SDK в этом проекте используются бесплатные и открытые возможности в [EasyEdge](https://ai.baidu.com/easyedge/app/openSource), за что мы хотели бы поблагодарить вас. + +## License + +
+ +FastDeploy следует [протоколу Apache-2.0 с открытым исходным кодом](. /LICENSE). diff --git a/docs/docs_i18n/README_हिन्दी.md b/docs/docs_i18n/README_हिन्दी.md new file mode 100644 index 000000000..62ce1a886 --- /dev/null +++ b/docs/docs_i18n/README_हिन्दी.md @@ -0,0 +1,334 @@ + [English](../../README_EN.md) | [简体中文](../../README_CN.md) | हिन्दी | [日本語](./README_日本語.md) | [한국인](./README_한국어.md) | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md) + +![⚡️FastDeploy](https://user-images.githubusercontent.com/31974251/185771818-5d4423cd-c94c-4a49-9894-bc7a8d1c29d0.png) + +

+ +

+ + + + + + + + +

+ +

+ संस्थापन + | + दस्तावेज़ीकरण का उपयोग करें + | + APIप्रलेखन + | + चेंजलॉग +

+ +**⚡️फास्टडिप्लोय**एक एआई अनुमान तैनाती उपकरण है जो **सभी परिदृश्य**, **उपयोग करने में आसान और लचीला** और **बेहद कुशल** है। एक📦**आउट-ऑफ-द-बॉक्स** **क्लाउड-एज** परिनियोजन अनुभव प्रदान करता है, 🔥150+ से अधिक **टेक्स्ट**, **विजन**, **स्पीच** और **क्रॉस-मोडल** मॉडल का समर्थन करता है, और 🔚 **एंड-टू-एंड** अनुमान प्रदर्शन अनुकूलन को लागू करता है। डेवलपर्स की जरूरतों को पूरा करने के लिए छवि वर्गीकरण, ऑब्जेक्ट डिटेक्शन, छवि विभाजन, चेहरे का पता लगाने, चेहरे की पहचान, मुख्य बिंदु का पता लगाने, कटआउट, ओसीआर, एनएलपी, टीटीएस और अन्य कार्यों सहित **बहु-परिदृश्य, बहु-हार्डवेयर, बहु-मंच** उद्योग की तैनाती की जरूरत है। +| [Image Classification](examples/vision/classification) | [Object Detection](examples/vision/detection) | [Semantic Segmentation](examples/vision/segmentation/paddleseg) | [Potrait Segmentation](examples/vision/segmentation/paddleseg) | +|:----------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| +| | | | | +| [**Image Matting**](examples/vision/matting) | [**Real-Time Matting**](examples/vision/matting) | [**OCR**](examples/vision/ocr) | [**Face Alignment**](examples/vision/facealign) | +| | | | | +| [**Pose Estimation**](examples/vision/keypointdetection) | [**Behavior Recognition**](https://github.com/PaddlePaddle/FastDeploy/issues/6) | [**NLP**](examples/text) | [**Speech**](examples/audio/pp-tts) | +| | | |

**input** :早上好今天是2020
/10/29,最低温度是-3°C。

**output**: [](https://paddlespeech.bj.bcebos.com/Parakeet/docs/demos/parakeet_espnet_fs2_pwg_demo/tn_g2p/parakeet/001.wav)

| + + +## **सामुदायिक संचार** + +* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas + +* **वीचैट**: क्यूआर कोड स्कैन करें, तकनीकी समुदाय में शामिल होने के लिए प्रश्नावली भरें, और सामुदायिक डेवलपर्स के साथ तैनाती के दर्द बिंदुओं और समाधानों पर चर्चा करें + +
+ +
+ +## डायरेक्टरी + +* **🖥️ सर्वर-साइड परिनियोजन** + + * [Python SDK एक त्वरित शुरुआत है](#fastdeploy-quick-start-python) + * [C++ SDK एक त्वरित शुरुआत है](#fastdeploy-quick-start-cpp) + * [सर्वर-साइड मॉडल समर्थन सूची](#fastdeploy-server-models) + +* **📲 मोबाइल और एंड-साइड परिनियोजन** + + * [एंड-साइड मॉडल समर्थन सूची](#fastdeploy-edge-models) + +* **🌐 और एप्लेट तैनाती** + + * [Web-साइड मॉडल समर्थन सूची](#fastdeploy-web-models) +* [Acknowledge](#fastdeploy-acknowledge) +* [License](#fastdeploy-license) + +## 🖥️ सर्वर-साइड परिनियोजन + +
+ +
+ +पायथन एसडीके क्विक स्टार्ट (विवरण के लिए यहां क्लिक करें)
+ +#### त्वरित स्थापना + +##### पूर्व-निर्भरता + +- CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6 +- OS: Linux x86_64/macOS/Windows 10 + +##### संस्करण स्थापित करें + +```bash +pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +##### [Conda स्थापना (अनुशंसित) ](docs/cn/build_and_install/download_prebuilt_libraries.md) + +```bash +conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2 +``` + +##### CPU संस्करण स्थापित करें + +```bash +pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +#### Python अनुमान उदाहरण + +* मॉडल और चित्र तैयार करें + +```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 +``` + +* परीक्षण अनुमान परिणाम + +```python +# GPU/TensorRT तैनाती संदर्भ examples/vision/detection/paddledetection/python +import cv2 +import fastdeploy.vision as vision + +model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml") +im = cv2.imread("000000014439.jpg") +result = model.predict(im.copy()) +print(result) + +vis_im = vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("vis_image.jpg", vis_im) + +``` + +
+ +
+ +
+ + C++ SDK त्वरित प्रारंभ (विवरण के लिए यहां क्लिक करें)
+ + +#### संस्थापन + +C++ SDK त्वरित प्रारंभ (विवरण के लिए क्लिक करें)(docs/cn/build_and_install/download_prebuilt_libraries.md)文档 + +#### C++ अनुमान उदाहरण + +* मॉडल और चित्र तैयार करें + +```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 +``` + +* अनुमान परिणामों का परीक्षण करें + +```C++ +// GPU/TensorRTपरिनियोजन संदर्भ examples/vision/detection/paddledetection/cpp +#include "fastdeploy/vision.h" + +int main(int argc, char* argv[]) { + namespace vision = fastdeploy::vision; + auto model = vision::detection::PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml"); + auto im = cv::imread("000000014439.jpg"); + + vision::DetectionResult res; + model.Predict(&im, &res); + + auto vis_im = vision::Visualize::VisDetection(im, res, 0.5); + cv::imwrite("vis_image.jpg", vis_im); + return 0; +} +``` + +
+ +अधिक परिनियोजन उदाहरणों के लिए, कृपया मॉडल परिनियोजन उदाहरण देखें(examples) . + +
+ +### सर्वर-साइड मॉडल समर्थन सूची 🔥🔥🔥🔥🔥 + +प्रतीक विवरण: (1) ✅: पहले से समर्थित; (2) ❔:गति पर ; (3) N/A: समर्थित नहीं;
+ +
सर्वर-साइड मॉडल समर्थन सूची (ढहने के लिए क्लिक करें)
+ +
+ +
+ +| कार्य परिदृश्य | नमूना | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | +|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:| +| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | Serving | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | | +| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | +| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ | + + +
+ +
+ +## 📲 मोबाइल और एंड-साइड परिनियोजन 🔥🔥🔥🔥 + +
+ +### एंड-साइड मॉडल समर्थन सूची +
एंड-साइड मॉडल समर्थन सूची (पतन के लिए क्लिक करें)
+ +
+ +
+ +| कार्य परिदृश्य | नमूना | आकार(MB) | Linux | Android | Linux | Linux | Linux | Linux | Linux | TBD... | +|:------------------:|:-----------------------------------------------------------------------------------------:|:--------:|:-------:|:-------:|:-------:|:-----------------------:|:------------------------------:|:---------------------------:|:--------------------------------:|:-------:| +| --- | --- | --- | ARM CPU | ARM CPU | Rockchip-NPU
RK3568/RK3588 | Rockchip-NPU
RV1109/RV1126/RK1808 | Amlogic-NPU
A311D/S905D/C308X | NXP-NPU
i.MX 8M Plus | TBD...| | +| Classification | [PaddleClas/ResNet50](examples/vision/classification/paddleclas) | 98 | ✅ | ✅ | ❔ | ✅ | | | | +| Classification | [PaddleClas/PP-LCNet](examples/vision/classification/paddleclas) | 11.9 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-LCNetv2](examples/vision/classification/paddleclas) | 26.6 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/EfficientNet](examples/vision/classification/paddleclas) | 31.4 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/GhostNet](examples/vision/classification/paddleclas) | 20.8 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV1](examples/vision/classification/paddleclas) | 17 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV2](examples/vision/classification/paddleclas) | 14.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV3](examples/vision/classification/paddleclas) | 22 | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -- | +| Classification | [PaddleClas/ShuffleNetV2](examples/vision/classification/paddleclas) | 9.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/SqueezeNetV1.1](examples/vision/classification/paddleclas) | 5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/Inceptionv3](examples/vision/classification/paddleclas) | 95.5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-HGNet](examples/vision/classification/paddleclas) | 59 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Detection | [PaddleDetection/PP-PicoDet_s_320_coco_lcnet](examples/vision/detection/paddledetection) | 4.9 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -- | +| Face Detection | [deepinsight/SCRFD](./examples/vision/facedet/scrfd) | 2.5 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Keypoint Detection | [PaddleDetection/PP-TinyPose](examples/vision/keypointdetection/tiny_pose) | 5.5 | ✅ | ✅ | ❔ | ❔ | ❔ | ❔ | -- | +| Segmentation | [PaddleSeg/PP-LiteSeg(STDC1)](examples/vision/segmentation/paddleseg) | 32.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg-Lite](examples/vision/segmentation/paddleseg) | 0.556 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/HRNet-w18](examples/vision/segmentation/paddleseg) | 38.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg](examples/vision/segmentation/paddleseg) | 107.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Unet](examples/vision/segmentation/paddleseg) | 53.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Deeplabv3](examples/vision/segmentation/paddleseg) | 150 | ❔ | ✅ | ✅ | | | | | +| OCR | [PaddleOCR/PP-OCRv2](examples/vision/ocr/PP-OCRv2) | 2.3+4.4 | ✅ | ✅ | ❔ | -- | -- | -- | -- | +| OCR | [PaddleOCR/PP-OCRv3](examples/vision/ocr/PP-OCRv3) | 2.4+10.6 | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | -- | + + +
+ +## 🌐 🌐 Web और एप्लेट तैनाती + +
+ +
Web और मिनी प्रोग्राम परिनियोजन समर्थन सूची (ढहने के लिए क्लिक करें)
+ +| कार्य परिदृश्य | नमूना | [web_demo](examples/application/js/web_demo) | +|:------------------:|:-------------------------------------------------------------------------------------------:|:--------------------------------------------:| +| --- | --- | [Paddle.js](examples/application/js) | +| Detection | [FaceDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Detection | [ScrewDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Segmentation | [PaddleSeg/HumanSeg](./examples/application/js/web_demo/src/pages/cv/segmentation/HumanSeg) | ✅ | +| Object Recognition | [GestureRecognition](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| Object Recognition | [ItemIdentification](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/application/js/web_demo/src/pages/cv/ocr) | ✅ | + +
+ + +
+ +## Acknowledge + +यह परियोजना SDK पीढ़ी और डाउनलोड हम [EasyEdge](https://ai.baidu.com/easyedge/app/openSource) में मुक्त और खुली क्षमताओं का उपयोग करने के लिए आभारी हैं। + +## License + +
+ +FastDeploy निम्नानुसार है [Apache-2.0 खुला स्रोत लाइसेंस](./LICENSE)。 diff --git a/docs/docs_i18n/README_日本語.md b/docs/docs_i18n/README_日本語.md new file mode 100644 index 000000000..8ca76f1f3 --- /dev/null +++ b/docs/docs_i18n/README_日本語.md @@ -0,0 +1,334 @@ +[English](../../README_EN.md) | [简体中文](../../README_CN.md) | [हिन्दी](./README_हिन्दी.md) | 日本語 | [한국인](./README_한국어.md) | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md) + +![⚡️FastDeploy](https://user-images.githubusercontent.com/31974251/185771818-5d4423cd-c94c-4a49-9894-bc7a8d1c29d0.png) + +

+ +

+ + + + + + + + +

+ +

+ インストール + | + ドキュメント + | + APIドキュメンテーション + | + Changelog +

+ +**⚡️FastDeploy**は、**オールシナリオで使いやすく**、**柔軟で非常に効率的な**AI推論デプロイツールです。 🔥150以上の**テキスト**、**ビジョン**、**スピーチ**および🔚クロスモーダルモデルをサポートし、エンドツーエンドの推論パフォーマンスの最適化を可能にする、すぐに使えるクラウド側のデプロイメントエクスペリエンスを提供します。 これには、画像分類、物体検出、画像分割、顔検出、顔認識、キーポイント検出、キーイング、OCR、NLP、TTSなどのタスクが含まれ、**マルチシーン**、**マルチハードウェア**、**マルチプラットフォーム**の産業展開に対する開発者のニーズに応えています。 +| [Image Classification](examples/vision/classification) | [Object Detection](examples/vision/detection) | [Semantic Segmentation](examples/vision/segmentation/paddleseg) | [Potrait Segmentation](examples/vision/segmentation/paddleseg) | +|:----------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| +| | | | | +| [**Image Matting**](examples/vision/matting) | [**Real-Time Matting**](examples/vision/matting) | [**OCR**](examples/vision/ocr) | [**Face Alignment**](examples/vision/facealign) | +| | | | | +| [**Pose Estimation**](examples/vision/keypointdetection) | [**Behavior Recognition**](https://github.com/PaddlePaddle/FastDeploy/issues/6) | [**NLP**](examples/text) | [**Speech**](examples/audio/pp-tts) | +| | | |

**input** :早上好今天是2020
/10/29,最低温度是-3°C。

**output**: [](https://paddlespeech.bj.bcebos.com/Parakeet/docs/demos/parakeet_espnet_fs2_pwg_demo/tn_g2p/parakeet/001.wav)

| + + +## **地域交流** + +* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas + +* **WeChat**: QRコードをスキャンしてアンケートに回答すると、テクニカルコミュニティに参加でき、コミュニティの開発者と導入時の問題点や解決策について議論することができます。 + +
+ +
+ +## カタログ + +* **🖥️ サーバーサイドのデプロイメント** + + * [Python SDK クイックスタート](#fastdeploy-quick-start-python) + * [C++ SDK クイックスタート](#fastdeploy-quick-start-cpp) + * [サーバーサイドモデル対応表](#fastdeploy-server-models) + +* **📲 モバイルとエンドサイドデプロイメント** + + * [エンドサイドモデル対応表](#fastdeploy-edge-models) + +* **🌐 Webとアプレットの展開** + + * [Webサイドモデル対応表](#fastdeploy-web-models) +* [Acknowledge](#fastdeploy-acknowledge) +* [License](#fastdeploy-license) + +## 🖥️ サーバーサイドのデプロイメント + +
+ +
+ +Python SDK クイックスタート(クリックで詳細表示)
+ +#### クイックインストール + +##### プリディペンデンス + +- CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6 +- OS: Linux x86_64/macOS/Windows 10 + +##### GPU版のインストール + +```bash +pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +##### [Condaのインストール(推奨)](docs/cn/build_and_install/download_prebuilt_libraries.md) + +```bash +conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2 +``` + +##### CPUバージョンのインストール + +```bash +pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +#### Pythonの推論例 + +* モデルや画像の準備 + +```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 +``` + +* 推論結果のテスト + +```python +# GPU/TensorRTデプロイメントリファレンス examples/vision/detection/paddledetection/python +import cv2 +import fastdeploy.vision as vision + +model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml") +im = cv2.imread("000000014439.jpg") +result = model.predict(im.copy()) +print(result) + +vis_im = vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("vis_image.jpg", vis_im) + +``` + +
+ +
+ +
+ +C++ SDK クイックスタート(クリックで詳細表示)
+ + +#### インストール + +- リファレンス [C++プリコンパイル版ライブラリダウンロード](docs/cn/build_and_install/download_prebuilt_libraries.md)文档 + +#### C++の推論例 + +* モデルや画像の準備 + +```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 +``` + +* 推論結果のテスト + +```C++ +// GPU/TensorRTデプロイメントリファレンス examples/vision/detection/paddledetection/cpp +#include "fastdeploy/vision.h" + +int main(int argc, char* argv[]) { + namespace vision = fastdeploy::vision; + auto model = vision::detection::PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml"); + auto im = cv::imread("000000014439.jpg"); + + vision::DetectionResult res; + model.Predict(&im, &res); + + auto vis_im = vision::Visualize::VisDetection(im, res, 0.5); + cv::imwrite("vis_image.jpg", vis_im); + return 0; +} +``` + +
+ +その他の展開例については、[モデルの展開例]を参照してください(examples) . + +
+ +### サーバーサイドの対応機種一覧 🔥🔥🔥🔥🔥 + +表記: (1) ✅: 対応済み; (2) ❔:進行中 ; (3) N/A: 未対応;
+ +
サーバーサイドモデル対応一覧(クリックで縮小します)
+ +
+ +
+ +| ミッションシナリオ | モデル | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | +|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:| +| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | Serving | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | | +| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | +| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ | + + +
+ +
+ +## 📲 モバイルとエンドサイドの展開 🔥🔥🔥🔥 + +
+ +### エンドユーザーモデル対応表 +
エンドユーザーモデル対応表(クリックで縮小)
+ +
+ +
+ +| ミッションシナリオ | モデル | サイズ(MB) | Linux | Android | Linux | Linux | Linux | Linux | Linux | TBD... | +|:------------------:|:-----------------------------------------------------------------------------------------:|:--------:|:-------:|:-------:|:-------:|:-----------------------:|:------------------------------:|:---------------------------:|:--------------------------------:|:-------:| +| --- | --- | --- | ARM CPU | ARM CPU | Rockchip-NPU
RK3568/RK3588 | Rockchip-NPU
RV1109/RV1126/RK1808 | Amlogic-NPU
A311D/S905D/C308X | NXP-NPU
i.MX 8M Plus | TBD...| | +| Classification | [PaddleClas/ResNet50](examples/vision/classification/paddleclas) | 98 | ✅ | ✅ | ❔ | ✅ | | | | +| Classification | [PaddleClas/PP-LCNet](examples/vision/classification/paddleclas) | 11.9 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-LCNetv2](examples/vision/classification/paddleclas) | 26.6 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/EfficientNet](examples/vision/classification/paddleclas) | 31.4 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/GhostNet](examples/vision/classification/paddleclas) | 20.8 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV1](examples/vision/classification/paddleclas) | 17 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV2](examples/vision/classification/paddleclas) | 14.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV3](examples/vision/classification/paddleclas) | 22 | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -- | +| Classification | [PaddleClas/ShuffleNetV2](examples/vision/classification/paddleclas) | 9.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/SqueezeNetV1.1](examples/vision/classification/paddleclas) | 5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/Inceptionv3](examples/vision/classification/paddleclas) | 95.5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-HGNet](examples/vision/classification/paddleclas) | 59 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Detection | [PaddleDetection/PP-PicoDet_s_320_coco_lcnet](examples/vision/detection/paddledetection) | 4.9 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -- | +| Face Detection | [deepinsight/SCRFD](./examples/vision/facedet/scrfd) | 2.5 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Keypoint Detection | [PaddleDetection/PP-TinyPose](examples/vision/keypointdetection/tiny_pose) | 5.5 | ✅ | ✅ | ❔ | ❔ | ❔ | ❔ | -- | +| Segmentation | [PaddleSeg/PP-LiteSeg(STDC1)](examples/vision/segmentation/paddleseg) | 32.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg-Lite](examples/vision/segmentation/paddleseg) | 0.556 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/HRNet-w18](examples/vision/segmentation/paddleseg) | 38.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg](examples/vision/segmentation/paddleseg) | 107.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Unet](examples/vision/segmentation/paddleseg) | 53.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Deeplabv3](examples/vision/segmentation/paddleseg) | 150 | ❔ | ✅ | ✅ | | | | | +| OCR | [PaddleOCR/PP-OCRv2](examples/vision/ocr/PP-OCRv2) | 2.3+4.4 | ✅ | ✅ | ❔ | -- | -- | -- | -- | +| OCR | [PaddleOCR/PP-OCRv3](examples/vision/ocr/PP-OCRv3) | 2.4+10.6 | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | -- | + + +
+ +## 🌐 🌐 Webとアプレットのデプロイメント + +
+ +
ウェブ・アプレット展開サポートリスト(クリックで縮小)
+ +| ミッションシナリオ | モデル | [web_demo](examples/application/js/web_demo) | +|:------------------:|:-------------------------------------------------------------------------------------------:|:--------------------------------------------:| +| --- | --- | [Paddle.js](examples/application/js) | +| Detection | [FaceDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Detection | [ScrewDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Segmentation | [PaddleSeg/HumanSeg](./examples/application/js/web_demo/src/pages/cv/segmentation/HumanSeg) | ✅ | +| Object Recognition | [GestureRecognition](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| Object Recognition | [ItemIdentification](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/application/js/web_demo/src/pages/cv/ocr) | ✅ | + +
+ + +
+ +## Acknowledge + +このプロジェクトでは、SDKの生成とダウンロードに [EasyEdge](https://ai.baidu.com/easyedge/app/openSource) の無償かつオープンな機能を利用しており、そのことに謝意を表したいと思います。 + +## License + +
+ +FastDeploy は、[Apache-2.0 オープンソースプロトコル] (./LICENSE)に従っています。 diff --git a/docs/docs_i18n/README_한국인.md b/docs/docs_i18n/README_한국인.md new file mode 100644 index 000000000..f9ca96d1e --- /dev/null +++ b/docs/docs_i18n/README_한국인.md @@ -0,0 +1,335 @@ +[English](../../README_EN.md) | [简体中文](../../README_CN.md) | [हिन्दी](./README_हिन्दी.md) | [日本語](./README_日本語.md) | 한국인 | [Pу́сский язы́к](.//README_Ру́сский_язы́к.md) + +![⚡️FastDeploy](https://user-images.githubusercontent.com/31974251/185771818-5d4423cd-c94c-4a49-9894-bc7a8d1c29d0.png) + +

+ +

+ + + + + + + + +

+ +

+ 설치 + | + 문서 사용하기 + | + API문서 + | + 로그 업데이트 +

+ +**⚡Fastdeploy** 장면쉽게 유연 한 극,효율적 AI 추리 도구 가 배치 돼 있다.📦 제공 개표 즉의**구름을 단**부처 체험 지원 넘 🔥 150 +**text**,**비전**,**speech**과**다른 모드**모델 🔚 실현에 차 려 단'의 추리 성능 최적화 한다.이미지 분류, 객체 검출, 이미지 분할, 얼굴 검출, 얼굴 인식, 포인트 검출, 퍼팅, OCR, NLP, TTS 등의 작업을 포함하고 있어 개발자의**다중 장면, 다중 하드웨어, 다중 플랫폼**을 위한 산업 배치 요구를 충족시킨다. + +| [Image Classification](examples/vision/classification) | [Object Detection](examples/vision/detection) | [Semantic Segmentation](examples/vision/segmentation/paddleseg) | [Potrait Segmentation](examples/vision/segmentation/paddleseg) | +|:----------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| +| | | | | +| [**Image Matting**](examples/vision/matting) | [**Real-Time Matting**](examples/vision/matting) | [**OCR**](examples/vision/ocr) | [**Face Alignment**](examples/vision/facealign) | +| | | | | +| [**Pose Estimation**](examples/vision/keypointdetection) | [**Behavior Recognition**](https://github.com/PaddlePaddle/FastDeploy/issues/6) | [**NLP**](examples/text) | [**Speech**](examples/audio/pp-tts) | +| | | |

**input** :早上好今天是2020
/10/29,最低温度是-3°C。

**output**: [](https://paddlespeech.bj.bcebos.com/Parakeet/docs/demos/parakeet_espnet_fs2_pwg_demo/tn_g2p/parakeet/001.wav)

| + + +## **지역 사회 교류** + +* **Slack**:Join our [Slack community](https://join.slack.com/t/fastdeployworkspace/shared_invite/zt-1jznah134-3rxY~ytRb8rcPqkn9g~PDg) and chat with other community members about ideas + +* **위챗**: QR 코드를 스캔하고 설문지를 기입하여 기술 커뮤니티에 가입하며 커뮤니티 개발자와 함께 배치의 통점과 방안을 토론한다 + +
+ +
+ +## 목록 + +* **🖥️ 서버측 배포** + + * [Python SDK 빠른 시작](#fastdeploy-quick-start-python) + * [C++ SDK 시작](#fastdeploy-quick-start-cpp) + * [서비스 모델 지원 목록](#fastdeploy-server-models) + +* **📲 모바일 및 측면 배치** + + * [측면 모델 지원 목록](#fastdeploy-edge-models) + +* **🌐 웹과 애플릿 배포** + + * [웹 쪽 모델 지원 목록](#fastdeploy-web-models) +* [Acknowledge](#fastdeploy-acknowledge) +* [License](#fastdeploy-license) + +## 🖥️ 서비스 배포 + +
+ +
+ +파이썬 SDK 빠른 시작 (자세한내용은 클릭)
+ +#### 빠른 설치 + +##### 선행의존성 + +- CUDA >= 11.2、cuDNN >= 8.0、Python >= 3.6 +- OS: Linux x86_64/macOS/Windows 10 + +##### GPU 버전을 설치합니다 + +```bash +pip install numpy opencv-python fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +##### [Conda 설치 (추천) ](docs/cn/build_and_install/download_prebuilt_libraries.md) + +```bash +conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2 +``` + +##### CPU 버전 설치 + +```bash +pip install numpy opencv-python fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html +``` + +#### Python 추리 예제 + +* 모형과 그림을 준비하다 + +```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 +``` + +* 테스트 추론 결과 + +```python +# GPU/TensorRT 배치 참조 examples/vision/detection/paddledetection/python +import cv2 +import fastdeploy.vision as vision + +model = vision.detection.PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml") +im = cv2.imread("000000014439.jpg") +result = model.predict(im.copy()) +print(result) + +vis_im = vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("vis_image.jpg", vis_im) + +``` + +
+ +
+ +
+ + C++ SDK 빠른 시작 (클릭 후 자세히 보기)
+ + +#### 설치 + +[C++ 라이브러리 다운로드](docs/cn/build_and_install/download_prebuilt_libraries.md)참조u + +#### C++ 추론 예제 + +* 모형과 그림을 준비하다 + +```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 +``` + +* 추리 결과를 테스트하다 + +```C++ +// GPU/TensorRT배치 참조examples/vision/detection/paddledetection/cpp +#include "fastdeploy/vision.h" + +int main(int argc, char* argv[]) { + namespace vision = fastdeploy::vision; + auto model = vision::detection::PPYOLOE("ppyoloe_crn_l_300e_coco/model.pdmodel", + "ppyoloe_crn_l_300e_coco/model.pdiparams", + "ppyoloe_crn_l_300e_coco/infer_cfg.yml"); + auto im = cv::imread("000000014439.jpg"); + + vision::DetectionResult res; + model.Predict(&im, &res); + + auto vis_im = vision::Visualize::VisDetection(im, res, 0.5); + cv::imwrite("vis_image.jpg", vis_im); + return 0; +} +``` + +
+ +더 많은 배치 사례를 참고하시기 바랍니다 [모델 배포 예제](examples). + +
+ +### 서비스 모델 지원 목록🔥🔥🔥🔥🔥 + +부호 설명: (1) ✅: 지원 되여 있어야 한다; (2) ❔:진행 중이다; (3) N/A:지원되지 않습니다;
+ +
서비스 모델 지원 목록 (누르면 축소 가능)
+ +
+ +
+ +| 작업 장면 | 모형 | Linux | Linux | Win | Win | Mac | Mac | Linux | Linux | Linux | Linux | Linux | +|:----------------------:|:--------------------------------------------------------------------------------------------:|:------------------------------------------------:|:----------:|:-------:|:----------:|:-------:|:-------:|:-----------:|:---------------:|:-------------:|:-------------:|:-------:| +| --- | --- | X86 CPU | NVIDIA GPU | X86 CPU | NVIDIA GPU | X86 CPU | Arm CPU | AArch64 CPU | Phytium D2000CPU | NVIDIA Jetson | Graphcore IPU | Serving | +| Classification | [PaddleClas/ResNet50](./examples/vision/classification/paddleclas) | [✅](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [TorchVison/ResNet](examples/vision/classification/resnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [ltralytics/YOLOv5Cls](examples/vision/classification/yolov5cls) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Classification | [PaddleClas/PP-LCNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/PP-LCNetv2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/EfficientNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/GhostNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/MobileNetV3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/ShuffleNetV2](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/SqueeezeNetV1.1](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Classification | [PaddleClas/Inceptionv3](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Classification | [PaddleClas/PP-HGNet](./examples/vision/classification/paddleclas) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| Detection | [PaddleDetection/PP-YOLOE](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PicoDet](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOX](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/YOLOv3](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLO](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/PP-YOLOv2](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Faster-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [PaddleDetection/Mask-RCNN](./examples/vision/detection/paddledetection) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [Megvii-BaseDetection/YOLOX](./examples/vision/detection/yolox) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7](./examples/vision/detection/yolov7) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_trt](./examples/vision/detection/yolov7end2end_trt) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/YOLOv7end2end_ort_](./examples/vision/detection/yolov7end2end_ort) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [meituan/YOLOv6](./examples/vision/detection/yolov6) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ultralytics/YOLOv5](./examples/vision/detection/yolov5) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Detection | [WongKinYiu/YOLOR](./examples/vision/detection/yolor) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Detection | [WongKinYiu/ScaledYOLOv4](./examples/vision/detection/scaledyolov4) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [ppogg/YOLOv5Lite](./examples/vision/detection/yolov5lite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Detection | [RangiLyu/NanoDetPlus](./examples/vision/detection/nanodet_plus) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/TinyPose](./examples/vision/keypointdetection/tiny_pose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| KeyPoint | [PaddleDetection/PicoDet + TinyPose](./examples/vision/keypointdetection/det_keypoint_unite) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| HeadPose | [omasaht/headpose](examples/vision/headpose) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Tracking | [PaddleDetection/PP-Tracking](examples/vision/tracking/pptracking) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv2](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/vision/ocr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | +| Segmentation | [PaddleSeg/PP-LiteSeg](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegLite](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/HRNet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/PP-HumanSegServer](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Unet](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Segmentation | [PaddleSeg/Deeplabv3](./examples/vision/segmentation/paddleseg) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceDetection | [biubug6/RetinaFace](./examples/vision/facedet/retinaface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [Linzaer/UltraFace](./examples/vision/facedet/ultraface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [deepcam-cn/YOLOv5Face](./examples/vision/facedet/yolov5face) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceDetection | [insightface/SCRFD](./examples/vision/facedet/scrfd) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Hsintao/PFLD](examples/vision/facealign/pfld) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceAlign | [Single430FaceLandmark1000](./examples/vision/facealign/face_landmark_1000) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceAlign | [jhb86253817/PIPNet](./examples/vision/facealign) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/ArcFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/CosFace](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/PartialFC](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| FaceRecognition | [insightface/VPL](./examples/vision/faceid/insightface) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [ZHKKKe/MODNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PeterL1n/RobustVideoMatting]() | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-Matting](./examples/vision/matting/ppmatting) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/PP-HumanMatting](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Matting | [PaddleSeg/ModNet](./examples/vision/matting/modnet) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/BasicVSR](./) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/EDVR](./examples/vision/sr/edvr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Video Super-Resolution | [PaddleGAN/PP-MSVSR](./examples/vision/sr/ppmsvsr) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | +| Information Extraction | [PaddleNLP/UIE](./examples/text/uie) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | | +| NLP | [PaddleNLP/ERNIE-3.0](./examples/text/ernie-3.0) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | ❔ | ✅ | +| Speech | [PaddleSpeech/PP-TTS](./examples/audio/pp-tts) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❔ | ❔ | -- | ✅ | + + +
+ +
+ +## 📲 모바일 및 측면 배치 🔥🔥🔥🔥 + +
+ +### 측면 모델 지원 목록 +
측면 모델 지원 목록 (누르면 축소 가능)
+ +
+ +
+ +| 작업 장면 | 모형 | 크기(MB) | Linux | Android | Linux | Linux | Linux | Linux | Linux | TBD... | +|:------------------:|:-----------------------------------------------------------------------------------------:|:--------:|:-------:|:-------:|:-------:|:-----------------------:|:------------------------------:|:---------------------------:|:--------------------------------:|:-------:| +| --- | --- | --- | ARM CPU | ARM CPU | Rockchip-NPU
RK3568/RK3588 | Rockchip-NPU
RV1109/RV1126/RK1808 | Amlogic-NPU
A311D/S905D/C308X | NXP-NPU
i.MX 8M Plus | TBD...| | +| Classification | [PaddleClas/ResNet50](examples/vision/classification/paddleclas) | 98 | ✅ | ✅ | ❔ | ✅ | | | | +| Classification | [PaddleClas/PP-LCNet](examples/vision/classification/paddleclas) | 11.9 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-LCNetv2](examples/vision/classification/paddleclas) | 26.6 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/EfficientNet](examples/vision/classification/paddleclas) | 31.4 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/GhostNet](examples/vision/classification/paddleclas) | 20.8 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV1](examples/vision/classification/paddleclas) | 17 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV2](examples/vision/classification/paddleclas) | 14.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/MobileNetV3](examples/vision/classification/paddleclas) | 22 | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | -- | +| Classification | [PaddleClas/ShuffleNetV2](examples/vision/classification/paddleclas) | 9.2 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/SqueezeNetV1.1](examples/vision/classification/paddleclas) | 5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/Inceptionv3](examples/vision/classification/paddleclas) | 95.5 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Classification | [PaddleClas/PP-HGNet](examples/vision/classification/paddleclas) | 59 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- | +| Detection | [PaddleDetection/PP-PicoDet_s_320_coco_lcnet](examples/vision/detection/paddledetection) | 4.9 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -- | +| Face Detection | [deepinsight/SCRFD](./examples/vision/facedet/scrfd) | 2.5 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Keypoint Detection | [PaddleDetection/PP-TinyPose](examples/vision/keypointdetection/tiny_pose) | 5.5 | ✅ | ✅ | ❔ | ❔ | ❔ | ❔ | -- | +| Segmentation | [PaddleSeg/PP-LiteSeg(STDC1)](examples/vision/segmentation/paddleseg) | 32.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg-Lite](examples/vision/segmentation/paddleseg) | 0.556 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/HRNet-w18](examples/vision/segmentation/paddleseg) | 38.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/PP-HumanSeg](examples/vision/segmentation/paddleseg) | 107.2 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Unet](examples/vision/segmentation/paddleseg) | 53.7 | ✅ | ✅ | ✅ | -- | -- | -- | -- | +| Segmentation | [PaddleSeg/Deeplabv3](examples/vision/segmentation/paddleseg) | 150 | ❔ | ✅ | ✅ | | | | | +| OCR | [PaddleOCR/PP-OCRv2](examples/vision/ocr/PP-OCRv2) | 2.3+4.4 | ✅ | ✅ | ❔ | -- | -- | -- | -- | +| OCR | [PaddleOCR/PP-OCRv3](examples/vision/ocr/PP-OCRv3) | 2.4+10.6 | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | -- | + + +
+ +## 🌐 🌐 웹과 애플 릿 포치 + +
+ +
웹 및 애플릿 배포 지원 목록 (누르면 축소)
+ +| 작업 장면 | 모형 | [web_demo](examples/application/js/web_demo) | +|:------------------:|:-------------------------------------------------------------------------------------------:|:--------------------------------------------:| +| --- | --- | [Paddle.js](examples/application/js) | +| Detection | [FaceDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Detection | [ScrewDetection](examples/application/js/web_demo/src/pages/cv/detection) | ✅ | +| Segmentation | [PaddleSeg/HumanSeg](./examples/application/js/web_demo/src/pages/cv/segmentation/HumanSeg) | ✅ | +| Object Recognition | [GestureRecognition](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| Object Recognition | [ItemIdentification](examples/application/js/web_demo/src/pages/cv/recognition) | ✅ | +| OCR | [PaddleOCR/PP-OCRv3](./examples/application/js/web_demo/src/pages/cv/ocr) | ✅ | + +
+ + +
+ +## Acknowledge + +이 프로젝트의 SDK 생성 및 다운로드는 EasyEdge (https://ai.baidu.com/easyedge/app/openSource) 의 무료 오픈 기능을 사용하여 진행되었습니다. 이에 감사드립니다. + +## License + +
+ +Fastdeploy 컴플라이언스 [Apache e-2.0 오픈 소스 프로토콜](./LICENSE)。 diff --git a/docs/en/build_and_install/README.md b/docs/en/build_and_install/README.md old mode 100644 new mode 100755 index 4beaaeec8..0958c3778 --- a/docs/en/build_and_install/README.md +++ b/docs/en/build_and_install/README.md @@ -12,6 +12,9 @@ English | [中文](../../cn/build_and_install/README.md) - [Build and Install on IPU Platform](ipu.md) - [Build and Install on Nvidia Jetson Platform](jetson.md) - [Build and Install on Android Platform](android.md) +- [Build and Install on RV1126 Platform](rv1126.md) +- [Build and Install on A311D Platform](a311d.md) +- [Build and Install on KunlunXin XPU Platform](xpu.md) ## Build options @@ -25,6 +28,8 @@ English | [中文](../../cn/build_and_install/README.md) | ENABLE_VISION | Default OFF,whether to enable vision models deployment module | | ENABLE_TEXT | Default OFF,whether to enable text models deployment module | | WITH_GPU | Default OFF, if build on GPU, this need to be ON | +| WITH_XPU | Default OFF,if deploy on KunlunXin XPU,this need to be ON | +| WITH_TIMVX | Default OFF,if deploy on RV1126/RV1109/A311D,this need to be ON | | CUDA_DIRECTORY | Default /usr/local/cuda, if build on GPU, this defines the path of CUDA(>=11.2) | | TRT_DIRECTORY | If build with ENABLE_TRT_BACKEND=ON, this defines the path of TensorRT(>=8.4) | | ORT_DIRECTORY | [Optional] If build with ENABLE_ORT_BACKEND=ON, this flag defines the path of ONNX Runtime, but if this flag is not set, it will download ONNX Runtime library automatically | diff --git a/docs/en/build_and_install/a311d.md b/docs/en/build_and_install/a311d.md new file mode 100755 index 000000000..872c1b93c --- /dev/null +++ b/docs/en/build_and_install/a311d.md @@ -0,0 +1,105 @@ +# How to Build A311D Deployment Environment + +FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html). + +This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library. + +The relevant compilation options are described as follows: +|Compile Options|Default Values|Description|Remarks| +|:---|:---|:---|:---| +|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the A311D library| - | +|WITH_TIMVX|OFF|It needs to be set to ON when compiling the A311D library| - | +|TARGET_ABI|NONE|It needs to be set to arm64 when compiling the A311D library| - | + +For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md) + +## Cross-compilation environment construction + +### Host Environment Requirements +- os:Ubuntu == 16.04 +- cmake: version >= 3.10.0 + +### Building the compilation environment +You can enter the FastDeploy/tools/timvx directory and use the following command to install: +```bash +cd FastDeploy/tools/timvx +bash install.sh +``` +You can also install it with the following commands: +```bash + # 1. Install basic software +apt update +apt-get install -y --no-install-recommends \ + gcc g++ git make wget python unzip + +# 2. Install arm gcc toolchains +apt-get install -y --no-install-recommends \ + g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \ + g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + +# 3. Install cmake 3.10 or above +wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \ + tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \ + mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \ + ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \ + ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake +``` + +## FastDeploy cross-compilation library compilation based on PaddleLite +After setting up the cross-compilation environment, the compilation command is as follows: +```bash +# Download the latest source code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy +mkdir build && cd build + +# CMake configuration with A311D toolchain +cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \ + -DWITH_TIMVX=ON \ + -DTARGET_ABI=arm64 \ + -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \ + -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启 + -Wno-dev .. + +# Build FastDeploy A311D C++ SDK +make -j8 +make install +``` +After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled. + +## Prepare the Soc environment +Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.4.3 +```bash +dmesg | grep Galcore +``` +If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct. + +There are two ways to modify the current NPU driver version: +1. Manually replace the NPU driver version. (recommend) +2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version. + +### Manually replace the NPU driver version +1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files +```bash +wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz +tar -xf PaddleLite-generic-demo.tar.gz +``` +2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111. +3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/arm64/lib/verisilicon_timvx/viv_sdk_6_4_4_3/lib/a311d/4.9.113` path to the development board. +4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2. +5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.4.3 + +### flash +According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.4.3 version of the NPU driver. + +For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing) + +## Deployment example based on FastDeploy on A311D +1. For deploying the PaddleClas classification model on A311D, please refer to: [C++ deployment example of PaddleClas classification model on A311D](../../../examples/vision/classification/paddleclas/a311d/README.md) + +2. For deploying PPYOLOE detection model on A311D, please refer to: [C++ deployment example of PPYOLOE detection model on A311D](../../../examples/vision/detection/paddledetection/a311d/README.md) + +3. For deploying YOLOv5 detection model on A311D, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on A311D](../../../examples/vision/detection/yolov5/a311d/README.md) + +4. For deploying PP-LiteSeg segmentation model on A311D, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on A311D](../../../examples/vision/segmentation/paddleseg/a311d/README.md) diff --git a/docs/en/build_and_install/cpu.md b/docs/en/build_and_install/cpu.md index f280cce69..bc01fb1f2 100644 --- a/docs/en/build_and_install/cpu.md +++ b/docs/en/build_and_install/cpu.md @@ -30,6 +30,11 @@ Prerequisite for Compiling on Linux & Mac: - gcc/g++ >= 5.4 (8.2 is recommended) - cmake >= 3.18.0 +It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`) +``` +sudo apt-get install libopencv-dev +``` + ``` git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy @@ -38,7 +43,8 @@ cmake .. -DENABLE_ORT_BACKEND=ON \ -DENABLE_PADDLE_BACKEND=ON \ -DENABLE_OPENVINO_BACKEND=ON \ -DCMAKE_INSTALL_PREFIX=${PWD}/compiled_fastdeploy_sdk \ - -DENABLE_VISION=ON + -DENABLE_VISION=ON \ + -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 make -j12 make install ``` @@ -84,6 +90,11 @@ All compilation options are introduced via environment variables ### Linux & Mac +It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`) +``` +sudo apt-get install libopencv-dev +``` + ``` git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python @@ -91,6 +102,8 @@ export ENABLE_ORT_BACKEND=ON export ENABLE_PADDLE_BACKEND=ON export ENABLE_OPENVINO_BACKEND=ON export ENABLE_VISION=ON +# The OPENCV_DIRECTORY is optional, if not exported, a prebuilt OpenCV library will be downloaded +export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 python setup.py build python setup.py bdist_wheel diff --git a/docs/en/build_and_install/download_prebuilt_libraries.md b/docs/en/build_and_install/download_prebuilt_libraries.md index 52dbdd627..37b199ba0 100644 --- a/docs/en/build_and_install/download_prebuilt_libraries.md +++ b/docs/en/build_and_install/download_prebuilt_libraries.md @@ -22,7 +22,7 @@ FastDeploy supports Computer Vision, Text and NLP model deployment on CPU and Nv ### Python SDK -Install the released version(the newest 1.0.0 for now) +Install the released version(the newest 1.0.1 for now) ``` pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html @@ -42,12 +42,12 @@ conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn= ### C++ SDK -Install the released version(Latest 1.0.0) +Install the released version(Latest 1.0.1) | Platform | File | Description | |:----------- |:--------------------------------------------------------------------------------------------------------------------- |:--------------------------------------------------------- | -| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.0.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2 | -| Windows x64 | [fastdeploy-win-x64-gpu-1.0.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.0.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 | +| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.1.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2 | +| Windows x64 | [fastdeploy-win-x64-gpu-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.1.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 | Install the Develop version(Nightly build) @@ -69,7 +69,7 @@ FastDeploy supports computer vision, text and NLP model deployment on CPU with P ### Python SDK -Install the released version(Latest 1.0.0 for now) +Install the released version(Latest 1.0.1 for now) ``` pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html @@ -83,15 +83,15 @@ pip install fastdeploy-python==0.0.0 -f https://www.paddlepaddle.org.cn/whl/fast ### C++ SDK -Install the released version(Latest 1.0.0 for now, Android is 1.0.0) +Install the released version(Latest 1.0.1 for now, Android is 1.0.1) | Platform | File | Description | |:------------- |:--------------------------------------------------------------------------------------------------------------------- |:------------------------------ | -| Linux x64 | [fastdeploy-linux-x64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.0.tgz) | g++ 8.2 | -| Windows x64 | [fastdeploy-win-x64-1.0.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.0.zip) | Visual Studio 16 2019 | -| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.0.tgz) | clang++ 10.0.0| -| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.0.tgz) | clang++ 13.0.0 | -| Linux aarch64 | [fastdeploy-osx-arm64-1.0.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.0.tgz) | gcc 6.3 | +| Linux x64 | [fastdeploy-linux-x64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.1.tgz) | g++ 8.2 | +| Windows x64 | [fastdeploy-win-x64-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.1.zip) | Visual Studio 16 2019 | +| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.1.tgz) | clang++ 10.0.0| +| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.1.tgz) | clang++ 13.0.0 | +| Linux aarch64 | [fastdeploy-osx-arm64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.1.tgz) | gcc 6.3 | | Android armv7&v8 | [fastdeploy-android-1.0.0-shared.tgz](https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-1.0.0-shared.tgz)| NDK 25, clang++, support arm64-v8a及armeabi-v7a | ## Java SDK diff --git a/docs/en/build_and_install/gpu.md b/docs/en/build_and_install/gpu.md index 40357f118..df0645262 100644 --- a/docs/en/build_and_install/gpu.md +++ b/docs/en/build_and_install/gpu.md @@ -34,6 +34,11 @@ Prerequisite for Compiling on Linux: - cuda >= 11.2 - cudnn >= 8.2 +It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`) +``` +sudo apt-get install libopencv-dev +``` + ``` git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy @@ -46,7 +51,8 @@ cmake .. -DENABLE_ORT_BACKEND=ON \ -DTRT_DIRECTORY=/Paddle/TensorRT-8.4.1.5 \ -DCUDA_DIRECTORY=/usr/local/cuda \ -DCMAKE_INSTALL_PREFIX=${PWD}/compiled_fastdeploy_sdk \ - -DENABLE_VISION=ON + -DENABLE_VISION=ON \ + -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 make -j12 make install ``` @@ -106,6 +112,11 @@ Prerequisite for Compiling on Linux: All compilation options are imported via environment variables +It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`) +``` +sudo apt-get install libopencv-dev +``` + ``` git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python @@ -117,6 +128,8 @@ export ENABLE_TRT_BACKEND=ON export WITH_GPU=ON export TRT_DIRECTORY=/Paddle/TensorRT-8.4.1.5 export CUDA_DIRECTORY=/usr/local/cuda +# The OPENCV_DIRECTORY is optional, if not exported, a prebuilt OpenCV library will be downloaded +export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 python setup.py build python setup.py bdist_wheel diff --git a/docs/en/build_and_install/jetson.md b/docs/en/build_and_install/jetson.md index e606b6d29..8d16f3149 100644 --- a/docs/en/build_and_install/jetson.md +++ b/docs/en/build_and_install/jetson.md @@ -1,7 +1,7 @@ # How to Build FastDeploy Library on Nvidia Jetson Platform -FastDeploy supports CPU inference with ONNX Runtime and GPU inference with Nvidia TensorRT on Nvidia Jetson platform +FastDeploy supports CPU inference with ONNX Runtime and GPU inference with Nvidia TensorRT/Paddle Inference on Nvidia Jetson platform ## How to Build and Install FastDeploy C++ Library @@ -11,12 +11,16 @@ Prerequisite for Compiling on NVIDIA Jetson: - cmake >= 3.10.0 - jetpack >= 4.6.1 +If you need to integrate Paddle Inference backend(Support CPU/GPU),please download and decompress the prebuilt library in [Paddle Inference prebuild libraries](https://www.paddlepaddle.org.cn/inference/v2.4/guides/install/download_lib.html#c) according to your develop envriment. + ``` git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build cmake .. -DBUILD_ON_JETSON=ON \ -DENABLE_VISION=ON \ + -DENABLE_PADDLE_BACKEND=ON \ # This is optional, can be OFF if you don't need + -DPADDLEINFERENCE_DIRECTORY=/Download/paddle_inference_jetson \ -DCMAKE_INSTALL_PREFIX=${PWD}/installed_fastdeploy make -j8 make install @@ -35,6 +39,8 @@ Prerequisite for Compiling on NVIDIA Jetson: Notice the `wheel` is required if you need to pack a wheel, execute `pip install wheel` first. +If you need to integrate Paddle Inference backend(Support CPU/GPU),please download and decompress the prebuilt library in [Paddle Inference prebuild libraries](https://www.paddlepaddle.org.cn/inference/v2.4/guides/install/download_lib.html#c) according to your develop envriment. + All compilation options are imported via environment variables ``` @@ -43,6 +49,10 @@ cd FastDeploy/python export BUILD_ON_JETSON=ON export ENABLE_VISION=ON +# ENABLE_PADDLE_BACKEND & PADDLEINFERENCE_DIRECTORY are optional +export ENABLE_PADDLE_BACKEND=ON +export PADDLEINFERENCE_DIRECTORY=/Download/paddle_inference_jetson + python setup.py build python setup.py bdist_wheel ``` diff --git a/docs/en/build_and_install/rv1126.md b/docs/en/build_and_install/rv1126.md new file mode 100755 index 000000000..a56535363 --- /dev/null +++ b/docs/en/build_and_install/rv1126.md @@ -0,0 +1,105 @@ +# How to Build RV1126 Deployment Environment + +FastDeploy supports AI deployment on Rockchip Soc based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html). + +This document describes how to compile the PaddleLite-based C++ FastDeploy cross-compilation library. + +The relevant compilation options are described as follows: +|Compile Options|Default Values|Description|Remarks| +|:---|:---|:---|:---| +|ENABLE_LITE_BACKEND|OFF|It needs to be set to ON when compiling the RK library| - | +|WITH_TIMVX|OFF|It needs to be set to ON when compiling the RK library| - | +|TARGET_ABI|NONE|It needs to be set to armhf when compiling the RK library| - | + +For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md) + +## Cross-compilation environment construction + +### Host Environment Requirements +- os:Ubuntu == 16.04 +- cmake: version >= 3.10.0 + +### Building the compilation environment +You can enter the FastDeploy/tools/timvx directory and use the following command to install: +```bash +cd FastDeploy/tools/timvx +bash install.sh +``` +You can also install it with the following commands: +```bash + # 1. Install basic software +apt update +apt-get install -y --no-install-recommends \ + gcc g++ git make wget python unzip + +# 2. Install arm gcc toolchains +apt-get install -y --no-install-recommends \ + g++-arm-linux-gnueabi gcc-arm-linux-gnueabi \ + g++-arm-linux-gnueabihf gcc-arm-linux-gnueabihf \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + +# 3. Install cmake 3.10 or above +wget -c https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \ + tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \ + mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \ + ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \ + ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake +``` + +## FastDeploy cross-compilation library compilation based on PaddleLite +After setting up the cross-compilation environment, the compilation command is as follows: +```bash +# Download the latest source code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy +mkdir build && cd build + +# CMake configuration with RK toolchain +cmake -DCMAKE_TOOLCHAIN_FILE=./../cmake/toolchain.cmake \ + -DWITH_TIMVX=ON \ + -DTARGET_ABI=armhf \ + -DCMAKE_INSTALL_PREFIX=fastdeploy-tmivx \ + -DENABLE_VISION=ON \ # 是否编译集成视觉模型的部署模块,可选择开启 + -Wno-dev .. + +# Build FastDeploy RV1126 C++ SDK +make -j8 +make install +``` +After the compilation is complete, the fastdeploy-tmivx directory will be generated, indicating that the FastDeploy library based on PadddleLite TIM-VX has been compiled. + +## Prepare the Soc environment +Before deployment, ensure that the version of the driver galcore.so of the Verisilicon Linux Kernel NPU meets the requirements. Before deployment, please log in to the development board, and enter the following command through the command line to query the NPU driver version. The recommended version of the Rockchip driver is: 6.4.6.5 +```bash +dmesg | grep Galcore +``` +If the current version does not comply with the above, please read the following content carefully to ensure that the underlying NPU driver environment is correct. + +There are two ways to modify the current NPU driver version: +1. Manually replace the NPU driver version. (recommend) +2. flash the machine, and flash the firmware that meets the requirements of the NPU driver version. + +### Manually replace the NPU driver version +1. Use the following command to download and decompress the PaddleLite demo, which provides ready-made driver files +```bash +wget https://paddlelite-demo.bj.bcebos.com/devices/generic/PaddleLite-generic-demo.tar.gz +tar -xf PaddleLite-generic-demo.tar.gz +``` +2. Use `uname -a` to check `Linux Kernel` version, it is determined to be version 4.19.111. +3. Upload `galcore.ko` under `PaddleLite-generic-demo/libs/PaddleLite/linux/armhf/lib/verisilicon_timvx/viv_sdk_6_4_6_5/lib/1126/4.19.111/` path to the development board. +4. Log in to the development board, enter `sudo rmmod galcore` on the command line to uninstall the original driver, and enter `sudo insmod galcore.ko` to load the uploaded device driver. (Whether sudo is needed depends on the actual situation of the development board. For some adb-linked devices, please adb root in advance). If this step fails, go to method 2. +5. Enter `dmesg | grep Galcore` in the development board to query the NPU driver version, and it is determined to be: 6.4.6.5 + +### flash +According to the specific development board model, ask the development board seller or the official website customer service for the firmware and flashing method corresponding to the 6.4.6.5 version of the NPU driver. + +For more details, please refer to: [PaddleLite prepares the device environment](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/verisilicon_timvx.html#zhunbeishebeihuanjing) + +## Deployment example based on FastDeploy on RV1126 +1. For deploying the PaddleClas classification model on RV1126, please refer to: [C++ deployment example of PaddleClas classification model on RV1126](../../../examples/vision/classification/paddleclas/rv1126/README.md) + +2. For deploying PPYOLOE detection model on RV1126, please refer to: [C++ deployment example of PPYOLOE detection model on RV1126](../../../examples/vision/detection/paddledetection/rv1126/README.md) + +3. For deploying YOLOv5 detection model on RV1126, please refer to: [C++ Deployment Example of YOLOv5 Detection Model on RV1126](../../../examples/vision/detection/yolov5/rv1126/README.md) + +4. For deploying PP-LiteSeg segmentation model on RV1126, please refer to: [C++ Deployment Example of PP-LiteSeg Segmentation Model on RV1126](../../../examples/vision/segmentation/paddleseg/rv1126/README.md) diff --git a/docs/en/build_and_install/xpu.md b/docs/en/build_and_install/xpu.md new file mode 100755 index 000000000..403837e5d --- /dev/null +++ b/docs/en/build_and_install/xpu.md @@ -0,0 +1,78 @@ +# How to Build KunlunXin XPU Deployment Environment + +FastDeploy supports deployment AI on KunlunXin XPU based on Paddle-Lite backend. For more detailed information, please refer to: [PaddleLite Deployment Example](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/kunlunxin_xpu.html#xpu)。 + +This document describes how to compile the C++ FastDeploy library based on PaddleLite. + +The relevant compilation options are described as follows: +|Compile Options|Default Values|Description|Remarks| +|:---|:---|:---|:---| +| ENABLE_LITE_BACKEND | OFF | It needs to be set to ON when compiling the RK library| - | +| WITH_XPU | OFF | It needs to be set to ON when compiling the KunlunXin XPU library| - | +| ENABLE_ORT_BACKEND | OFF | whether to intergrate ONNX Runtime backend | - | +| ENABLE_PADDLE_BACKEND | OFF | whether to intergrate Paddle Inference backend | - | +| ENABLE_OPENVINO_BACKEND | OFF | whether to intergrate OpenVINO backend | - | +| ENABLE_VISION | OFF | whether to intergrate vision models | - | +| ENABLE_TEXT | OFF | whether to intergrate text models | - | + +The configuration for third libraries(Optional, if the following option is not defined, the prebuilt third libraries will download automaticly while building FastDeploy). +| Option | Description | +| :---------------------- | :--------------------------------------------------------------------------------------------- | +| ORT_DIRECTORY | While ENABLE_ORT_BACKEND=ON, use ORT_DIRECTORY to specify your own ONNX Runtime library path. | +| OPENCV_DIRECTORY | While ENABLE_VISION=ON, use OPENCV_DIRECTORY to specify your own OpenCV library path. | +| OPENVINO_DIRECTORY | While ENABLE_OPENVINO_BACKEND=ON, use OPENVINO_DIRECTORY to specify your own OpenVINO library path. | + +For more compilation options, please refer to [Description of FastDeploy compilation options](./README.md) + +## C++ FastDeploy library compilation based on PaddleLite +- OS: Linux +- gcc/g++: version >= 8.2 +- cmake: version >= 3.15 + +It it recommend install OpenCV library manually, and define `-DOPENCV_DIRECTORY` to set path of OpenCV library(If the flag is not defined, a prebuilt OpenCV library will be downloaded automaticly while building FastDeploy, but the prebuilt OpenCV cannot support reading video file or other function e.g `imshow`) +``` +sudo apt-get install libopencv-dev +``` + +The compilation command is as follows: +```bash +# Download the latest source code +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy +mkdir build && cd build + +# CMake configuration with KunlunXin xpu toolchain +cmake -DWITH_XPU=ON \ + -DWITH_GPU=OFF \ + -DENABLE_ORT_BACKEND=ON \ + -DENABLE_PADDLE_BACKEND=ON \ + -DCMAKE_INSTALL_PREFIX=fastdeploy-xpu \ + -DENABLE_VISION=ON \ + -DOPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 \ + .. + +# Build FastDeploy KunlunXin XPU C++ SDK +make -j8 +make install +``` +After the compilation is complete, the fastdeploy-xpu directory will be generated, indicating that the PadddleLite-based FastDeploy library has been compiled. + +## Python compile +The compilation command is as follows: +```bash +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/python +export WITH_XPU=ON +export WITH_GPU=OFF +export ENABLE_ORT_BACKEND=ON +export ENABLE_PADDLE_BACKEND=ON +export ENABLE_VISION=ON +# The OPENCV_DIRECTORY is optional, if not exported, a prebuilt OpenCV library will be downloaded +export OPENCV_DIRECTORY=/usr/lib/x86_64-linux-gnu/cmake/opencv4 + +python setup.py build +python setup.py bdist_wheel +``` +After the compilation is completed, the compiled `wheel` package will be generated in the `FastDeploy/python/dist` directory, just pip install it directly + +During the compilation process, if you modify the compilation parameters, in order to avoid the cache impact, you can delete the two subdirectories `build` and `.setuptools-cmake-build` under the `FastDeploy/python` directory and then recompile. diff --git a/docs/en/faq/use_sdk_on_linux.md b/docs/en/faq/use_sdk_on_linux.md index 4dcffb3a4..653389f43 100644 --- a/docs/en/faq/use_sdk_on_linux.md +++ b/docs/en/faq/use_sdk_on_linux.md @@ -1,3 +1,5 @@ +English | [中文](../../cn/faq/use_sdk_on_linux.md) + # C++ Deployment on Linux 1. After compilation, and execute the binary file, throw error `error while loading shared libraries` @@ -7,10 +9,10 @@ When we execute the binary file, it requires the dependent libraries can be foun ./infer_ppyoloe_demo: error while loading shared libraries: libonnxruntime.so.1.12.0: cannot open shared object file: No such file or directory ``` -FastDeploy provides a shell scripts to help export the libraries path to `LD_LIBRARY_PATH`, execute the follwing command +FastDeploy provides a shell scripts to help export the libraries path to `LD_LIBRARY_PATH`, execute the following command ``` source /Downloads/fastdeploy-linux-x64-1.0.0/fastdeploy_init.sh ``` -And now you can execute the binary file again. \ No newline at end of file +And now you can execute the binary file again. diff --git a/docs/en/faq/use_sdk_on_windows.md b/docs/en/faq/use_sdk_on_windows.md index 367f6e1df..315e5ef6a 100644 --- a/docs/en/faq/use_sdk_on_windows.md +++ b/docs/en/faq/use_sdk_on_windows.md @@ -1,3 +1,5 @@ +English | [中文](../../cn/faq/use_sdk_on_windows.md) + # Using the FastDeploy C++ SDK on Windows Platform ## Contents diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8aa469b6a..5c9fbdce0 100755 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -48,13 +48,7 @@ function(add_fastdeploy_executable FIELD CC_FILE) if(EXISTS ${TEMP_TARGET_FILE} AND TARGET fastdeploy) add_executable(${TEMP_TARGET_NAME} ${TEMP_TARGET_FILE}) target_link_libraries(${TEMP_TARGET_NAME} PUBLIC fastdeploy) - if(TARGET gflags) - if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) - target_link_libraries(${TEMP_TARGET_NAME} PRIVATE gflags pthread) - else() - target_link_libraries(${TEMP_TARGET_NAME} PRIVATE gflags) - endif() - endif() + target_link_libraries(${TEMP_TARGET_NAME} PRIVATE ${GFLAGS_LIBRARIES}) config_fastdeploy_executable_link_flags(${TEMP_TARGET_NAME}) math(EXPR _EXAMPLES_NUM "${EXAMPLES_NUM} + 1") set(EXAMPLES_NUM ${_EXAMPLES_NUM} PARENT_SCOPE) diff --git a/examples/vision/classification/paddleclas/a311d/README.md b/examples/vision/classification/paddleclas/a311d/README.md new file mode 100755 index 000000000..0fb75854a --- /dev/null +++ b/examples/vision/classification/paddleclas/a311d/README.md @@ -0,0 +1,11 @@ +# PaddleClas 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 PaddleLite 部署 PaddleClas 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/classification/paddleclas/a311d/cpp/CMakeLists.txt b/examples/vision/classification/paddleclas/a311d/cpp/CMakeLists.txt new file mode 100755 index 000000000..baaf8331f --- /dev/null +++ b/examples/vision/classification/paddleclas/a311d/cpp/CMakeLists.txt @@ -0,0 +1,38 @@ +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}) +include_directories(${FastDeploy_INCLUDE_DIRS}) + +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) + +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install) + +install(TARGETS infer_demo DESTINATION ./) + +install(DIRECTORY models DESTINATION ./) +install(DIRECTORY images DESTINATION ./) +# install(DIRECTORY run_with_adb.sh DESTINATION ./) + +file(GLOB FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/*) +install(PROGRAMS ${FASTDEPLOY_LIBS} DESTINATION lib) + +file(GLOB OPENCV_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/opencv/lib/lib*) +install(PROGRAMS ${OPENCV_LIBS} DESTINATION lib) + +file(GLOB PADDLELITE_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/lib*) +install(PROGRAMS ${PADDLELITE_LIBS} DESTINATION lib) + +file(GLOB TIMVX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/verisilicon_timvx/*) +install(PROGRAMS ${TIMVX_LIBS} DESTINATION lib) + +file(GLOB ADB_TOOLS run_with_adb.sh) +install(PROGRAMS ${ADB_TOOLS} DESTINATION ./) diff --git a/examples/vision/classification/paddleclas/a311d/cpp/README.md b/examples/vision/classification/paddleclas/a311d/cpp/README.md new file mode 100755 index 000000000..c1d926c9a --- /dev/null +++ b/examples/vision/classification/paddleclas/a311d/cpp/README.md @@ -0,0 +1,53 @@ +# PaddleClas A311D 开发板 C++ 部署示例 +本目录下提供的 `infer.cc`,可以帮助用户快速完成 PaddleClas 量化模型在 A311D 上的部署推理加速。 + +## 部署准备 +### FastDeploy 交叉编译环境准备 +- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建) + +### 量化模型准备 +- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 +- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.) +- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) + +## 在 A311D 上部署量化后的 ResNet50_Vd 分类模型 +请按照以下步骤完成在 A311D 上部署 ResNet50_Vd 量化模型: +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddlelite-的-fastdeploy-交叉编译库编译) + +2. 将编译后的库拷贝到当前目录,可使用如下命令: +```bash +cp -r FastDeploy/build/fastdeploy-tmivx/ FastDeploy/examples/vision/classification/paddleclas/a311d/cpp/ +``` + +3. 在当前路径下载部署所需的模型和示例图片: +```bash +mkdir models && mkdir images +wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz +tar -xvf ResNet50_vd_infer.tgz +cp -r ResNet50_vd_infer models +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg +cp -r ILSVRC2012_val_00000010.jpeg images +``` + +4. 编译部署示例,可使入如下命令: +```bash +mkdir build && cd build +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=arm64 .. +make -j8 +make install +# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 +``` + +5. 基于 adb 工具部署 ResNet50_vd 分类模型到晶晨 A311D,可使用如下命令: +```bash +# 进入 install 目录 +cd FastDeploy/examples/vision/classification/paddleclas/a311d/cpp/build/install/ +# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID +bash run_with_adb.sh infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg $DEVICE_ID +``` + +部署成功后运行结果如下: + + + +需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) diff --git a/examples/vision/classification/paddleclas/a311d/cpp/infer.cc b/examples/vision/classification/paddleclas/a311d/cpp/infer.cc new file mode 100755 index 000000000..140311eec --- /dev/null +++ b/examples/vision/classification/paddleclas/a311d/cpp/infer.cc @@ -0,0 +1,60 @@ +// 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 "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) { + auto model_file = model_dir + sep + "inference.pdmodel"; + auto params_file = model_dir + sep + "inference.pdiparams"; + auto config_file = model_dir + sep + "inference_cls.yaml"; + + fastdeploy::RuntimeOption option; + option.UseTimVX(); + + auto model = fastdeploy::vision::classification::PaddleClasModel( + model_file, params_file, config_file, option); + + assert(model.Initialized()); + + auto im = cv::imread(image_file); + + fastdeploy::vision::ClassifyResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + std::cout << res.Str() << std::endl; + +} + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cout << "Usage: infer_demo path/to/quant_model " + "path/to/image " + "e.g ./infer_demo ./ResNet50_vd_quant ./test.jpeg" + << std::endl; + return -1; + } + + std::string model_dir = argv[1]; + std::string test_image = argv[2]; + InitAndInfer(model_dir, test_image); + return 0; +} diff --git a/examples/vision/classification/paddleclas/a311d/cpp/run_with_adb.sh b/examples/vision/classification/paddleclas/a311d/cpp/run_with_adb.sh new file mode 100755 index 000000000..aacaed4c5 --- /dev/null +++ b/examples/vision/classification/paddleclas/a311d/cpp/run_with_adb.sh @@ -0,0 +1,47 @@ +#!/bin/bash +HOST_SPACE=${PWD} +echo ${HOST_SPACE} +WORK_SPACE=/data/local/tmp/test + +# The first parameter represents the demo name +DEMO_NAME=image_classification_demo +if [ -n "$1" ]; then + DEMO_NAME=$1 +fi + +# The second parameter represents the model name +MODEL_NAME=mobilenet_v1_fp32_224 +if [ -n "$2" ]; then + MODEL_NAME=$2 +fi + +# The third parameter indicates the name of the image to be tested +IMAGE_NAME=0001.jpg +if [ -n "$3" ]; then + IMAGE_NAME=$3 +fi + +# The fourth parameter represents the ID of the device +ADB_DEVICE_NAME= +if [ -n "$4" ]; then + ADB_DEVICE_NAME="-s $4" +fi + +# Set the environment variables required during the running process +EXPORT_ENVIRONMENT_VARIABLES="export GLOG_v=5; export VIV_VX_ENABLE_GRAPH_TRANSFORM=-pcq:1; export VIV_VX_SET_PER_CHANNEL_ENTROPY=100; export TIMVX_BATCHNORM_FUSION_MAX_ALLOWED_QUANT_SCALE_DEVIATION=300000; export VSI_NN_LOG_LEVEL=5;" + +EXPORT_ENVIRONMENT_VARIABLES="${EXPORT_ENVIRONMENT_VARIABLES}export LD_LIBRARY_PATH=${WORK_SPACE}/lib:\$LD_LIBRARY_PATH;" + +# Please install adb, and DON'T run this in the docker. +set -e +adb $ADB_DEVICE_NAME shell "rm -rf $WORK_SPACE" +adb $ADB_DEVICE_NAME shell "mkdir -p $WORK_SPACE" + +# Upload the demo, librarys, model and test images to the device +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/lib $WORK_SPACE +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/${DEMO_NAME} $WORK_SPACE +adb $ADB_DEVICE_NAME push models $WORK_SPACE +adb $ADB_DEVICE_NAME push images $WORK_SPACE + +# Execute the deployment demo +adb $ADB_DEVICE_NAME shell "cd $WORK_SPACE; ${EXPORT_ENVIRONMENT_VARIABLES} chmod +x ./${DEMO_NAME}; ./${DEMO_NAME} ./models/${MODEL_NAME} ./images/$IMAGE_NAME" diff --git a/examples/vision/classification/paddleclas/cpp/README.md b/examples/vision/classification/paddleclas/cpp/README.md old mode 100644 new mode 100755 index 066340467..dff76da18 --- a/examples/vision/classification/paddleclas/cpp/README.md +++ b/examples/vision/classification/paddleclas/cpp/README.md @@ -30,6 +30,10 @@ wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/Ima ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1 # GPU上TensorRT推理 ./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 2 +# IPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 3 +# KunlunXin XPU推理 +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 4 ``` 以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: diff --git a/examples/vision/classification/paddleclas/cpp/infer.cc b/examples/vision/classification/paddleclas/cpp/infer.cc old mode 100644 new mode 100755 index bdd87ecdc..244accfa7 --- a/examples/vision/classification/paddleclas/cpp/infer.cc +++ b/examples/vision/classification/paddleclas/cpp/infer.cc @@ -96,6 +96,32 @@ void IpuInfer(const std::string& model_dir, const std::string& image_file) { std::cout << res.Str() << std::endl; } +void XpuInfer(const std::string& model_dir, const std::string& image_file) { + auto model_file = model_dir + sep + "inference.pdmodel"; + auto params_file = model_dir + sep + "inference.pdiparams"; + auto config_file = model_dir + sep + "inference_cls.yaml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseXpu(); + auto model = fastdeploy::vision::classification::PaddleClasModel( + 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::ClassifyResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + + // print res + std::cout << res.Str() << std::endl; +} + void TrtInfer(const std::string& model_dir, const std::string& image_file) { auto model_file = model_dir + sep + "inference.pdmodel"; auto params_file = model_dir + sep + "inference.pdiparams"; @@ -128,7 +154,7 @@ int main(int argc, char* argv[]) { "e.g ./infer_demo ./ResNet50_vd ./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." + "with gpu; 2: run with gpu and use tensorrt backend; 3: run with ipu; 4: run with xpu." << std::endl; return -1; } @@ -141,6 +167,8 @@ int main(int argc, char* argv[]) { TrtInfer(argv[1], argv[2]); } else if (std::atoi(argv[3]) == 3) { IpuInfer(argv[1], argv[2]); + } else if (std::atoi(argv[3]) == 4) { + XpuInfer(argv[1], argv[2]); } return 0; } diff --git a/examples/vision/classification/paddleclas/python/README.md b/examples/vision/classification/paddleclas/python/README.md old mode 100644 new mode 100755 index 9d17e6f65..5a1baff7f --- a/examples/vision/classification/paddleclas/python/README.md +++ b/examples/vision/classification/paddleclas/python/README.md @@ -25,6 +25,8 @@ python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg - python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device gpu --use_trt True --topk 1 # IPU推理(注意:IPU推理首次运行会有序列化模型的操作,有一定耗时,需要耐心等待) python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device ipu --topk 1 +# XPU推理 +python infer.py --model ResNet50_vd_infer --image ILSVRC2012_val_00000010.jpeg --device xpu --topk 1 ``` 运行完成后返回结果如下所示 diff --git a/examples/vision/classification/paddleclas/python/infer.py b/examples/vision/classification/paddleclas/python/infer.py old mode 100644 new mode 100755 index 0b2d35a21..3c150533c --- a/examples/vision/classification/paddleclas/python/infer.py +++ b/examples/vision/classification/paddleclas/python/infer.py @@ -35,6 +35,9 @@ def build_option(args): if args.device.lower() == "ipu": option.use_ipu() + if args.device.lower() == "xpu": + option.use_xpu() + if args.use_trt: option.use_trt_backend() return option diff --git a/examples/vision/classification/paddleclas/rv1126/cpp/README.md b/examples/vision/classification/paddleclas/rv1126/cpp/README.md index feaba462f..b41fecace 100755 --- a/examples/vision/classification/paddleclas/rv1126/cpp/README.md +++ b/examples/vision/classification/paddleclas/rv1126/cpp/README.md @@ -32,7 +32,7 @@ cp -r ILSVRC2012_val_00000010.jpeg images 4. 编译部署示例,可使入如下命令: ```bash mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/timvx.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx .. +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=armhf .. make -j8 make install # 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 diff --git a/examples/vision/classification/paddleclas/rv1126/cpp/infer.cc b/examples/vision/classification/paddleclas/rv1126/cpp/infer.cc index c89510342..140311eec 100755 --- a/examples/vision/classification/paddleclas/rv1126/cpp/infer.cc +++ b/examples/vision/classification/paddleclas/rv1126/cpp/infer.cc @@ -48,7 +48,6 @@ int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Usage: infer_demo path/to/quant_model " "path/to/image " - "run_option, " "e.g ./infer_demo ./ResNet50_vd_quant ./test.jpeg" << std::endl; return -1; diff --git a/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py b/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py old mode 100644 new mode 100755 index b328b249b..0ab7dcdc4 --- a/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py +++ b/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py @@ -84,7 +84,6 @@ class TritonPythonModel: be the same as `requests` """ responses = [] - # print("num:", len(requests), flush=True) for request in requests: infer_outputs = pb_utils.get_input_tensor_by_name( request, self.input_names[0]) diff --git a/examples/vision/classification/resnet/python/infer.py b/examples/vision/classification/resnet/python/infer.py index b8b268f3a..ba22304fc 100644 --- a/examples/vision/classification/resnet/python/infer.py +++ b/examples/vision/classification/resnet/python/infer.py @@ -46,5 +46,5 @@ model = fd.vision.classification.ResNet( args.model, runtime_option=runtime_option) # 预测图片分类结果 im = cv2.imread(args.image) -result = model.predict(im.copy(), args.topk) +result = model.predict(im, args.topk) print(result) diff --git a/examples/vision/classification/yolov5cls/python/infer.py b/examples/vision/classification/yolov5cls/python/infer.py index 576db32f2..55974a764 100644 --- a/examples/vision/classification/yolov5cls/python/infer.py +++ b/examples/vision/classification/yolov5cls/python/infer.py @@ -47,5 +47,5 @@ model = fd.vision.classification.YOLOv5Cls( # 预测图片分类结果 im = cv2.imread(args.image) -result = model.predict(im.copy(), args.topk) +result = model.predict(im, args.topk) print(result) diff --git a/examples/vision/detection/README.md b/examples/vision/detection/README.md index 3273ff602..522a4d79e 100644 --- a/examples/vision/detection/README.md +++ b/examples/vision/detection/README.md @@ -12,7 +12,7 @@ FastDeploy目前支持如下目标检测模型部署 | [PaddleDetection/FasterRCNN](./paddledetection) | FasterRCNN系列模型 | Paddle | [Release/2.4](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4) | | [WongKinYiu/YOLOv7](./yolov7) | YOLOv7、YOLOv7-X等系列模型 | ONNX | [Release/v0.1](https://github.com/WongKinYiu/yolov7/tree/v0.1) | | [RangiLyu/NanoDetPlus](./nanodet_plus) | NanoDetPlus 系列模型 | ONNX | [Release/v1.0.0-alpha-1](https://github.com/RangiLyu/nanodet/tree/v1.0.0-alpha-1) | -| [ultralytics/YOLOv5](./yolov5) | YOLOv5 系列模型 | ONNX | [Release/v6.0](https://github.com/ultralytics/yolov5/tree/v6.0) | +| [ultralytics/YOLOv5](./yolov5) | YOLOv5 系列模型 | ONNX | [Release/v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) | | [ppogg/YOLOv5-Lite](./yolov5lite) | YOLOv5-Lite 系列模型 | ONNX | [Release/v1.4](https://github.com/ppogg/YOLOv5-Lite/releases/tag/v1.4) | | [meituan/YOLOv6](./yolov6) | YOLOv6 系列模型 | ONNX | [Release/0.1.0](https://github.com/meituan/YOLOv6/releases/tag/0.1.0) | | [WongKinYiu/YOLOR](./yolor) | YOLOR 系列模型 | ONNX | [Release/weights](https://github.com/WongKinYiu/yolor/releases/tag/weights) | diff --git a/examples/vision/detection/nanodet_plus/cpp/infer.cc b/examples/vision/detection/nanodet_plus/cpp/infer.cc index 8443639cc..ec0bbee98 100644 --- a/examples/vision/detection/nanodet_plus/cpp/infer.cc +++ b/examples/vision/detection/nanodet_plus/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -30,7 +29,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { return; } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -73,7 +71,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -82,7 +79,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/nanodet_plus/python/infer.py b/examples/vision/detection/nanodet_plus/python/infer.py index 9e7bf184f..a60f3a3b4 100644 --- a/examples/vision/detection/nanodet_plus/python/infer.py +++ b/examples/vision/detection/nanodet_plus/python/infer.py @@ -52,7 +52,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/paddledetection/README.md b/examples/vision/detection/paddledetection/README.md index 4da1ba7e9..ae4ba494c 100644 --- a/examples/vision/detection/paddledetection/README.md +++ b/examples/vision/detection/paddledetection/README.md @@ -16,6 +16,10 @@ - [FasterRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/faster_rcnn) - [MaskRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/mask_rcnn) - [SSD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ssd) +- [YOLOv5系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov5) +- [YOLOv6系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov6) +- [YOLOv7系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov7) +- [RTMDet系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/rtmdet) ## 导出部署模型 @@ -23,6 +27,7 @@ **注意** - 在导出模型时不要进行NMS的去除操作,正常导出即可 +- 如果用于跑原生TensorRT后端(非Paddle Inference后端),不要添加--trt参数 - 导出模型时,不要添加`fuse_normalize=True`参数 ## 下载预训练模型 @@ -43,10 +48,19 @@ | [yolox_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolox_s_300e_coco.tgz) | 35MB | Box AP 40.4% | | | [faster_rcnn_r50_vd_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_r50_vd_fpn_2x_coco.tgz) | 160MB | Box AP 40.8%| 暂不支持TensorRT | | [mask_rcnn_r50_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/mask_rcnn_r50_1x_coco.tgz) | 128M | Box AP 37.4%, Mask AP 32.8%| 暂不支持TensorRT、ORT | -| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 21.7M | Box AP 73.8%| 暂不支持TensorRT、ORT | -| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 97.7M | Box AP 77.8%| 暂不支持TensorRT、ORT | -| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 24.4M | | 暂不支持TensorRT、ORT | +| [ssd_mobilenet_v1_300_120e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_mobilenet_v1_300_120e_voc.tgz) | 24.9M | Box AP 73.8%| 暂不支持TensorRT、ORT | +| [ssd_vgg16_300_240e_voc](https://bj.bcebos.com/paddlehub/fastdeploy/ssd_vgg16_300_240e_voc.tgz) | 106.5M | Box AP 77.8%| 暂不支持TensorRT、ORT | +| [ssdlite_mobilenet_v1_300_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ssdlite_mobilenet_v1_300_coco.tgz) | 29.1M | | 暂不支持TensorRT、ORT | +| [rtmdet_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_l_300e_coco.tgz) | 224M | Box AP 51.2%| | +| [rtmdet_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/rtmdet_s_300e_coco.tgz) | 42M | Box AP 44.5%| | +| [yolov5_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_l_300e_coco.tgz) | 183M | Box AP 48.9%| | +| [yolov5_s_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5_s_300e_coco.tgz) | 31M | Box AP 37.6%| | +| [yolov6_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_l_300e_coco.tgz) | 229M | Box AP 51.0%| | +| [yolov6_s_400e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_s_400e_coco.tgz) | 68M | Box AP 43.4%| | +| [yolov7_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_l_300e_coco.tgz) | 145M | Box AP 51.0%| | +| [yolov7_x_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_x_300e_coco.tgz) | 277M | Box AP 53.0%| | + ## 详细部署文档 - [Python部署](python) -- [C++部署](cpp) \ No newline at end of file +- [C++部署](cpp) diff --git a/examples/vision/detection/paddledetection/a311d/README.md b/examples/vision/detection/paddledetection/a311d/README.md new file mode 100755 index 000000000..e5ba7376d --- /dev/null +++ b/examples/vision/detection/paddledetection/a311d/README.md @@ -0,0 +1,11 @@ +# PP-YOLOE 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 PaddleLite 部署 PP-YOLOE 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/detection/paddledetection/a311d/cpp/CMakeLists.txt b/examples/vision/detection/paddledetection/a311d/cpp/CMakeLists.txt new file mode 100755 index 000000000..7a145177e --- /dev/null +++ b/examples/vision/detection/paddledetection/a311d/cpp/CMakeLists.txt @@ -0,0 +1,38 @@ +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}) +include_directories(${FastDeploy_INCLUDE_DIRS}) + +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer_ppyoloe.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) + +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install) + +install(TARGETS infer_demo DESTINATION ./) + +install(DIRECTORY models DESTINATION ./) +install(DIRECTORY images DESTINATION ./) +# install(DIRECTORY run_with_adb.sh DESTINATION ./) + +file(GLOB FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/*) +install(PROGRAMS ${FASTDEPLOY_LIBS} DESTINATION lib) + +file(GLOB OPENCV_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/opencv/lib/lib*) +install(PROGRAMS ${OPENCV_LIBS} DESTINATION lib) + +file(GLOB PADDLELITE_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/lib*) +install(PROGRAMS ${PADDLELITE_LIBS} DESTINATION lib) + +file(GLOB TIMVX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/verisilicon_timvx/*) +install(PROGRAMS ${TIMVX_LIBS} DESTINATION lib) + +file(GLOB ADB_TOOLS run_with_adb.sh) +install(PROGRAMS ${ADB_TOOLS} DESTINATION ./) diff --git a/examples/vision/detection/paddledetection/a311d/cpp/README.md b/examples/vision/detection/paddledetection/a311d/cpp/README.md new file mode 100755 index 000000000..d0f4ff63a --- /dev/null +++ b/examples/vision/detection/paddledetection/a311d/cpp/README.md @@ -0,0 +1,55 @@ +# PP-YOLOE 量化模型 C++ 部署示例 + +本目录下提供的 `infer.cc`,可以帮助用户快速完成 PP-YOLOE 量化模型在 A311D 上的部署推理加速。 + +## 部署准备 +### FastDeploy 交叉编译环境准备 +- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建) + +### 模型准备 +- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 +- 2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出模型模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe) +- 3. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的检测模型仍然需要FP32模型文件夹下的 infer_cfg.yml 文件,自行量化的模型文件夹内不包含此 yaml 文件,用户从 FP32 模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。) +- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) + +## 在 A311D 上部署量化后的 PP-YOLOE 检测模型 +请按照以下步骤完成在 A311D 上部署 PP-YOLOE 量化模型: +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddlelite-的-fastdeploy-交叉编译库编译) + +2. 将编译后的库拷贝到当前目录,可使用如下命令: +```bash +cp -r FastDeploy/build/fastdeploy-tmivx/ FastDeploy/examples/vision/detection/yolov5/a311d/cpp +``` + +3. 在当前路径下载部署所需的模型和示例图片: +```bash +mkdir models && mkdir images +wget https://bj.bcebos.com/fastdeploy/models/ppyoloe_noshare_qat.tar.gz +tar -xvf ppyoloe_noshare_qat.tar.gz +cp -r ppyoloe_noshare_qat models +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +cp -r 000000014439.jpg images +``` + +4. 编译部署示例,可使入如下命令: +```bash +mkdir build && cd build +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=arm64 .. +make -j8 +make install +# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 +``` + +5. 基于 adb 工具部署 PP-YOLOE 检测模型到晶晨 A311D +```bash +# 进入 install 目录 +cd FastDeploy/examples/vision/detection/paddledetection/a311d/cpp/build/install/ +# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID +bash run_with_adb.sh infer_demo ppyoloe_noshare_qat 000000014439.jpg $DEVICE_ID +``` + +部署成功后运行结果如下: + + + +需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) diff --git a/examples/vision/detection/paddledetection/a311d/cpp/infer_ppyoloe.cc b/examples/vision/detection/paddledetection/a311d/cpp/infer_ppyoloe.cc new file mode 100755 index 000000000..609a41d4b --- /dev/null +++ b/examples/vision/detection/paddledetection/a311d/cpp/infer_ppyoloe.cc @@ -0,0 +1,65 @@ +// 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 InitAndInfer(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 + "infer_cfg.yml"; + auto subgraph_file = model_dir + sep + "subgraph.txt"; + + fastdeploy::RuntimeOption option; + option.UseTimVX(); + option.SetLiteSubgraphPartitionPath(subgraph_file); + + auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file, + config_file, option); + assert(model.Initialized()); + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult 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::VisDetection(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/quant_model " + "path/to/image " + "e.g ./infer_demo ./PPYOLOE_L_quant ./test.jpeg" + << std::endl; + return -1; + } + + std::string model_dir = argv[1]; + std::string test_image = argv[2]; + InitAndInfer(model_dir, test_image); + return 0; +} diff --git a/examples/vision/detection/paddledetection/a311d/cpp/run_with_adb.sh b/examples/vision/detection/paddledetection/a311d/cpp/run_with_adb.sh new file mode 100755 index 000000000..dd7d7b47d --- /dev/null +++ b/examples/vision/detection/paddledetection/a311d/cpp/run_with_adb.sh @@ -0,0 +1,47 @@ +#!/bin/bash +HOST_SPACE=${PWD} +echo ${HOST_SPACE} +WORK_SPACE=/data/local/tmp/test + +# The first parameter represents the demo name +DEMO_NAME=image_classification_demo +if [ -n "$1" ]; then + DEMO_NAME=$1 +fi + +# The second parameter represents the model name +MODEL_NAME=mobilenet_v1_fp32_224 +if [ -n "$2" ]; then + MODEL_NAME=$2 +fi + +# The third parameter indicates the name of the image to be tested +IMAGE_NAME=0001.jpg +if [ -n "$3" ]; then + IMAGE_NAME=$3 +fi + +# The fourth parameter represents the ID of the device +ADB_DEVICE_NAME= +if [ -n "$4" ]; then + ADB_DEVICE_NAME="-s $4" +fi + +# Set the environment variables required during the running process +EXPORT_ENVIRONMENT_VARIABLES="export GLOG_v=5; export SUBGRAPH_ONLINE_MODE=true; export RKNPU_LOGLEVEL=5; export RKNN_LOG_LEVEL=5; ulimit -c unlimited; export VIV_VX_ENABLE_GRAPH_TRANSFORM=-pcq:1; export VIV_VX_SET_PER_CHANNEL_ENTROPY=100; export TIMVX_BATCHNORM_FUSION_MAX_ALLOWED_QUANT_SCALE_DEVIATION=300000; export VSI_NN_LOG_LEVEL=5;" + +EXPORT_ENVIRONMENT_VARIABLES="${EXPORT_ENVIRONMENT_VARIABLES}export LD_LIBRARY_PATH=${WORK_SPACE}/lib:\$LD_LIBRARY_PATH;" + +# Please install adb, and DON'T run this in the docker. +set -e +adb $ADB_DEVICE_NAME shell "rm -rf $WORK_SPACE" +adb $ADB_DEVICE_NAME shell "mkdir -p $WORK_SPACE" + +# Upload the demo, librarys, model and test images to the device +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/lib $WORK_SPACE +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/${DEMO_NAME} $WORK_SPACE +adb $ADB_DEVICE_NAME push models $WORK_SPACE +adb $ADB_DEVICE_NAME push images $WORK_SPACE + +# Execute the deployment demo +adb $ADB_DEVICE_NAME shell "cd $WORK_SPACE; ${EXPORT_ENVIRONMENT_VARIABLES} chmod +x ./${DEMO_NAME}; ./${DEMO_NAME} ./models/${MODEL_NAME} ./images/$IMAGE_NAME" diff --git a/examples/vision/detection/paddledetection/cpp/CMakeLists.txt b/examples/vision/detection/paddledetection/cpp/CMakeLists.txt index 9bbbdf32e..9382931a1 100644 --- a/examples/vision/detection/paddledetection/cpp/CMakeLists.txt +++ b/examples/vision/detection/paddledetection/cpp/CMakeLists.txt @@ -29,3 +29,18 @@ target_link_libraries(infer_ppyolo_demo ${FASTDEPLOY_LIBS}) add_executable(infer_mask_rcnn_demo ${PROJECT_SOURCE_DIR}/infer_mask_rcnn.cc) target_link_libraries(infer_mask_rcnn_demo ${FASTDEPLOY_LIBS}) + +add_executable(infer_ssd_demo ${PROJECT_SOURCE_DIR}/infer_ssd.cc) +target_link_libraries(infer_ssd_demo ${FASTDEPLOY_LIBS}) + +add_executable(infer_yolov5_demo ${PROJECT_SOURCE_DIR}/infer_yolov5.cc) +target_link_libraries(infer_yolov5_demo ${FASTDEPLOY_LIBS}) + +add_executable(infer_yolov6_demo ${PROJECT_SOURCE_DIR}/infer_yolov6.cc) +target_link_libraries(infer_yolov6_demo ${FASTDEPLOY_LIBS}) + +add_executable(infer_yolov7_demo ${PROJECT_SOURCE_DIR}/infer_yolov7.cc) +target_link_libraries(infer_yolov7_demo ${FASTDEPLOY_LIBS}) + +add_executable(infer_rtmdet_demo ${PROJECT_SOURCE_DIR}/infer_rtmdet.cc) +target_link_libraries(infer_rtmdet_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/detection/paddledetection/cpp/README.md b/examples/vision/detection/paddledetection/cpp/README.md index 63df0365a..d9217ab1e 100644 --- a/examples/vision/detection/paddledetection/cpp/README.md +++ b/examples/vision/detection/paddledetection/cpp/README.md @@ -1,6 +1,6 @@ # PaddleDetection C++部署示例 -本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 +本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 在部署前,需确认以下两个步骤 @@ -41,7 +41,7 @@ tar xvf ppyoloe_crn_l_300e_coco.tgz ### 模型类 -PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API +PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API ```c++ fastdeploy::vision::detection::PPYOLOE( const string& model_file, diff --git a/examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc b/examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc new file mode 100644 index 000000000..6262353ff --- /dev/null +++ b/examples/vision/detection/paddledetection/cpp/infer_rtmdet.cc @@ -0,0 +1,129 @@ +// 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 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 + "infer_cfg.yml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto model = fastdeploy::vision::detection::RTMDet(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, 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"; + auto config_file = model_dir + sep + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::detection::RTMDet(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +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 + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + auto model = fastdeploy::vision::detection::RTMDet(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::DetectionResult 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::VisDetection(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/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0" + << std::endl; + std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " + "with gpu." + << std::endl; + return -1; + } + + 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/detection/paddledetection/cpp/infer_yolov5.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov5.cc new file mode 100644 index 000000000..c33441b7d --- /dev/null +++ b/examples/vision/detection/paddledetection/cpp/infer_yolov5.cc @@ -0,0 +1,129 @@ +// 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 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 + "infer_cfg.yml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto model = fastdeploy::vision::detection::PaddleYOLOv5(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, 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"; + auto config_file = model_dir + sep + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::detection::PaddleYOLOv5(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +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 + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + auto model = fastdeploy::vision::detection::PaddleYOLOv5(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::DetectionResult 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::VisDetection(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/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0" + << std::endl; + std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " + "with gpu." + << std::endl; + return -1; + } + + 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/detection/paddledetection/cpp/infer_yolov6.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov6.cc new file mode 100644 index 000000000..8b7405ff6 --- /dev/null +++ b/examples/vision/detection/paddledetection/cpp/infer_yolov6.cc @@ -0,0 +1,129 @@ +// 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 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 + "infer_cfg.yml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto model = fastdeploy::vision::detection::PaddleYOLOv6(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, 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"; + auto config_file = model_dir + sep + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::detection::PaddleYOLOv6(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +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 + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + auto model = fastdeploy::vision::detection::PaddleYOLOv6(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::DetectionResult 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::VisDetection(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/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0" + << std::endl; + std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " + "with gpu." + << std::endl; + return -1; + } + + 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/detection/paddledetection/cpp/infer_yolov7.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov7.cc new file mode 100644 index 000000000..e13f5f545 --- /dev/null +++ b/examples/vision/detection/paddledetection/cpp/infer_yolov7.cc @@ -0,0 +1,128 @@ +// 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 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 + "infer_cfg.yml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto model = fastdeploy::vision::detection::PaddleYOLOv7(model_file, params_file, + config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, 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"; + auto config_file = model_dir + sep + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::detection::PaddleYOLOv7(model_file, params_file,config_file, option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + auto im_bak = im.clone(); + + fastdeploy::vision::DetectionResult 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::VisDetection(im_bak, res, 0.5); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +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 + "infer_cfg.yml"; + + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + auto model = fastdeploy::vision::detection::PaddleYOLOv7(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::DetectionResult 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::VisDetection(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/model_dir path/to/image run_option, " + "e.g ./infer_model ./ppyolo_dirname ./test.jpeg 0" + << std::endl; + std::cout << "The data type of run_option is int, 0: run with cpu; 1: run " + "with gpu." + << std::endl; + return -1; + } + + 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/detection/paddledetection/python/README.md b/examples/vision/detection/paddledetection/python/README.md index 7747ca071..993c1695d 100644 --- a/examples/vision/detection/paddledetection/python/README.md +++ b/examples/vision/detection/paddledetection/python/README.md @@ -41,6 +41,10 @@ fastdeploy.vision.detection.PPYOLO(model_file, params_file, config_file, runtime fastdeploy.vision.detection.FasterRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) fastdeploy.vision.detection.MaskRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) fastdeploy.vision.detection.SSD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) +fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE) ``` PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件 diff --git a/examples/vision/detection/paddledetection/python/infer_rtmdet.py b/examples/vision/detection/paddledetection/python/infer_rtmdet.py new file mode 100644 index 000000000..ec4c6cda8 --- /dev/null +++ b/examples/vision/detection/paddledetection/python/infer_rtmdet.py @@ -0,0 +1,59 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_dir", + required=True, + help="Path of PaddleDetection model directory") + 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( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + + if args.device.lower() == "gpu": + option.use_gpu() + + if args.use_trt: + option.use_trt_backend() + return option + + +args = parse_arguments() + +model_file = os.path.join(args.model_dir, "model.pdmodel") +params_file = os.path.join(args.model_dir, "model.pdiparams") +config_file = os.path.join(args.model_dir, "infer_cfg.yml") + +# 配置runtime,加载模型 +runtime_option = build_option(args) +model = fd.vision.detection.RTMDet( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片检测结果 +im = cv2.imread(args.image) +result = model.predict(im.copy()) +print(result) + +# 预测结果可视化 +vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("visualized_result.jpg", vis_im) +print("Visualized result save in ./visualized_result.jpg") diff --git a/examples/vision/detection/paddledetection/python/infer_yolov5.py b/examples/vision/detection/paddledetection/python/infer_yolov5.py new file mode 100644 index 000000000..ea6c764e2 --- /dev/null +++ b/examples/vision/detection/paddledetection/python/infer_yolov5.py @@ -0,0 +1,59 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_dir", + required=True, + help="Path of PaddleDetection model directory") + 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( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + + if args.device.lower() == "gpu": + option.use_gpu() + + if args.use_trt: + option.use_trt_backend() + return option + + +args = parse_arguments() + +model_file = os.path.join(args.model_dir, "model.pdmodel") +params_file = os.path.join(args.model_dir, "model.pdiparams") +config_file = os.path.join(args.model_dir, "infer_cfg.yml") + +# 配置runtime,加载模型 +runtime_option = build_option(args) +model = fd.vision.detection.PaddleYOLOv5( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片检测结果 +im = cv2.imread(args.image) +result = model.predict(im.copy()) +print(result) + +# 预测结果可视化 +vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("visualized_result.jpg", vis_im) +print("Visualized result save in ./visualized_result.jpg") diff --git a/examples/vision/detection/paddledetection/python/infer_yolov6.py b/examples/vision/detection/paddledetection/python/infer_yolov6.py new file mode 100644 index 000000000..81dfab331 --- /dev/null +++ b/examples/vision/detection/paddledetection/python/infer_yolov6.py @@ -0,0 +1,59 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_dir", + required=True, + help="Path of PaddleDetection model directory") + 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( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + + if args.device.lower() == "gpu": + option.use_gpu() + + if args.use_trt: + option.use_trt_backend() + return option + + +args = parse_arguments() + +model_file = os.path.join(args.model_dir, "model.pdmodel") +params_file = os.path.join(args.model_dir, "model.pdiparams") +config_file = os.path.join(args.model_dir, "infer_cfg.yml") + +# 配置runtime,加载模型 +runtime_option = build_option(args) +model = fd.vision.detection.PaddleYOLOv6( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片检测结果 +im = cv2.imread(args.image) +result = model.predict(im.copy()) +print(result) + +# 预测结果可视化 +vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("visualized_result.jpg", vis_im) +print("Visualized result save in ./visualized_result.jpg") diff --git a/examples/vision/detection/paddledetection/python/infer_yolov7.py b/examples/vision/detection/paddledetection/python/infer_yolov7.py new file mode 100644 index 000000000..d06332e02 --- /dev/null +++ b/examples/vision/detection/paddledetection/python/infer_yolov7.py @@ -0,0 +1,59 @@ +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_dir", + required=True, + help="Path of PaddleDetection model directory") + 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( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + + if args.device.lower() == "gpu": + option.use_gpu() + + if args.use_trt: + option.use_trt_backend() + return option + + +args = parse_arguments() + +model_file = os.path.join(args.model_dir, "model.pdmodel") +params_file = os.path.join(args.model_dir, "model.pdiparams") +config_file = os.path.join(args.model_dir, "infer_cfg.yml") + +# 配置runtime,加载模型 +runtime_option = build_option(args) +model = fd.vision.detection.PaddleYOLOv7( + model_file, params_file, config_file, runtime_option=runtime_option) + +# 预测图片检测结果 +im = cv2.imread(args.image) +result = model.predict(im.copy()) +print(result) + +# 预测结果可视化 +vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) +cv2.imwrite("visualized_result.jpg", vis_im) +print("Visualized result save in ./visualized_result.jpg") diff --git a/examples/vision/detection/paddledetection/rknpu2/README.md b/examples/vision/detection/paddledetection/rknpu2/README.md index d5f339db5..d242cf339 100644 --- a/examples/vision/detection/paddledetection/rknpu2/README.md +++ b/examples/vision/detection/paddledetection/rknpu2/README.md @@ -45,8 +45,8 @@ model_path: ./picodet_s_416_coco_lcnet/picodet_s_416_coco_lcnet.onnx output_folder: ./picodet_s_416_coco_lcnet target_platform: RK3568 normalize: - mean: [[0.485,0.456,0.406],[0,0,0]] - std: [[0.229,0.224,0.225],[0.003921,0.003921]] + mean: [[0.485,0.456,0.406]] + std: [[0.229,0.224,0.225]] outputs: ['tmp_17','p2o.Concat.9'] ``` @@ -113,5 +113,7 @@ Preprocess: type: Resize ``` +## 其他链接 +- [Cpp部署](./cpp) - [Python部署](./python) - [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/paddledetection/rknpu2/cpp/infer_picodet.cc b/examples/vision/detection/paddledetection/rknpu2/cpp/infer_picodet.cc index 12f405b52..8535aa338 100644 --- a/examples/vision/detection/paddledetection/rknpu2/cpp/infer_picodet.cc +++ b/examples/vision/detection/paddledetection/rknpu2/cpp/infer_picodet.cc @@ -15,26 +15,39 @@ #include #include "fastdeploy/vision.h" #include -double __get_us(struct timeval t) { return (t.tv_sec * 1000000 + t.tv_usec); } -void InferPicodet(const std::string& model_dir, const std::string& image_file); -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 ./picodet_model_dir ./test.jpeg" - << std::endl; - return -1; +void ONNXInfer(const std::string& model_dir, const std::string& image_file) { + std::string model_file = model_dir + "/picodet_s_416_coco_lcnet.onnx"; + std::string params_file; + std::string config_file = model_dir + "/deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto format = fastdeploy::ModelFormat::ONNX; + + auto model = fastdeploy::vision::detection::PicoDet( + model_file, params_file, config_file,option,format); + model.GetPostprocessor().ApplyDecodeAndNMS(); + + fastdeploy::TimeCounter tc; + tc.Start(); + auto im = cv::imread(image_file); + fastdeploy::vision::DetectionResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; } + auto vis_im = fastdeploy::vision::VisDetection(im, res,0.5); + tc.End(); + tc.PrintInfo("PPDet in ONNX"); - InferPicodet(argv[1], argv[2]); - - return 0; + cv::imwrite("infer_onnx.jpg", vis_im); + std::cout + << "Visualized result saved in ./infer_onnx.jpg" + << std::endl; } -void InferPicodet(const std::string& model_dir, const std::string& image_file) { - struct timeval start_time, stop_time; - auto model_file = model_dir + "/picodet_s_416_coco_lcnet_rk3568.rknn"; +void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) { + auto model_file = model_dir + "/picodet_s_416_coco_lcnet_rk3588.rknn"; auto params_file = ""; auto config_file = model_dir + "/infer_cfg.yml"; @@ -51,16 +64,31 @@ void InferPicodet(const std::string& model_dir, const std::string& image_file) { auto im = cv::imread(image_file); fastdeploy::vision::DetectionResult res; - gettimeofday(&start_time, NULL); + fastdeploy::TimeCounter tc; + tc.Start(); if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - gettimeofday(&stop_time, NULL); - printf("infer use %f ms\n", (__get_us(stop_time) - __get_us(start_time)) / 1000); + tc.End(); + tc.PrintInfo("PPDet in RKNPU2"); std::cout << res.Str() << std::endl; auto vis_im = fastdeploy::vision::VisDetection(im, res,0.5); - cv::imwrite("picodet_result.jpg", vis_im); - std::cout << "Visualized result saved in ./picodet_result.jpg" << std::endl; -} \ No newline at end of file + cv::imwrite("infer_rknpu2.jpg", vis_im); + std::cout << "Visualized result saved in ./infer_rknpu2.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 ./picodet_model_dir ./test.jpeg" + << std::endl; + return -1; + } + RKNPU2Infer(argv[1], argv[2]); +//ONNXInfer(argv[1], argv[2]); + return 0; +} + diff --git a/examples/vision/detection/paddledetection/rv1126/cpp/README.md b/examples/vision/detection/paddledetection/rv1126/cpp/README.md index 5b366bd83..193a269fd 100755 --- a/examples/vision/detection/paddledetection/rv1126/cpp/README.md +++ b/examples/vision/detection/paddledetection/rv1126/cpp/README.md @@ -34,7 +34,7 @@ cp -r 000000014439.jpg images 4. 编译部署示例,可使入如下命令: ```bash mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/timvx.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx .. +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=armhf .. make -j8 make install # 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 diff --git a/examples/vision/detection/paddledetection/rv1126/cpp/infer_ppyoloe.cc b/examples/vision/detection/paddledetection/rv1126/cpp/infer_ppyoloe.cc index 77368584f..609a41d4b 100755 --- a/examples/vision/detection/paddledetection/rv1126/cpp/infer_ppyoloe.cc +++ b/examples/vision/detection/paddledetection/rv1126/cpp/infer_ppyoloe.cc @@ -53,7 +53,6 @@ int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Usage: infer_demo path/to/quant_model " "path/to/image " - "run_option, " "e.g ./infer_demo ./PPYOLOE_L_quant ./test.jpeg" << std::endl; return -1; diff --git a/examples/vision/detection/paddledetection/serving/README.md b/examples/vision/detection/paddledetection/serving/README.md index 008fe4f8e..d6a38c8d4 100644 --- a/examples/vision/detection/paddledetection/serving/README.md +++ b/examples/vision/detection/paddledetection/serving/README.md @@ -75,7 +75,7 @@ I0928 04:51:15.826578 206 http_server.cc:167] Started Metrics Service at 0.0.0.0 wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg #安装客户端依赖 -python3 -m pip install tritonclient\[all\] +python3 -m pip install tritonclient[all] # 发送请求 python3 paddledet_grpc_client.py diff --git a/examples/vision/detection/rkyolo/README.md b/examples/vision/detection/rkyolo/README.md new file mode 100644 index 000000000..015e22506 --- /dev/null +++ b/examples/vision/detection/rkyolo/README.md @@ -0,0 +1,18 @@ +# RKYOLO准备部署模型 + +RKYOLO参考[rknn_model_zoo](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo)的代码 +对RKYOLO系列模型进行了封装,目前支持RKYOLOV5系列模型的部署。 + +## 支持模型列表 + +* RKYOLOV5 + +## 模型转换example + +请参考[RKNN_model_convert](https://github.com/airockchip/rknn_model_zoo/tree/main/models/CV/object_detection/yolo/RKNN_model_convert) + + +## 其他链接 +- [Cpp部署](./cpp) +- [Python部署](./python) +- [视觉模型预测结果](../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/rkyolo/cpp/CMakeLists.txt b/examples/vision/detection/rkyolo/cpp/CMakeLists.txt new file mode 100644 index 000000000..524b94fea --- /dev/null +++ b/examples/vision/detection/rkyolo/cpp/CMakeLists.txt @@ -0,0 +1,37 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.10) +project(rknpu2_test) + +set(CMAKE_CXX_STANDARD 14) + +# 指定下载解压后的fastdeploy库路径 +set(FASTDEPLOY_INSTALL_DIR "thirdpartys/fastdeploy-0.0.3") + +include(${FASTDEPLOY_INSTALL_DIR}/FastDeployConfig.cmake) +include_directories(${FastDeploy_INCLUDE_DIRS}) + +add_executable(infer_rkyolo infer_rkyolo.cc) +target_link_libraries(infer_rkyolo ${FastDeploy_LIBS}) + + + +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install) + +install(TARGETS infer_rkyolo DESTINATION ./) + +install(DIRECTORY model DESTINATION ./) +install(DIRECTORY images DESTINATION ./) + +file(GLOB FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/*) +message("${FASTDEPLOY_LIBS}") +install(PROGRAMS ${FASTDEPLOY_LIBS} DESTINATION lib) + +file(GLOB ONNXRUNTIME_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/onnxruntime/lib/*) +install(PROGRAMS ${ONNXRUNTIME_LIBS} DESTINATION lib) + +install(DIRECTORY ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/opencv/lib DESTINATION ./) + +file(GLOB PADDLETOONNX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddle2onnx/lib/*) +install(PROGRAMS ${PADDLETOONNX_LIBS} DESTINATION lib) + +file(GLOB RKNPU2_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/rknpu2_runtime/${RKNN2_TARGET_SOC}/lib/*) +install(PROGRAMS ${RKNPU2_LIBS} DESTINATION lib) diff --git a/examples/vision/detection/rkyolo/cpp/README.md b/examples/vision/detection/rkyolo/cpp/README.md new file mode 100644 index 000000000..16f8df72d --- /dev/null +++ b/examples/vision/detection/rkyolo/cpp/README.md @@ -0,0 +1,69 @@ +# RKYOLO C++部署示例 + +本目录下提供`infer_xxxxx.cc`快速完成RKYOLO模型在Rockchip板子上上通过二代NPU加速部署的示例。 + +在部署前,需确认以下两个步骤: + +1. 软硬件环境满足要求 +2. 根据开发环境,下载预编译部署库或者从头编译FastDeploy仓库 + +以上步骤请参考[RK2代NPU部署库编译](../../../../../docs/cn/build_and_install/rknpu2.md)实现 + +## 生成基本目录文件 + +该例程由以下几个部分组成 +```text +. +├── CMakeLists.txt +├── build # 编译文件夹 +├── image # 存放图片的文件夹 +├── infer_rkyolo.cc +├── model # 存放模型文件的文件夹 +└── thirdpartys # 存放sdk的文件夹 +``` + +首先需要先生成目录结构 +```bash +mkdir build +mkdir images +mkdir model +mkdir thirdpartys +``` + +## 编译 + +### 编译并拷贝SDK到thirdpartys文件夹 + +请参考[RK2代NPU部署库编译](../../../../../../docs/cn/build_and_install/rknpu2.md)仓库编译SDK,编译完成后,将在build目录下生成 +fastdeploy-0.0.3目录,请移动它至thirdpartys目录下. + +### 拷贝模型文件,以及配置文件至model文件夹 +在Paddle动态图模型 -> Paddle静态图模型 -> ONNX模型的过程中,将生成ONNX文件以及对应的yaml配置文件,请将配置文件存放到model文件夹内。 +转换为RKNN后的模型文件也需要拷贝至model。 + +### 准备测试图片至image文件夹 +```bash +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +cp 000000014439.jpg ./images +``` + +### 编译example + +```bash +cd build +cmake .. +make -j8 +make install +``` + +## 运行例程 + +```bash +cd ./build/install +./infer_picodet model/ images/000000014439.jpg +``` + + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../../docs/api/vision_results/) diff --git a/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc b/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc new file mode 100644 index 000000000..3433c1f41 --- /dev/null +++ b/examples/vision/detection/rkyolo/cpp/infer_rkyolo.cc @@ -0,0 +1,55 @@ +// 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" + +void RKNPU2Infer(const std::string& model_file, const std::string& image_file) { + auto option = fastdeploy::RuntimeOption(); + option.UseRKNPU2(); + + auto format = fastdeploy::ModelFormat::RKNN; + + auto model = fastdeploy::vision::detection::RKYOLOV5( + model_file, option,format); + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult res; + fastdeploy::TimeCounter tc; + tc.Start(); + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisDetection(im, res,0.5); + tc.End(); + tc.PrintInfo("RKYOLOV5 in RKNN"); + std::cout << res.Str() << std::endl; + 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 ./picodet_model_dir ./test.jpeg" + << std::endl; + return -1; + } + + RKNPU2Infer(argv[1], argv[2]); + + return 0; +} + diff --git a/examples/vision/detection/rkyolo/python/README.md b/examples/vision/detection/rkyolo/python/README.md new file mode 100644 index 000000000..4549ec0f9 --- /dev/null +++ b/examples/vision/detection/rkyolo/python/README.md @@ -0,0 +1,34 @@ +# RKYOLO Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/rknpu2.md) + +本目录下提供`infer.py`快速完成Picodet在RKNPU上部署的示例。执行如下脚本即可完成 + +```bash +# 下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd FastDeploy/examples/vision/detection/rkyolo/python + +# 下载图片 +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + +# copy model +cp -r ./model /path/to/FastDeploy/examples/vision/detection/rkyolo/python + +# 推理 +python3 infer.py --model_file ./model/ \ + --image 000000014439.jpg +``` + + +## 注意事项 +RKNPU上对模型的输入要求是使用NHWC格式,且图片归一化操作会在转RKNN模型时,内嵌到模型中,因此我们在使用FastDeploy部署时, + +## 其它文档 + +- [PaddleDetection 模型介绍](..) +- [PaddleDetection C++部署](../cpp) +- [模型预测结果说明](../../../../../../docs/api/vision_results/) +- [转换PaddleDetection RKNN模型文档](../README.md) diff --git a/examples/vision/detection/rkyolo/python/infer.py b/examples/vision/detection/rkyolo/python/infer.py new file mode 100644 index 000000000..38eea0e8c --- /dev/null +++ b/examples/vision/detection/rkyolo/python/infer.py @@ -0,0 +1,53 @@ +# 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. +import fastdeploy as fd +import cv2 +import os + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_file", required=True, help="Path of rknn model.") + parser.add_argument( + "--image", type=str, required=True, help="Path of test image file.") + return parser.parse_args() + + +if __name__ == "__main__": + args = parse_arguments() + + model_file = args.model_file + params_file = "" + + # 配置runtime,加载模型 + runtime_option = fd.RuntimeOption() + runtime_option.use_rknpu2() + + model = fd.vision.detection.RKYOLOV5( + model_file, + runtime_option=runtime_option, + model_format=fd.ModelFormat.RKNN) + + # 预测图片分割结果 + im = cv2.imread(args.image) + result = model.predict(im) + print(result) + + # 可视化结果 + vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5) + cv2.imwrite("visualized_result.jpg", vis_im) + print("Visualized result save in ./visualized_result.jpg") diff --git a/examples/vision/detection/scaledyolov4/cpp/infer.cc b/examples/vision/detection/scaledyolov4/cpp/infer.cc index 7d912b223..683156cc9 100644 --- a/examples/vision/detection/scaledyolov4/cpp/infer.cc +++ b/examples/vision/detection/scaledyolov4/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/scaledyolov4/python/infer.py b/examples/vision/detection/scaledyolov4/python/infer.py index 9d990d77b..cd23e84e3 100644 --- a/examples/vision/detection/scaledyolov4/python/infer.py +++ b/examples/vision/detection/scaledyolov4/python/infer.py @@ -52,7 +52,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolor/cpp/infer.cc b/examples/vision/detection/yolor/cpp/infer.cc index 0fe8913d4..bacc18b40 100644 --- a/examples/vision/detection/yolor/cpp/infer.cc +++ b/examples/vision/detection/yolor/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolor/python/infer.py b/examples/vision/detection/yolor/python/infer.py index d5ab3dd7f..4111fa0ae 100644 --- a/examples/vision/detection/yolor/python/infer.py +++ b/examples/vision/detection/yolor/python/infer.py @@ -54,7 +54,7 @@ else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov5/README.md b/examples/vision/detection/yolov5/README.md index 076ae01ce..095c8071d 100644 --- a/examples/vision/detection/yolov5/README.md +++ b/examples/vision/detection/yolov5/README.md @@ -1,8 +1,8 @@ # YOLOv5准备部署模型 -- YOLOv5 v6.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v6.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v6.0) - - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v6.0)提供的*.onnx可直接进行部署; - - (2)开发者基于自己数据训练的YOLOv5 v6.0模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。 +- YOLOv5 v7.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v7.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v7.0) + - (1)[官方库](https://github.com/ultralytics/yolov5/releases/tag/v7.0)提供的*.onnx可直接进行部署; + - (2)开发者基于自己数据训练的YOLOv5 v7.0模型,可使用[YOLOv5](https://github.com/ultralytics/yolov5)中的`export.py`导出ONNX文件后,完成部署。 ## 下载预训练ONNX模型 @@ -10,13 +10,11 @@ 为了方便开发者的测试,下面提供了YOLOv5导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库) | 模型 | 大小 | 精度 | |:---------------------------------------------------------------- |:----- |:----- | -| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.5MB | 28.4% | -| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28.9MB | 37.2% | -| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 84.7MB | 45.2% | -| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 186.2MB | 48.8% | -| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 346.9MB | 50.7% | - - +| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% | +| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% | +| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% | +| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% | +| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% | ## 详细部署文档 @@ -27,4 +25,4 @@ ## 版本说明 -- 本版本文档和代码基于[YOLOv5 v6.0](https://github.com/ultralytics/yolov5/tree/v6.0) 编写 +- 本版本文档和代码基于[YOLOv5 v7.0](https://github.com/ultralytics/yolov5/tree/v7.0) 编写 diff --git a/examples/vision/detection/yolov5/a311d/README.md b/examples/vision/detection/yolov5/a311d/README.md new file mode 100755 index 000000000..d0bcd10a9 --- /dev/null +++ b/examples/vision/detection/yolov5/a311d/README.md @@ -0,0 +1,11 @@ +# YOLOv5 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 PaddleLite 部署 YOLOv5 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/detection/yolov5/a311d/cpp/CMakeLists.txt b/examples/vision/detection/yolov5/a311d/cpp/CMakeLists.txt new file mode 100755 index 000000000..3c9eee38a --- /dev/null +++ b/examples/vision/detection/yolov5/a311d/cpp/CMakeLists.txt @@ -0,0 +1,37 @@ +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}) +include_directories(${FastDeploy_INCLUDE_DIRS}) + +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) + +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install) + +install(TARGETS infer_demo DESTINATION ./) + +install(DIRECTORY models DESTINATION ./) +install(DIRECTORY images DESTINATION ./) + +file(GLOB FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/*) +install(PROGRAMS ${FASTDEPLOY_LIBS} DESTINATION lib) + +file(GLOB OPENCV_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/opencv/lib/lib*) +install(PROGRAMS ${OPENCV_LIBS} DESTINATION lib) + +file(GLOB PADDLELITE_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/lib*) +install(PROGRAMS ${PADDLELITE_LIBS} DESTINATION lib) + +file(GLOB TIMVX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/verisilicon_timvx/*) +install(PROGRAMS ${TIMVX_LIBS} DESTINATION lib) + +file(GLOB ADB_TOOLS run_with_adb.sh) +install(PROGRAMS ${ADB_TOOLS} DESTINATION ./) diff --git a/examples/vision/detection/yolov5/a311d/cpp/README.md b/examples/vision/detection/yolov5/a311d/cpp/README.md new file mode 100755 index 000000000..d47027bb0 --- /dev/null +++ b/examples/vision/detection/yolov5/a311d/cpp/README.md @@ -0,0 +1,54 @@ +# YOLOv5 量化模型 C++ 部署示例 + +本目录下提供的 `infer.cc`,可以帮助用户快速完成 YOLOv5 量化模型在 A311D 上的部署推理加速。 + +## 部署准备 +### FastDeploy 交叉编译环境准备 +- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建) + +### 量化模型准备 +- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。 +- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。 +- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) + +## 在 A311D 上部署量化后的 YOLOv5 检测模型 +请按照以下步骤完成在 A311D 上部署 YOLOv5 量化模型: +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddlelite-的-fastdeploy-交叉编译库编译) + +2. 将编译后的库拷贝到当前目录,可使用如下命令: +```bash +cp -r FastDeploy/build/fastdeploy-tmivx/ FastDeploy/examples/vision/detection/yolov5/a311d/cpp +``` + +3. 在当前路径下载部署所需的模型和示例图片: +```bash +mkdir models && mkdir images +wget https://bj.bcebos.com/fastdeploy/models/yolov5s_ptq_model.tar.gz +tar -xvf yolov5s_ptq_model.tar.gz +cp -r yolov5s_ptq_model models +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +cp -r 000000014439.jpg images +``` + +4. 编译部署示例,可使入如下命令: +```bash +mkdir build && cd build +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=arm64 .. +make -j8 +make install +# 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 +``` + +5. 基于 adb 工具部署 YOLOv5 检测模型到晶晨 A311D +```bash +# 进入 install 目录 +cd FastDeploy/examples/vision/detection/yolov5/a311d/cpp/build/install/ +# 如下命令表示:bash run_with_adb.sh 需要运行的demo 模型路径 图片路径 设备的DEVICE_ID +bash run_with_adb.sh infer_demo yolov5s_ptq_model 000000014439.jpg $DEVICE_ID +``` + +部署成功后,vis_result.jpg 保存的结果如下: + + + +需要特别注意的是,在 A311D 上部署的模型需要是量化后的模型,模型的量化请参考:[模型量化](../../../../../../docs/cn/quantize.md) diff --git a/examples/vision/detection/yolov5/a311d/cpp/infer.cc b/examples/vision/detection/yolov5/a311d/cpp/infer.cc new file mode 100755 index 000000000..f1cf9e8dc --- /dev/null +++ b/examples/vision/detection/yolov5/a311d/cpp/infer.cc @@ -0,0 +1,64 @@ +// 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 InitAndInfer(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 subgraph_file = model_dir + sep + "subgraph.txt"; + + fastdeploy::RuntimeOption option; + option.UseTimVX(); + option.SetLiteSubgraphPartitionPath(subgraph_file); + + auto model = fastdeploy::vision::detection::YOLOv5( + model_file, params_file, option, fastdeploy::ModelFormat::PADDLE); + assert(model.Initialized()); + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult 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::VisDetection(im, 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 < 3) { + std::cout << "Usage: infer_demo path/to/quant_model " + "path/to/image " + "run_option, " + "e.g ./infer_demo ./yolov5s_quant ./000000014439.jpg" + << std::endl; + return -1; + } + + std::string model_dir = argv[1]; + std::string test_image = argv[2]; + InitAndInfer(model_dir, test_image); + return 0; +} diff --git a/examples/vision/detection/yolov5/a311d/cpp/run_with_adb.sh b/examples/vision/detection/yolov5/a311d/cpp/run_with_adb.sh new file mode 100755 index 000000000..aacaed4c5 --- /dev/null +++ b/examples/vision/detection/yolov5/a311d/cpp/run_with_adb.sh @@ -0,0 +1,47 @@ +#!/bin/bash +HOST_SPACE=${PWD} +echo ${HOST_SPACE} +WORK_SPACE=/data/local/tmp/test + +# The first parameter represents the demo name +DEMO_NAME=image_classification_demo +if [ -n "$1" ]; then + DEMO_NAME=$1 +fi + +# The second parameter represents the model name +MODEL_NAME=mobilenet_v1_fp32_224 +if [ -n "$2" ]; then + MODEL_NAME=$2 +fi + +# The third parameter indicates the name of the image to be tested +IMAGE_NAME=0001.jpg +if [ -n "$3" ]; then + IMAGE_NAME=$3 +fi + +# The fourth parameter represents the ID of the device +ADB_DEVICE_NAME= +if [ -n "$4" ]; then + ADB_DEVICE_NAME="-s $4" +fi + +# Set the environment variables required during the running process +EXPORT_ENVIRONMENT_VARIABLES="export GLOG_v=5; export VIV_VX_ENABLE_GRAPH_TRANSFORM=-pcq:1; export VIV_VX_SET_PER_CHANNEL_ENTROPY=100; export TIMVX_BATCHNORM_FUSION_MAX_ALLOWED_QUANT_SCALE_DEVIATION=300000; export VSI_NN_LOG_LEVEL=5;" + +EXPORT_ENVIRONMENT_VARIABLES="${EXPORT_ENVIRONMENT_VARIABLES}export LD_LIBRARY_PATH=${WORK_SPACE}/lib:\$LD_LIBRARY_PATH;" + +# Please install adb, and DON'T run this in the docker. +set -e +adb $ADB_DEVICE_NAME shell "rm -rf $WORK_SPACE" +adb $ADB_DEVICE_NAME shell "mkdir -p $WORK_SPACE" + +# Upload the demo, librarys, model and test images to the device +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/lib $WORK_SPACE +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/${DEMO_NAME} $WORK_SPACE +adb $ADB_DEVICE_NAME push models $WORK_SPACE +adb $ADB_DEVICE_NAME push images $WORK_SPACE + +# Execute the deployment demo +adb $ADB_DEVICE_NAME shell "cd $WORK_SPACE; ${EXPORT_ENVIRONMENT_VARIABLES} chmod +x ./${DEMO_NAME}; ./${DEMO_NAME} ./models/${MODEL_NAME} ./images/$IMAGE_NAME" diff --git a/examples/vision/detection/yolov5/cpp/CMakeLists.txt b/examples/vision/detection/yolov5/cpp/CMakeLists.txt old mode 100644 new mode 100755 index 93540a7e8..2b3f8c54f --- a/examples/vision/detection/yolov5/cpp/CMakeLists.txt +++ b/examples/vision/detection/yolov5/cpp/CMakeLists.txt @@ -12,3 +12,7 @@ include_directories(${FASTDEPLOY_INCS}) add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) # 添加FastDeploy库依赖 target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) + +add_executable(infer_paddle_demo ${PROJECT_SOURCE_DIR}/infer_paddle_model.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_paddle_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/detection/yolov5/cpp/README.md b/examples/vision/detection/yolov5/cpp/README.md old mode 100644 new mode 100755 index ece3826a5..581f1c49b --- a/examples/vision/detection/yolov5/cpp/README.md +++ b/examples/vision/detection/yolov5/cpp/README.md @@ -12,16 +12,33 @@ ```bash mkdir build cd build -# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +# 下载 FastDeploy 预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz tar xvf fastdeploy-linux-x64-x.x.x.tgz cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j -#下载官方转换好的yolov5模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx +#下载官方转换好的 yolov5 Paddle 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar +tar -xvf yolov5s_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg +# CPU推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 0 +# GPU推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 1 +# GPU上TensorRT推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 2 +# XPU推理 +./infer_paddle_demo yolov5s_infer 000000014439.jpg 3 +``` + +上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤: +```bash +# 1. 下载官方转换好的 yolov5 ONNX 模型文件和测试图片 +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx +wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg + # CPU推理 ./infer_demo yolov5s.onnx 000000014439.jpg 0 # GPU推理 @@ -29,7 +46,6 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000 # GPU上TensorRT推理 ./infer_demo yolov5s.onnx 000000014439.jpg 2 ``` - 运行完成可视化结果如下图所示 diff --git a/examples/vision/detection/yolov5/cpp/infer.cc b/examples/vision/detection/yolov5/cpp/infer.cc old mode 100644 new mode 100755 index a7ac1fe81..fb20686de --- a/examples/vision/detection/yolov5/cpp/infer.cc +++ b/examples/vision/detection/yolov5/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -105,4 +102,4 @@ int main(int argc, char* argv[]) { TrtInfer(argv[1], argv[2]); } return 0; -} +} \ No newline at end of file diff --git a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc new file mode 100755 index 000000000..d5692ce7c --- /dev/null +++ b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc @@ -0,0 +1,154 @@ +// 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 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"; + fastdeploy::RuntimeOption option; + option.UseCpu(); + auto model = fastdeploy::vision::detection::YOLOv5( + model_file, params_file, option, fastdeploy::ModelFormat::PADDLE); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult 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::VisDetection(im, 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_dir, const std::string& image_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::detection::YOLOv5( + model_file, params_file, option, fastdeploy::ModelFormat::PADDLE); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult 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::VisDetection(im, 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_dir, const std::string& image_file) { + auto model_file = model_dir + sep + "model.pdmodel"; + auto params_file = model_dir + sep + "model.pdiparams"; + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + option.SetTrtInputShape("images", {1, 3, 640, 640}); + auto model = fastdeploy::vision::detection::YOLOv5( + model_file, params_file, option, fastdeploy::ModelFormat::PADDLE); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult 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::Visualize::VisDetection(im, res); + cv::imwrite("vis_result.jpg", vis_im); + std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; +} + +void XpuInfer(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"; + fastdeploy::RuntimeOption option; + option.UseXpu(); + auto model = fastdeploy::vision::detection::YOLOv5( + model_file, params_file, option, fastdeploy::ModelFormat::PADDLE); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::DetectionResult 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::VisDetection(im, 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_model ./yolov5s_infer ./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 XPU." + << std::endl; + return -1; + } + + 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]); + } else if (std::atoi(argv[3]) == 3) { + XpuInfer(argv[1], argv[2]); + } + return 0; +} diff --git a/examples/vision/detection/yolov5/python/README.md b/examples/vision/detection/yolov5/python/README.md old mode 100644 new mode 100755 index 4f47b3084..83f6ed781 --- a/examples/vision/detection/yolov5/python/README.md +++ b/examples/vision/detection/yolov5/python/README.md @@ -13,15 +13,18 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/vision/detection/yolov5/python/ #下载yolov5模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s_infer.tar +tar -xf yolov5s_infer.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg # CPU推理 -python infer.py --model yolov5s.onnx --image 000000014439.jpg --device cpu +python infer.py --model yolov5s_infer --image 000000014439.jpg --device cpu # GPU推理 -python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu +python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu # GPU上使用TensorRT推理 -python infer.py --model yolov5s.onnx --image 000000014439.jpg --device gpu --use_trt True +python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True +# XPU推理 +python infer.py --model yolov5s_infer --image 000000014439.jpg --device xpu ``` 运行完成可视化结果如下图所示 diff --git a/examples/vision/detection/yolov5/python/infer.py b/examples/vision/detection/yolov5/python/infer.py old mode 100644 new mode 100755 index fdded06c9..b155af0ed --- a/examples/vision/detection/yolov5/python/infer.py +++ b/examples/vision/detection/yolov5/python/infer.py @@ -1,20 +1,20 @@ import fastdeploy as fd import cv2 +import os def parse_arguments(): import argparse import ast parser = argparse.ArgumentParser() - parser.add_argument( - "--model", default=None, help="Path of yolov5 onnx model.") + parser.add_argument("--model", default=None, help="Path of yolov5 model.") parser.add_argument( "--image", default=None, help="Path of test image file.") parser.add_argument( "--device", type=str, default='cpu', - help="Type of inference device, support 'cpu' or 'gpu'.") + help="Type of inference device, support 'cpu' or 'gpu' or 'xpu'.") parser.add_argument( "--use_trt", type=ast.literal_eval, @@ -25,6 +25,8 @@ def parse_arguments(): def build_option(args): option = fd.RuntimeOption() + if args.device.lower() == "xpu": + option.use_xpu() if args.device.lower() == "gpu": option.use_gpu() @@ -37,14 +39,15 @@ def build_option(args): args = parse_arguments() -if args.model is None: - model = fd.download_model(name='YOLOv5s') -else: - model = args.model - # 配置runtime,加载模型 runtime_option = build_option(args) -model = fd.vision.detection.YOLOv5(model, runtime_option=runtime_option) +model_file = os.path.join(args.model, "model.pdmodel") +params_file = os.path.join(args.model, "model.pdiparams") +model = fd.vision.detection.YOLOv5( + model_file, + params_file, + runtime_option=runtime_option, + model_format=fd.ModelFormat.PADDLE) # 预测图片检测结果 if args.image is None: @@ -52,7 +55,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov5/quantize/cpp/infer.cc b/examples/vision/detection/yolov5/quantize/cpp/infer.cc index e429b2aad..1addf1507 100644 --- a/examples/vision/detection/yolov5/quantize/cpp/infer.cc +++ b/examples/vision/detection/yolov5/quantize/cpp/infer.cc @@ -29,7 +29,6 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, assert(model.Initialized()); auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -39,7 +38,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov5/quantize/python/infer.py b/examples/vision/detection/yolov5/quantize/python/infer.py index da502fe93..996bc5419 100644 --- a/examples/vision/detection/yolov5/quantize/python/infer.py +++ b/examples/vision/detection/yolov5/quantize/python/infer.py @@ -71,7 +71,7 @@ model = fd.vision.detection.YOLOv5( # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov5/rv1126/cpp/README.md b/examples/vision/detection/yolov5/rv1126/cpp/README.md index 9711577f2..b974a8ebe 100755 --- a/examples/vision/detection/yolov5/rv1126/cpp/README.md +++ b/examples/vision/detection/yolov5/rv1126/cpp/README.md @@ -33,7 +33,7 @@ cp -r 000000014439.jpg images 4. 编译部署示例,可使入如下命令: ```bash mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/timvx.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx .. +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=armhf .. make -j8 make install # 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 diff --git a/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py b/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py index 30a744b68..7c608db43 100644 --- a/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py +++ b/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py @@ -61,31 +61,7 @@ class TritonPythonModel: dtype = pb_utils.triton_string_to_numpy(output_config["data_type"]) self.output_dtype.append(dtype) print("postprocess output names:", self.output_names) - - def yolov5_postprocess(self, infer_outputs, im_infos): - """ - Parameters - ---------- - infer_outputs : numpy.array - Contains the batch of inference results - im_infos : numpy.array(b'{}') - Returns - ------- - numpy.array - yolov5 postprocess result - """ - results = [] - for i_batch in range(len(im_infos)): - new_infer_output = infer_outputs[i_batch:i_batch + 1] - new_im_info = im_infos[i_batch].decode('utf-8').replace("'", '"') - new_im_info = json.loads(new_im_info) - - result = fd.vision.detection.YOLOv5.postprocess( - [new_infer_output, ], new_im_info) - - r_str = fd.vision.utils.fd_result_to_json(result) - results.append(r_str) - return np.array(results, dtype=np.object) + self.postprocessor_ = fd.vision.detection.YOLOv5Postprocessor() def execute(self, requests): """`execute` must be implemented in every Python model. `execute` @@ -107,7 +83,6 @@ class TritonPythonModel: be the same as `requests` """ responses = [] - # print("num:", len(requests), flush=True) for request in requests: infer_outputs = pb_utils.get_input_tensor_by_name( request, self.input_names[0]) @@ -115,10 +90,15 @@ class TritonPythonModel: self.input_names[1]) infer_outputs = infer_outputs.as_numpy() im_infos = im_infos.as_numpy() + for i in range(im_infos.shape[0]): + im_infos[i] = json.loads(im_infos[i].decode('utf-8').replace( + "'", '"')) - results = self.yolov5_postprocess(infer_outputs, im_infos) + results = self.postprocessor_.run([infer_outputs], im_infos) + r_str = fd.vision.utils.fd_result_to_json(results) + r_np = np.array(r_str, dtype=np.object) - out_tensor = pb_utils.Tensor(self.output_names[0], results) + out_tensor = pb_utils.Tensor(self.output_names[0], r_np) inference_response = pb_utils.InferenceResponse( output_tensors=[out_tensor, ]) responses.append(inference_response) diff --git a/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py b/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py index cd22aa37b..cf4f7e8e8 100644 --- a/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py +++ b/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py @@ -61,21 +61,7 @@ class TritonPythonModel: dtype = pb_utils.triton_string_to_numpy(output_config["data_type"]) self.output_dtype.append(dtype) print("preprocess output names:", self.output_names) - - def yolov5_preprocess(self, input_data): - """ - According to Triton input, the preprocessing results of YoloV5 model are obtained. - """ - im_infos = [] - pre_outputs = [] - for i_batch in input_data: - pre_output, im_info = fd.vision.detection.YOLOv5.preprocess( - i_batch) - pre_outputs.append(pre_output) - im_infos.append(im_info) - im_infos = np.array(im_infos, dtype=np.object) - pre_outputs = np.concatenate(pre_outputs, axis=0) - return pre_outputs, im_infos + self.preprocessor_ = fd.vision.detection.YOLOv5Preprocessor() def execute(self, requests): """`execute` must be implemented in every Python model. `execute` @@ -97,18 +83,21 @@ class TritonPythonModel: be the same as `requests` """ responses = [] - # print("num:", len(requests), flush=True) for request in requests: data = pb_utils.get_input_tensor_by_name(request, self.input_names[0]) data = data.as_numpy() - outputs = self.yolov5_preprocess(data) - output_tensors = [] - for idx, output in enumerate(outputs): - output_tensors.append( - pb_utils.Tensor(self.output_names[idx], output)) + outputs, im_infos = self.preprocessor_.run(data) + + # YOLOv5 preprocess has two output + dlpack_tensor = outputs[0].to_dlpack() + output_tensor_0 = pb_utils.Tensor.from_dlpack(self.output_names[0], + dlpack_tensor) + output_tensor_1 = pb_utils.Tensor( + self.output_names[1], np.array( + im_infos, dtype=np.object)) inference_response = pb_utils.InferenceResponse( - output_tensors=output_tensors) + output_tensors=[output_tensor_0, output_tensor_1]) responses.append(inference_response) return responses diff --git a/examples/vision/detection/yolov5lite/cpp/infer.cc b/examples/vision/detection/yolov5lite/cpp/infer.cc index ac32bca93..0a3f7b81b 100644 --- a/examples/vision/detection/yolov5lite/cpp/infer.cc +++ b/examples/vision/detection/yolov5lite/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov5lite/python/infer.py b/examples/vision/detection/yolov5lite/python/infer.py index b1ec69046..2242a33a5 100644 --- a/examples/vision/detection/yolov5lite/python/infer.py +++ b/examples/vision/detection/yolov5lite/python/infer.py @@ -52,7 +52,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov6/cpp/infer.cc b/examples/vision/detection/yolov6/cpp/infer.cc index 72b2e7bed..dbca64f40 100644 --- a/examples/vision/detection/yolov6/cpp/infer.cc +++ b/examples/vision/detection/yolov6/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov6/python/infer.py b/examples/vision/detection/yolov6/python/infer.py index 0a0a163fb..47bf3e689 100644 --- a/examples/vision/detection/yolov6/python/infer.py +++ b/examples/vision/detection/yolov6/python/infer.py @@ -52,7 +52,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov6/quantize/cpp/README.md b/examples/vision/detection/yolov6/quantize/cpp/README.md index 7ad762100..a929f8ced 100755 --- a/examples/vision/detection/yolov6/quantize/cpp/README.md +++ b/examples/vision/detection/yolov6/quantize/cpp/README.md @@ -23,7 +23,7 @@ cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x make -j #下载FastDeloy提供的yolov6s量化模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_qat_model.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_qat_model_new.tar tar -xvf yolov6s_qat_model.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg diff --git a/examples/vision/detection/yolov6/quantize/cpp/infer.cc b/examples/vision/detection/yolov6/quantize/cpp/infer.cc index b40200962..adda977f3 100644 --- a/examples/vision/detection/yolov6/quantize/cpp/infer.cc +++ b/examples/vision/detection/yolov6/quantize/cpp/infer.cc @@ -29,7 +29,6 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, assert(model.Initialized()); auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -39,7 +38,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov6/quantize/python/README.md b/examples/vision/detection/yolov6/quantize/python/README.md index 057e13f9a..e9b80bb6f 100755 --- a/examples/vision/detection/yolov6/quantize/python/README.md +++ b/examples/vision/detection/yolov6/quantize/python/README.md @@ -17,7 +17,7 @@ git clone https://github.com/PaddlePaddle/FastDeploy.git cd examples/slim/yolov6/python #下载FastDeloy提供的yolov6s量化模型文件和测试图片 -wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_qat_model.tar +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s_qat_model_new.tar tar -xvf yolov6s_qat_model.tar wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg diff --git a/examples/vision/detection/yolov6/quantize/python/infer.py b/examples/vision/detection/yolov6/quantize/python/infer.py index da9fa3d97..77f46d4c2 100644 --- a/examples/vision/detection/yolov6/quantize/python/infer.py +++ b/examples/vision/detection/yolov6/quantize/python/infer.py @@ -71,7 +71,7 @@ model = fd.vision.detection.YOLOv6( # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov7/cpp/infer.cc b/examples/vision/detection/yolov7/cpp/infer.cc index cf79a16ad..5fd848b8e 100644 --- a/examples/vision/detection/yolov7/cpp/infer.cc +++ b/examples/vision/detection/yolov7/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov7/python/infer.py b/examples/vision/detection/yolov7/python/infer.py index b0ece7e47..468b47dc5 100644 --- a/examples/vision/detection/yolov7/python/infer.py +++ b/examples/vision/detection/yolov7/python/infer.py @@ -52,7 +52,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) # 预测结果可视化 vis_im = fd.vision.vis_detection(im, result) diff --git a/examples/vision/detection/yolov7/quantize/cpp/infer.cc b/examples/vision/detection/yolov7/quantize/cpp/infer.cc index 0eda80b6c..9ae42b582 100644 --- a/examples/vision/detection/yolov7/quantize/cpp/infer.cc +++ b/examples/vision/detection/yolov7/quantize/cpp/infer.cc @@ -29,7 +29,6 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, assert(model.Initialized()); auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -39,7 +38,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file, std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov7/quantize/python/infer.py b/examples/vision/detection/yolov7/quantize/python/infer.py index de84e4061..d07834c7c 100644 --- a/examples/vision/detection/yolov7/quantize/python/infer.py +++ b/examples/vision/detection/yolov7/quantize/python/infer.py @@ -71,7 +71,7 @@ model = fd.vision.detection.YOLOv7( # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc b/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc index a0e70544a..5c9df2816 100644 --- a/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc +++ b/examples/vision/detection/yolov7end2end_ort/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolov7end2end_ort/python/infer.py b/examples/vision/detection/yolov7end2end_ort/python/infer.py index 2b812b71a..914facb59 100644 --- a/examples/vision/detection/yolov7end2end_ort/python/infer.py +++ b/examples/vision/detection/yolov7end2end_ort/python/infer.py @@ -44,7 +44,7 @@ model = fd.vision.detection.YOLOv7End2EndORT( # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc b/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc index 1c7a17d37..4f7a2f791 100644 --- a/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc +++ b/examples/vision/detection/yolov7end2end_trt/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -47,7 +46,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -56,7 +54,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -74,7 +72,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -83,7 +80,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -107,4 +104,4 @@ int main(int argc, char* argv[]) { TrtInfer(argv[1], argv[2]); } return 0; -} \ No newline at end of file +} diff --git a/examples/vision/detection/yolov7end2end_trt/python/infer.py b/examples/vision/detection/yolov7end2end_trt/python/infer.py index d179de06f..b1ad8ea0c 100644 --- a/examples/vision/detection/yolov7end2end_trt/python/infer.py +++ b/examples/vision/detection/yolov7end2end_trt/python/infer.py @@ -44,7 +44,7 @@ model = fd.vision.detection.YOLOv7End2EndTRT( # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 diff --git a/examples/vision/detection/yolox/cpp/infer.cc b/examples/vision/detection/yolox/cpp/infer.cc index 2eeaccbf8..836ab7e63 100644 --- a/examples/vision/detection/yolox/cpp/infer.cc +++ b/examples/vision/detection/yolox/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::DetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/detection/yolox/python/infer.py b/examples/vision/detection/yolox/python/infer.py index 69203010b..c5e71754a 100644 --- a/examples/vision/detection/yolox/python/infer.py +++ b/examples/vision/detection/yolox/python/infer.py @@ -52,7 +52,7 @@ if args.image is None: else: image = args.image im = cv2.imread(image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 vis_im = fd.vision.vis_detection(im, result) diff --git a/examples/vision/facealign/face_landmark_1000/cpp/CMakeLists.txt b/examples/vision/facealign/face_landmark_1000/cpp/CMakeLists.txt index c417fcb38..74e6eb7e7 100644 --- a/examples/vision/facealign/face_landmark_1000/cpp/CMakeLists.txt +++ b/examples/vision/facealign/face_landmark_1000/cpp/CMakeLists.txt @@ -10,9 +10,5 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) include_directories(${FASTDEPLOY_INCS}) add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) -# 添加FastDeploy库依赖 -if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags pthread) -else() - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags) -endif() + +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} ${GFLAGS_LIBRARIES}) diff --git a/examples/vision/facealign/face_landmark_1000/cpp/README.md b/examples/vision/facealign/face_landmark_1000/cpp/README.md index 755a20664..00b5391b5 100644 --- a/examples/vision/facealign/face_landmark_1000/cpp/README.md +++ b/examples/vision/facealign/face_landmark_1000/cpp/README.md @@ -7,7 +7,7 @@ - 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 ```bash mkdir build diff --git a/examples/vision/facealign/face_landmark_1000/python/infer.py b/examples/vision/facealign/face_landmark_1000/python/infer.py index bbb3a19c8..9eaedfb63 100644 --- a/examples/vision/facealign/face_landmark_1000/python/infer.py +++ b/examples/vision/facealign/face_landmark_1000/python/infer.py @@ -82,7 +82,7 @@ model = fd.vision.facealign.FaceLandmark1000( # for image im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_face_alignment(im, result) diff --git a/examples/vision/facealign/pfld/cpp/CMakeLists.txt b/examples/vision/facealign/pfld/cpp/CMakeLists.txt index c417fcb38..7d1bd2ee1 100755 --- a/examples/vision/facealign/pfld/cpp/CMakeLists.txt +++ b/examples/vision/facealign/pfld/cpp/CMakeLists.txt @@ -10,9 +10,4 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) include_directories(${FASTDEPLOY_INCS}) add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) -# 添加FastDeploy库依赖 -if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags pthread) -else() - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags) -endif() +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} ${GFLAGS_LIBRARIES}) diff --git a/examples/vision/facealign/pfld/cpp/README.md b/examples/vision/facealign/pfld/cpp/README.md index d061b010a..06ce4a2f4 100644 --- a/examples/vision/facealign/pfld/cpp/README.md +++ b/examples/vision/facealign/pfld/cpp/README.md @@ -7,7 +7,7 @@ - 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 ```bash mkdir build diff --git a/examples/vision/facealign/pfld/python/infer.py b/examples/vision/facealign/pfld/python/infer.py index 622fbf822..0a695e8c6 100755 --- a/examples/vision/facealign/pfld/python/infer.py +++ b/examples/vision/facealign/pfld/python/infer.py @@ -80,7 +80,7 @@ model = fd.vision.facealign.PFLD(args.model, runtime_option=runtime_option) # for image im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_face_alignment(im, result) diff --git a/examples/vision/facealign/pipnet/cpp/CMakeLists.txt b/examples/vision/facealign/pipnet/cpp/CMakeLists.txt index c417fcb38..7d1bd2ee1 100644 --- a/examples/vision/facealign/pipnet/cpp/CMakeLists.txt +++ b/examples/vision/facealign/pipnet/cpp/CMakeLists.txt @@ -10,9 +10,4 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) include_directories(${FASTDEPLOY_INCS}) add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) -# 添加FastDeploy库依赖 -if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags pthread) -else() - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags) -endif() +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} ${GFLAGS_LIBRARIES}) diff --git a/examples/vision/facealign/pipnet/python/infer.py b/examples/vision/facealign/pipnet/python/infer.py index 628b86f79..46f9c2d90 100644 --- a/examples/vision/facealign/pipnet/python/infer.py +++ b/examples/vision/facealign/pipnet/python/infer.py @@ -85,7 +85,7 @@ model = fd.vision.facealign.PIPNet(args.model, runtime_option=runtime_option) model.num_landmarks = args.num_landmarks # for image im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_face_alignment(im, result) diff --git a/examples/vision/facedet/retinaface/cpp/infer.cc b/examples/vision/facedet/retinaface/cpp/infer.cc index a1fd27b6e..f125e4ba7 100644 --- a/examples/vision/facedet/retinaface/cpp/infer.cc +++ b/examples/vision/facedet/retinaface/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/facedet/retinaface/python/infer.py b/examples/vision/facedet/retinaface/python/infer.py index 3b0152b1c..6b7f63e5e 100644 --- a/examples/vision/facedet/retinaface/python/infer.py +++ b/examples/vision/facedet/retinaface/python/infer.py @@ -43,7 +43,7 @@ model = fd.vision.facedet.RetinaFace(args.model, runtime_option=runtime_option) # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 vis_im = fd.vision.vis_face_detection(im, result) diff --git a/examples/vision/facedet/scrfd/cpp/infer.cc b/examples/vision/facedet/scrfd/cpp/infer.cc index c804218ee..c09403741 100644 --- a/examples/vision/facedet/scrfd/cpp/infer.cc +++ b/examples/vision/facedet/scrfd/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/facedet/scrfd/python/infer.py b/examples/vision/facedet/scrfd/python/infer.py index a99e66385..af141e011 100644 --- a/examples/vision/facedet/scrfd/python/infer.py +++ b/examples/vision/facedet/scrfd/python/infer.py @@ -43,7 +43,7 @@ model = fd.vision.facedet.SCRFD(args.model, runtime_option=runtime_option) # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 vis_im = fd.vision.vis_face_detection(im, result) diff --git a/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc b/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc index a01f1b184..e009d2ead 100644 --- a/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc +++ b/examples/vision/facedet/scrfd/rknpu2/cpp/infer.cc @@ -2,50 +2,13 @@ #include #include "fastdeploy/vision.h" -void InferScrfd(const std::string& device = "cpu"); - -int main() { - InferScrfd("npu"); - return 0; -} - -fastdeploy::RuntimeOption GetOption(const std::string& device) { - auto option = fastdeploy::RuntimeOption(); - if (device == "npu") { - option.UseRKNPU2(); - } else { - option.UseCpu(); - } - return option; -} - -fastdeploy::ModelFormat GetFormat(const std::string& device) { - auto format = fastdeploy::ModelFormat::ONNX; - if (device == "npu") { - format = fastdeploy::ModelFormat::RKNN; - } else { - format = fastdeploy::ModelFormat::ONNX; - } - return format; -} - -std::string GetModelPath(std::string& model_path, const std::string& device) { - if (device == "npu") { - model_path += "rknn"; - } else { - model_path += "onnx"; - } - return model_path; -} - -void InferScrfd(const std::string& device) { - std::string model_file = - "./model/scrfd_500m_bnkps_shape640x640_rk3588."; +void ONNXInfer(const std::string& model_dir, const std::string& image_file) { + std::string model_file = model_dir + "/scrfd_500m_bnkps_shape640x640.onnx"; std::string params_file; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto format = fastdeploy::ModelFormat::ONNX; - fastdeploy::RuntimeOption option = GetOption(device); - fastdeploy::ModelFormat format = GetFormat(device); - model_file = GetModelPath(model_file, device); auto model = fastdeploy::vision::facedet::SCRFD( model_file, params_file, option, format); @@ -53,27 +16,68 @@ void InferScrfd(const std::string& device) { std::cerr << "Failed to initialize." << std::endl; return; } - auto image_file = - "./images/test_lite_face_detector_3.jpg"; + + fastdeploy::TimeCounter tc; + tc.Start(); auto im = cv::imread(image_file); - - if (device == "npu") { - model.DisableNormalizeAndPermute(); - } - fastdeploy::vision::FaceDetectionResult res; - clock_t start = clock(); if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - clock_t end = clock(); - auto dur = static_cast(end - start); - printf("InferScrfd use time:%f\n", - (dur / CLOCKS_PER_SEC)); - - std::cout << res.Str() << std::endl; auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im, res); - cv::imwrite("vis_result.jpg", vis_im); - std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; + tc.End(); + tc.PrintInfo("SCRFD in ONNX"); + + cv::imwrite("infer_onnx.jpg", vis_im); + 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 + "/scrfd_500m_bnkps_shape640x640_rk3588.rknn"; + std::string params_file; + auto option = fastdeploy::RuntimeOption(); + option.UseRKNPU2(); + auto format = fastdeploy::ModelFormat::RKNN; + + auto model = fastdeploy::vision::facedet::SCRFD(model_file, params_file, option, format); + + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + model.DisableNormalizeAndPermute(); + + fastdeploy::TimeCounter tc; + tc.Start(); + auto im = cv::imread(image_file); + fastdeploy::vision::FaceDetectionResult res; + if (!model.Predict(&im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); + tc.End(); + tc.PrintInfo("SCRFD in RKNN"); + + cv::imwrite("infer_rknn.jpg", vis_im); + std::cout + << "Visualized result saved in ./infer_rknn.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 ./picodet_model_dir ./test.jpeg" + << std::endl; + return -1; + } + + RKNPU2Infer(argv[1], argv[2]); + ONNXInfer(argv[1], argv[2]); + return 0; } \ No newline at end of file diff --git a/examples/vision/facedet/scrfd/rknpu2/python/infer.py b/examples/vision/facedet/scrfd/rknpu2/python/infer.py index 3b3fc9d83..77e57a0f1 100644 --- a/examples/vision/facedet/scrfd/rknpu2/python/infer.py +++ b/examples/vision/facedet/scrfd/rknpu2/python/infer.py @@ -49,7 +49,7 @@ model.disable_normalize_and_permute() # 预测图片分割结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 diff --git a/examples/vision/facedet/ultraface/cpp/infer.cc b/examples/vision/facedet/ultraface/cpp/infer.cc index b45bb3b0b..b50674e1d 100644 --- a/examples/vision/facedet/ultraface/cpp/infer.cc +++ b/examples/vision/facedet/ultraface/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/facedet/ultraface/python/infer.py b/examples/vision/facedet/ultraface/python/infer.py index 5399110b9..2087ce5bf 100644 --- a/examples/vision/facedet/ultraface/python/infer.py +++ b/examples/vision/facedet/ultraface/python/infer.py @@ -43,7 +43,7 @@ model = fd.vision.facedet.UltraFace(args.model, runtime_option=runtime_option) # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 vis_im = fd.vision.vis_face_detection(im, result) diff --git a/examples/vision/facedet/yolov5face/cpp/infer.cc b/examples/vision/facedet/yolov5face/cpp/infer.cc index 418834e1e..ecdcfcd0c 100644 --- a/examples/vision/facedet/yolov5face/cpp/infer.cc +++ b/examples/vision/facedet/yolov5face/cpp/infer.cc @@ -22,7 +22,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -31,7 +30,7 @@ void CpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -46,7 +45,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -55,7 +53,7 @@ void GpuInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } @@ -72,7 +70,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } auto im = cv::imread(image_file); - auto im_bak = im.clone(); fastdeploy::vision::FaceDetectionResult res; if (!model.Predict(&im, &res)) { @@ -81,7 +78,7 @@ void TrtInfer(const std::string& model_file, const std::string& image_file) { } std::cout << res.Str() << std::endl; - auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im_bak, res); + auto vis_im = fastdeploy::vision::VisFaceDetection(im, res); cv::imwrite("vis_result.jpg", vis_im); std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl; } diff --git a/examples/vision/facedet/yolov5face/python/infer.py b/examples/vision/facedet/yolov5face/python/infer.py index a9f044682..ca907afb4 100644 --- a/examples/vision/facedet/yolov5face/python/infer.py +++ b/examples/vision/facedet/yolov5face/python/infer.py @@ -43,7 +43,7 @@ model = fd.vision.facedet.YOLOv5Face(args.model, runtime_option=runtime_option) # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 预测结果可视化 vis_im = fd.vision.vis_face_detection(im, result) diff --git a/examples/vision/facedet/yolov7face/cpp/CMakeLists.txt b/examples/vision/facedet/yolov7face/cpp/CMakeLists.txt new file mode 100644 index 000000000..4ec242a44 --- /dev/null +++ b/examples/vision/facedet/yolov7face/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +PROJECT(infer_demo C CXX) +CMAKE_MINIMUM_REQUIRED (VERSION 3.10) + +# Specifies the path to the fastdeploy library after you have downloaded it +option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") + +include(../../../../../FastDeploy.cmake) + +# Add the FastDeploy dependency header +include_directories(${FASTDEPLOY_INCS}) + +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# Add the FastDeploy library dependency +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/vision/facedet/yolov7face/cpp/README.md b/examples/vision/facedet/yolov7face/cpp/README.md new file mode 100644 index 000000000..3b68ff41c --- /dev/null +++ b/examples/vision/facedet/yolov7face/cpp/README.md @@ -0,0 +1,90 @@ +# YOLOv7Face C++部署示例 + +本目录下提供`infer.cc`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试 + +```bash +mkdir build +cd build +# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用 +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2 +tar xvf fastdeploy-linux-x64-x.x.x.tgz # x.x.x > 1.0.2 +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x # x.x.x > 1.0.2 +make -j + +#下载官方转换好的YOLOv7Face模型文件和测试图片 +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-tiny-face.onnx + +#使用yolov7-tiny-face.onnx模型 +# CPU推理 +./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov7-tiny-face.onnx test_lite_face_detector_3.jpg 2 + +#使用yolov7-lite-e.onnx模型 +# CPU推理 +./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 0 +# GPU推理 +./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 1 +# GPU上TensorRT推理 +./infer_demo yolov7-lite-e.onnx test_lite_face_detector_3.jpg 2 +``` + +运行完成可视化结果如下图所示 + + + +以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考: +- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md) + +## YOLOv7Face C++接口 + +### YOLOv7Face类 + +```c++ +fastdeploy::vision::facedet::YOLOv7Face( + const string& model_file, + const string& params_file = "", + const RuntimeOption& runtime_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX) +``` + +YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式。 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX时,此参数传入空字符串即可 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX格式 + +#### Predict函数 + +> ```c++ +> YOLOv7Face::Predict(cv::Mat* im, FaceDetectionResult* result, +> float conf_threshold = 0.3, +> float nms_iou_threshold = 0.5) +> ``` +> +> 模型预测接口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **im**: 输入图像,注意需为HWC,BGR格式 +> > * **result**: 检测结果,包括检测框,各个框的置信度, FaceDetectionResult说明参考[视觉模型预测结果](../../../../../docs/api/vision_results/) +> > * **conf_threshold**: 检测框置信度过滤阈值 +> > * **nms_iou_threshold**: NMS处理过程中iou阈值 + +- [模型介绍](../../) +- [Python部署](../python) +- [视觉模型预测结果](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov7face/cpp/infer.cc b/examples/vision/facedet/yolov7face/cpp/infer.cc new file mode 100644 index 000000000..973b65be3 --- /dev/null +++ b/examples/vision/facedet/yolov7face/cpp/infer.cc @@ -0,0 +1,105 @@ +// 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" + +void CpuInfer(const std::string& model_file, const std::string& image_file) { + auto model = fastdeploy::vision::facedet::YOLOv7Face(model_file); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::FaceDetectionResult 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::VisFaceDetection(im, 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& image_file) { + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + auto model = fastdeploy::vision::facedet::YOLOv7Face(model_file, "", option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::FaceDetectionResult 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::VisFaceDetection(im, 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& image_file) { + auto option = fastdeploy::RuntimeOption(); + option.UseGpu(); + option.UseTrtBackend(); + option.SetTrtInputShape("images", {1, 3, 640, 640}); + auto model = fastdeploy::vision::facedet::YOLOv7Face(model_file, "", option); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + + auto im = cv::imread(image_file); + + fastdeploy::vision::FaceDetectionResult 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::VisFaceDetection(im, 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_model yolov5s-face.onnx ./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; + } + + 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/facedet/yolov7face/python/README.md b/examples/vision/facedet/yolov7face/python/README.md new file mode 100644 index 000000000..0c4dd0f57 --- /dev/null +++ b/examples/vision/facedet/yolov7face/python/README.md @@ -0,0 +1,87 @@ +# YOLOv7Face Python部署示例 + +在部署前,需确认以下两个步骤 + +- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) +- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) + +本目录下提供`infer.py`快速完成YOLOv7Face在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成 + +```bash +#下载部署示例代码 +git clone https://github.com/PaddlePaddle/FastDeploy.git +cd examples/vision/facedet/yolov7face/python/ + +#下载YOLOv7Face模型文件和测试图片 +wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_face_detector_3.jpg +wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-lite-e.onnx + +#使用yolov7-tiny-face.onnx模型 +# CPU推理 +python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov7-tiny-face.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True + +#使用yolov7-lite-e.onnx模型 +# CPU推理 +python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device cpu +# GPU推理 +python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu +# GPU上使用TensorRT推理 +python infer.py --model yolov7-lite-e.onnx --image test_lite_face_detector_3.jpg --device gpu --use_trt True +``` + +运行完成可视化结果如下图所示 + + + +## YOLOv7Face Python接口 + +```python +fastdeploy.vision.facedet.YOLOv7Face(model_file, params_file=None, runtime_option=None, model_format=ModelFormat.ONNX) +``` + +YOLOv7Face模型加载和初始化,其中model_file为导出的ONNX模型格式 + +**参数** + +> * **model_file**(str): 模型文件路径 +> * **params_file**(str): 参数文件路径,当模型格式为ONNX格式时,此参数无需设定 +> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置 +> * **model_format**(ModelFormat): 模型格式,默认为ONNX + +### predict函数 + +> ```python +> YOLOv7Face.predict(image_data, conf_threshold=0.3, nms_iou_threshold=0.5) +> ``` +> +> 模型预测结口,输入图像直接输出检测结果。 +> +> **参数** +> +> > * **image_data**(np.ndarray): 输入数据,注意需为HWC,BGR格式 +> > * **conf_threshold**(float): 检测框置信度过滤阈值 +> > * **nms_iou_threshold**(float): NMS处理过程中iou阈值 + +> **返回** +> +> > 返回`fastdeploy.vision.FaceDetectionResult`结构体,结构体说明参考文档[视觉模型预测结果](../../../../../docs/api/vision_results/) + +### 类成员属性 +#### 预处理参数 +用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果 + +> > * **size**(list[int]): 通过此参数修改预处理过程中resize的大小,包含两个整型元素,表示[width, height], 默认值为[640, 640] +> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[114, 114, 114] +> > * **is_no_pad**(bool): 通过此参数让图片是否通过填充的方式进行resize, `is_no_pad=True` 表示不使用填充的方式,默认值为`is_no_pad=False` +> > * **is_mini_pad**(bool): 通过此参数可以将resize之后图像的宽高这是为最接近`size`成员变量的值, 并且满足填充的像素大小是可以被`stride`成员变量整除的。默认值为`is_mini_pad=False` +> > * **stride**(int): 配合`is_mini_pad`成员变量使用, 默认值为`stride=32` + +## 其它文档 + +- [YOLOv7Face 模型介绍](..) +- [YOLOv7Face C++部署](../cpp) +- [模型预测结果说明](../../../../../docs/api/vision_results/) diff --git a/examples/vision/facedet/yolov7face/python/infer.py b/examples/vision/facedet/yolov7face/python/infer.py new file mode 100644 index 000000000..d06b507ee --- /dev/null +++ b/examples/vision/facedet/yolov7face/python/infer.py @@ -0,0 +1,51 @@ +import fastdeploy as fd +import cv2 + + +def parse_arguments(): + import argparse + import ast + parser = argparse.ArgumentParser() + parser.add_argument( + "--model", required=True, help="Path of yolov7face onnx 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( + "--use_trt", + type=ast.literal_eval, + default=False, + help="Wether to use tensorrt.") + return parser.parse_args() + + +def build_option(args): + option = fd.RuntimeOption() + + if args.device.lower() == "gpu": + option.use_gpu() + + if args.use_trt: + option.use_trt_backend() + option.set_trt_input_shape("images", [1, 3, 640, 640]) + return option + + +args = parse_arguments() + +# Configure runtime and load the model +runtime_option = build_option(args) +model = fd.vision.facedet.YOLOv7Face(args.model, runtime_option=runtime_option) + +# Predict image detection results +im = cv2.imread(args.image) +result = model.predict(im) +print(result) +# Visualization of prediction Results +vis_im = fd.vision.vis_face_detection(im, result) +cv2.imwrite("visualized_result.jpg", vis_im) +print("Visualized result save in ./visualized_result.jpg") diff --git a/examples/vision/headpose/fsanet/cpp/CMakeLists.txt b/examples/vision/headpose/fsanet/cpp/CMakeLists.txt index c417fcb38..7d1bd2ee1 100755 --- a/examples/vision/headpose/fsanet/cpp/CMakeLists.txt +++ b/examples/vision/headpose/fsanet/cpp/CMakeLists.txt @@ -10,9 +10,4 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) include_directories(${FASTDEPLOY_INCS}) add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) -# 添加FastDeploy库依赖 -if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags pthread) -else() - target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} gflags) -endif() +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} ${GFLAGS_LIBRARIES}) diff --git a/examples/vision/headpose/fsanet/cpp/README.md b/examples/vision/headpose/fsanet/cpp/README.md index 51e0a179d..1d1b1e943 100755 --- a/examples/vision/headpose/fsanet/cpp/README.md +++ b/examples/vision/headpose/fsanet/cpp/README.md @@ -7,7 +7,7 @@ - 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) - 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md) -以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本0.7.0以上(x.x.x>=0.7.0) +以Linux上CPU推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2), 或使用nightly built版本 ```bash mkdir build diff --git a/examples/vision/headpose/fsanet/python/infer.py b/examples/vision/headpose/fsanet/python/infer.py index 866ce6d5c..488e35153 100644 --- a/examples/vision/headpose/fsanet/python/infer.py +++ b/examples/vision/headpose/fsanet/python/infer.py @@ -80,7 +80,7 @@ model = fd.vision.headpose.FSANet(args.model, runtime_option=runtime_option) # for image im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_headpose(im, result) diff --git a/examples/vision/matting/modnet/cpp/infer.cc b/examples/vision/matting/modnet/cpp/infer.cc index fe1ebc910..aa280eddd 100644 --- a/examples/vision/matting/modnet/cpp/infer.cc +++ b/examples/vision/matting/modnet/cpp/infer.cc @@ -23,7 +23,6 @@ void CpuInfer(const std::string& model_file, const std::string& image_file, } model.size = {256, 256}; auto im = cv::imread(image_file); - auto im_bak = im.clone(); cv::Mat bg = cv::imread(background_file); fastdeploy::vision::MattingResult res; @@ -32,9 +31,9 @@ void CpuInfer(const std::string& model_file, const std::string& image_file, return; } - auto vis_im = fastdeploy::vision::VisMatting(im_bak, res); + auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = - fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res); + fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); cv::imwrite("visualized_result_fg.jpg", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " @@ -54,7 +53,6 @@ void GpuInfer(const std::string& model_file, const std::string& image_file, model.size = {256, 256}; auto im = cv::imread(image_file); - auto im_bak = im.clone(); cv::Mat bg = cv::imread(background_file); fastdeploy::vision::MattingResult res; @@ -63,9 +61,9 @@ void GpuInfer(const std::string& model_file, const std::string& image_file, return; } - auto vis_im = fastdeploy::vision::VisMatting(im_bak, res); + auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = - fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res); + fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); cv::imwrite("visualized_result_fg.jpg", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " @@ -86,7 +84,6 @@ void TrtInfer(const std::string& model_file, const std::string& image_file, } model.size = {256, 256}; auto im = cv::imread(image_file); - auto im_bak = im.clone(); cv::Mat bg = cv::imread(background_file); fastdeploy::vision::MattingResult res; @@ -95,9 +92,9 @@ void TrtInfer(const std::string& model_file, const std::string& image_file, return; } - auto vis_im = fastdeploy::vision::VisMatting(im_bak, res); + auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = - fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res); + fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); cv::imwrite("visualized_result_fg.jpg", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " diff --git a/examples/vision/matting/modnet/python/infer.py b/examples/vision/matting/modnet/python/infer.py index 408ba2340..37c749010 100644 --- a/examples/vision/matting/modnet/python/infer.py +++ b/examples/vision/matting/modnet/python/infer.py @@ -52,11 +52,11 @@ model.size = (256, 256) # 预测图片抠图结果 im = cv2.imread(args.image) bg = cv2.imread(args.bg) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_matting_alpha(im, result) -vis_im_with_bg = fd.vision.swap_background_matting(im, bg, result) +vis_im_with_bg = fd.vision.swap_background(im, bg, result) cv2.imwrite("visualized_result_fg.jpg", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( diff --git a/examples/vision/matting/ppmatting/cpp/infer.cc b/examples/vision/matting/ppmatting/cpp/infer.cc index 304e4239a..2acb2a8ca 100644 --- a/examples/vision/matting/ppmatting/cpp/infer.cc +++ b/examples/vision/matting/ppmatting/cpp/infer.cc @@ -35,16 +35,15 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file, } auto im = cv::imread(image_file); - auto im_bak = im.clone(); cv::Mat bg = cv::imread(background_file); fastdeploy::vision::MattingResult res; if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - auto vis_im = fastdeploy::vision::VisMatting(im_bak, res); + auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = - fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res); + fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); cv::imwrite("visualized_result_fg.jpg", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " @@ -69,16 +68,15 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file, } auto im = cv::imread(image_file); - auto im_bak = im.clone(); cv::Mat bg = cv::imread(background_file); fastdeploy::vision::MattingResult res; if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - auto vis_im = fastdeploy::vision::VisMatting(im_bak, res); + auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = - fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res); + fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); cv::imwrite("visualized_result_fg.jpg", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " @@ -104,16 +102,15 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file, } auto im = cv::imread(image_file); - auto im_bak = im.clone(); cv::Mat bg = cv::imread(background_file); fastdeploy::vision::MattingResult res; if (!model.Predict(&im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - auto vis_im = fastdeploy::vision::VisMatting(im_bak, res); + auto vis_im = fastdeploy::vision::VisMatting(im, res); auto vis_im_with_bg = - fastdeploy::vision::Visualize::SwapBackgroundMatting(im_bak, bg, res); + fastdeploy::vision::SwapBackground(im, bg, res); cv::imwrite("visualized_result.jpg", vis_im_with_bg); cv::imwrite("visualized_result_fg.jpg", vis_im); std::cout << "Visualized result save in ./visualized_result_replaced_bg.jpg " diff --git a/examples/vision/matting/ppmatting/python/infer.py b/examples/vision/matting/ppmatting/python/infer.py index 61031e1b6..89913cd11 100644 --- a/examples/vision/matting/ppmatting/python/infer.py +++ b/examples/vision/matting/ppmatting/python/infer.py @@ -56,11 +56,11 @@ model = fd.vision.matting.PPMatting( # 预测图片抠图结果 im = cv2.imread(args.image) bg = cv2.imread(args.bg) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_matting(im, result) -vis_im_with_bg = fd.vision.swap_background_matting(im, bg, result) +vis_im_with_bg = fd.vision.swap_background(im, bg, result) cv2.imwrite("visualized_result_fg.jpg", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( diff --git a/examples/vision/matting/rvm/python/infer.py b/examples/vision/matting/rvm/python/infer.py index 11951b00f..0e9eb6b21 100755 --- a/examples/vision/matting/rvm/python/infer.py +++ b/examples/vision/matting/rvm/python/infer.py @@ -73,7 +73,7 @@ if args.video is not None: # for video cap = cv2.VideoCapture(args.video) # Define the codec and create VideoWriter object - fourcc = cv2.VideoWriter_fourcc(*'mp4v') + fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') composition = cv2.VideoWriter(output_composition, fourcc, 20.0, (1080, 1920)) alpha = cv2.VideoWriter(output_alpha, fourcc, 20.0, (1080, 1920)) @@ -86,7 +86,7 @@ if args.video is not None: break result = model.predict(frame) vis_im = fd.vision.vis_matting(frame, result) - vis_im_with_bg = fd.vision.swap_background_matting(frame, bg, result) + vis_im_with_bg = fd.vision.swap_background(frame, bg, result) alpha.write(vis_im) composition.write(vis_im_with_bg) cv2.waitKey(30) @@ -100,11 +100,11 @@ if args.video is not None: if args.image is not None: # for image im = cv2.imread(args.image) - result = model.predict(im.copy()) + result = model.predict(im) print(result) # 可视化结果 vis_im = fd.vision.vis_matting(im, result) - vis_im_with_bg = fd.vision.swap_background_matting(im, bg, result) + vis_im_with_bg = fd.vision.swap_background(im, bg, result) cv2.imwrite("visualized_result_fg.jpg", vis_im) cv2.imwrite("visualized_result_replaced_bg.jpg", vis_im_with_bg) print( diff --git a/examples/vision/ocr/PP-OCRv2/cpp/README.md b/examples/vision/ocr/PP-OCRv2/cpp/README.md index 965ece716..1bb794f5e 100644 --- a/examples/vision/ocr/PP-OCRv2/cpp/README.md +++ b/examples/vision/ocr/PP-OCRv2/cpp/README.md @@ -82,6 +82,7 @@ PPOCRv2 的初始化,由检测,识别模型串联构成(无分类器) > ``` > bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result); +> bool Predict(const cv::Mat& img, fastdeploy::vision::OCRResult* result); > ``` > > 模型预测接口,输入一张图片,返回OCR预测结果 diff --git a/examples/vision/ocr/PP-OCRv2/cpp/infer.cc b/examples/vision/ocr/PP-OCRv2/cpp/infer.cc index 7bac320d5..6cde6390f 100644 --- a/examples/vision/ocr/PP-OCRv2/cpp/infer.cc +++ b/examples/vision/ocr/PP-OCRv2/cpp/infer.cc @@ -33,13 +33,18 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model auto cls_option = option; auto rec_option = option; + // The cls and rec model can inference a batch of images now. + // User could initialize the inference batch size and set them after create PPOCR model. + int cls_batch_size = 1; + int rec_batch_size = 6; + // If use TRT backend, the dynamic shape will be set as follow. // We recommend that users set the length and height of the detection model to a multiple of 32. det_option.SetTrtInputShape("x", {1, 3, 64,64}, {1, 3, 640, 640}, {1, 3, 960, 960}); - cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {10, 3, 48, 320}, {32, 3, 48, 1024}); - rec_option.SetTrtInputShape("x", {1, 3, 32, 10}, {10, 3, 32, 320}, - {32, 3, 32, 2304}); + cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {cls_batch_size, 3, 48, 320}, {cls_batch_size, 3, 48, 1024}); + rec_option.SetTrtInputShape("x", {1, 3, 32, 10}, {rec_batch_size, 3, 32, 320}, + {rec_batch_size, 3, 32, 2304}); // Users could save TRT cache file to disk as follow. // det_option.SetTrtCacheFile(det_model_dir + sep + "det_trt_cache.trt"); @@ -58,6 +63,12 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model // auto ppocr_v2 = fastdeploy::pipeline::PPOCRv2(&det_model, &rec_model); auto ppocr_v2 = fastdeploy::pipeline::PPOCRv2(&det_model, &cls_model, &rec_model); + // Set inference batch size for cls model and rec model, the value could be -1 and 1 to positive infinity. + // When inference batch size is set to -1, it means that the inference batch size + // of the cls and rec models will be the same as the number of boxes detected by the det model. + ppocr_v2.SetClsBatchSize(cls_batch_size); + ppocr_v2.SetRecBatchSize(rec_batch_size); + if(!ppocr_v2.Initialized()){ std::cerr << "Failed to initialize PP-OCR." << std::endl; return; diff --git a/examples/vision/ocr/PP-OCRv2/python/infer.py b/examples/vision/ocr/PP-OCRv2/python/infer.py index af915143a..1487d795f 100644 --- a/examples/vision/ocr/PP-OCRv2/python/infer.py +++ b/examples/vision/ocr/PP-OCRv2/python/infer.py @@ -106,6 +106,11 @@ rec_label_file = args.rec_label_file # 用户也可根据自行需求分别配置 runtime_option = build_option(args) +# PPOCR的cls和rec模型现在已经支持推理一个Batch的数据 +# 定义下面两个变量后, 可用于设置trt输入shape, 并在PPOCR模型初始化后, 完成Batch推理设置 +cls_batch_size = 1 +rec_batch_size = 6 + # 当使用TRT时,分别给三个模型的runtime设置动态shape,并完成模型的创建. # 注意: 需要在检测模型创建完成后,再设置分类模型的动态输入并创建分类模型, 识别模型同理. # 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数. @@ -118,16 +123,18 @@ det_model = fd.vision.ocr.DBDetector( det_model_file, det_params_file, runtime_option=det_option) cls_option = runtime_option -cls_option.set_trt_input_shape("x", [1, 3, 48, 10], [10, 3, 48, 320], - [32, 3, 48, 1024]) +cls_option.set_trt_input_shape("x", [1, 3, 48, 10], + [cls_batch_size, 3, 48, 320], + [cls_batch_size, 3, 48, 1024]) # 用户可以把TRT引擎文件保存至本地 # cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt") cls_model = fd.vision.ocr.Classifier( cls_model_file, cls_params_file, runtime_option=cls_option) rec_option = runtime_option -rec_option.set_trt_input_shape("x", [1, 3, 32, 10], [10, 3, 32, 320], - [32, 3, 32, 2304]) +rec_option.set_trt_input_shape("x", [1, 3, 32, 10], + [rec_batch_size, 3, 32, 320], + [rec_batch_size, 3, 32, 2304]) # 用户可以把TRT引擎文件保存至本地 # rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt") rec_model = fd.vision.ocr.Recognizer( @@ -137,6 +144,12 @@ rec_model = fd.vision.ocr.Recognizer( ppocr_v2 = fd.vision.ocr.PPOCRv2( det_model=det_model, cls_model=cls_model, rec_model=rec_model) +# 给cls和rec模型设置推理时的batch size +# 此值能为-1, 和1到正无穷 +# 当此值为-1时, cls和rec模型的batch size将默认和det模型检测出的框的数量相同 +ppocr_v2.cls_batch_size = cls_batch_size +ppocr_v2.rec_batch_size = rec_batch_size + # 预测图片准备 im = cv2.imread(args.image) diff --git a/examples/vision/ocr/PP-OCRv3/cpp/infer.cc b/examples/vision/ocr/PP-OCRv3/cpp/infer.cc index 911b311e3..90b77679f 100644 --- a/examples/vision/ocr/PP-OCRv3/cpp/infer.cc +++ b/examples/vision/ocr/PP-OCRv3/cpp/infer.cc @@ -33,13 +33,19 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model auto cls_option = option; auto rec_option = option; + // The cls and rec model can inference a batch of images now. + // User could initialize the inference batch size and set them after create PPOCR model. + int cls_batch_size = 1; + int rec_batch_size = 6; + // If use TRT backend, the dynamic shape will be set as follow. // We recommend that users set the length and height of the detection model to a multiple of 32. + // We also recommend that users set the Trt input shape as follow. det_option.SetTrtInputShape("x", {1, 3, 64,64}, {1, 3, 640, 640}, {1, 3, 960, 960}); - cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {10, 3, 48, 320}, {64, 3, 48, 1024}); - rec_option.SetTrtInputShape("x", {1, 3, 48, 10}, {10, 3, 48, 320}, - {64, 3, 48, 2304}); + cls_option.SetTrtInputShape("x", {1, 3, 48, 10}, {cls_batch_size, 3, 48, 320}, {cls_batch_size, 3, 48, 1024}); + rec_option.SetTrtInputShape("x", {1, 3, 48, 10}, {rec_batch_size, 3, 48, 320}, + {rec_batch_size, 3, 48, 2304}); // Users could save TRT cache file to disk as follow. // det_option.SetTrtCacheFile(det_model_dir + sep + "det_trt_cache.trt"); @@ -57,6 +63,12 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model // The classification model is optional, so the PP-OCR can also be connected in series as follows // auto ppocr_v3 = fastdeploy::pipeline::PPOCRv3(&det_model, &rec_model); auto ppocr_v3 = fastdeploy::pipeline::PPOCRv3(&det_model, &cls_model, &rec_model); + + // Set inference batch size for cls model and rec model, the value could be -1 and 1 to positive infinity. + // When inference batch size is set to -1, it means that the inference batch size + // of the cls and rec models will be the same as the number of boxes detected by the det model. + ppocr_v3.SetClsBatchSize(cls_batch_size); + ppocr_v3.SetRecBatchSize(rec_batch_size); if(!ppocr_v3.Initialized()){ std::cerr << "Failed to initialize PP-OCR." << std::endl; diff --git a/examples/vision/ocr/PP-OCRv3/python/infer.py b/examples/vision/ocr/PP-OCRv3/python/infer.py index b6b27b240..1ec962cb5 100644 --- a/examples/vision/ocr/PP-OCRv3/python/infer.py +++ b/examples/vision/ocr/PP-OCRv3/python/infer.py @@ -106,6 +106,11 @@ rec_label_file = args.rec_label_file # 用户也可根据自行需求分别配置 runtime_option = build_option(args) +# PPOCR的cls和rec模型现在已经支持推理一个Batch的数据 +# 定义下面两个变量后, 可用于设置trt输入shape, 并在PPOCR模型初始化后, 完成Batch推理设置 +cls_batch_size = 1 +rec_batch_size = 6 + # 当使用TRT时,分别给三个模型的runtime设置动态shape,并完成模型的创建. # 注意: 需要在检测模型创建完成后,再设置分类模型的动态输入并创建分类模型, 识别模型同理. # 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数. @@ -118,16 +123,18 @@ det_model = fd.vision.ocr.DBDetector( det_model_file, det_params_file, runtime_option=det_option) cls_option = runtime_option -cls_option.set_trt_input_shape("x", [1, 3, 48, 10], [10, 3, 48, 320], - [64, 3, 48, 1024]) +cls_option.set_trt_input_shape("x", [1, 3, 48, 10], + [cls_batch_size, 3, 48, 320], + [cls_batch_size, 3, 48, 1024]) # 用户可以把TRT引擎文件保存至本地 # cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt") cls_model = fd.vision.ocr.Classifier( cls_model_file, cls_params_file, runtime_option=cls_option) rec_option = runtime_option -rec_option.set_trt_input_shape("x", [1, 3, 48, 10], [10, 3, 48, 320], - [64, 3, 48, 2304]) +rec_option.set_trt_input_shape("x", [1, 3, 48, 10], + [rec_batch_size, 3, 48, 320], + [rec_batch_size, 3, 48, 2304]) # 用户可以把TRT引擎文件保存至本地 # rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt") rec_model = fd.vision.ocr.Recognizer( @@ -137,6 +144,12 @@ rec_model = fd.vision.ocr.Recognizer( ppocr_v3 = fd.vision.ocr.PPOCRv3( det_model=det_model, cls_model=cls_model, rec_model=rec_model) +# 给cls和rec模型设置推理时的batch size +# 此值能为-1, 和1到正无穷 +# 当此值为-1时, cls和rec模型的batch size将默认和det模型检测出的框的数量相同 +ppocr_v3.cls_batch_size = cls_batch_size +ppocr_v3.rec_batch_size = rec_batch_size + # 预测图片准备 im = cv2.imread(args.image) diff --git a/examples/vision/segmentation/paddleseg/a311d/README.md b/examples/vision/segmentation/paddleseg/a311d/README.md new file mode 100755 index 000000000..f65172cdd --- /dev/null +++ b/examples/vision/segmentation/paddleseg/a311d/README.md @@ -0,0 +1,11 @@ +# PP-LiteSeg 量化模型在 A311D 上的部署 +目前 FastDeploy 已经支持基于 PaddleLite 部署 PP-LiteSeg 量化模型到 A311D 上。 + +模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md) + + +## 详细部署文档 + +在 A311D 上只支持 C++ 的部署。 + +- [C++部署](cpp) diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt new file mode 100755 index 000000000..baaf8331f --- /dev/null +++ b/examples/vision/segmentation/paddleseg/a311d/cpp/CMakeLists.txt @@ -0,0 +1,38 @@ +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}) +include_directories(${FastDeploy_INCLUDE_DIRS}) + +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) +# 添加FastDeploy库依赖 +target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) + +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install) + +install(TARGETS infer_demo DESTINATION ./) + +install(DIRECTORY models DESTINATION ./) +install(DIRECTORY images DESTINATION ./) +# install(DIRECTORY run_with_adb.sh DESTINATION ./) + +file(GLOB FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/*) +install(PROGRAMS ${FASTDEPLOY_LIBS} DESTINATION lib) + +file(GLOB OPENCV_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/opencv/lib/lib*) +install(PROGRAMS ${OPENCV_LIBS} DESTINATION lib) + +file(GLOB PADDLELITE_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/lib*) +install(PROGRAMS ${PADDLELITE_LIBS} DESTINATION lib) + +file(GLOB TIMVX_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/paddlelite/lib/verisilicon_timvx/*) +install(PROGRAMS ${TIMVX_LIBS} DESTINATION lib) + +file(GLOB ADB_TOOLS run_with_adb.sh) +install(PROGRAMS ${ADB_TOOLS} DESTINATION ./) diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/README.md b/examples/vision/segmentation/paddleseg/a311d/cpp/README.md new file mode 100755 index 000000000..872784188 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/a311d/cpp/README.md @@ -0,0 +1,54 @@ +# 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文件到量化后的模型文件夹内即可.) +- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md) + +## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型 +请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型: +1. 交叉编译编译 FastDeploy 库,具体请参考:[交叉编译 FastDeploy](../../../../../../docs/cn/build_and_install/a311d.md#基于-paddlelite-的-fastdeploy-交叉编译库编译) + +2. 将编译后的库拷贝到当前目录,可使用如下命令: +```bash +cp -r FastDeploy/build/fastdeploy-tmivx/ FastDeploy/examples/vision/segmentation/paddleseg/a311d/cpp +``` + +3. 在当前路径下载部署所需的模型和示例图片: +```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. 编译部署示例,可使入如下命令: +```bash +mkdir build && cd build +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -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/a311d/cpp/infer.cc b/examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc new file mode 100755 index 000000000..b6138e8fb --- /dev/null +++ b/examples/vision/segmentation/paddleseg/a311d/cpp/infer.cc @@ -0,0 +1,65 @@ +// 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 InitAndInfer(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 subgraph_file = model_dir + sep + "subgraph.txt"; + + fastdeploy::RuntimeOption option; + option.UseTimVX(); + option.SetLiteSubgraphPartitionPath(subgraph_file); + + auto model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file,option); + + assert(model.Initialized()); + + 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/quant_model " + "path/to/image " + "e.g ./infer_demo ./ResNet50_vd_quant ./test.jpeg" + << std::endl; + return -1; + } + + std::string model_dir = argv[1]; + std::string test_image = argv[2]; + InitAndInfer(model_dir, test_image); + return 0; +} diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh b/examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh new file mode 100755 index 000000000..aacaed4c5 --- /dev/null +++ b/examples/vision/segmentation/paddleseg/a311d/cpp/run_with_adb.sh @@ -0,0 +1,47 @@ +#!/bin/bash +HOST_SPACE=${PWD} +echo ${HOST_SPACE} +WORK_SPACE=/data/local/tmp/test + +# The first parameter represents the demo name +DEMO_NAME=image_classification_demo +if [ -n "$1" ]; then + DEMO_NAME=$1 +fi + +# The second parameter represents the model name +MODEL_NAME=mobilenet_v1_fp32_224 +if [ -n "$2" ]; then + MODEL_NAME=$2 +fi + +# The third parameter indicates the name of the image to be tested +IMAGE_NAME=0001.jpg +if [ -n "$3" ]; then + IMAGE_NAME=$3 +fi + +# The fourth parameter represents the ID of the device +ADB_DEVICE_NAME= +if [ -n "$4" ]; then + ADB_DEVICE_NAME="-s $4" +fi + +# Set the environment variables required during the running process +EXPORT_ENVIRONMENT_VARIABLES="export GLOG_v=5; export VIV_VX_ENABLE_GRAPH_TRANSFORM=-pcq:1; export VIV_VX_SET_PER_CHANNEL_ENTROPY=100; export TIMVX_BATCHNORM_FUSION_MAX_ALLOWED_QUANT_SCALE_DEVIATION=300000; export VSI_NN_LOG_LEVEL=5;" + +EXPORT_ENVIRONMENT_VARIABLES="${EXPORT_ENVIRONMENT_VARIABLES}export LD_LIBRARY_PATH=${WORK_SPACE}/lib:\$LD_LIBRARY_PATH;" + +# Please install adb, and DON'T run this in the docker. +set -e +adb $ADB_DEVICE_NAME shell "rm -rf $WORK_SPACE" +adb $ADB_DEVICE_NAME shell "mkdir -p $WORK_SPACE" + +# Upload the demo, librarys, model and test images to the device +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/lib $WORK_SPACE +adb $ADB_DEVICE_NAME push ${HOST_SPACE}/${DEMO_NAME} $WORK_SPACE +adb $ADB_DEVICE_NAME push models $WORK_SPACE +adb $ADB_DEVICE_NAME push images $WORK_SPACE + +# Execute the deployment demo +adb $ADB_DEVICE_NAME shell "cd $WORK_SPACE; ${EXPORT_ENVIRONMENT_VARIABLES} chmod +x ./${DEMO_NAME}; ./${DEMO_NAME} ./models/${MODEL_NAME} ./images/$IMAGE_NAME" diff --git a/examples/vision/segmentation/paddleseg/python/infer.py b/examples/vision/segmentation/paddleseg/python/infer.py index 866e32bfb..9df7665a2 100644 --- a/examples/vision/segmentation/paddleseg/python/infer.py +++ b/examples/vision/segmentation/paddleseg/python/infer.py @@ -49,7 +49,7 @@ model = fd.vision.segmentation.PaddleSegModel( # 预测图片分割结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 diff --git a/examples/vision/segmentation/paddleseg/quantize/python/infer.py b/examples/vision/segmentation/paddleseg/quantize/python/infer.py index f95f04d17..85a875c1e 100644 --- a/examples/vision/segmentation/paddleseg/quantize/python/infer.py +++ b/examples/vision/segmentation/paddleseg/quantize/python/infer.py @@ -72,5 +72,5 @@ model = fd.vision.segmentation.PaddleSegModel( # 预测图片检测结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc index bfc108d05..4e02ae32e 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc @@ -15,83 +15,84 @@ #include #include "fastdeploy/vision.h" -void InferHumanPPHumansegv2Lite(const std::string& device = "cpu"); - -int main() { - InferHumanPPHumansegv2Lite("npu"); - return 0; -} - -fastdeploy::RuntimeOption GetOption(const std::string& device) { - auto option = fastdeploy::RuntimeOption(); - if (device == "npu") { - option.UseRKNPU2(); - } else { - option.UseCpu(); - } - return option; -} - -fastdeploy::ModelFormat GetFormat(const std::string& device) { - auto format = fastdeploy::ModelFormat::ONNX; - if (device == "npu") { - format = fastdeploy::ModelFormat::RKNN; - } else { - format = fastdeploy::ModelFormat::ONNX; - } - return format; -} - -std::string GetModelPath(std::string& model_path, const std::string& device) { - if (device == "npu") { - model_path += "rknn"; - } else { - model_path += "onnx"; - } - return model_path; -} - -void InferHumanPPHumansegv2Lite(const std::string& device) { - std::string model_file = - "./model/Portrait_PP_HumanSegV2_Lite_256x144_infer/" - "Portrait_PP_HumanSegV2_Lite_256x144_infer_rk3588."; +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 params_file; - std::string config_file = - "./model/Portrait_PP_HumanSegV2_Lite_256x144_infer/deploy.yaml"; + std::string config_file = model_dir + "/deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseCpu(); + auto format = fastdeploy::ModelFormat::ONNX; - fastdeploy::RuntimeOption option = GetOption(device); - fastdeploy::ModelFormat format = GetFormat(device); - model_file = GetModelPath(model_file, device); auto model = fastdeploy::vision::segmentation::PaddleSegModel( model_file, params_file, config_file, option, format); - if (!model.Initialized()) { std::cerr << "Failed to initialize." << std::endl; return; } - auto image_file = - "./images/portrait_heng.jpg"; + + fastdeploy::TimeCounter tc; + tc.Start(); auto im = cv::imread(image_file); - - if (device == "npu") { - model.GetPreprocessor().DisableNormalizeAndPermute(); - } - fastdeploy::vision::SegmentationResult res; - clock_t start = clock(); if (!model.Predict(im, &res)) { std::cerr << "Failed to predict." << std::endl; return; } - clock_t end = clock(); - auto dur = (double)(end - start); - printf("infer_human_pp_humansegv2_lite_npu use time:%f\n", - (dur / CLOCKS_PER_SEC)); - - std::cout << res.Str() << std::endl; auto vis_im = fastdeploy::vision::VisSegmentation(im, res); - cv::imwrite("human_pp_humansegv2_lite_npu_result.jpg", vis_im); + tc.End(); + tc.PrintInfo("PPSeg in ONNX"); + + cv::imwrite("infer_onnx.jpg", vis_im); std::cout - << "Visualized result saved in ./human_pp_humansegv2_lite_npu_result.jpg" + << "Visualized result saved in ./infer_onnx.jpg" << std::endl; -} \ No newline at end of file +} + +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 params_file; + std::string config_file = model_dir + "/deploy.yaml"; + auto option = fastdeploy::RuntimeOption(); + option.UseRKNPU2(); + auto format = fastdeploy::ModelFormat::RKNN; + + auto model = fastdeploy::vision::segmentation::PaddleSegModel( + model_file, params_file, config_file, option, format); + if (!model.Initialized()) { + std::cerr << "Failed to initialize." << std::endl; + return; + } + model.GetPreprocessor().DisableNormalizeAndPermute(); + + fastdeploy::TimeCounter tc; + tc.Start(); + auto im = cv::imread(image_file); + fastdeploy::vision::SegmentationResult res; + if (!model.Predict(im, &res)) { + std::cerr << "Failed to predict." << std::endl; + return; + } + auto vis_im = fastdeploy::vision::VisSegmentation(im, res); + tc.End(); + tc.PrintInfo("PPSeg in RKNPU2"); + + cv::imwrite("infer_rknn.jpg", vis_im); + std::cout + << "Visualized result saved in ./infer_rknn.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 ./picodet_model_dir ./test.jpeg" + << std::endl; + return -1; + } + + RKNPU2Infer(argv[1], argv[2]); + ONNXInfer(argv[1], argv[2]); + return 0; +} + diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py b/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py index 8841132a9..4168d591d 100644 --- a/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py +++ b/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py @@ -49,11 +49,11 @@ model = fd.vision.segmentation.PaddleSegModel( runtime_option=runtime_option, model_format=fd.ModelFormat.RKNN) -model.disable_normalize_and_permute() +model.preprocessor.disable_normalize_and_permute() # 预测图片分割结果 im = cv2.imread(args.image) -result = model.predict(im.copy()) +result = model.predict(im) print(result) # 可视化结果 diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md b/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md index 6295fa728..bf7cafc3b 100755 --- a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md +++ b/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md @@ -33,7 +33,7 @@ cp -r cityscapes_demo.png images 4. 编译部署示例,可使入如下命令: ```bash mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/timvx.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx .. +cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../fastdeploy-tmivx/toolchain.cmake -DFASTDEPLOY_INSTALL_DIR=${PWD}/../fastdeploy-tmivx -DTARGET_ABI=armhf .. make -j8 make install # 成功编译之后,会生成 install 文件夹,里面有一个运行 demo 和部署所需的库 diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc index 8c9c7456c..f084e6719 100755 --- a/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc +++ b/examples/vision/segmentation/paddleseg/rv1126/cpp/infer.cc @@ -53,7 +53,6 @@ int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Usage: infer_demo path/to/quant_model " "path/to/image " - "run_option, " "e.g ./infer_demo ./ResNet50_vd_quant ./test.jpeg" << std::endl; return -1; diff --git a/fastdeploy/backends/lite/lite_backend.cc b/fastdeploy/backends/lite/lite_backend.cc index 89e3e8931..b6dffc813 100755 --- a/fastdeploy/backends/lite/lite_backend.cc +++ b/fastdeploy/backends/lite/lite_backend.cc @@ -43,24 +43,33 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) { option_ = option; std::vector valid_places; if (option_.enable_int8) { - valid_places.push_back( + if(option_.enable_xpu) { + valid_places.push_back( + paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)}); + } else { + valid_places.push_back( paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)}); + } FDINFO << "Lite::Backend enable_int8 option is ON ! Lite::Backend will " << "inference with int8 precision!" << std::endl; } if (option_.enable_fp16) { - paddle::lite_api::MobileConfig check_fp16_config; - // Determine whether the device supports the FP16 - // instruction set (or whether it is an arm device - // of the armv8.2 architecture) - supported_fp16_ = check_fp16_config.check_fp16_valid(); - if (supported_fp16_) { + if(option_.enable_xpu){ valid_places.push_back( - paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)}); - FDINFO << "Your device is supported fp16 ! Lite::Backend will " - << "inference with fp16 precision!" << std::endl; + paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)}); } else { - FDWARNING << "This device is not supported fp16, will skip fp16 option."; + paddle::lite_api::MobileConfig check_fp16_config; + // Determine whether the device supports the FP16 + // instruction set (or whether it is an arm device + // of the armv8.2 architecture) + supported_fp16_ = check_fp16_config.check_fp16_valid(); + if (supported_fp16_) { + valid_places.push_back( + paddle::lite_api::Place{TARGET(kARM), PRECISION(kFP16)}); + FDINFO << "The device supports FP16, Lite::Backend will inference with FP16 precision." << std::endl; + } else { + FDWARNING << "The device doesn't support FP16, will fallback to FP32."; + } } } if (!option_.nnadapter_subgraph_partition_config_path.empty()) { @@ -90,9 +99,24 @@ void LiteBackend::BuildOption(const LiteBackendOption& option) { valid_places.push_back( paddle::lite_api::Place{TARGET(kARM), PRECISION(kInt8)}); } - - valid_places.push_back( + + if(option_.enable_xpu){ + valid_places.push_back( + paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFloat)}); + valid_places.push_back( + paddle::lite_api::Place{TARGET(kX86), PRECISION(kFloat)}); + config_.set_xpu_dev_per_thread(option_.device_id); + config_.set_xpu_workspace_l3_size_per_thread(option_.xpu_l3_workspace_size); + config_.set_xpu_l3_cache_method(option_.xpu_l3_workspace_size, option_.xpu_locked); + config_.set_xpu_conv_autotune(option_.xpu_autotune, option_.xpu_autotune_file); + config_.set_xpu_multi_encoder_method(option_.xpu_precision, option_.xpu_adaptive_seqlen); + if (option_.xpu_enable_multi_stream) { + config_.enable_xpu_multi_stream(); + } + } else { + valid_places.push_back( paddle::lite_api::Place{TARGET(kARM), PRECISION(kFloat)}); + } config_.set_valid_places(valid_places); if (option_.threads > 0) { config_.set_threads(option_.threads); @@ -170,7 +194,9 @@ bool LiteBackend::InitFromPaddle(const std::string& model_file, auto shape = tensor->shape(); info.shape.assign(shape.begin(), shape.end()); info.name = output_names[i]; - info.dtype = LiteDataTypeToFD(tensor->precision()); + if(!option_.enable_xpu){ + info.dtype = LiteDataTypeToFD(tensor->precision()); + } outputs_desc_.emplace_back(info); } @@ -216,28 +242,28 @@ bool LiteBackend::Infer(std::vector& inputs, // Adjust dims only, allocate lazy. tensor->Resize(inputs[i].shape); if (inputs[i].dtype == FDDataType::FP32) { - tensor->CopyFromCpu( + tensor->CopyFromCpu( reinterpret_cast(const_cast( inputs[i].CpuData()))); } else if (inputs[i].dtype == FDDataType::INT32) { - tensor->CopyFromCpu( + tensor->CopyFromCpu( reinterpret_cast(const_cast( inputs[i].CpuData()))); } else if (inputs[i].dtype == FDDataType::INT8) { - tensor->CopyFromCpu( + tensor->CopyFromCpu( reinterpret_cast(const_cast( inputs[i].CpuData()))); } else if (inputs[i].dtype == FDDataType::UINT8) { - tensor->CopyFromCpu( + tensor->CopyFromCpu( reinterpret_cast(const_cast( inputs[i].CpuData()))); } else if (inputs[i].dtype == FDDataType::INT64) { -#ifdef __aarch64__ - tensor->CopyFromCpu( +#if (defined(__aarch64__) || defined(__x86_64__) || defined(_M_X64) || defined(_M_ARM64)) + tensor->CopyFromCpu( reinterpret_cast(const_cast( inputs[i].CpuData()))); #else - FDASSERT(false, "FDDataType::INT64 is not support for Arm v7 now!"); + FDASSERT(false, "FDDataType::INT64 is not support for x86/armv7 now!"); #endif } else { FDASSERT(false, "Unexpected data type of %d.", inputs[i].dtype); @@ -249,6 +275,9 @@ bool LiteBackend::Infer(std::vector& inputs, outputs->resize(outputs_desc_.size()); for (size_t i = 0; i < outputs_desc_.size(); ++i) { auto tensor = predictor_->GetOutput(i); + if(outputs_desc_[i].dtype != LiteDataTypeToFD(tensor->precision())){ + outputs_desc_[i].dtype = LiteDataTypeToFD(tensor->precision()); + } (*outputs)[i].Resize(tensor->shape(), outputs_desc_[i].dtype, outputs_desc_[i].name); memcpy((*outputs)[i].MutableData(), tensor->data(), diff --git a/fastdeploy/backends/lite/lite_backend.h b/fastdeploy/backends/lite/lite_backend.h index 9a7718739..41232cb7a 100755 --- a/fastdeploy/backends/lite/lite_backend.h +++ b/fastdeploy/backends/lite/lite_backend.h @@ -53,6 +53,15 @@ struct LiteBackendOption { std::string nnadapter_mixed_precision_quantization_config_path = ""; bool enable_timvx = false; bool enable_cann = false; + bool enable_xpu = false; + int device_id = 0; + int xpu_l3_workspace_size = 0xfffc00; + bool xpu_locked = false; + bool xpu_autotune = true; + std::string xpu_autotune_file = ""; + std::string xpu_precision = "int16"; + bool xpu_adaptive_seqlen = false; + bool xpu_enable_multi_stream = false; }; // Convert data type from paddle lite to fastdeploy diff --git a/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc b/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc index 16edf7561..ac9429450 100644 --- a/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc +++ b/fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "fastdeploy/backends/rknpu/rknpu2/rknpu2_backend.h" - +#include "fastdeploy/utils/perf.h" namespace fastdeploy { RKNPU2Backend::~RKNPU2Backend() { // Release memory uniformly here @@ -190,6 +190,7 @@ bool RKNPU2Backend::GetModelInputOutputInfos() { FDERROR << "rknpu2_backend only support input format is NHWC or UNDEFINED" << std::endl; } + // copy input_attrs_ to input tensor info std::string temp_name = input_attrs_[i].name; std::vector temp_shape{}; @@ -197,16 +198,13 @@ bool RKNPU2Backend::GetModelInputOutputInfos() { for (int j = 0; j < input_attrs_[i].n_dims; j++) { temp_shape[j] = (int)input_attrs_[i].dims[j]; } - FDDataType temp_dtype = - fastdeploy::RKNPU2Backend::RknnTensorTypeToFDDataType( - input_attrs_[i].type); + FDDataType temp_dtype = fastdeploy::RKNPU2Backend::RknnTensorTypeToFDDataType(input_attrs_[i].type); TensorInfo temp_input_info = {temp_name, temp_shape, temp_dtype}; inputs_desc_[i] = temp_input_info; } // Get detailed output parameters - output_attrs_ = - (rknn_tensor_attr*)malloc(sizeof(rknn_tensor_attr) * io_num.n_output); + output_attrs_ = (rknn_tensor_attr*)malloc(sizeof(rknn_tensor_attr) * io_num.n_output); memset(output_attrs_, 0, io_num.n_output * sizeof(rknn_tensor_attr)); outputs_desc_.resize(io_num.n_output); @@ -223,15 +221,11 @@ bool RKNPU2Backend::GetModelInputOutputInfos() { return false; } - // If the output dimension is 3, the runtime will automatically change it to 4. + // If the output dimension is 3, the runtime will automatically change it to 4. // Obviously, this is wrong, and manual correction is required here. int n_dims = output_attrs_[i].n_dims; if((n_dims == 4) && (output_attrs_[i].dims[3] == 1)){ n_dims--; - FDWARNING << "The output[" - << i - << "].shape[3] is 1, remove this dim." - << std::endl; } // copy output_attrs_ to output tensor @@ -242,9 +236,8 @@ bool RKNPU2Backend::GetModelInputOutputInfos() { temp_shape[j] = (int)output_attrs_[i].dims[j]; } - FDDataType temp_dtype = - fastdeploy::RKNPU2Backend::RknnTensorTypeToFDDataType( - output_attrs_[i].type); + // The data type of output data is changed to FP32 + FDDataType temp_dtype = FDDataType::FP32; TensorInfo temp_input_info = {temp_name, temp_shape, temp_dtype}; outputs_desc_[i] = temp_input_info; } @@ -261,11 +254,12 @@ bool RKNPU2Backend::GetModelInputOutputInfos() { void RKNPU2Backend::DumpTensorAttr(rknn_tensor_attr& attr) { printf("index=%d, name=%s, n_dims=%d, dims=[%d, %d, %d, %d], " "n_elems=%d, size=%d, fmt=%s, type=%s, " - "qnt_type=%s, zp=%d, scale=%f\n", + "qnt_type=%s, zp=%d, scale=%f, pass_through=%d", attr.index, attr.name, attr.n_dims, attr.dims[0], attr.dims[1], attr.dims[2], attr.dims[3], attr.n_elems, attr.size, get_format_string(attr.fmt), get_type_string(attr.type), - get_qnt_type_string(attr.qnt_type), attr.zp, attr.scale); + get_qnt_type_string(attr.qnt_type), attr.zp, attr.scale, + attr.pass_through); } TensorInfo RKNPU2Backend::GetInputInfo(int index) { @@ -316,7 +310,12 @@ bool RKNPU2Backend::Infer(std::vector& inputs, input_attrs_[i].type = input_type; input_attrs_[i].size = inputs[0].Nbytes(); input_attrs_[i].size_with_stride = inputs[0].Nbytes(); - input_attrs_[i].pass_through = 0; + if(input_attrs_[i].type == RKNN_TENSOR_FLOAT16 || + input_attrs_[i].type == RKNN_TENSOR_FLOAT32){ + FDINFO << "The input model is not a quantitative model. " + "Close the normalize operation." << std::endl; + } + input_mems_[i] = rknn_create_mem(ctx, inputs[i].Nbytes()); if (input_mems_[i] == nullptr) { FDERROR << "rknn_create_mem input_mems_ error." << std::endl; @@ -341,9 +340,13 @@ bool RKNPU2Backend::Infer(std::vector& inputs, FDERROR << "rknn_create_mem output_mems_ error." << std::endl; return false; } - // default output type is depend on model, this requires float32 to compute top5 + + // The data type of output data is changed to FP32 output_attrs_[i].type = RKNN_TENSOR_FLOAT32; + + // default output type is depend on model, this requires float32 to compute top5 ret = rknn_set_io_mem(ctx, output_mems_[i], &output_attrs_[i]); + // set output memory and attribute if (ret != RKNN_SUCC) { FDERROR << "output tensor memory rknn_set_io_mem fail! ret=" << ret @@ -354,7 +357,7 @@ bool RKNPU2Backend::Infer(std::vector& inputs, this->infer_init = true; } - + // Copy input data to input tensor memory for (uint32_t i = 0; i < io_num.n_input; i++) { uint32_t width = input_attrs_[i].dims[2]; @@ -370,7 +373,6 @@ bool RKNPU2Backend::Infer(std::vector& inputs, return false; } } - // run rknn ret = rknn_run(ctx, nullptr); diff --git a/fastdeploy/core/fd_tensor.h b/fastdeploy/core/fd_tensor.h index 3c79b0c88..c6e1ed5cb 100644 --- a/fastdeploy/core/fd_tensor.h +++ b/fastdeploy/core/fd_tensor.h @@ -25,6 +25,7 @@ namespace fastdeploy { struct FASTDEPLOY_DECL FDTensor { + // std::vector data; void* buffer_ = nullptr; std::vector shape = {0}; diff --git a/fastdeploy/core/fd_type.cc b/fastdeploy/core/fd_type.cc index 35de01fe3..a73859dde 100755 --- a/fastdeploy/core/fd_type.cc +++ b/fastdeploy/core/fd_type.cc @@ -65,6 +65,9 @@ std::string Str(const Device& d) { case Device::CANN: out = "Device::CANN"; break; + case Device::XPU: + out = "Device::XPU"; + break; default: out = "Device::UNKOWN"; } @@ -85,6 +88,9 @@ std::ostream& operator<<(std::ostream& out,const Device& d){ case Device::TIMVX: out << "Device::TIMVX"; break; + case Device::XPU: + out << "Device::XPU"; + break; case Device::CANN: out << "Device::CANN"; break; diff --git a/fastdeploy/core/fd_type.h b/fastdeploy/core/fd_type.h index e121e8fdd..ee202a9b2 100755 --- a/fastdeploy/core/fd_type.h +++ b/fastdeploy/core/fd_type.h @@ -22,7 +22,7 @@ namespace fastdeploy { -enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX, CANN}; +enum FASTDEPLOY_DECL Device { CPU, GPU, RKNPU, IPU, TIMVX, XPU, CANN}; FASTDEPLOY_DECL std::string Str(const Device& d); diff --git a/fastdeploy/fastdeploy_model.cc b/fastdeploy/fastdeploy_model.cc index a30c15a7c..185efde0a 100755 --- a/fastdeploy/fastdeploy_model.cc +++ b/fastdeploy/fastdeploy_model.cc @@ -52,6 +52,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() { bool use_rknpu = (runtime_option.device == Device::RKNPU); bool use_timvx = (runtime_option.device == Device::TIMVX); bool use_cann = (runtime_option.device == Device::CANN); + bool use_xpu = (runtime_option.device == Device::XPU); if (use_gpu) { if (!IsSupported(valid_gpu_backends, runtime_option.backend)) { @@ -72,6 +73,10 @@ bool FastDeployModel::InitRuntimeWithSpecifiedBackend() { if (!IsSupported(valid_cann_backends, runtime_option.backend)) { FDERROR << "The valid cann backends of model " << ModelName() << " are " << Str(valid_cann_backends) << ", " << runtime_option.backend << " is not supported." << std::endl; return false; + } else if (use_xpu) { + if (!IsSupported(valid_xpu_backends, runtime_option.backend)) { + FDERROR << "The valid xpu backends of model " << ModelName() << " are " << Str(valid_xpu_backends) << ", " << runtime_option.backend << " is not supported." << std::endl; + return false; } } else if(use_ipu) { if (!IsSupported(valid_ipu_backends, runtime_option.backend)) { @@ -110,6 +115,8 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() { return CreateTimVXBackend(); } else if (runtime_option.device == Device::CANN) { return CreateCANNBackend(); + } else if (runtime_option.device == Device::XPU) { + return CreateXPUBackend(); } else if (runtime_option.device == Device::IPU) { #ifdef WITH_IPU return CreateIpuBackend(); @@ -119,7 +126,7 @@ bool FastDeployModel::InitRuntimeWithSpecifiedDevice() { return false; #endif } - FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX/CANN now." << std::endl; + FDERROR << "Only support CPU/GPU/IPU/RKNPU/TIMVX/XPU/CANN now." << std::endl; return false; } @@ -233,6 +240,30 @@ bool FastDeployModel::CreateTimVXBackend() { return false; } +bool FastDeployModel::CreateXPUBackend() { + if (valid_xpu_backends.size() == 0) { + FDERROR << "There's no valid xpu backends for model: " << ModelName() + << std::endl; + return false; + } + + for (size_t i = 0; i < valid_xpu_backends.size(); ++i) { + if (!IsBackendAvailable(valid_xpu_backends[i])) { + continue; + } + runtime_option.backend = valid_xpu_backends[i]; + runtime_ = std::unique_ptr(new Runtime()); + if (!runtime_->Init(runtime_option)) { + return false; + } + runtime_initialized_ = true; + return true; + } + FDERROR << "Found no valid backend for model: " << ModelName() << std::endl; + return false; +} + + bool FastDeployModel::CreateCANNBackend() { if (valid_cann_backends.size() == 0) { FDERROR << "There's no valid cann backends for model: " << ModelName() @@ -256,6 +287,7 @@ bool FastDeployModel::CreateCANNBackend() { return false; } + bool FastDeployModel::CreateIpuBackend() { if (valid_ipu_backends.size() == 0) { FDERROR << "There's no valid ipu backends for model: " << ModelName() diff --git a/fastdeploy/fastdeploy_model.h b/fastdeploy/fastdeploy_model.h index 529850d64..7e9bac16d 100755 --- a/fastdeploy/fastdeploy_model.h +++ b/fastdeploy/fastdeploy_model.h @@ -48,6 +48,9 @@ class FASTDEPLOY_DECL FastDeployModel { /** Model's valid cann backends. This member defined all the cann backends have successfully tested for the model */ std::vector valid_cann_backends = {}; + /** Model's valid KunlunXin xpu backends. This member defined all the KunlunXin xpu backends have successfully tested for the model + */ + std::vector valid_xpu_backends = {}; /** Model's valid hardware backends. This member defined all the gpu backends have successfully tested for the model */ std::vector valid_rknpu_backends = {}; @@ -115,6 +118,20 @@ class FASTDEPLOY_DECL FastDeployModel { std::vector().swap(reused_output_tensors_); } + virtual fastdeploy::Runtime* CloneRuntime() { + return runtime_->Clone(); + } + + virtual bool SetRuntime(fastdeploy::Runtime* clone_runtime) { + runtime_ = std::unique_ptr(clone_runtime); + return true; + } + + virtual std::unique_ptr Clone() { + FDERROR << ModelName() << " doesn't support Cone() now." << std::endl; + return nullptr; + } + protected: virtual bool InitRuntime(); @@ -132,10 +149,9 @@ class FASTDEPLOY_DECL FastDeployModel { bool CreateIpuBackend(); bool CreateRKNPUBackend(); bool CreateTimVXBackend(); + bool CreateXPUBackend(); bool CreateCANNBackend(); - std::shared_ptr runtime_; - bool runtime_initialized_ = false; // whether to record inference time bool enable_record_time_of_runtime_ = false; diff --git a/fastdeploy/pybind/main.cc.in b/fastdeploy/pybind/main.cc.in index 97aafc64a..1b227edc6 100644 --- a/fastdeploy/pybind/main.cc.in +++ b/fastdeploy/pybind/main.cc.in @@ -35,6 +35,8 @@ pybind11::dtype FDDataTypeToNumpyDataType(const FDDataType& fd_dtype) { dt = pybind11::dtype::of(); } else if (fd_dtype == FDDataType::UINT8) { dt = pybind11::dtype::of(); + } else if (fd_dtype == FDDataType::INT8) { + dt = pybind11::dtype::of(); } else if (fd_dtype == FDDataType::FP16) { dt = pybind11::dtype::of(); } else { @@ -55,12 +57,14 @@ FDDataType NumpyDataTypeToFDDataType(const pybind11::dtype& np_dtype) { return FDDataType::FP64; } else if (np_dtype.is(pybind11::dtype::of())) { return FDDataType::UINT8; + } else if (np_dtype.is(pybind11::dtype::of())) { + return FDDataType::INT8; } else if (np_dtype.is(pybind11::dtype::of())) { return FDDataType::FP16; } FDASSERT(false, "NumpyDataTypeToFDDataType() only support " - "int32/int64/float32/float64/float16 now."); + "int8/int32/int64/float32/float64/float16 now."); return FDDataType::FP32; } diff --git a/fastdeploy/pybind/main.h b/fastdeploy/pybind/main.h index 471579ab1..c0ea4497a 100644 --- a/fastdeploy/pybind/main.h +++ b/fastdeploy/pybind/main.h @@ -67,9 +67,11 @@ FDDataType CTypeToFDDataType() { return FDDataType::FP32; } else if (std::is_same::value) { return FDDataType::FP64; + } else if (std::is_same::value) { + return FDDataType::INT8; } - FDASSERT(false, - "CTypeToFDDataType only support int32/int64/float32/float64 now."); + FDASSERT(false, "CTypeToFDDataType only support " + "int8/int32/int64/float32/float64 now."); return FDDataType::FP32; } diff --git a/fastdeploy/pybind/runtime.cc b/fastdeploy/pybind/runtime.cc old mode 100644 new mode 100755 index 789c0d7d2..7c3a28365 --- a/fastdeploy/pybind/runtime.cc +++ b/fastdeploy/pybind/runtime.cc @@ -24,6 +24,7 @@ void BindRuntime(pybind11::module& m) { .def("use_cpu", &RuntimeOption::UseCpu) .def("use_rknpu2", &RuntimeOption::UseRKNPU2) .def("use_cann", &RuntimeOption::UseCANN) + .def("use_xpu", &RuntimeOption::UseXpu) .def("set_external_stream", &RuntimeOption::SetExternalStream) .def("set_cpu_thread_num", &RuntimeOption::SetCpuThreadNum) .def("use_paddle_backend", &RuntimeOption::UsePaddleBackend) @@ -108,7 +109,21 @@ void BindRuntime(pybind11::module& m) { .def_readwrite("ipu_available_memory_proportion", &RuntimeOption::ipu_available_memory_proportion) .def_readwrite("ipu_enable_half_partial", - &RuntimeOption::ipu_enable_half_partial); + &RuntimeOption::ipu_enable_half_partial) + .def_readwrite("xpu_l3_workspace_size", + &RuntimeOption::xpu_l3_workspace_size) + .def_readwrite("xpu_locked", + &RuntimeOption::xpu_locked) + .def_readwrite("xpu_autotune", + &RuntimeOption::xpu_autotune) + .def_readwrite("xpu_autotune_file", + &RuntimeOption::xpu_autotune_file) + .def_readwrite("xpu_precision", + &RuntimeOption::xpu_precision) + .def_readwrite("xpu_adaptive_seqlen", + &RuntimeOption::xpu_adaptive_seqlen) + .def_readwrite("xpu_enable_multi_stream", + &RuntimeOption::xpu_enable_multi_stream); pybind11::class_(m, "TensorInfo") .def_readwrite("name", &TensorInfo::name) diff --git a/fastdeploy/runtime.cc b/fastdeploy/runtime.cc old mode 100644 new mode 100755 index 30abd15b3..acb9c6977 --- a/fastdeploy/runtime.cc +++ b/fastdeploy/runtime.cc @@ -236,7 +236,26 @@ void RuntimeOption::UseRKNPU2(fastdeploy::rknpu2::CpuName rknpu2_name, void RuntimeOption::UseTimVX() { enable_timvx = true; device = Device::TIMVX; - UseLiteBackend(); +} + +void RuntimeOption::UseXpu(int xpu_id, + int l3_workspace_size, + bool locked, + bool autotune, + const std::string &autotune_file, + const std::string &precision, + bool adaptive_seqlen, + bool enable_multi_stream) { + enable_xpu = true; + device_id = xpu_id; + xpu_l3_workspace_size = l3_workspace_size; + xpu_locked=locked; + xpu_autotune=autotune; + xpu_autotune_file=autotune_file; + xpu_precision = precision; + xpu_adaptive_seqlen=adaptive_seqlen; + xpu_enable_multi_stream=enable_multi_stream; + device = Device::XPU; } void RuntimeOption::UseCANN(){ @@ -567,8 +586,8 @@ bool Runtime::Init(const RuntimeOption& _option) { FDINFO << "Runtime initialized with Backend::OPENVINO in " << Str(option.device) << "." << std::endl; } else if (option.backend == Backend::LITE) { - FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX || option.device == Device::CANN, - "Backend::LITE only supports Device::CPU/Device::TIMVX/Device::CANN."); + FDASSERT(option.device == Device::CPU || option.device == Device::TIMVX || option.device == Device::XPU || option.device == Device::CANN, + "Backend::LITE only supports Device::CPU/Device::TIMVX/Device::XPU."); CreateLiteBackend(); FDINFO << "Runtime initialized with Backend::LITE in " << Str(option.device) << "." << std::endl; @@ -825,6 +844,16 @@ void Runtime::CreateLiteBackend() { lite_option.nnadapter_mixed_precision_quantization_config_path = option.lite_nnadapter_mixed_precision_quantization_config_path; lite_option.enable_timvx = option.enable_timvx; lite_option.enable_cann = option.enable_cann; + lite_option.enable_xpu = option.enable_xpu; + lite_option.device_id = option.device_id; + lite_option.xpu_l3_workspace_size = option.xpu_l3_workspace_size; + lite_option.xpu_locked = option.xpu_locked; + lite_option.xpu_autotune = option.xpu_autotune; + lite_option.xpu_autotune_file = option.xpu_autotune_file; + lite_option.xpu_precision = option.xpu_precision; + lite_option.xpu_adaptive_seqlen = option.xpu_adaptive_seqlen; + lite_option.xpu_enable_multi_stream = option.xpu_enable_multi_stream; + FDASSERT(option.model_format == ModelFormat::PADDLE, "LiteBackend only support model format of ModelFormat::PADDLE"); backend_ = utils::make_unique(); diff --git a/fastdeploy/runtime.h b/fastdeploy/runtime.h old mode 100644 new mode 100755 index d33f5cdce..5c0f63559 --- a/fastdeploy/runtime.h +++ b/fastdeploy/runtime.h @@ -105,6 +105,37 @@ struct FASTDEPLOY_DECL RuntimeOption { /// Use CANN to inference void UseCANN(); + /// + /// \brief Turn on XPU. + /// + /// \param xpu_id the XPU card to use (default is 0). + /// \param l3_workspace_size The size of the video memory allocated by the l3 + /// cache, the maximum is 16M. + /// \param locked Whether the allocated L3 cache can be locked. If false, + /// it means that the L3 cache is not locked, and the allocated L3 + /// cache can be shared by multiple models, and multiple models + /// sharing the L3 cache will be executed sequentially on the card. + /// \param autotune Whether to autotune the conv operator in the model. If + /// true, when the conv operator of a certain dimension is executed + /// for the first time, it will automatically search for a better + /// algorithm to improve the performance of subsequent conv operators + /// of the same dimension. + /// \param autotune_file Specify the path of the autotune file. If + /// autotune_file is specified, the algorithm specified in the + /// file will be used and autotune will not be performed again. + /// \param precision Calculation accuracy of multi_encoder + /// \param adaptive_seqlen Is the input of multi_encoder variable length + /// \param enable_multi_stream Whether to enable the multi stream of xpu. + /// + void UseXpu(int xpu_id = 0, + int l3_workspace_size = 0xfffc00, + bool locked = false, + bool autotune = true, + const std::string& autotune_file = "", + const std::string& precision = "int16", + bool adaptive_seqlen = false, + bool enable_multi_stream = false); + void SetExternalStream(void* external_stream); /* @@ -404,6 +435,7 @@ struct FASTDEPLOY_DECL RuntimeOption { bool enable_timvx = false; bool enable_cann = false; + bool enable_xpu = false; // ======Only for Trt Backend======= std::map> trt_max_shape; @@ -412,7 +444,7 @@ struct FASTDEPLOY_DECL RuntimeOption { std::string trt_serialize_file = ""; bool trt_enable_fp16 = false; bool trt_enable_int8 = false; - size_t trt_max_batch_size = 32; + size_t trt_max_batch_size = 1; size_t trt_max_workspace_size = 1 << 30; // ======Only for PaddleTrt Backend======= std::vector trt_disabled_ops_{}; @@ -436,6 +468,15 @@ struct FASTDEPLOY_DECL RuntimeOption { fastdeploy::rknpu2::CoreMask rknpu2_core_mask_ = fastdeploy::rknpu2::CoreMask::RKNN_NPU_CORE_AUTO; + // ======Only for XPU Backend======= + int xpu_l3_workspace_size = 0xfffc00; + bool xpu_locked = false; + bool xpu_autotune = true; + std::string xpu_autotune_file = ""; + std::string xpu_precision = "int16"; + bool xpu_adaptive_seqlen = false; + bool xpu_enable_multi_stream = false; + std::string model_file = ""; // Path of model file std::string params_file = ""; // Path of parameters file, can be empty // format of input model diff --git a/fastdeploy/vision.h b/fastdeploy/vision.h index 9bea1550e..732f9e7a5 100644 --- a/fastdeploy/vision.h +++ b/fastdeploy/vision.h @@ -28,6 +28,7 @@ #include "fastdeploy/vision/detection/contrib/yolov7end2end_ort.h" #include "fastdeploy/vision/detection/contrib/yolov7end2end_trt.h" #include "fastdeploy/vision/detection/contrib/yolox.h" +#include "fastdeploy/vision/detection/contrib/rknpu2/model.h" #include "fastdeploy/vision/detection/ppdet/model.h" #include "fastdeploy/vision/facealign/contrib/face_landmark_1000.h" #include "fastdeploy/vision/facealign/contrib/pfld.h" @@ -36,6 +37,7 @@ #include "fastdeploy/vision/facedet/contrib/scrfd.h" #include "fastdeploy/vision/facedet/contrib/ultraface.h" #include "fastdeploy/vision/facedet/contrib/yolov5face.h" +#include "fastdeploy/vision/facedet/yolov7-face/yolov7face.h" #include "fastdeploy/vision/faceid/contrib/adaface.h" #include "fastdeploy/vision/faceid/contrib/arcface.h" #include "fastdeploy/vision/faceid/contrib/cosface.h" diff --git a/fastdeploy/vision/classification/ppcls/model.cc b/fastdeploy/vision/classification/ppcls/model.cc index 455bd975a..73f843b71 100755 --- a/fastdeploy/vision/classification/ppcls/model.cc +++ b/fastdeploy/vision/classification/ppcls/model.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "fastdeploy/vision/classification/ppcls/model.h" +#include "fastdeploy/utils/unique_ptr.h" namespace fastdeploy { namespace vision { @@ -29,6 +30,7 @@ PaddleClasModel::PaddleClasModel(const std::string& model_file, valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT}; valid_timvx_backends = {Backend::LITE}; valid_cann_backends = {Backend::LITE}; + valid_xpu_backends = {Backend::LITE}; valid_ipu_backends = {Backend::PDINFER}; } else if (model_format == ModelFormat::ONNX) { valid_cpu_backends = {Backend::ORT, Backend::OPENVINO}; @@ -42,6 +44,12 @@ PaddleClasModel::PaddleClasModel(const std::string& model_file, initialized = Initialize(); } +std::unique_ptr PaddleClasModel::Clone() const { + std::unique_ptr clone_model = utils::make_unique(PaddleClasModel(*this)); + clone_model->SetRuntime(clone_model->CloneRuntime()); + return clone_model; +} + bool PaddleClasModel::Initialize() { if (!InitRuntime()) { FDERROR << "Failed to initialize fastdeploy backend." << std::endl; diff --git a/fastdeploy/vision/classification/ppcls/model.h b/fastdeploy/vision/classification/ppcls/model.h index e24477073..5971147fb 100644 --- a/fastdeploy/vision/classification/ppcls/model.h +++ b/fastdeploy/vision/classification/ppcls/model.h @@ -40,6 +40,12 @@ class FASTDEPLOY_DECL PaddleClasModel : public FastDeployModel { const RuntimeOption& custom_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE); + /** \brief Clone a new PaddleClasModel with less memory usage when multiple instances of the same model are created + * + * \return new PaddleClasModel* type unique pointer + */ + virtual std::unique_ptr Clone() const; + /// Get model's name virtual std::string ModelName() const { return "PaddleClas/Model"; } diff --git a/fastdeploy/vision/classification/ppcls/ppcls_pybind.cc b/fastdeploy/vision/classification/ppcls/ppcls_pybind.cc index 4d54c1405..1873e73e5 100644 --- a/fastdeploy/vision/classification/ppcls/ppcls_pybind.cc +++ b/fastdeploy/vision/classification/ppcls/ppcls_pybind.cc @@ -63,6 +63,9 @@ void BindPaddleClas(pybind11::module& m) { m, "PaddleClasModel") .def(pybind11::init()) + .def("clone", [](vision::classification::PaddleClasModel& self) { + return self.Clone(); + }) .def("predict", [](vision::classification::PaddleClasModel& self, pybind11::array& data) { cv::Mat im = PyArrayToCvMat(data); vision::ClassifyResult result; diff --git a/fastdeploy/vision/detection/contrib/rknpu2/model.h b/fastdeploy/vision/detection/contrib/rknpu2/model.h new file mode 100644 index 000000000..8fe036cb5 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/model.h @@ -0,0 +1,101 @@ +// 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. + +#pragma once +#include "fastdeploy/vision/detection/contrib/rknpu2/rkyolo.h" +namespace fastdeploy { +namespace vision { +namespace detection { + +class FASTDEPLOY_DECL RKYOLOV5 : public RKYOLO { + public: + /** \brief Set path of model file and configuration file, and the configuration of runtime + * + * \param[in] model_file Path of model file, e.g picodet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g picodet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g picodet/infer_cfg.yml + * \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + */ + RKYOLOV5(const std::string& model_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::RKNN) + : RKYOLO(model_file, custom_option, model_format) { + valid_cpu_backends = {}; + valid_gpu_backends = {}; + valid_rknpu_backends = {Backend::RKNPU2}; + std::vector anchors = {10, 13, 16, 30, 33, 23, 30, 61, 62, + 45, 59, 119, 116, 90, 156, 198, 373, 326}; + int anchor_per_branch_ = 3; + GetPostprocessor().SetAnchor(anchors, anchor_per_branch_); + } + + virtual std::string ModelName() const { return "RKYOLOV5"; } +}; + +class FASTDEPLOY_DECL RKYOLOV7 : public RKYOLO { + public: + /** \brief Set path of model file and configuration file, and the configuration of runtime + * + * \param[in] model_file Path of model file, e.g picodet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g picodet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g picodet/infer_cfg.yml + * \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + */ + RKYOLOV7(const std::string& model_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::RKNN) + : RKYOLO(model_file, custom_option, model_format) { + valid_cpu_backends = {}; + valid_gpu_backends = {}; + valid_rknpu_backends = {Backend::RKNPU2}; + std::vector anchors = {12, 16, 19, 36, 40, 28, 36, 75, 76, + 55, 72, 146, 142, 110, 192, 243, 459, 401}; + int anchor_per_branch_ = 3; + GetPostprocessor().SetAnchor(anchors, anchor_per_branch_); + } + + virtual std::string ModelName() const { return "RKYOLOV7"; } +}; + +class FASTDEPLOY_DECL RKYOLOX : public RKYOLO { + public: + /** \brief Set path of model file and configuration file, and the configuration of runtime + * + * \param[in] model_file Path of model file, e.g picodet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g picodet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g picodet/infer_cfg.yml + * \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + */ + RKYOLOX(const std::string& model_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::RKNN) + : RKYOLO(model_file, custom_option, model_format) { + valid_cpu_backends = {}; + valid_gpu_backends = {}; + valid_rknpu_backends = {Backend::RKNPU2}; + std::vector anchors = {10, 13, 16, 30, 33, 23, 30, 61, 62, + 45, 59, 119, 116, 90, 156, 198, 373, 326}; + int anchor_per_branch_ = 1; + GetPostprocessor().SetAnchor(anchors, anchor_per_branch_); + } + + virtual std::string ModelName() const { return "RKYOLOV7"; } +}; + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc new file mode 100755 index 000000000..581cac2e8 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.cc @@ -0,0 +1,214 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2 (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 +// +// 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/detection/contrib/rknpu2/postprocessor.h" +#include "fastdeploy/vision/utils/utils.h" + +namespace fastdeploy { +namespace vision { +namespace detection { + +RKYOLOPostprocessor::RKYOLOPostprocessor() {} + +bool RKYOLOPostprocessor::Run(const std::vector& tensors, + std::vector* results) { + results->resize(tensors[0].shape[0]); + for (int num = 0; num < tensors[0].shape[0]; ++num) { + int validCount = 0; + std::vector filterBoxes; + std::vector boxesScore; + std::vector classId; + for (int i = 0; i < tensors.size(); i++) { + auto tensor_shape = tensors[i].shape; + auto skip_num = std::accumulate(tensor_shape.begin(), tensor_shape.end(), + 1, std::multiplies()); + int skip_address = num * skip_num; + int stride = strides_[i]; + int grid_h = height_ / stride; + int grid_w = width_ / stride; + int* anchor = &(anchors_.data()[i * 2 * anchor_per_branch_]); + if (tensors[i].dtype == FDDataType::FP32) { + validCount = validCount + + ProcessFP16((float*)tensors[i].Data() + skip_address, + anchor, grid_h, grid_w, stride, filterBoxes, + boxesScore, classId, conf_threshold_); + } else { + FDERROR << "RKYOLO Only Support FP32 Model." + << "But the result's type is " + << Str(tensors[i].dtype) + << std::endl; + } + } + + // no object detect + if (validCount <= 0) { + FDINFO << "The number of object detect is 0." << std::endl; + return true; + } + + std::vector indexArray; + for (int i = 0; i < validCount; ++i) { + indexArray.push_back(i); + } + + QuickSortIndiceInverse(boxesScore, 0, validCount - 1, indexArray); + + if (anchor_per_branch_ == 3) { + NMS(validCount, filterBoxes, classId, indexArray, nms_threshold_, false); + } else if (anchor_per_branch_ == 1) { + NMS(validCount, filterBoxes, classId, indexArray, nms_threshold_, true); + } else { + FDERROR << "anchor_per_branch_ only support 3 or 1." << std::endl; + return false; + } + + int last_count = 0; + (*results)[num].Clear(); + (*results)[num].Reserve(validCount); + + /* box valid detect target */ + for (int i = 0; i < validCount; ++i) { + if (indexArray[i] == -1 || boxesScore[i] < conf_threshold_ || + last_count >= obj_num_bbox_max_size) { + continue; + } + int n = indexArray[i]; + float x1 = filterBoxes[n * 4 + 0]; + float y1 = filterBoxes[n * 4 + 1]; + float x2 = x1 + filterBoxes[n * 4 + 2]; + float y2 = y1 + filterBoxes[n * 4 + 3]; + int id = classId[n]; + (*results)[num].boxes.emplace_back(std::array{ + (float)((Clamp(x1, 0, width_) - pad_hw_values_[num][1] / 2) / + scale_[num]), + (float)((Clamp(y1, 0, height_) - pad_hw_values_[num][0] / 2) / + scale_[num]), + (float)((Clamp(x2, 0, width_) - pad_hw_values_[num][1] / 2) / + scale_[num]), + (float)((Clamp(y2, 0, height_) - pad_hw_values_[num][0] / 2) / + scale_[0])}); + (*results)[num].label_ids.push_back(id); + (*results)[num].scores.push_back(boxesScore[i]); + last_count++; + } + } + return true; +} + +int RKYOLOPostprocessor::ProcessFP16(float* input, int* anchor, int grid_h, + int grid_w, int stride, + std::vector& boxes, + std::vector& boxScores, + std::vector& classId, + float threshold) { + + int validCount = 0; + int grid_len = grid_h * grid_w; + // float thres_sigmoid = threshold; + for (int a = 0; a < anchor_per_branch_; a++) { + for (int i = 0; i < grid_h; i++) { + for (int j = 0; j < grid_w; j++) { + float box_confidence = + input[(prob_box_size_ * a + 4) * grid_len + i * grid_w + j]; + if (box_confidence >= threshold) { + int offset = (prob_box_size_ * a) * grid_len + i * grid_w + j; + float* in_ptr = input + offset; + + float maxClassProbs = in_ptr[5 * grid_len]; + int maxClassId = 0; + for (int k = 1; k < obj_class_num_; ++k) { + float prob = in_ptr[(5 + k) * grid_len]; + if (prob > maxClassProbs) { + maxClassId = k; + maxClassProbs = prob; + } + } + float box_conf_f32 = (box_confidence); + float class_prob_f32 = (maxClassProbs); + float limit_score = 0; + if (anchor_per_branch_ == 1) { + limit_score = class_prob_f32; + } else { + limit_score = box_conf_f32 * class_prob_f32; + } + // printf("limit score: %f", limit_score); + if (limit_score > conf_threshold_) { + float box_x, box_y, box_w, box_h; + if (anchor_per_branch_ == 1) { + box_x = *in_ptr; + box_y = (in_ptr[grid_len]); + box_w = exp(in_ptr[2 * grid_len]) * stride; + box_h = exp(in_ptr[3 * grid_len]) * stride; + } else { + box_x = *in_ptr * 2.0 - 0.5; + box_y = (in_ptr[grid_len]) * 2.0 - 0.5; + box_w = (in_ptr[2 * grid_len]) * 2.0; + box_h = (in_ptr[3 * grid_len]) * 2.0; + box_w *= box_w; + box_h *= box_h; + } + box_x = (box_x + j) * (float)stride; + box_y = (box_y + i) * (float)stride; + box_w *= (float)anchor[a * 2]; + box_h *= (float)anchor[a * 2 + 1]; + box_x -= (box_w / 2.0); + box_y -= (box_h / 2.0); + + boxes.push_back(box_x); + boxes.push_back(box_y); + boxes.push_back(box_w); + boxes.push_back(box_h); + boxScores.push_back(box_conf_f32 * class_prob_f32); + classId.push_back(maxClassId); + validCount++; + } + } + } + } + } + return validCount; +} + +int RKYOLOPostprocessor::QuickSortIndiceInverse(std::vector& input, + int left, int right, + std::vector& indices) { + float key; + int key_index; + int low = left; + int high = right; + if (left < right) { + key_index = indices[left]; + key = input[left]; + while (low < high) { + while (low < high && input[high] <= key) { + high--; + } + input[low] = input[high]; + indices[low] = indices[high]; + while (low < high && input[low] >= key) { + low++; + } + input[high] = input[low]; + indices[high] = indices[low]; + } + input[low] = key; + indices[low] = key_index; + QuickSortIndiceInverse(input, left, low - 1, indices); + QuickSortIndiceInverse(input, low + 1, right, indices); + } + return low; +} + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h new file mode 100755 index 000000000..b65479415 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h @@ -0,0 +1,110 @@ +// 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. + +#pragma once + +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" +#include "fastdeploy/vision/detection/contrib/rknpu2/utils.h" +#include +namespace fastdeploy { +namespace vision { +namespace detection { +/*! @brief Postprocessor object for YOLOv5 serials model. + */ +class FASTDEPLOY_DECL RKYOLOPostprocessor { + public: + /** \brief Create a postprocessor instance for YOLOv5 serials model + */ + RKYOLOPostprocessor(); + + /** \brief Process the result of runtime and fill to DetectionResult structure + * + * \param[in] tensors The inference result from runtime + * \param[in] result The output result of detection + * \param[in] ims_info The shape info list, record input_shape and output_shape + * \return true if the postprocess successed, otherwise false + */ + bool Run(const std::vector& tensors, + std::vector* results); + + /// Set nms_threshold, default 0.45 + void SetNMSThreshold(const float& nms_threshold) { + nms_threshold_ = nms_threshold; + } + + /// Set conf_threshold, default 0.25 + void SetConfThreshold(const float& conf_threshold) { + conf_threshold_ = conf_threshold; + } + + /// Get conf_threshold, default 0.25 + float GetConfThreshold() const { return conf_threshold_; } + + /// Get nms_threshold, default 0.45 + float GetNMSThreshold() const { return nms_threshold_; } + + // Set height and weight + void SetHeightAndWeight(int& height, int& width) { + height_ = height; + width_ = width; + } + + // Set pad_hw_values + void SetPadHWValues(std::vector> pad_hw_values) { + pad_hw_values_ = pad_hw_values; + } + + // Set scale + void SetScale(std::vector scale) { + scale_ = scale; + } + + // Set Anchor + void SetAnchor(std::vector anchors, int anchor_per_branch) { + anchors_ = anchors; + anchor_per_branch_ = anchor_per_branch; + } + + private: + std::vector anchors_ = {10, 13, 16, 30, 33, 23, 30, 61, 62, + 45, 59, 119, 116, 90, 156, 198, 373, 326}; + int strides_[3] = {8, 16, 32}; + int height_ = 0; + int width_ = 0; + int anchor_per_branch_ = 0; + + int ProcessFP16(float *input, int *anchor, int grid_h, + int grid_w, int stride, + std::vector &boxes, + std::vector &boxScores, + std::vector &classId, + float threshold); + // Model + int QuickSortIndiceInverse(std::vector& input, int left, int right, + std::vector& indices); + + // post_process values + std::vector> pad_hw_values_; + std::vector scale_; + float nms_threshold_ = 0.45; + float conf_threshold_ = 0.25; + int prob_box_size_ = 85; + int obj_class_num_ = 80; + int obj_num_bbox_max_size = 200; +}; + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc new file mode 100755 index 000000000..a5ce8849e --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.cc @@ -0,0 +1,109 @@ +// 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/detection/contrib/rknpu2/preprocessor.h" +#include "fastdeploy/function/concat.h" + +namespace fastdeploy { +namespace vision { +namespace detection { + +RKYOLOPreprocessor::RKYOLOPreprocessor() { + size_ = {640, 640}; + padding_value_ = {114.0, 114.0, 114.0}; + is_mini_pad_ = false; + is_no_pad_ = false; + is_scale_up_ = true; + stride_ = 32; + max_wh_ = 7680.0; +} + +void RKYOLOPreprocessor::LetterBox(FDMat* mat) { + float scale = + std::min(size_[1] * 1.0 / mat->Height(), size_[0] * 1.0 / mat->Width()); + if (!is_scale_up_) { + scale = std::min(scale, 1.0f); + } + scale_.push_back(scale); + + int resize_h = int(round(mat->Height() * scale)); + int resize_w = int(round(mat->Width() * scale)); + + int pad_w = size_[0] - resize_w; + int pad_h = size_[1] - resize_h; + if (is_mini_pad_) { + pad_h = pad_h % stride_; + pad_w = pad_w % stride_; + } else if (is_no_pad_) { + pad_h = 0; + pad_w = 0; + resize_h = size_[1]; + resize_w = size_[0]; + } + + pad_hw_values_.push_back({pad_h, pad_w}); + + if (std::fabs(scale - 1.0f) > 1e-06) { + Resize::Run(mat, resize_w, resize_h); + } + if (pad_h > 0 || pad_w > 0) { + float half_h = pad_h * 1.0 / 2; + int top = int(round(half_h - 0.1)); + int bottom = int(round(half_h + 0.1)); + float half_w = pad_w * 1.0 / 2; + int left = int(round(half_w - 0.1)); + int right = int(round(half_w + 0.1)); + Pad::Run(mat, top, bottom, left, right, padding_value_); + } +} + +bool RKYOLOPreprocessor::Preprocess(FDMat* mat, FDTensor* output) { + // RKYOLO's preprocess steps + // 1. letterbox + // 2. convert_and_permute(swap_rb=true) + LetterBox(mat); + BGR2RGB::Run(mat); + mat->ShareWithTensor(output); + output->ExpandDim(0); // reshape to n, h, w, c + return true; +} + +bool RKYOLOPreprocessor::Run(std::vector* images, + std::vector* outputs) { + if (images->size() == 0) { + FDERROR << "The size of input images should be greater than 0." + << std::endl; + return false; + } + outputs->resize(1); + // Concat all the preprocessed data to a batch tensor + std::vector tensors(images->size()); + for (size_t i = 0; i < images->size(); ++i) { + if (!Preprocess(&(*images)[i], &tensors[i])) { + FDERROR << "Failed to preprocess input image." << std::endl; + return false; + } + } + + if (tensors.size() == 1) { + (*outputs)[0] = std::move(tensors[0]); + } else { + function::Concat(tensors, &((*outputs)[0]), 0); + } + return true; +} + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h new file mode 100755 index 000000000..ad08dd751 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h @@ -0,0 +1,99 @@ +// 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. + +#pragma once +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" + +namespace fastdeploy { +namespace vision { +namespace detection { +/*! @brief Preprocessor object for YOLOv5 serials model. + */ +class FASTDEPLOY_DECL RKYOLOPreprocessor { + public: + /** \brief Create a preprocessor instance for YOLOv5 serials model + */ + RKYOLOPreprocessor(); + + /** \brief Process the input image and prepare input tensors for runtime + * + * \param[in] images The input image data list, all the elements are returned by cv::imread() + * \param[in] outputs The output tensors which will feed in runtime + * \param[in] ims_info The shape info list, record input_shape and output_shape + * \return true if the preprocess successed, otherwise false + */ + bool Run(std::vector* images, std::vector* outputs); + + /// Set target size, tuple of (width, height), default size = {640, 640} + void SetSize(const std::vector& size) { size_ = size; } + + /// Get target size, tuple of (width, height), default size = {640, 640} + std::vector GetSize() const { return size_; } + + /// Set padding value, size should be the same as channels + void SetPaddingValue(const std::vector& padding_value) { + padding_value_ = padding_value; + } + + /// Get padding value, size should be the same as channels + std::vector GetPaddingValue() const { return padding_value_; } + + /// Set is_scale_up, if is_scale_up is false, the input image only + /// can be zoom out, the maximum resize scale cannot exceed 1.0, default true + void SetScaleUp(bool is_scale_up) { is_scale_up_ = is_scale_up; } + + /// Get is_scale_up, default true + bool GetScaleUp() const { return is_scale_up_; } + + std::vector> GetPadHWValues() const { + return pad_hw_values_; + } + std::vector GetScale() const { return scale_; } + + protected: + bool Preprocess(FDMat* mat, FDTensor* output); + + void LetterBox(FDMat* mat); + + // target size, tuple of (width, height), default size = {640, 640} + std::vector size_; + + // padding value, size should be the same as channels + std::vector padding_value_; + + // only pad to the minimum rectange which height and width is times of stride + bool is_mini_pad_; + + // while is_mini_pad = false and is_no_pad = true, + // will resize the image to the set size + bool is_no_pad_; + + // if is_scale_up is false, the input image only can be zoom out, + // the maximum resize scale cannot exceed 1.0 + bool is_scale_up_; + + // padding stride, for is_mini_pad + int stride_; + + // for offseting the boxes by classes when using NMS + float max_wh_; + + std::vector> pad_hw_values_; + std::vector scale_; +}; + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc new file mode 100644 index 000000000..49f5804af --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.cc @@ -0,0 +1,83 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT +// +// 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/detection/contrib/rknpu2/rkyolo.h" + +namespace fastdeploy { +namespace vision { +namespace detection { + +RKYOLO::RKYOLO(const std::string& model_file, + const fastdeploy::RuntimeOption& custom_option, + const fastdeploy::ModelFormat& model_format) { + if (model_format == ModelFormat::RKNN) { + valid_cpu_backends = {}; + valid_gpu_backends = {}; + valid_rknpu_backends = {Backend::RKNPU2}; + } else { + FDERROR << "RKYOLO Only Support run in RKNPU2" << std::endl; + } + runtime_option = custom_option; + runtime_option.model_format = model_format; + runtime_option.model_file = model_file; + initialized = Initialize(); +} + +bool RKYOLO::Initialize() { + if (!InitRuntime()) { + FDERROR << "Failed to initialize fastdeploy backend." << std::endl; + return false; + } + auto size = GetPreprocessor().GetSize(); + GetPostprocessor().SetHeightAndWeight(size[0], size[1]); + return true; +} + +bool RKYOLO::Predict(const cv::Mat& im, DetectionResult* result) { + std::vector results; + if (!BatchPredict({im}, &results)) { + return false; + } + *result = std::move(results[0]); + return true; +} + +bool RKYOLO::BatchPredict(const std::vector& images, + std::vector* results) { + std::vector fd_images = WrapMat(images); + + if (!preprocessor_.Run(&fd_images, &reused_input_tensors_)) { + FDERROR << "Failed to preprocess the input image." << std::endl; + return false; + } + + reused_input_tensors_[0].name = InputInfoOfRuntime(0).name; + if (!Infer(reused_input_tensors_, &reused_output_tensors_)) { + FDERROR << "Failed to inference by runtime." << std::endl; + return false; + } + + auto pad_hw_values_ = preprocessor_.GetPadHWValues(); + postprocessor_.SetPadHWValues(preprocessor_.GetPadHWValues()); + postprocessor_.SetScale(preprocessor_.GetScale()); + if (!postprocessor_.Run(reused_output_tensors_, results)) { + FDERROR << "Failed to postprocess the inference results by runtime." + << std::endl; + return false; + } + return true; +} + +} // namespace detection +} // namespace vision +} // namespace fastdeploy \ No newline at end of file diff --git a/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.h b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.h new file mode 100644 index 000000000..d7190eb73 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo.h @@ -0,0 +1,64 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT +// +// 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. + +#pragma once + +#include "fastdeploy/fastdeploy_model.h" +#include "fastdeploy/vision/detection/contrib/rknpu2/postprocessor.h" +#include "fastdeploy/vision/detection/contrib/rknpu2/preprocessor.h" + +namespace fastdeploy { +namespace vision { +namespace detection { + +class FASTDEPLOY_DECL RKYOLO : public FastDeployModel { + public: + RKYOLO(const std::string& model_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::RKNN); + + std::string ModelName() const { return "RKYOLO"; } + + /** \brief Predict the detection result for an input image + * + * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format + * \param[in] result The output detection result will be writen to this structure + * \return true if the prediction successed, otherwise false + */ + virtual bool Predict(const cv::Mat& img, DetectionResult* result); + + /** \brief Predict the detection results for a batch of input images + * + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * \return true if the prediction successed, otherwise false + */ + virtual bool BatchPredict(const std::vector& imgs, + std::vector* results); + + /// Get preprocessor reference of YOLOv5 + RKYOLOPreprocessor& GetPreprocessor() { return preprocessor_; } + + /// Get postprocessor reference of YOLOv5 + RKYOLOPostprocessor& GetPostprocessor() { return postprocessor_; } + + protected: + bool Initialize(); + RKYOLOPreprocessor preprocessor_; + RKYOLOPostprocessor postprocessor_; +}; + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/rkyolo_pybind.cc b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo_pybind.cc new file mode 100755 index 000000000..716464458 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/rkyolo_pybind.cc @@ -0,0 +1,95 @@ +// 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/pybind/main.h" + +namespace fastdeploy { +void BindRKYOLO(pybind11::module& m) { + pybind11::class_( + m, "RKYOLOPreprocessor") + .def(pybind11::init<>()) + .def("run", [](vision::detection::RKYOLOPreprocessor& self, + std::vector& im_list) { + std::vector images; + for (size_t i = 0; i < im_list.size(); ++i) { + images.push_back(vision::WrapMat(PyArrayToCvMat(im_list[i]))); + } + std::vector outputs; + if (!self.Run(&images, &outputs)) { + throw std::runtime_error("Failed to preprocess the input data in PaddleClasPreprocessor."); + } + for (size_t i = 0; i < outputs.size(); ++i) { + outputs[i].StopSharing(); + } + return outputs; + }) + .def_property("size", &vision::detection::RKYOLOPreprocessor::GetSize, + &vision::detection::RKYOLOPreprocessor::SetSize) + .def_property("padding_value", &vision::detection::RKYOLOPreprocessor::GetPaddingValue, + &vision::detection::RKYOLOPreprocessor::SetPaddingValue) + .def_property("is_scale_up", &vision::detection::RKYOLOPreprocessor::GetScaleUp, + &vision::detection::RKYOLOPreprocessor::SetScaleUp); + + pybind11::class_( + m, "RKYOLOPostprocessor") + .def(pybind11::init<>()) + .def("run", [](vision::detection::RKYOLOPostprocessor& self, + std::vector& inputs) { + std::vector results; + if (!self.Run(inputs, &results)) { + throw std::runtime_error("Failed to postprocess the runtime result in RKYOLOV5Postprocessor."); + } + return results; + }) + .def("run", [](vision::detection::RKYOLOPostprocessor& self, + std::vector& input_array) { + std::vector results; + std::vector inputs; + PyArrayToTensorList(input_array, &inputs, /*share_buffer=*/true); + if (!self.Run(inputs, &results)) { + throw std::runtime_error("Failed to postprocess the runtime result in RKYOLOV5Postprocessor."); + } + return results; + }) + .def_property("conf_threshold", &vision::detection::RKYOLOPostprocessor::GetConfThreshold, + &vision::detection::RKYOLOPostprocessor::SetConfThreshold) + .def_property("nms_threshold", &vision::detection::RKYOLOPostprocessor::GetNMSThreshold, + &vision::detection::RKYOLOPostprocessor::SetNMSThreshold); + + pybind11::class_(m, "RKYOLOV5") + .def(pybind11::init()) + .def("predict", + [](vision::detection::RKYOLOV5& self, + pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::DetectionResult res; + self.Predict(mat, &res); + return res; + }) + .def("batch_predict", [](vision::detection::RKYOLOV5& self, + std::vector& data) { + std::vector images; + for (size_t i = 0; i < data.size(); ++i) { + images.push_back(PyArrayToCvMat(data[i])); + } + std::vector results; + self.BatchPredict(images, &results); + return results; + }) + .def_property_readonly("preprocessor", &vision::detection::RKYOLOV5::GetPreprocessor) + .def_property_readonly("postprocessor", &vision::detection::RKYOLOV5::GetPostprocessor); +} +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/rknpu2/utils.cc b/fastdeploy/vision/detection/contrib/rknpu2/utils.cc new file mode 100644 index 000000000..4271def4a --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/utils.cc @@ -0,0 +1,93 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT +// +// 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/detection/contrib/rknpu2/utils.h" +namespace fastdeploy { +namespace vision { +namespace detection { +float Clamp(float val, int min, int max) { + return val > min ? (val < max ? val : max) : min; +} + +float Sigmoid(float x) { return 1.0 / (1.0 + expf(-x)); } + +float UnSigmoid(float y) { return -1.0 * logf((1.0 / y) - 1.0); } + +inline int32_t __clip(float val, float min, float max) { + float f = val <= min ? min : (val >= max ? max : val); + return f; +} + +int8_t QntF32ToAffine(float f32, int32_t zp, float scale) { + float dst_val = (f32 / scale) + zp; + int8_t res = (int8_t)__clip(dst_val, -128, 127); + return res; +} + +float DeqntAffineToF32(int8_t qnt, int32_t zp, float scale) { + return ((float)qnt - (float)zp) * scale; +} + +static float CalculateOverlap(float xmin0, float ymin0, float xmax0, + float ymax0, float xmin1, float ymin1, + float xmax1, float ymax1) { + float w = fmax(0.f, fmin(xmax0, xmax1) - fmax(xmin0, xmin1) + 1.0); + float h = fmax(0.f, fmin(ymax0, ymax1) - fmax(ymin0, ymin1) + 1.0); + float i = w * h; + float u = (xmax0 - xmin0 + 1.0) * (ymax0 - ymin0 + 1.0) + + (xmax1 - xmin1 + 1.0) * (ymax1 - ymin1 + 1.0) - i; + return u <= 0.f ? 0.f : (i / u); +} + +int NMS(int valid_count, std::vector& output_locations, + std::vector& class_id, std::vector& order, float threshold, + bool class_agnostic) { + // printf("class_agnostic: %d\n", class_agnostic); + for (int i = 0; i < valid_count; ++i) { + if (order[i] == -1) { + continue; + } + int n = order[i]; + for (int j = i + 1; j < valid_count; ++j) { + int m = order[j]; + if (m == -1) { + continue; + } + + if (!class_agnostic && class_id[n] != class_id[m]) { + continue; + } + + float xmin0 = output_locations[n * 4 + 0]; + float ymin0 = output_locations[n * 4 + 1]; + float xmax0 = output_locations[n * 4 + 0] + output_locations[n * 4 + 2]; + float ymax0 = output_locations[n * 4 + 1] + output_locations[n * 4 + 3]; + + float xmin1 = output_locations[m * 4 + 0]; + float ymin1 = output_locations[m * 4 + 1]; + float xmax1 = output_locations[m * 4 + 0] + output_locations[m * 4 + 2]; + float ymax1 = output_locations[m * 4 + 1] + output_locations[m * 4 + 3]; + + float iou = CalculateOverlap(xmin0, ymin0, xmax0, ymax0, xmin1, ymin1, + xmax1, ymax1); + + if (iou > threshold) { + order[j] = -1; + } + } + } + return 0; +} +} // namespace detection +} // namespace vision +} // namespace fastdeploy \ No newline at end of file diff --git a/fastdeploy/vision/detection/contrib/rknpu2/utils.h b/fastdeploy/vision/detection/contrib/rknpu2/utils.h new file mode 100644 index 000000000..1fa533082 --- /dev/null +++ b/fastdeploy/vision/detection/contrib/rknpu2/utils.h @@ -0,0 +1,34 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT +// +// 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. +#pragma once +#include +#include +#include + +namespace fastdeploy { +namespace vision { +namespace detection { +float Clamp(float val, int min, int max); +float Sigmoid(float x); +float UnSigmoid(float y); +inline static int32_t __clip(float val, float min, float max); +int8_t QntF32ToAffine(float f32, int32_t zp, float scale); +float DeqntAffineToF32(int8_t qnt, int32_t zp, float scale); +int NMS(int valid_count, std::vector& output_locations, + std::vector& class_id, std::vector& order, float threshold, + bool class_agnostic); + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc index 5310202bd..14704aa22 100755 --- a/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc +++ b/fastdeploy/vision/detection/contrib/yolov5/yolov5.cc @@ -27,6 +27,7 @@ YOLOv5::YOLOv5(const std::string& model_file, const std::string& params_file, } else { valid_cpu_backends = {Backend::PDINFER, Backend::ORT, Backend::LITE}; valid_gpu_backends = {Backend::PDINFER, Backend::ORT, Backend::TRT}; + valid_xpu_backends = {Backend::LITE}; valid_timvx_backends = {Backend::LITE}; valid_cann_backends = {Backend::LITE}; } diff --git a/fastdeploy/vision/detection/detection_pybind.cc b/fastdeploy/vision/detection/detection_pybind.cc index b3a7a6ad9..9d585e18c 100644 --- a/fastdeploy/vision/detection/detection_pybind.cc +++ b/fastdeploy/vision/detection/detection_pybind.cc @@ -27,6 +27,7 @@ void BindNanoDetPlus(pybind11::module& m); void BindPPDet(pybind11::module& m); void BindYOLOv7End2EndTRT(pybind11::module& m); void BindYOLOv7End2EndORT(pybind11::module& m); +void BindRKYOLO(pybind11::module& m); void BindDetection(pybind11::module& m) { auto detection_module = @@ -42,5 +43,6 @@ void BindDetection(pybind11::module& m) { BindNanoDetPlus(detection_module); BindYOLOv7End2EndTRT(detection_module); BindYOLOv7End2EndORT(detection_module); + BindRKYOLO(detection_module); } } // namespace fastdeploy diff --git a/fastdeploy/vision/detection/ppdet/base.cc b/fastdeploy/vision/detection/ppdet/base.cc index 0d4e0f290..489e63634 100755 --- a/fastdeploy/vision/detection/ppdet/base.cc +++ b/fastdeploy/vision/detection/ppdet/base.cc @@ -1,6 +1,7 @@ #include "fastdeploy/vision/detection/ppdet/base.h" #include "fastdeploy/vision/utils/utils.h" #include "yaml-cpp/yaml.h" +#include "fastdeploy/utils/unique_ptr.h" namespace fastdeploy { namespace vision { @@ -18,6 +19,12 @@ PPDetBase::PPDetBase(const std::string& model_file, runtime_option.params_file = params_file; } +std::unique_ptr PPDetBase::Clone() const { + std::unique_ptr clone_model = fastdeploy::utils::make_unique(PPDetBase(*this)); + clone_model->SetRuntime(clone_model->CloneRuntime()); + return clone_model; +} + bool PPDetBase::Initialize() { if (!InitRuntime()) { FDERROR << "Failed to initialize fastdeploy backend." << std::endl; diff --git a/fastdeploy/vision/detection/ppdet/base.h b/fastdeploy/vision/detection/ppdet/base.h index bffc477a5..7465d54b9 100644 --- a/fastdeploy/vision/detection/ppdet/base.h +++ b/fastdeploy/vision/detection/ppdet/base.h @@ -45,6 +45,12 @@ class FASTDEPLOY_DECL PPDetBase : public FastDeployModel { const RuntimeOption& custom_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE); + /** \brief Clone a new PaddleDetModel with less memory usage when multiple instances of the same model are created + * + * \return new PaddleDetModel* type unique pointer + */ + virtual std::unique_ptr Clone() const; + /// Get model's name virtual std::string ModelName() const { return "PaddleDetection/BaseModel"; } diff --git a/fastdeploy/vision/detection/ppdet/model.h b/fastdeploy/vision/detection/ppdet/model.h index 8af006fad..1187b1290 100755 --- a/fastdeploy/vision/detection/ppdet/model.h +++ b/fastdeploy/vision/detection/ppdet/model.h @@ -183,6 +183,70 @@ class FASTDEPLOY_DECL SSD : public PPDetBase { virtual std::string ModelName() const { return "PaddleDetection/SSD"; } }; +class FASTDEPLOY_DECL PaddleYOLOv5 : public PPDetBase { + public: + PaddleYOLOv5(const std::string& model_file, const std::string& params_file, + const std::string& config_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) + : PPDetBase(model_file, params_file, config_file, custom_option, + model_format) { + valid_cpu_backends = {Backend::ORT, Backend::PDINFER}; + valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT}; + initialized = Initialize(); + } + + virtual std::string ModelName() const { return "PaddleDetection/YOLOv5"; } +}; + +class FASTDEPLOY_DECL PaddleYOLOv6 : public PPDetBase { + public: + PaddleYOLOv6(const std::string& model_file, const std::string& params_file, + const std::string& config_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) + : PPDetBase(model_file, params_file, config_file, custom_option, + model_format) { + valid_cpu_backends = {Backend::OPENVINO, Backend::ORT, Backend::PDINFER}; + valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT}; + initialized = Initialize(); + } + + virtual std::string ModelName() const { return "PaddleDetection/YOLOv6"; } +}; + +class FASTDEPLOY_DECL PaddleYOLOv7 : public PPDetBase { + public: + PaddleYOLOv7(const std::string& model_file, const std::string& params_file, + const std::string& config_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) + : PPDetBase(model_file, params_file, config_file, custom_option, + model_format) { + valid_cpu_backends = {Backend::ORT, Backend::PDINFER}; + valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT}; + initialized = Initialize(); + } + + virtual std::string ModelName() const { return "PaddleDetection/YOLOv7"; } +}; + +class FASTDEPLOY_DECL RTMDet : public PPDetBase { + public: + RTMDet(const std::string& model_file, const std::string& params_file, + const std::string& config_file, + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::PADDLE) + : PPDetBase(model_file, params_file, config_file, custom_option, + model_format) { + valid_cpu_backends = {Backend::OPENVINO, Backend::ORT, Backend::PDINFER}; + valid_gpu_backends = {Backend::ORT, Backend::PDINFER, Backend::TRT}; + initialized = Initialize(); + } + + virtual std::string ModelName() const { return "PaddleDetection/RTMDet"; } +}; + } // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc b/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc index fedf3f795..09c89dfce 100644 --- a/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc +++ b/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc @@ -77,6 +77,9 @@ void BindPPDet(pybind11::module& m) { self.BatchPredict(images, &results); return results; }) + .def("clone", [](vision::detection::PPDetBase& self) { + return self.Clone(); + }) .def_property_readonly("preprocessor", &vision::detection::PPDetBase::GetPreprocessor) .def_property_readonly("postprocessor", &vision::detection::PPDetBase::GetPostprocessor); @@ -112,5 +115,21 @@ void BindPPDet(pybind11::module& m) { pybind11::class_(m, "SSD") .def(pybind11::init()); + + pybind11::class_(m, "PaddleYOLOv5") + .def(pybind11::init()); + + pybind11::class_(m, "PaddleYOLOv6") + .def(pybind11::init()); + + pybind11::class_(m, "PaddleYOLOv7") + .def(pybind11::init()); + + pybind11::class_(m, "RTMDet") + .def(pybind11::init()); } } // namespace fastdeploy diff --git a/fastdeploy/vision/facedet/facedet_pybind.cc b/fastdeploy/vision/facedet/facedet_pybind.cc index 3d9a812af..e5a62542d 100644 --- a/fastdeploy/vision/facedet/facedet_pybind.cc +++ b/fastdeploy/vision/facedet/facedet_pybind.cc @@ -19,6 +19,7 @@ namespace fastdeploy { void BindRetinaFace(pybind11::module& m); void BindUltraFace(pybind11::module& m); void BindYOLOv5Face(pybind11::module& m); +void BindYOLOv7Face(pybind11::module& m); void BindSCRFD(pybind11::module& m); void BindFaceDet(pybind11::module& m) { @@ -26,6 +27,7 @@ void BindFaceDet(pybind11::module& m) { BindRetinaFace(facedet_module); BindUltraFace(facedet_module); BindYOLOv5Face(facedet_module); + BindYOLOv7Face(facedet_module); BindSCRFD(facedet_module); } } // namespace fastdeploy diff --git a/fastdeploy/vision/facedet/yolov7-face/postprocessor.cc b/fastdeploy/vision/facedet/yolov7-face/postprocessor.cc new file mode 100644 index 000000000..e2c92a6d1 --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/postprocessor.cc @@ -0,0 +1,101 @@ +// 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/facedet/yolov7-face/postprocessor.h" +#include "fastdeploy/vision/utils/utils.h" + +namespace fastdeploy { + +namespace vision { + +namespace facedet { + +Yolov7FacePostprocessor::Yolov7FacePostprocessor() { + conf_threshold_ = 0.5; + nms_threshold_ = 0.45; + max_wh_ = 7680.0; +} + +bool Yolov7FacePostprocessor::Run(const std::vector& infer_result, + std::vector* results, + const std::vector>>& ims_info) { + int batch = infer_result[0].shape[0]; + + results->resize(batch); + + for (size_t bs = 0; bs < batch; ++bs) { + (*results)[bs].Clear(); + (*results)[bs].Reserve(infer_result[0].shape[1]); + if (infer_result[0].dtype != FDDataType::FP32) { + FDERROR << "Only support post process with float32 data." << std::endl; + return false; + } + const float* data = reinterpret_cast(infer_result[0].Data()) + bs * infer_result[0].shape[1] * infer_result[0].shape[2]; + for (size_t i = 0; i < infer_result[0].shape[1]; ++i) { + int s = i * infer_result[0].shape[2]; + float confidence = data[s + 4]; + const float* reg_cls_ptr = data + s; + const float* class_score = data + s + 5; + confidence *= (*class_score); + // filter boxes by conf_threshold + if (confidence <= conf_threshold_) { + continue; + } + float x = reg_cls_ptr[0]; + float y = reg_cls_ptr[1]; + float w = reg_cls_ptr[2]; + float h = reg_cls_ptr[3]; + + // convert from [x, y, w, h] to [x1, y1, x2, y2] + (*results)[bs].boxes.emplace_back(std::array{ + (x - w / 2.f), (y - h / 2.f), (x + w / 2.f), (y + h / 2.f)}); + (*results)[bs].scores.push_back(confidence); + } + + if ((*results)[bs].boxes.size() == 0) { + return true; + } + + utils::NMS(&((*results)[bs]), nms_threshold_); + + // scale the boxes to the origin image shape + auto iter_out = ims_info[bs].find("output_shape"); + auto iter_ipt = ims_info[bs].find("input_shape"); + FDASSERT(iter_out != ims_info[bs].end() && iter_ipt != ims_info[bs].end(), + "Cannot find input_shape or output_shape from im_info."); + float out_h = iter_out->second[0]; + float out_w = iter_out->second[1]; + float ipt_h = iter_ipt->second[0]; + float ipt_w = iter_ipt->second[1]; + float scale = std::min(out_h / ipt_h, out_w / ipt_w); + for (size_t i = 0; i < (*results)[bs].boxes.size(); ++i) { + float pad_h = (out_h - ipt_h * scale) / 2; + float pad_w = (out_w - ipt_w * scale) / 2; + // clip box + (*results)[bs].boxes[i][0] = std::max(((*results)[bs].boxes[i][0] - pad_w) / scale, 0.0f); + (*results)[bs].boxes[i][1] = std::max(((*results)[bs].boxes[i][1] - pad_h) / scale, 0.0f); + (*results)[bs].boxes[i][2] = std::max(((*results)[bs].boxes[i][2] - pad_w) / scale, 0.0f); + (*results)[bs].boxes[i][3] = std::max(((*results)[bs].boxes[i][3] - pad_h) / scale, 0.0f); + (*results)[bs].boxes[i][0] = std::min((*results)[bs].boxes[i][0], ipt_w - 1.0f); + (*results)[bs].boxes[i][1] = std::min((*results)[bs].boxes[i][1], ipt_h - 1.0f); + (*results)[bs].boxes[i][2] = std::min((*results)[bs].boxes[i][2], ipt_w - 1.0f); + (*results)[bs].boxes[i][3] = std::min((*results)[bs].boxes[i][3], ipt_h - 1.0f); + } + } + return true; +} + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/facedet/yolov7-face/postprocessor.h b/fastdeploy/vision/facedet/yolov7-face/postprocessor.h new file mode 100644 index 000000000..4a1b0d852 --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/postprocessor.h @@ -0,0 +1,68 @@ +// 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. + +#pragma once +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" + +namespace fastdeploy { + +namespace vision { + +namespace facedet { + +class FASTDEPLOY_DECL Yolov7FacePostprocessor{ + public: + /*! @brief Postprocessor object for YOLOv7Face serials model. + */ + Yolov7FacePostprocessor(); + + /** \brief Process the result of runtime and fill to FaceDetectionResult structure + * + * \param[in] infer_result The inference result from runtime + * \param[in] results The output result of detection + * \param[in] ims_info The shape info list, record input_shape and output_shape + * \return true if the postprocess successed, otherwise false + */ + bool Run(const std::vector& infer_result, + std::vector* results, + const std::vector>>& ims_info); + + /// Set conf_threshold, default 0.5 + void SetConfThreshold(const float& conf_threshold) { + conf_threshold_ = conf_threshold; + } + + /// Get conf_threshold, default 0.5 + float GetConfThreshold() const { return conf_threshold_; } + + /// Set nms_threshold, default 0.45 + void SetNMSThreshold(const float& nms_threshold) { + nms_threshold_ = nms_threshold; + } + + /// Get nms_threshold, default 0.45 + float GetNMSThreshold() const { return nms_threshold_; } + + protected: + float conf_threshold_; + float nms_threshold_; + bool multi_label_; + float max_wh_; +}; + +} // namespace facedet +} // namespace vision +} // namespace fastdeploy diff --git a/fastdeploy/vision/facedet/yolov7-face/preprocessor.cc b/fastdeploy/vision/facedet/yolov7-face/preprocessor.cc new file mode 100644 index 000000000..83301d76d --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/preprocessor.cc @@ -0,0 +1,120 @@ +// 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/facedet/yolov7-face/preprocessor.h" +#include "fastdeploy/function/concat.h" +#include "fastdeploy/vision/common/processors/mat.h" + +namespace fastdeploy { + +namespace vision { + +namespace facedet { + +Yolov7FacePreprocessor::Yolov7FacePreprocessor() { + size_ = {640, 640}; + padding_color_value_ = {114.0, 114.0, 114.0}; + is_mini_pad_ = false; + is_no_pad_ = false; + is_scale_up_ = false; + stride_ = 32; + max_wh_ = 7680.0; +} + +bool Yolov7FacePreprocessor::Run(std::vector* images, std::vector* outputs, + std::vector>>* ims_info) { + if (images->size() == 0) { + FDERROR << "The size of input images should be greater than 0." << std::endl; + return false; + } + ims_info->resize(images->size()); + outputs->resize(1); + std::vector tensors(images->size()); + for (size_t i = 0; i < images->size(); i++) { + if (!Preprocess(&(*images)[i], &tensors[i], &(*ims_info)[i])) { + FDERROR << "Failed to preprocess input image." << std::endl; + return false; + } + } + + if (tensors.size() == 1) { + (*outputs)[0] = std::move(tensors[0]); + } else { + function::Concat(tensors, &((*outputs)[0]), 0); + } + return true; +} + +bool Yolov7FacePreprocessor::Preprocess(FDMat* mat, FDTensor* output, + std::map>* im_info){ + // Record the shape of image and the shape of preprocessed image + (*im_info)["input_shape"] = {static_cast(mat->Height()), + static_cast(mat->Width())}; + + // yolov7-face's preprocess steps + // 1. letterbox + // 2. convert_and_permute(swap_rb=true) + LetterBox(mat); + std::vector alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f}; + std::vector beta = {0.0f, 0.0f, 0.0f}; + ConvertAndPermute::Run(mat, alpha, beta, true); + + // Record output shape of preprocessed image + (*im_info)["output_shape"] = {static_cast(mat->Height()), + static_cast(mat->Width())}; + + mat->ShareWithTensor(output); + output->ExpandDim(0); // reshape to n, h, w, c + return true; +} + +void Yolov7FacePreprocessor::LetterBox(FDMat* mat) { + float scale = + std::min(size_[1] * 1.0 / mat->Height(), size_[0] * 1.0 / mat->Width()); + if (!is_scale_up_) { + scale = std::min(scale, 1.0f); + } + + int resize_h = int(round(mat->Height() * scale)); + int resize_w = int(round(mat->Width() * scale)); + + int pad_w = size_[0] - resize_w; + int pad_h = size_[1] - resize_h; + if (is_mini_pad_) { + pad_h = pad_h % stride_; + pad_w = pad_w % stride_; + } else if (is_no_pad_) { + pad_h = 0; + pad_w = 0; + resize_h = size_[1]; + resize_w = size_[0]; + } + Resize::Run(mat, resize_w, resize_h); + + if (pad_h > 0 || pad_w > 0) { + float half_h = pad_h * 1.0 / 2; + int top = int(round(half_h - 0.1)); + int bottom = int(round(half_h + 0.1)); + float half_w = pad_w * 1.0 / 2; + int left = int(round(half_w - 0.1)); + int right = int(round(half_w + 0.1)); + Pad::Run(mat, top, bottom, left, right, padding_color_value_); + } +} + +} // namespace facedet + +} // namespace vision + +} // namespacefastdeploy \ No newline at end of file diff --git a/fastdeploy/vision/facedet/yolov7-face/preprocessor.h b/fastdeploy/vision/facedet/yolov7-face/preprocessor.h new file mode 100644 index 000000000..4bd8644b7 --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/preprocessor.h @@ -0,0 +1,100 @@ +// 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. + +#pragma once +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" + +namespace fastdeploy { + +namespace vision { + +namespace facedet { + +class FASTDEPLOY_DECL Yolov7FacePreprocessor{ + public: + /** \brief Create a preprocessor instance for YOLOv7Face serials model + */ + Yolov7FacePreprocessor(); + + /** \brief Process the input image and prepare input tensors for runtime + * + * \param[in] images The input image data list, all the elements are returned by cv::imread() + * \param[in] outputs The output tensors which will feed in runtime + * \param[in] ims_info The shape info list, record input_shape and output_shape + * \ret + */ + bool Run(std::vector* images, std::vector* outputs, + std::vector>>* ims_info); + + /// Set target size, tuple of (width, height), default size = {640, 640} + void SetSize(const std::vector& size) { size_ = size; } + + /// Get target size, tuple of (width, height), default size = {640, 640} + std::vector GetSize() const { return size_; } + + /// Set padding value, size should be the same as channels + void SetPaddingColorValue(const std::vector& padding_color_value) { + padding_color_value_ = padding_color_value; + } + + /// Get padding value, size should be the same as channels + std::vector GetPaddingColorValue() const { + return padding_color_value_; + } + + /// Set is_scale_up, if is_scale_up is false, the input image only + /// can be zoom out, the maximum resize scale cannot exceed 1.0, default true + void SetScaleUp(bool is_scale_up) { + is_scale_up_ = is_scale_up; + } + + /// Get is_scale_up, default true + bool GetScaleUp() const { return is_scale_up_; } + + protected: + bool Preprocess(FDMat * mat, FDTensor* output, + std::map>* im_info); + + void LetterBox(FDMat* mat); + + // target size, tuple of (width, height), default size = {640, 640} + std::vector size_; + + // padding value, size should be the same as channels + std::vector padding_color_value_; + + // only pad to the minimum rectange which height and width is times of stride + bool is_mini_pad_; + + // while is_mini_pad = false and is_no_pad = true, + // will resize the image to the set size + bool is_no_pad_; + + // if is_scale_up is false, the input image only can be zoom out, + // the maximum resize scale cannot exceed 1.0 + bool is_scale_up_; + + // padding stride, for is_mini_pad + int stride_; + + // for offseting the boxes by classes when using NMS + float max_wh_; +}; + +} // namespace facedet + +} // namespace vision + +} // namespace fastdeploy diff --git a/fastdeploy/vision/facedet/yolov7-face/yolov7face.cc b/fastdeploy/vision/facedet/yolov7-face/yolov7face.cc new file mode 100644 index 000000000..7c2906f39 --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/yolov7face.cc @@ -0,0 +1,88 @@ +// 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/facedet/yolov7-face/yolov7face.h" +#include "fastdeploy/utils/perf.h" +#include "fastdeploy/vision/utils/utils.h" + +namespace fastdeploy{ + +namespace vision{ + +namespace facedet{ + +YOLOv7Face::YOLOv7Face(const std::string& model_file, + const std::string& params_file, + const RuntimeOption& custom_option, + const ModelFormat& model_format) { + if (model_format == ModelFormat::ONNX) { + valid_cpu_backends = {Backend::ORT}; + valid_gpu_backends = {Backend::ORT, Backend::TRT}; + } else { + valid_cpu_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; + runtime_option.params_file = params_file; + initialized = Initialize(); +} + +bool YOLOv7Face::Initialize(){ + if (!InitRuntime()){ + FDERROR << "Failed to initialize fastdeploy backend." << std::endl; + return false; + } + return true; +} + +bool YOLOv7Face::Predict(const cv::Mat& im, FaceDetectionResult* result){ + std::vector results; + if (!BatchPredict({im}, &results)) { + return false; + } + *result = std::move(results[0]); + return true; +} + +bool YOLOv7Face::BatchPredict(const std::vector& images, + std::vector* results){ + std::vector fd_images = WrapMat(images); + FDASSERT(images.size() == 1, "Only support batch = 1 now."); + std::vector>> ims_info; + if (!preprocessor_.Run(&fd_images, &reused_input_tensors_, &ims_info)) { + FDERROR << "Failed to preprocess the input image." << std::endl; + return false; + } + + reused_input_tensors_[0].name = InputInfoOfRuntime(0).name; + if (!Infer(reused_input_tensors_, &reused_output_tensors_)) { + FDERROR << "Failed to inference by runtime." << std::endl; + return false; + } + + if (!postprocessor_.Run(reused_output_tensors_, results, ims_info)){ + FDERROR << "Failed to postprocess the inference results by runtime." << std::endl; + return false; + } + + return true; +} + +} // namespace facedet + +} // namespace vision + +} // namespace fastdeploy \ No newline at end of file diff --git a/fastdeploy/vision/facedet/yolov7-face/yolov7face.h b/fastdeploy/vision/facedet/yolov7-face/yolov7face.h new file mode 100644 index 000000000..6410fe590 --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/yolov7face.h @@ -0,0 +1,81 @@ +// 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. + +#pragma once +#include "fastdeploy/fastdeploy_model.h" +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" +#include "fastdeploy/vision/facedet/yolov7-face/preprocessor.h" +#include "fastdeploy/vision/facedet/yolov7-face/postprocessor.h" + +namespace fastdeploy { + +namespace vision { + +namespace facedet { +/*! @brief YOLOv7Face model object used when to load a YOLOv7Face model exported by YOLOv7Face. + */ +class FASTDEPLOY_DECL YOLOv7Face: public FastDeployModel{ + public: + /** \brief Set path of model file and the configuration of runtime. + * + * \param[in] model_file Path of model file, e.g ./yolov7face.onnx + * \param[in] params_file Path of parameter file, e.g ppyoloe/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in "valid_cpu_backends" + * \param[in] model_format Model format of the loaded model, default is ONNX format + */ + YOLOv7Face(const std::string& model_file, const std::string& params_file = "", + const RuntimeOption& custom_option = RuntimeOption(), + const ModelFormat& model_format = ModelFormat::ONNX); + + std::string ModelName() {return "yolov7-face";} + + /** \brief Predict the detection result for an input image + * + * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format + * \param[in] result The output detection result will be writen to this structure + * \return true if the prediction successed, otherwise false + */ + virtual bool Predict(const cv::Mat& im, FaceDetectionResult* result); + + /** \brief Predict the detection results for a batch of input images + * + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * \return true if the prediction successed, otherwise false + */ + virtual bool BatchPredict(const std::vector& images, + std::vector* results); + + /// Get preprocessor reference of YOLOv7Face + virtual Yolov7FacePreprocessor& GetPreprocessor() { + return preprocessor_; + } + + /// Get postprocessor reference of YOLOv7Face + virtual Yolov7FacePostprocessor& GetPostprocessor() { + return postprocessor_; + } + + protected: + bool Initialize(); + Yolov7FacePreprocessor preprocessor_; + Yolov7FacePostprocessor postprocessor_; +}; + +} // namespace facedet + +} // namespace vision + +} // namespace fastdeploy diff --git a/fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc b/fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc new file mode 100644 index 000000000..c0c99d425 --- /dev/null +++ b/fastdeploy/vision/facedet/yolov7-face/yolov7face_pybind.cc @@ -0,0 +1,87 @@ +// 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/pybind/main.h" + +namespace fastdeploy { +void BindYOLOv7Face(pybind11::module& m) { + pybind11::class_( + m, "Yolov7FacePreprocessor") + .def(pybind11::init<>()) + .def("run", [](vision::facedet::Yolov7FacePreprocessor& self, std::vector& im_list) { + std::vector images; + for (size_t i = 0; i < im_list.size(); ++i) { + images.push_back(vision::WrapMat(PyArrayToCvMat(im_list[i]))); + } + std::vector outputs; + std::vector>> ims_info; + if (!self.Run(&images, &outputs, &ims_info)) { + throw std::runtime_error("Failed to preprocess the input data in PaddleClasPreprocessor."); + } + for (size_t i = 0; i < outputs.size(); ++i) { + outputs[i].StopSharing(); + } + return make_pair(outputs, ims_info); + }) + .def_property("size", &vision::facedet::Yolov7FacePreprocessor::GetSize, &vision::facedet::Yolov7FacePreprocessor::SetSize) + .def_property("padding_color_value", &vision::facedet::Yolov7FacePreprocessor::GetPaddingColorValue, &vision::facedet::Yolov7FacePreprocessor::SetPaddingColorValue) + .def_property("is_scale_up", &vision::facedet::Yolov7FacePreprocessor::GetScaleUp, &vision::facedet::Yolov7FacePreprocessor::SetScaleUp); + + pybind11::class_( + m, "YOLOv7FacePostprocessor") + .def(pybind11::init<>()) + .def("run", [](vision::facedet::Yolov7FacePostprocessor& self, std::vector& inputs, + const std::vector>>& ims_info) { + std::vector results; + if (!self.Run(inputs, &results, ims_info)) { + throw std::runtime_error("Failed to postprocess the runtime result in Yolov7Postprocessor."); + } + return results; + }) + .def("run", [](vision::facedet::Yolov7FacePostprocessor& self, std::vector& input_array, + const std::vector>>& ims_info) { + std::vector results; + std::vector inputs; + PyArrayToTensorList(input_array, &inputs, /*share_buffer=*/true); + if (!self.Run(inputs, &results, ims_info)) { + throw std::runtime_error("Failed to postprocess the runtime result in YOLOv7Postprocessor."); + } + return results; + }) + .def_property("conf_threshold", &vision::facedet::Yolov7FacePostprocessor::GetConfThreshold, &vision::facedet::Yolov7FacePostprocessor::SetConfThreshold) + .def_property("nms_threshold", &vision::facedet::Yolov7FacePostprocessor::GetNMSThreshold, &vision::facedet::Yolov7FacePostprocessor::SetNMSThreshold); + + pybind11::class_(m, "YOLOv7Face") + .def(pybind11::init()) + .def("predict", + [](vision::facedet::YOLOv7Face& self, pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::FaceDetectionResult res; + self.Predict(mat, &res); + return res; + }) + .def("batch_predict", [](vision::facedet::YOLOv7Face& self, std::vector& data) { + std::vector images; + for (size_t i = 0; i < data.size(); ++i) { + images.push_back(PyArrayToCvMat(data[i])); + } + std::vector results; + self.BatchPredict(images, &results); + return results; + }) + .def_property_readonly("preprocessor", &vision::facedet::YOLOv7Face::GetPreprocessor) + .def_property_readonly("postprocessor", &vision::facedet::YOLOv7Face::GetPostprocessor); +} +} // namespace fastdeploy diff --git a/fastdeploy/vision/ocr/ppocr/classifier.cc b/fastdeploy/vision/ocr/ppocr/classifier.cc index 97121c010..bd10372e4 100755 --- a/fastdeploy/vision/ocr/ppocr/classifier.cc +++ b/fastdeploy/vision/ocr/ppocr/classifier.cc @@ -51,7 +51,7 @@ bool Classifier::Initialize() { return true; } -bool Classifier::Predict(cv::Mat& img, int32_t* cls_label, float* cls_score) { +bool Classifier::Predict(const cv::Mat& img, int32_t* cls_label, float* cls_score) { std::vector cls_labels(1); std::vector cls_scores(1); bool success = BatchPredict({img}, &cls_labels, &cls_scores); diff --git a/fastdeploy/vision/ocr/ppocr/classifier.h b/fastdeploy/vision/ocr/ppocr/classifier.h index ddc4db27a..cd035e269 100755 --- a/fastdeploy/vision/ocr/ppocr/classifier.h +++ b/fastdeploy/vision/ocr/ppocr/classifier.h @@ -43,11 +43,21 @@ class FASTDEPLOY_DECL Classifier : public FastDeployModel { const ModelFormat& model_format = ModelFormat::PADDLE); /// Get model's name std::string ModelName() const { return "ppocr/ocr_cls"; } - virtual bool Predict(cv::Mat& img, int32_t* cls_label, float* cls_score); + + /** \brief Predict the input image and get OCR classification model cls_result. + * + * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] cls_label The label result of cls model will be written in to this param. + * \param[in] cls_score The score result of cls model will be written in to this param. + * \return true if the prediction is successed, otherwise false. + */ + virtual bool Predict(const cv::Mat& img, + int32_t* cls_label, float* cls_score); /** \brief BatchPredict the input image and get OCR classification model cls_result. * * \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. - * \param[in] cls_results The output of OCR classification model cls_result will be writen to this structure. + * \param[in] cls_labels The label results of cls model will be written in to this vector. + * \param[in] cls_scores The score results of cls model will be written in to this vector. * \return true if the prediction is successed, otherwise false. */ virtual bool BatchPredict(const std::vector& images, diff --git a/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h b/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h index a755e1294..d9702e1a1 100644 --- a/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h +++ b/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h @@ -28,8 +28,8 @@ class FASTDEPLOY_DECL ClassifierPostprocessor { /** \brief Process the result of runtime and fill to ClassifyResult structure * * \param[in] tensors The inference result from runtime - * \param[in] cls_labels The output result of classification - * \param[in] cls_scores The output result of classification + * \param[in] cls_labels The output label results of classification model + * \param[in] cls_scores The output score results of classification model * \return true if the postprocess successed, otherwise false */ bool Run(const std::vector& tensors, diff --git a/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h b/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h index ed75d55b2..8c1c81611 100644 --- a/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h +++ b/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h @@ -26,8 +26,8 @@ class FASTDEPLOY_DECL ClassifierPreprocessor { public: /** \brief Process the input image and prepare input tensors for runtime * - * \param[in] images The input image data list, all the elements are returned by cv::imread() - * \param[in] outputs The output tensors which will feed in runtime + * \param[in] images The input data list, all the elements are FDMat + * \param[in] outputs The output tensors which will be fed into runtime * \return true if the preprocess successed, otherwise false */ bool Run(std::vector* images, std::vector* outputs); diff --git a/fastdeploy/vision/ocr/ppocr/det_preprocessor.h b/fastdeploy/vision/ocr/ppocr/det_preprocessor.h index d66e785d3..705f19c7b 100644 --- a/fastdeploy/vision/ocr/ppocr/det_preprocessor.h +++ b/fastdeploy/vision/ocr/ppocr/det_preprocessor.h @@ -26,7 +26,7 @@ class FASTDEPLOY_DECL DBDetectorPreprocessor { public: /** \brief Process the input image and prepare input tensors for runtime * - * \param[in] images The input image data list, all the elements are returned by cv::imread() + * \param[in] images The input data list, all the elements are FDMat * \param[in] outputs The output tensors which will feed in runtime * \param[in] batch_det_img_info_ptr The output of preprocess * \return true if the preprocess successed, otherwise false diff --git a/fastdeploy/vision/ocr/ppocr/ppocr_v2.cc b/fastdeploy/vision/ocr/ppocr/ppocr_v2.cc index 2ee2f903f..756604dde 100755 --- a/fastdeploy/vision/ocr/ppocr/ppocr_v2.cc +++ b/fastdeploy/vision/ocr/ppocr/ppocr_v2.cc @@ -74,11 +74,15 @@ bool PPOCRv2::Initialized() const { } return true; } - bool PPOCRv2::Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result) { + return Predict(*img, result); +} + +bool PPOCRv2::Predict(const cv::Mat& img, + fastdeploy::vision::OCRResult* result) { std::vector batch_result(1); - bool success = BatchPredict({*img},&batch_result); + bool success = BatchPredict({img},&batch_result); if(!success){ return success; } diff --git a/fastdeploy/vision/ocr/ppocr/ppocr_v2.h b/fastdeploy/vision/ocr/ppocr/ppocr_v2.h index 05f2b9309..69164cb56 100755 --- a/fastdeploy/vision/ocr/ppocr/ppocr_v2.h +++ b/fastdeploy/vision/ocr/ppocr/ppocr_v2.h @@ -59,6 +59,8 @@ class FASTDEPLOY_DECL PPOCRv2 : public FastDeployModel { * \return true if the prediction successed, otherwise false. */ virtual bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result); + virtual bool Predict(const cv::Mat& img, + fastdeploy::vision::OCRResult* result); /** \brief BatchPredict the input image and get OCR result. * * \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. diff --git a/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h b/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h index 711ae3a01..5f9aa70f2 100644 --- a/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h +++ b/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h @@ -35,8 +35,8 @@ class FASTDEPLOY_DECL RecognizerPostprocessor { /** \brief Process the result of runtime and fill to RecognizerResult * * \param[in] tensors The inference result from runtime - * \param[in] texts The output result of recognizer - * \param[in] rec_scores The output result of recognizer + * \param[in] texts The output text results of recognizer + * \param[in] rec_scores The output score results of recognizer * \return true if the postprocess successed, otherwise false */ bool Run(const std::vector& tensors, diff --git a/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h b/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h index 1dad75870..c6c942468 100644 --- a/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h +++ b/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h @@ -26,8 +26,8 @@ class FASTDEPLOY_DECL RecognizerPreprocessor { public: /** \brief Process the input image and prepare input tensors for runtime * - * \param[in] images The input image data list, all the elements are returned by cv::imread() - * \param[in] outputs The output tensors which will feed in runtime + * \param[in] images The input data list, all the elements are FDMat + * \param[in] outputs The output tensors which will be fed into runtime * \return true if the preprocess successed, otherwise false */ bool Run(std::vector* images, std::vector* outputs); diff --git a/fastdeploy/vision/ocr/ppocr/recognizer.cc b/fastdeploy/vision/ocr/ppocr/recognizer.cc index 3fabc6c68..3be884ddd 100755 --- a/fastdeploy/vision/ocr/ppocr/recognizer.cc +++ b/fastdeploy/vision/ocr/ppocr/recognizer.cc @@ -54,7 +54,7 @@ bool Recognizer::Initialize() { return true; } -bool Recognizer::Predict(cv::Mat& img, std::string* text, float* rec_score) { +bool Recognizer::Predict(const cv::Mat& img, std::string* text, float* rec_score) { std::vector texts(1); std::vector rec_scores(1); bool success = BatchPredict({img}, &texts, &rec_scores); diff --git a/fastdeploy/vision/ocr/ppocr/recognizer.h b/fastdeploy/vision/ocr/ppocr/recognizer.h index 4ee12bb6a..bba8a4447 100755 --- a/fastdeploy/vision/ocr/ppocr/recognizer.h +++ b/fastdeploy/vision/ocr/ppocr/recognizer.h @@ -45,11 +45,19 @@ class FASTDEPLOY_DECL Recognizer : public FastDeployModel { const ModelFormat& model_format = ModelFormat::PADDLE); /// Get model's name std::string ModelName() const { return "ppocr/ocr_rec"; } - virtual bool Predict(cv::Mat& img, std::string* text, float* rec_score); + /** \brief Predict the input image and get OCR recognition model result. + * + * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] text The text result of rec model will be written into this parameter. + * \param[in] rec_score The sccore result of rec model will be written into this parameter. + * \return true if the prediction is successed, otherwise false. + */ + virtual bool Predict(const cv::Mat& img, std::string* text, float* rec_score); /** \brief BatchPredict the input image and get OCR recognition model result. * * \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. - * \param[in] rec_results The output of OCR recognition model result will be writen to this structure. + * \param[in] texts The list of text results of rec model will be written into this vector. + * \param[in] rec_scores The list of sccore result of rec model will be written into this vector. * \return true if the prediction is successed, otherwise false. */ virtual bool BatchPredict(const std::vector& images, diff --git a/fastdeploy/vision/segmentation/ppseg/model.cc b/fastdeploy/vision/segmentation/ppseg/model.cc index 057a6a5f0..a82f73d88 100755 --- a/fastdeploy/vision/segmentation/ppseg/model.cc +++ b/fastdeploy/vision/segmentation/ppseg/model.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "fastdeploy/vision/segmentation/ppseg/model.h" +#include "fastdeploy/utils/unique_ptr.h" namespace fastdeploy { namespace vision { @@ -36,6 +37,12 @@ PaddleSegModel::PaddleSegModel(const std::string& model_file, initialized = Initialize(); } +std::unique_ptr PaddleSegModel::Clone() const { + std::unique_ptr clone_model = fastdeploy::utils::make_unique(PaddleSegModel(*this)); + clone_model->SetRuntime(clone_model->CloneRuntime()); + return clone_model; +} + bool PaddleSegModel::Initialize() { if (!InitRuntime()) { FDERROR << "Failed to initialize fastdeploy backend." << std::endl; diff --git a/fastdeploy/vision/segmentation/ppseg/model.h b/fastdeploy/vision/segmentation/ppseg/model.h index bf6d6f5b1..414005240 100644 --- a/fastdeploy/vision/segmentation/ppseg/model.h +++ b/fastdeploy/vision/segmentation/ppseg/model.h @@ -41,6 +41,12 @@ class FASTDEPLOY_DECL PaddleSegModel : public FastDeployModel { const RuntimeOption& custom_option = RuntimeOption(), const ModelFormat& model_format = ModelFormat::PADDLE); + /** \brief Clone a new PaddleSegModel with less memory usage when multiple instances of the same model are created + * + * \return new PaddleDetModel* type unique pointer + */ + virtual std::unique_ptr Clone() const; + /// Get model's name std::string ModelName() const { return "PaddleSeg"; } diff --git a/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc b/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc index 34642b62a..e687d3cc4 100644 --- a/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc +++ b/fastdeploy/vision/segmentation/ppseg/ppseg_pybind.cc @@ -47,6 +47,9 @@ void BindPPSeg(pybind11::module& m) { m, "PaddleSegModel") .def(pybind11::init()) + .def("clone", [](vision::segmentation::PaddleSegModel& self) { + return self.Clone(); + }) .def("predict", [](vision::segmentation::PaddleSegModel& self, pybind11::array& data) { diff --git a/fastdeploy/vision/vision_pybind.cc b/fastdeploy/vision/vision_pybind.cc index 55312d1a3..cecd4f7c3 100644 --- a/fastdeploy/vision/vision_pybind.cc +++ b/fastdeploy/vision/vision_pybind.cc @@ -37,6 +37,21 @@ void BindVision(pybind11::module& m) { .def(pybind11::init()) .def_readwrite("data", &vision::Mask::data) .def_readwrite("shape", &vision::Mask::shape) + .def(pybind11::pickle( + [](const vision::Mask &m) { + return pybind11::make_tuple(m.data, m.shape); + }, + [](pybind11::tuple t) { + if (t.size() != 2) + throw std::runtime_error("vision::Mask pickle with invalid state!"); + + vision::Mask m; + m.data = t[0].cast>(); + m.shape = t[1].cast>(); + + return m; + } + )) .def("__repr__", &vision::Mask::Str) .def("__str__", &vision::Mask::Str); @@ -44,6 +59,21 @@ void BindVision(pybind11::module& m) { .def(pybind11::init()) .def_readwrite("label_ids", &vision::ClassifyResult::label_ids) .def_readwrite("scores", &vision::ClassifyResult::scores) + .def(pybind11::pickle( + [](const vision::ClassifyResult &c) { + return pybind11::make_tuple(c.label_ids, c.scores); + }, + [](pybind11::tuple t) { + if (t.size() != 2) + throw std::runtime_error("vision::ClassifyResult pickle with invalid state!"); + + vision::ClassifyResult c; + c.label_ids = t[0].cast>(); + c.scores = t[1].cast>(); + + return c; + } + )) .def("__repr__", &vision::ClassifyResult::Str) .def("__str__", &vision::ClassifyResult::Str); @@ -54,6 +84,24 @@ void BindVision(pybind11::module& m) { .def_readwrite("label_ids", &vision::DetectionResult::label_ids) .def_readwrite("masks", &vision::DetectionResult::masks) .def_readwrite("contain_masks", &vision::DetectionResult::contain_masks) + .def(pybind11::pickle( + [](const vision::DetectionResult &d) { + return pybind11::make_tuple(d.boxes, d.scores, d.label_ids, d.masks, d.contain_masks); + }, + [](pybind11::tuple t) { + if (t.size() != 5) + throw std::runtime_error("vision::DetectionResult pickle with Invalid state!"); + + vision::DetectionResult d; + d.boxes = t[0].cast>>(); + d.scores = t[1].cast>(); + d.label_ids = t[2].cast>(); + d.masks = t[3].cast>(); + d.contain_masks = t[4].cast(); + + return d; + } + )) .def("__repr__", &vision::DetectionResult::Str) .def("__str__", &vision::DetectionResult::Str); @@ -104,6 +152,23 @@ void BindVision(pybind11::module& m) { .def_readwrite("score_map", &vision::SegmentationResult::score_map) .def_readwrite("shape", &vision::SegmentationResult::shape) .def_readwrite("contain_score_map", &vision::SegmentationResult::contain_score_map) + .def(pybind11::pickle( + [](const vision::SegmentationResult &s) { + return pybind11::make_tuple(s.label_map, s.score_map, s.shape, s.contain_score_map); + }, + [](pybind11::tuple t) { + if (t.size() != 4) + throw std::runtime_error("vision::SegmentationResult pickle with Invalid state!"); + + vision::SegmentationResult s; + s.label_map = t[0].cast>(); + s.score_map = t[1].cast>(); + s.shape = t[2].cast>(); + s.contain_score_map = t[3].cast(); + + return s; + } + )) .def("__repr__", &vision::SegmentationResult::Str) .def("__str__", &vision::SegmentationResult::Str); diff --git a/fastdeploy/vision/visualize/segmentation.cc b/fastdeploy/vision/visualize/segmentation.cc index 9e4fe4149..37d0f572e 100644 --- a/fastdeploy/vision/visualize/segmentation.cc +++ b/fastdeploy/vision/visualize/segmentation.cc @@ -25,7 +25,7 @@ namespace fastdeploy { namespace vision { #ifdef __ARM_NEON -static constexpr int VIS_SEG_OMP_NUM_THREADS=2; +static constexpr int VIS_SEG_OMP_NUM_THREADS = 2; static inline void QuantizeBlendingWeight8( float weight, uint8_t* old_multi_factor, uint8_t* new_multi_factor) { @@ -55,15 +55,25 @@ static cv::Mat FastVisSegmentationNEON( const uint8_t *im_ptr = static_cast(im.data); if (!quantize_weight) { + uint8x16_t zerox16 = vdupq_n_u8(0); #pragma omp parallel for proc_bind(close) \ num_threads(VIS_SEG_OMP_NUM_THREADS) schedule(static) for (int i = 0; i < size - 15; i += 16) { + uint8x16x3_t bgrx16x3 = vld3q_u8(im_ptr + i * 3); // 48 bytes uint8x16_t labelx16 = vld1q_u8(label_ptr + i); // 16 bytes + uint8x16_t ibx16 = bgrx16x3.val[0]; + uint8x16_t igx16 = bgrx16x3.val[1]; + uint8x16_t irx16 = bgrx16x3.val[2]; // e.g 0b00000001 << 7 -> 0b10000000 128; + uint8x16_t mbx16 = vshlq_n_u8(labelx16, 7); + uint8x16_t mgx16 = vshlq_n_u8(labelx16, 4); + uint8x16_t mrx16 = vshlq_n_u8(labelx16, 3); uint8x16x3_t vbgrx16x3; - vbgrx16x3.val[0] = vshlq_n_u8(labelx16, 7); - vbgrx16x3.val[1] = vshlq_n_u8(labelx16, 4); - vbgrx16x3.val[2] = vshlq_n_u8(labelx16, 3); + // Keep the pixels of input im if mask = 0 + uint8x16_t cezx16 = vceqq_u8(labelx16, zerox16); + vbgrx16x3.val[0] = vorrq_u8(vandq_u8(cezx16, ibx16), mbx16); + vbgrx16x3.val[1] = vorrq_u8(vandq_u8(cezx16, igx16), mgx16); + vbgrx16x3.val[2] = vorrq_u8(vandq_u8(cezx16, irx16), mrx16); vst3q_u8(vis_ptr + i * 3, vbgrx16x3); } for (int i = size - 15; i < size; i++) { @@ -72,7 +82,7 @@ static cv::Mat FastVisSegmentationNEON( vis_ptr[i * 3 + 1] = (label << 4); vis_ptr[i * 3 + 2] = (label << 3); } - // Blend colors use opencv + // Blend the colors use OpenCV cv::addWeighted(im, 1.0 - weight, vis_img, weight, 0, vis_img); return vis_img; } @@ -113,8 +123,9 @@ static cv::Mat FastVisSegmentationNEON( return vis_img; } - uint8x16_t old_mulx16 = vdupq_n_u8(old_multi_factor); - uint8x16_t new_mulx16 = vdupq_n_u8(new_multi_factor); + uint8x16_t zerox16 = vdupq_n_u8(0); + uint8x16_t old_fx16 = vdupq_n_u8(old_multi_factor); + uint8x16_t new_fx16 = vdupq_n_u8(new_multi_factor); // Blend the two colors together with quantize 'weight'. #pragma omp parallel for proc_bind(close) \ num_threads(VIS_SEG_OMP_NUM_THREADS) schedule(static) @@ -128,21 +139,29 @@ static cv::Mat FastVisSegmentationNEON( uint8x16_t mbx16 = vshlq_n_u8(labelx16, 7); uint8x16_t mgx16 = vshlq_n_u8(labelx16, 4); uint8x16_t mrx16 = vshlq_n_u8(labelx16, 3); - // TODO: keep the pixels of input im if mask = 0 - uint8x16_t ibx16_mshr, igx16_mshr, irx16_mshr; - uint8x16_t mbx16_mshr, mgx16_mshr, mrx16_mshr; // Moving 7 bits to the right tends to result in zero, // So, We choose to shift 3 bits to get an approximation - ibx16_mshr = vmulq_u8(vshrq_n_u8(ibx16, 3), old_mulx16); - igx16_mshr = vmulq_u8(vshrq_n_u8(igx16, 3), old_mulx16); - irx16_mshr = vmulq_u8(vshrq_n_u8(irx16, 3), old_mulx16); - mbx16_mshr = vmulq_u8(vshrq_n_u8(mbx16, 3), new_mulx16); - mgx16_mshr = vmulq_u8(vshrq_n_u8(mgx16, 3), new_mulx16); - mrx16_mshr = vmulq_u8(vshrq_n_u8(mrx16, 3), new_mulx16); - uint8x16x3_t vbgr16x3; - vbgr16x3.val[0] = vaddq_u8(ibx16_mshr, mbx16_mshr); - vbgr16x3.val[1] = vaddq_u8(igx16_mshr, mgx16_mshr); - vbgr16x3.val[2] = vaddq_u8(irx16_mshr, mrx16_mshr); + uint8x16_t ibx16_mshr = vmulq_u8(vshrq_n_u8(ibx16, 3), old_fx16); + uint8x16_t igx16_mshr = vmulq_u8(vshrq_n_u8(igx16, 3), old_fx16); + uint8x16_t irx16_mshr = vmulq_u8(vshrq_n_u8(irx16, 3), old_fx16); + uint8x16_t mbx16_mshr = vmulq_u8(vshrq_n_u8(mbx16, 3), new_fx16); + uint8x16_t mgx16_mshr = vmulq_u8(vshrq_n_u8(mgx16, 3), new_fx16); + uint8x16_t mrx16_mshr = vmulq_u8(vshrq_n_u8(mrx16, 3), new_fx16); + uint8x16_t qbx16 = vqaddq_u8(ibx16_mshr, mbx16_mshr); + uint8x16_t qgx16 = vqaddq_u8(igx16_mshr, mgx16_mshr); + uint8x16_t qrx16 = vqaddq_u8(irx16_mshr, mrx16_mshr); + // Keep the pixels of input im if label = 0 (means mask = 0) + uint8x16_t cezx16 = vceqq_u8(labelx16, zerox16); + uint8x16_t abx16 = vandq_u8(cezx16, ibx16); + uint8x16_t agx16 = vandq_u8(cezx16, igx16); + uint8x16_t arx16 = vandq_u8(cezx16, irx16); + uint8x16x3_t vbgr16x3; + // Reset qx values to 0 if label is 0, then, keep mask values + // if label is not 0 + uint8x16_t ncezx16 = vmvnq_u8(cezx16); + vbgr16x3.val[0] = vorrq_u8(abx16, vandq_u8(ncezx16, qbx16)); + vbgr16x3.val[1] = vorrq_u8(agx16, vandq_u8(ncezx16, qgx16)); + vbgr16x3.val[2] = vorrq_u8(arx16, vandq_u8(ncezx16, qrx16)); // Store the blended pixels to vis img vst3q_u8(vis_ptr + i * 3, vbgr16x3); } @@ -172,9 +191,15 @@ static cv::Mat VisSegmentationCommonCpu( for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int category_id = result.label_map[index++]; - vis_img.at(i, j)[0] = color_map[3 * category_id + 0]; - vis_img.at(i, j)[1] = color_map[3 * category_id + 1]; - vis_img.at(i, j)[2] = color_map[3 * category_id + 2]; + if (category_id == 0) { + vis_img.at(i, j)[0] = im.at(i, j)[0]; + vis_img.at(i, j)[1] = im.at(i, j)[1]; + vis_img.at(i, j)[2] = im.at(i, j)[2]; + } else { + vis_img.at(i, j)[0] = color_map[3 * category_id + 0]; + vis_img.at(i, j)[1] = color_map[3 * category_id + 1]; + vis_img.at(i, j)[2] = color_map[3 * category_id + 2]; + } } } cv::addWeighted(im, 1.0 - weight, vis_img, weight, 0, vis_img); diff --git a/java/android/app/build.gradle b/java/android/app/build.gradle index d58cb3dd5..23b204135 100644 --- a/java/android/app/build.gradle +++ b/java/android/app/build.gradle @@ -5,7 +5,7 @@ android { defaultConfig { applicationId 'com.baidu.paddle.fastdeploy.app.examples' - minSdkVersion 15 + minSdkVersion 16 //noinspection ExpiredTargetSdkVersion targetSdkVersion 28 versionCode 1 @@ -79,6 +79,10 @@ def FD_JAVA_SDK = [ [ 'src' : 'https://bj.bcebos.com/fastdeploy/test/fastdeploy-android-sdk-latest-dev.aar', 'dest': 'libs' + ], + [ + 'src' : 'https://bj.bcebos.com/fastdeploy/test/bdasr_V3_20210628_cfe8c44.aar', + 'dest': 'libs' ] ] @@ -95,11 +99,13 @@ task downloadAndExtractModels(type: DefaultTask) { String[] modelPaths = model.src.split("/") String modelName = modelPaths[modelPaths.length - 1] String modelPrefix = modelName.substring(0, modelName.length() - 4) - // Download the target model if not exists - boolean copyFiles = !file("${model.dest}/${modelPrefix}").exists() - if (!file("${cachePath}/${modelName}").exists()) { - println "[INFO] Downloading ${model.src} -> ${cachePath}/${modelName}" - ant.get(src: model.src, dest: file("${cachePath}/${modelName}")) + boolean copyFiles = false + if (!file("${model.dest}/${modelPrefix}").exists()) { + // Download the target model if not exists + if (!file("${cachePath}/${modelName}").exists()) { + println "[INFO] Downloading ${model.src} -> ${cachePath}/${modelName}" + ant.get(src: model.src, dest: file("${cachePath}/${modelName}")) + } copyFiles = true } if (copyFiles) { @@ -127,11 +133,13 @@ task downloadAndExtractSDKs(type: DefaultTask) { FD_JAVA_SDK.eachWithIndex { sdk, index -> String[] sdkPaths = sdk.src.split("/") String sdkName = sdkPaths[sdkPaths.length - 1] - // Download the target SDK if not exists - boolean copyFiles = !file("${sdk.dest}/${sdkName}").exists() - if (!file("${cachePath}/${sdkName}").exists()) { - println "[INFO] Downloading ${sdk.src} -> ${cachePath}/${sdkName}" - ant.get(src: sdk.src, dest: file("${cachePath}/${sdkName}")) + boolean copyFiles = false + if (!file("${sdk.dest}/${sdkName}").exists()) { + // Download the target SDK if not exists + if (!file("${cachePath}/${sdkName}").exists()) { + println "[INFO] Downloading ${sdk.src} -> ${cachePath}/${sdkName}" + ant.get(src: sdk.src, dest: file("${cachePath}/${sdkName}")) + } copyFiles = true } if (copyFiles) { @@ -148,4 +156,4 @@ task downloadAndExtractSDKs(type: DefaultTask) { } preBuild.dependsOn downloadAndExtractSDKs -preBuild.dependsOn downloadAndExtractModels \ No newline at end of file +preBuild.dependsOn downloadAndExtractModels diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantMainActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantMainActivity.java new file mode 100644 index 000000000..8b96cea31 --- /dev/null +++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantMainActivity.java @@ -0,0 +1,210 @@ +package com.baidu.paddle.fastdeploy.app.examples.text.applications; + +import static com.baidu.paddle.fastdeploy.ui.Utils.isNetworkAvailable; + +import android.Manifest; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.Log; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import com.baidu.aip.asrwakeup3.core.mini.AutoCheck; +import com.baidu.aip.asrwakeup3.core.util.AuthUtil; +import com.baidu.paddle.fastdeploy.app.examples.R; +import com.baidu.speech.EventListener; +import com.baidu.speech.EventManager; +import com.baidu.speech.EventManagerFactory; +import com.baidu.speech.asr.SpeechConstant; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class VoiceAssistantMainActivity extends Activity implements View.OnClickListener, EventListener { + private Button startVoiceBtn; + private TextView voiceOutput; + private Button startIntentBtn; + private TextView intentOutput; + private ImageView back; + private EventManager asr; + private Boolean isStartVoice = false; + private String voiceTxt = ""; + private int times = 0; + private final int REQUEST_PERMISSION = 0; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Fullscreen + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); + + setContentView(R.layout.voice_assistant_activity_main); + + init(); + } + + private void init() { + checkPermission(); + asr = EventManagerFactory.create(this, "asr"); + asr.registerListener(this); + startVoiceBtn = findViewById(R.id.btn_voice); + startVoiceBtn.setOnClickListener(this); + voiceOutput = findViewById(R.id.tv_voice_output); + back = findViewById(R.id.iv_back); + back.setOnClickListener(this); + startIntentBtn = findViewById(R.id.btn_intent); + startIntentBtn.setOnClickListener(this); + intentOutput = findViewById(R.id.tv_intent_output); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.btn_voice: + if (!isNetworkAvailable(this)) { + new AlertDialog.Builder(VoiceAssistantMainActivity.this) + .setMessage("请先连接互联网。") + .setCancelable(true) + .show(); + return; + } + if (!isStartVoice) { + isStartVoice = true; + startVoiceBtn.setText("停止录音"); + start(); + } else { + isStartVoice = false; + startVoiceBtn.setText("开始录音"); + stop(); + } + break; + case R.id.iv_back: + finish(); + break; + case R.id.btn_intent: + if (voiceTxt.equals("")) { + new AlertDialog.Builder(VoiceAssistantMainActivity.this) + .setMessage("请先录音。") + .setCancelable(true) + .show(); + return; + } + intentOutput.setText("我刚才说了:" + voiceTxt); + break; + } + } + + @Override + public void onEvent(String name, String params, byte[] data, int offset, int length) { + if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) { + if (params.contains("\"final_result\"")) { + if (params.contains("[")) { + voiceTxt = params.substring(params.lastIndexOf('[') + 1, params.lastIndexOf(']')); + } + voiceOutput.setText(voiceTxt); + } + } + } + + private void start() { + Map params = AuthUtil.getParam(); + String event = null; + event = SpeechConstant.ASR_START; + params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, false); + (new AutoCheck(getApplicationContext(), new Handler() { + public void handleMessage(Message msg) { + if (msg.what == 100) { + AutoCheck autoCheck = (AutoCheck) msg.obj; + synchronized (autoCheck) { + String message = autoCheck.obtainErrorMessage(); + Log.e(getClass().getName(), message); + } + } + } + }, false)).checkAsr(params); + String json = null; + json = new JSONObject(params).toString(); + asr.send(event, json, null, 0, 0); + } + + private void stop() { + asr.send(SpeechConstant.ASR_STOP, null, null, 0, 0); + } + + @Override + protected void onPause() { + super.onPause(); + asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0); + asr.unregisterListener(this); + } + + private void checkPermission() { + times++; + final List permissionsList = new ArrayList<>(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if ((checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED)) + permissionsList.add(Manifest.permission.RECORD_AUDIO); + if ((checkSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED)) + permissionsList.add(Manifest.permission.ACCESS_NETWORK_STATE); + if ((checkSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) { + permissionsList.add(Manifest.permission.INTERNET); + } + if ((checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) { + permissionsList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } + if (permissionsList.size() != 0) { + if (times == 1) { + requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), + REQUEST_PERMISSION); + } else { + new AlertDialog.Builder(this) + .setCancelable(true) + .setTitle("提示") + .setMessage("获取不到授权,APP将无法正常使用,请允许APP获取权限!") + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface arg0, int arg1) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + requestPermissions(permissionsList.toArray(new String[permissionsList.size()]), + REQUEST_PERMISSION); + } + } + }).setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface arg0, int arg1) { + finish(); + } + }).show(); + } + } + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + checkPermission(); + } +} diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantWelcomeActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantWelcomeActivity.java new file mode 100644 index 000000000..5dbf8a7ac --- /dev/null +++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/text/applications/VoiceAssistantWelcomeActivity.java @@ -0,0 +1,30 @@ +package com.baidu.paddle.fastdeploy.app.examples.text.applications; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.View; + +import com.baidu.paddle.fastdeploy.app.examples.R; + +public class VoiceAssistantWelcomeActivity extends Activity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + ); + getWindow().setStatusBarColor(Color.TRANSPARENT); + } + setContentView(R.layout.voice_assistant_welcome); + } + + public void startActivity(View view) { + Intent intent = new Intent(VoiceAssistantWelcomeActivity.this, VoiceAssistantMainActivity.class); + startActivity(intent); + } +} diff --git a/java/android/app/src/main/res/layout/voice_assistant_activity_main.xml b/java/android/app/src/main/res/layout/voice_assistant_activity_main.xml new file mode 100644 index 000000000..c6376ac38 --- /dev/null +++ b/java/android/app/src/main/res/layout/voice_assistant_activity_main.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + +