From 266ae046f26472c219ca080ddf3a5590e496c577 Mon Sep 17 00:00:00 2001 From: chenjian Date: Mon, 27 Feb 2023 20:19:13 +0800 Subject: [PATCH] [C API] Refactor code structure (#1449) * refactor code * move files * fix doc * fix --- c_api/CMakeLists.txt | 2 +- c_api/fastdeploy_capi/core/config.h | 22 ++++++ c_api/fastdeploy_capi/{ => core}/config.h.in | 0 c_api/fastdeploy_capi/{ => core}/fd_common.h | 0 c_api/fastdeploy_capi/{ => core}/fd_type.cc | 4 +- c_api/fastdeploy_capi/{ => core}/fd_type.h | 4 +- c_api/fastdeploy_capi/enum_variables.h | 71 ------------------- .../{ => internal}/types_internal.cc | 2 +- .../{ => internal}/types_internal.h | 2 +- .../fastdeploy_capi/runtime/enum_variables.h | 71 +++++++++++++++++++ .../{ => runtime}/runtime_option.cc | 4 +- .../{ => runtime}/runtime_option.h | 2 +- c_api/fastdeploy_capi/vision.h | 6 +- .../vision/classification/ppcls/model.cc | 2 +- .../vision/classification/ppcls/model.h | 6 +- .../vision/detection/ppdet/model.cc | 2 +- .../vision/detection/ppdet/model.h | 6 +- .../fastdeploy_capi/vision/ocr/ppocr/model.cc | 2 +- .../fastdeploy_capi/vision/ocr/ppocr/model.h | 6 +- c_api/fastdeploy_capi/vision/result.cc | 2 +- c_api/fastdeploy_capi/vision/result.h | 4 +- .../vision/segmentation/ppseg/model.cc | 2 +- .../vision/segmentation/ppseg/model.h | 6 +- c_api/fastdeploy_capi/vision/visualize.cc | 2 +- c_api/fastdeploy_capi/vision/visualize.h | 4 +- docs/cn/faq/develop_c_api_for_a_new_model.md | 6 +- docs/en/faq/develop_c_api_for_a_new_model.md | 6 +- .../classification/paddleclas/c/README.md | 2 +- .../classification/paddleclas/c/infer.c | 4 +- .../detection/paddledetection/c/README.md | 2 +- .../paddledetection/c/infer_ppyoloe.c | 4 +- examples/vision/ocr/PP-OCRv2/c/infer.c | 14 ++-- examples/vision/ocr/PP-OCRv3/c/infer.c | 14 ++-- .../segmentation/paddleseg/cpu-gpu/c/infer.c | 4 +- 34 files changed, 158 insertions(+), 132 deletions(-) create mode 100755 c_api/fastdeploy_capi/core/config.h rename c_api/fastdeploy_capi/{ => core}/config.h.in (100%) rename c_api/fastdeploy_capi/{ => core}/fd_common.h (100%) rename c_api/fastdeploy_capi/{ => core}/fd_type.cc (92%) rename c_api/fastdeploy_capi/{ => core}/fd_type.h (96%) delete mode 100644 c_api/fastdeploy_capi/enum_variables.h rename c_api/fastdeploy_capi/{ => internal}/types_internal.cc (99%) rename c_api/fastdeploy_capi/{ => internal}/types_internal.h (99%) create mode 100644 c_api/fastdeploy_capi/runtime/enum_variables.h rename c_api/fastdeploy_capi/{ => runtime}/runtime_option.cc (99%) rename c_api/fastdeploy_capi/{ => runtime}/runtime_option.h (99%) diff --git a/c_api/CMakeLists.txt b/c_api/CMakeLists.txt index 4f3934165f..b75bde8fdd 100644 --- a/c_api/CMakeLists.txt +++ b/c_api/CMakeLists.txt @@ -19,7 +19,7 @@ if(NOT WITH_CAPI) return() endif() -configure_file(${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/c_api/fastdeploy_capi/config.h.in ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/c_api/fastdeploy_capi/config.h) +configure_file(${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/c_api/fastdeploy_capi/core/config.h.in ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/c_api/fastdeploy_capi/core/config.h) file(GLOB_RECURSE DEPLOY_CAPI_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/c_api/fastdeploy_capi/*.cc) if(NOT ENABLE_VISION) file(GLOB_RECURSE DEPLOY_VISION_CAPI_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/c_api/fastdeploy_capi/vision/*.cc) diff --git a/c_api/fastdeploy_capi/core/config.h b/c_api/fastdeploy_capi/core/config.h new file mode 100755 index 0000000000..73ad1145a0 --- /dev/null +++ b/c_api/fastdeploy_capi/core/config.h @@ -0,0 +1,22 @@ +// Copyright (c) 2023 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 + +#ifndef ENABLE_VISION +#define ENABLE_VISION +#endif + +#ifndef ENABLE_TEXT +#define ENABLE_TEXT +#endif diff --git a/c_api/fastdeploy_capi/config.h.in b/c_api/fastdeploy_capi/core/config.h.in similarity index 100% rename from c_api/fastdeploy_capi/config.h.in rename to c_api/fastdeploy_capi/core/config.h.in diff --git a/c_api/fastdeploy_capi/fd_common.h b/c_api/fastdeploy_capi/core/fd_common.h similarity index 100% rename from c_api/fastdeploy_capi/fd_common.h rename to c_api/fastdeploy_capi/core/fd_common.h diff --git a/c_api/fastdeploy_capi/fd_type.cc b/c_api/fastdeploy_capi/core/fd_type.cc similarity index 92% rename from c_api/fastdeploy_capi/fd_type.cc rename to c_api/fastdeploy_capi/core/fd_type.cc index 34390888a2..9c0e7c93c0 100644 --- a/c_api/fastdeploy_capi/fd_type.cc +++ b/c_api/fastdeploy_capi/core/fd_type.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy_capi/fd_type.h" +#include "fastdeploy_capi/core/fd_type.h" #include -#include "fastdeploy_capi/fd_common.h" +#include "fastdeploy_capi/core/fd_common.h" #ifdef __cplusplus extern "C" { diff --git a/c_api/fastdeploy_capi/fd_type.h b/c_api/fastdeploy_capi/core/fd_type.h similarity index 96% rename from c_api/fastdeploy_capi/fd_type.h rename to c_api/fastdeploy_capi/core/fd_type.h index 6833fd6012..cee4014475 100644 --- a/c_api/fastdeploy_capi/fd_type.h +++ b/c_api/fastdeploy_capi/core/fd_type.h @@ -17,8 +17,8 @@ #include #include -#include "fastdeploy_capi/enum_variables.h" -#include "fastdeploy_capi/fd_common.h" +#include "fastdeploy_capi/runtime/enum_variables.h" +#include "fastdeploy_capi/core/fd_common.h" typedef struct FD_C_OneDimArrayUint8 { size_t size; diff --git a/c_api/fastdeploy_capi/enum_variables.h b/c_api/fastdeploy_capi/enum_variables.h deleted file mode 100644 index 05a3d4c9f1..0000000000 --- a/c_api/fastdeploy_capi/enum_variables.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) 2023 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 - -#define FD_ENUM(type) \ - typedef int32_t type; \ - enum - -FD_ENUM(FD_C_ModelFormat){ - AUTOREC, ///< Auto recognize the model format by model file name - PADDLE, ///< Model with paddlepaddle format - ONNX, ///< Model with ONNX format - RKNN, ///< Model with RKNN format - TORCHSCRIPT, ///< Model with TorchScript format - SOPHGO, ///< Model with SOPHGO format -}; - -FD_ENUM(FD_C_rknpu2_CpuName){ - RK356X = 0, /* run on RK356X. */ - RK3588 = 1, /* default,run on RK3588. */ - UNDEFINED, -}; - -FD_ENUM(FD_C_rknpu2_CoreMask){ - RKNN_NPU_CORE_AUTO = 0, //< default, run on NPU core randomly. - RKNN_NPU_CORE_0 = 1, //< run on NPU core 0. - RKNN_NPU_CORE_1 = 2, //< run on NPU core 1. - RKNN_NPU_CORE_2 = 4, //< run on NPU core 2. - RKNN_NPU_CORE_0_1 = RKNN_NPU_CORE_0 | - RKNN_NPU_CORE_1, //< run on NPU core 1 and core 2. - RKNN_NPU_CORE_0_1_2 = RKNN_NPU_CORE_0_1 | - RKNN_NPU_CORE_2, //< run on NPU core 1 and core 2. - RKNN_NPU_CORE_UNDEFINED, -}; - -FD_ENUM(FD_C_LitePowerMode){ - LITE_POWER_HIGH = 0, ///< Use Lite Backend with high power mode - LITE_POWER_LOW = 1, ///< Use Lite Backend with low power mode - LITE_POWER_FULL = 2, ///< Use Lite Backend with full power mode - LITE_POWER_NO_BIND = 3, ///< Use Lite Backend with no bind power mode - LITE_POWER_RAND_HIGH = 4, ///< Use Lite Backend with rand high mode - LITE_POWER_RAND_LOW = 5 ///< Use Lite Backend with rand low power mode -}; - -FD_ENUM(FD_C_ResultType){ - UNKNOWN_RESULT, - CLASSIFY, - DETECTION, - SEGMENTATION, - OCR, - MOT, - FACE_DETECTION, - FACE_ALIGNMENT, - FACE_RECOGNITION, - MATTING, - MASK, - KEYPOINT_DETECTION, - HEADPOSE, -}; diff --git a/c_api/fastdeploy_capi/types_internal.cc b/c_api/fastdeploy_capi/internal/types_internal.cc similarity index 99% rename from c_api/fastdeploy_capi/types_internal.cc rename to c_api/fastdeploy_capi/internal/types_internal.cc index adb7a088e5..823ba90b75 100644 --- a/c_api/fastdeploy_capi/types_internal.cc +++ b/c_api/fastdeploy_capi/internal/types_internal.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" namespace fastdeploy { diff --git a/c_api/fastdeploy_capi/types_internal.h b/c_api/fastdeploy_capi/internal/types_internal.h similarity index 99% rename from c_api/fastdeploy_capi/types_internal.h rename to c_api/fastdeploy_capi/internal/types_internal.h index 5549deca44..cd4f3dc76b 100644 --- a/c_api/fastdeploy_capi/types_internal.h +++ b/c_api/fastdeploy_capi/internal/types_internal.h @@ -15,7 +15,7 @@ #pragma once #include "fastdeploy/runtime/runtime_option.h" -#include "fastdeploy_capi/fd_type.h" +#include "fastdeploy_capi/core/fd_type.h" #include #ifdef ENABLE_VISION diff --git a/c_api/fastdeploy_capi/runtime/enum_variables.h b/c_api/fastdeploy_capi/runtime/enum_variables.h new file mode 100644 index 0000000000..f30760d2fe --- /dev/null +++ b/c_api/fastdeploy_capi/runtime/enum_variables.h @@ -0,0 +1,71 @@ +// Copyright (c) 2023 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 + +#define FD_ENUM(type) \ + typedef int32_t type; \ + enum + +FD_ENUM(FD_C_ModelFormat){ + FD_C_ModelFormat_AUTOREC, ///< Auto recognize the model format by model file name + FD_C_ModelFormat_PADDLE, ///< Model with paddlepaddle format + FD_C_ModelFormat_ONNX, ///< Model with ONNX format + FD_C_ModelFormat_RKNN, ///< Model with RKNN format + FD_C_ModelFormat_TORCHSCRIPT, ///< Model with TorchScript format + FD_C_ModelFormat_SOPHGO, ///< Model with SOPHGO format +}; + +FD_ENUM(FD_C_rknpu2_CpuName){ + FD_C_ModelFormat_RK356X = 0, /* run on RK356X. */ + FD_C_ModelFormat_RK3588 = 1, /* default,run on RK3588. */ + FD_C_ModelFormat_UNDEFINED, +}; + +FD_ENUM(FD_C_rknpu2_CoreMask){ + FD_C_ModelFormat_RKNN_NPU_CORE_AUTO = 0, //< default, run on NPU core randomly. + FD_C_ModelFormat_RKNN_NPU_CORE_0 = 1, //< run on NPU core 0. + FD_C_ModelFormat_RKNN_NPU_CORE_1 = 2, //< run on NPU core 1. + FD_C_ModelFormat_RKNN_NPU_CORE_2 = 4, //< run on NPU core 2. + FD_C_ModelFormat_RKNN_NPU_CORE_0_1 = FD_C_ModelFormat_RKNN_NPU_CORE_0 | + FD_C_ModelFormat_RKNN_NPU_CORE_1, //< run on NPU core 1 and core 2. + FD_C_ModelFormat_RKNN_NPU_CORE_0_1_2 = FD_C_ModelFormat_RKNN_NPU_CORE_0_1 | + FD_C_ModelFormat_RKNN_NPU_CORE_2, //< run on NPU core 1 and core 2. + FD_C_ModelFormat_RKNN_NPU_CORE_UNDEFINED, +}; + +FD_ENUM(FD_C_LitePowerMode){ + FD_C_ModelFormat_LITE_POWER_HIGH = 0, ///< Use Lite Backend with high power mode + FD_C_ModelFormat_LITE_POWER_LOW = 1, ///< Use Lite Backend with low power mode + FD_C_ModelFormat_LITE_POWER_FULL = 2, ///< Use Lite Backend with full power mode + FD_C_ModelFormat_LITE_POWER_NO_BIND = 3, ///< Use Lite Backend with no bind power mode + FD_C_ModelFormat_LITE_POWER_RAND_HIGH = 4, ///< Use Lite Backend with rand high mode + FD_C_ModelFormat_LITE_POWER_RAND_LOW = 5 ///< Use Lite Backend with rand low power mode +}; + +FD_ENUM(FD_C_ResultType){ + FD_C_ModelFormat_UNKNOWN_RESULT, + FD_C_ModelFormat_CLASSIFY, + FD_C_ModelFormat_DETECTION, + FD_C_ModelFormat_SEGMENTATION, + FD_C_ModelFormat_OCR, + FD_C_ModelFormat_MOT, + FD_C_ModelFormat_FACE_DETECTION, + FD_C_ModelFormat_FACE_ALIGNMENT, + FD_C_ModelFormat_FACE_RECOGNITION, + FD_C_ModelFormat_MATTING, + FD_C_ModelFormat_MASK, + FD_C_ModelFormat_KEYPOINT_DETECTION, + FD_C_ModelFormat_HEADPOSE, +}; diff --git a/c_api/fastdeploy_capi/runtime_option.cc b/c_api/fastdeploy_capi/runtime/runtime_option.cc similarity index 99% rename from c_api/fastdeploy_capi/runtime_option.cc rename to c_api/fastdeploy_capi/runtime/runtime_option.cc index 4683d468d7..f0694a2710 100644 --- a/c_api/fastdeploy_capi/runtime_option.cc +++ b/c_api/fastdeploy_capi/runtime/runtime_option.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy_capi/runtime_option.h" +#include "fastdeploy_capi/runtime/runtime_option.h" #include "fastdeploy/utils/utils.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #ifdef __cplusplus extern "C" { diff --git a/c_api/fastdeploy_capi/runtime_option.h b/c_api/fastdeploy_capi/runtime/runtime_option.h similarity index 99% rename from c_api/fastdeploy_capi/runtime_option.h rename to c_api/fastdeploy_capi/runtime/runtime_option.h index 40d220bbe4..c07bb90800 100644 --- a/c_api/fastdeploy_capi/runtime_option.h +++ b/c_api/fastdeploy_capi/runtime/runtime_option.h @@ -14,7 +14,7 @@ #pragma once -#include "fastdeploy_capi/fd_type.h" +#include "fastdeploy_capi/core/fd_type.h" typedef struct FD_C_RuntimeOptionWrapper FD_C_RuntimeOptionWrapper; diff --git a/c_api/fastdeploy_capi/vision.h b/c_api/fastdeploy_capi/vision.h index 2edb072041..f2da5d2bdf 100644 --- a/c_api/fastdeploy_capi/vision.h +++ b/c_api/fastdeploy_capi/vision.h @@ -13,7 +13,7 @@ // limitations under the License. #pragma once -#include "fastdeploy_capi/config.h" +#include "fastdeploy_capi/core/config.h" #ifdef ENABLE_VISION #include "fastdeploy_capi/vision/classification/ppcls/model.h" @@ -24,5 +24,5 @@ #include "fastdeploy_capi/vision/visualize.h" #endif -#include "fastdeploy_capi/fd_type.h" -#include "fastdeploy_capi/runtime_option.h" +#include "fastdeploy_capi/core/fd_type.h" +#include "fastdeploy_capi/runtime/runtime_option.h" diff --git a/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc b/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc index ecd0460ed2..ac7232af6f 100644 --- a/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc +++ b/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc @@ -14,7 +14,7 @@ #include "fastdeploy_capi/vision/classification/ppcls/model.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #ifdef __cplusplus extern "C" { diff --git a/c_api/fastdeploy_capi/vision/classification/ppcls/model.h b/c_api/fastdeploy_capi/vision/classification/ppcls/model.h index c523e76ac3..6393dd86b1 100644 --- a/c_api/fastdeploy_capi/vision/classification/ppcls/model.h +++ b/c_api/fastdeploy_capi/vision/classification/ppcls/model.h @@ -14,9 +14,9 @@ #pragma once -#include "fastdeploy_capi/fd_common.h" -#include "fastdeploy_capi/fd_type.h" -#include "fastdeploy_capi/runtime_option.h" +#include "fastdeploy_capi/core/fd_common.h" +#include "fastdeploy_capi/core/fd_type.h" +#include "fastdeploy_capi/runtime/runtime_option.h" #include "fastdeploy_capi/vision/result.h" typedef struct FD_C_PaddleClasModelWrapper FD_C_PaddleClasModelWrapper; diff --git a/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc b/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc index 5db1b91a1f..f20d88e9b9 100644 --- a/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc +++ b/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc @@ -14,7 +14,7 @@ #include "fastdeploy_capi/vision/detection/ppdet/model.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #include "fastdeploy_capi/vision/visualize.h" #ifdef __cplusplus diff --git a/c_api/fastdeploy_capi/vision/detection/ppdet/model.h b/c_api/fastdeploy_capi/vision/detection/ppdet/model.h index 71b74bcdfc..87b8e33021 100644 --- a/c_api/fastdeploy_capi/vision/detection/ppdet/model.h +++ b/c_api/fastdeploy_capi/vision/detection/ppdet/model.h @@ -14,9 +14,9 @@ #pragma once -#include "fastdeploy_capi/fd_common.h" -#include "fastdeploy_capi/fd_type.h" -#include "fastdeploy_capi/runtime_option.h" +#include "fastdeploy_capi/core/fd_common.h" +#include "fastdeploy_capi/core/fd_type.h" +#include "fastdeploy_capi/runtime/runtime_option.h" #include "fastdeploy_capi/vision/result.h" #include "fastdeploy_capi/vision/detection/ppdet/base_define.h" diff --git a/c_api/fastdeploy_capi/vision/ocr/ppocr/model.cc b/c_api/fastdeploy_capi/vision/ocr/ppocr/model.cc index 0085287954..0da91e9953 100644 --- a/c_api/fastdeploy_capi/vision/ocr/ppocr/model.cc +++ b/c_api/fastdeploy_capi/vision/ocr/ppocr/model.cc @@ -28,7 +28,7 @@ #include "fastdeploy_capi/vision/ocr/ppocr/model.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #include "fastdeploy_capi/vision/visualize.h" #ifdef __cplusplus diff --git a/c_api/fastdeploy_capi/vision/ocr/ppocr/model.h b/c_api/fastdeploy_capi/vision/ocr/ppocr/model.h index ea32c46459..b1a1fd0a50 100644 --- a/c_api/fastdeploy_capi/vision/ocr/ppocr/model.h +++ b/c_api/fastdeploy_capi/vision/ocr/ppocr/model.h @@ -14,9 +14,9 @@ #pragma once -#include "fastdeploy_capi/fd_common.h" -#include "fastdeploy_capi/fd_type.h" -#include "fastdeploy_capi/runtime_option.h" +#include "fastdeploy_capi/core/fd_common.h" +#include "fastdeploy_capi/core/fd_type.h" +#include "fastdeploy_capi/runtime/runtime_option.h" #include "fastdeploy_capi/vision/result.h" #include "fastdeploy_capi/vision/ocr/ppocr/base_define.h" diff --git a/c_api/fastdeploy_capi/vision/result.cc b/c_api/fastdeploy_capi/vision/result.cc index ab52a6bcf6..44cc6cbfe5 100644 --- a/c_api/fastdeploy_capi/vision/result.cc +++ b/c_api/fastdeploy_capi/vision/result.cc @@ -15,7 +15,7 @@ #include "fastdeploy_capi/vision/result.h" #include "fastdeploy/utils/utils.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #ifdef __cplusplus extern "C" { diff --git a/c_api/fastdeploy_capi/vision/result.h b/c_api/fastdeploy_capi/vision/result.h index 320e4ba335..853983ee0d 100644 --- a/c_api/fastdeploy_capi/vision/result.h +++ b/c_api/fastdeploy_capi/vision/result.h @@ -14,8 +14,8 @@ #pragma once -#include "fastdeploy_capi/fd_common.h" -#include "fastdeploy_capi/fd_type.h" +#include "fastdeploy_capi/core/fd_common.h" +#include "fastdeploy_capi/core/fd_type.h" typedef struct FD_C_ClassifyResultWrapper FD_C_ClassifyResultWrapper; typedef struct FD_C_DetectionResultWrapper FD_C_DetectionResultWrapper; diff --git a/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.cc b/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.cc index f3f69dae36..277ef7db94 100644 --- a/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.cc +++ b/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.cc @@ -14,7 +14,7 @@ #include "fastdeploy_capi/vision/segmentation/ppseg/model.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #ifdef __cplusplus extern "C" { diff --git a/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.h b/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.h index cf2a83ba5b..1e561bff36 100644 --- a/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.h +++ b/c_api/fastdeploy_capi/vision/segmentation/ppseg/model.h @@ -14,9 +14,9 @@ #pragma once -#include "fastdeploy_capi/fd_common.h" -#include "fastdeploy_capi/fd_type.h" -#include "fastdeploy_capi/runtime_option.h" +#include "fastdeploy_capi/core/fd_common.h" +#include "fastdeploy_capi/core/fd_type.h" +#include "fastdeploy_capi/runtime/runtime_option.h" #include "fastdeploy_capi/vision/result.h" typedef struct FD_C_PaddleSegModelWrapper FD_C_PaddleSegModelWrapper; diff --git a/c_api/fastdeploy_capi/vision/visualize.cc b/c_api/fastdeploy_capi/vision/visualize.cc index dbe3f6dba7..6e1dba56f1 100644 --- a/c_api/fastdeploy_capi/vision/visualize.cc +++ b/c_api/fastdeploy_capi/vision/visualize.cc @@ -15,7 +15,7 @@ #include "fastdeploy_capi/vision/visualize.h" #include "fastdeploy/vision/visualize/visualize.h" -#include "fastdeploy_capi/types_internal.h" +#include "fastdeploy_capi/internal/types_internal.h" #ifdef __cplusplus extern "C" { diff --git a/c_api/fastdeploy_capi/vision/visualize.h b/c_api/fastdeploy_capi/vision/visualize.h index 05a0a66926..cbfbd1595d 100644 --- a/c_api/fastdeploy_capi/vision/visualize.h +++ b/c_api/fastdeploy_capi/vision/visualize.h @@ -14,8 +14,8 @@ #pragma once -#include "fastdeploy_capi/fd_common.h" -#include "fastdeploy_capi/fd_type.h" +#include "fastdeploy_capi/core/fd_common.h" +#include "fastdeploy_capi/core/fd_type.h" #include "fastdeploy_capi/vision/result.h" #ifdef __cplusplus diff --git a/docs/cn/faq/develop_c_api_for_a_new_model.md b/docs/cn/faq/develop_c_api_for_a_new_model.md index 6aff8214ed..fc16ccb27c 100644 --- a/docs/cn/faq/develop_c_api_for_a_new_model.md +++ b/docs/cn/faq/develop_c_api_for_a_new_model.md @@ -66,7 +66,7 @@ typedef struct FD_C_SegmentationResult { FD_C_ResultType type; } FD_C_SegmentationResult; ``` -关于FD_C_OneDimArrayUint8之类的表示,可以参考文件c_api/fastdeploy_capi/fd_type.h。 +关于FD_C_OneDimArrayUint8之类的表示,可以参考文件c_api/fastdeploy_capi/core/fd_type.h。 之后需要定义两个函数,用来从fastdeploy::SegmentationResult和FD_C_SegmentationResult之间进行相互转化。由于对C++的结构使用了对应的Wrapper结构进行包裹,所以实际定义的是FD_C_SegmentationResultWrapper和FD_C_SegmentationResult之间的转化,对应下面两个函数。 ```c @@ -83,11 +83,11 @@ FD_C_SegmentationResultWrapperToCResult( 关于各种Result在C API中的实现位置为c_api/fastdeploy_capi/vision/result.cc。 -关于声明各种Wrapper的结构可以参考文件c_api/fastdeploy_capi/types_internal.h 。 +关于声明各种Wrapper的结构可以参考文件c_api/fastdeploy_capi/internal/types_internal.h 。 2. 提供模型接口的C API -打开文件fastdeploy/vision/segmentation/ppseg/model.h,里面定义了分割模型的C++接口,即fastdeploy::vision::segmentation::PaddleSegModel类。在C中创建一个Wrapper来表示这个类,为了方便后续对同一类别的模型进行快速定义和实现,c_api/fastdeploy_capi/types_internal.h中定义了宏来快速创建Wrapper,以及从Wrapper中取出所包裹的类的对象。例如定义创建分割类模型的Wrapper的宏为 +打开文件fastdeploy/vision/segmentation/ppseg/model.h,里面定义了分割模型的C++接口,即fastdeploy::vision::segmentation::PaddleSegModel类。在C中创建一个Wrapper来表示这个类,为了方便后续对同一类别的模型进行快速定义和实现,c_api/fastdeploy_capi/internal/types_internal.h中定义了宏来快速创建Wrapper,以及从Wrapper中取出所包裹的类的对象。例如定义创建分割类模型的Wrapper的宏为 ```c #define DEFINE_SEGMENTATION_MODEL_WRAPPER_STRUCT(typename, varname) typedef struct FD_C_##typename##Wrapper { \ std::unique_ptr varname; \ diff --git a/docs/en/faq/develop_c_api_for_a_new_model.md b/docs/en/faq/develop_c_api_for_a_new_model.md index 0acb519914..f5578f52cf 100644 --- a/docs/en/faq/develop_c_api_for_a_new_model.md +++ b/docs/en/faq/develop_c_api_for_a_new_model.md @@ -71,7 +71,7 @@ typedef struct FD_C_SegmentationResult { } FD_C_SegmentationResult; ``` -For representations such as FD_C_OneDimArrayUint8, refer to file c_api/fastdeploy_capi/fd_type.h. +For representations such as FD_C_OneDimArrayUint8, refer to file c_api/fastdeploy_capi/core/fd_type.h. Then you need to define two functions that convert between fastdeploy::SegmentationResult and FD_C_SegmentationResult. Since a corresponding Wrapper structure in C is used for wrapping C++ structures, what is actually defined is conversion between FD_C_SegmentationResultWrapper and FD_C_SegmentationResult, corresponding to the following two functions. @@ -90,10 +90,10 @@ There are also other API functions for creating and destroying structures that c The implementation of various Results in C API is located at c_api/fastdeploy_capi/vision/result.cc. -For declaring various Wrapper structures, refer to file c_api/fastdeploy_capi/types_internal.h . +For declaring various Wrapper structures, refer to file c_api/fastdeploy_capi/internal/types_internal.h . 2. Provide C API for model interface -Open file fastdeploy/vision/segmentation/ppseg/model.h, which defines the C++ interface for segmentation model, i.e. fastdeploy::vision::segmentation::PaddleSegModel class. Create a Wrapper in C to represent this class. For convenience of quick definition and implementation of models of the same category in the future, c_api/fastdeploy_capi/types_internal.h defines macros to quickly create Wrapper and extract the wrapped class object from Wrapper. For example, define a macro to create a Wrapper for segmentation model as +Open file fastdeploy/vision/segmentation/ppseg/model.h, which defines the C++ interface for segmentation model, i.e. fastdeploy::vision::segmentation::PaddleSegModel class. Create a Wrapper in C to represent this class. For convenience of quick definition and implementation of models of the same category in the future, c_api/fastdeploy_capi/internal/types_internal.h defines macros to quickly create Wrapper and extract the wrapped class object from Wrapper. For example, define a macro to create a Wrapper for segmentation model as ```c #define DEFINE_SEGMENTATION_MODEL_WRAPPER_STRUCT(typename, varname) typedef struct FD_C_##typename##Wrapper { \ diff --git a/examples/vision/classification/paddleclas/c/README.md b/examples/vision/classification/paddleclas/c/README.md index ed7493980d..5b4dd19450 100755 --- a/examples/vision/classification/paddleclas/c/README.md +++ b/examples/vision/classification/paddleclas/c/README.md @@ -92,7 +92,7 @@ FD_C_PaddleClasModelWrapper* FD_C_CreatePaddleClasModelWrapper( > * **params_file**(const char*): Parameter file path > * **config_file**(const char*): Configuration file path, which is the deployment yaml file exported by PaddleClas. > * **runtime_option**(FD_C_RuntimeOptionWrapper*): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(FD_C_ModelFormat): Model format. Paddle format by default +> * **model_format**(FD_C_ModelFormat): Model format. FD_C_ModelFormat_PADDLE format by default > > **Return** > * **fd_c_ppclas_wrapper**(FD_C_PaddleClasModelWrapper*): Pointer to manipulate PaddleClas object. diff --git a/examples/vision/classification/paddleclas/c/infer.c b/examples/vision/classification/paddleclas/c/infer.c index a1570f3916..204494be73 100644 --- a/examples/vision/classification/paddleclas/c/infer.c +++ b/examples/vision/classification/paddleclas/c/infer.c @@ -38,7 +38,7 @@ void CpuInfer(const char* model_dir, const char* image_file) { FD_C_RuntimeOptionWrapperUseCpu(option); FD_C_PaddleClasModelWrapper* model = FD_C_CreatePaddleClasModelWrapper( - model_file, params_file, config_file, option, PADDLE); + model_file, params_file, config_file, option, FD_C_ModelFormat_PADDLE); if (!FD_C_PaddleClasModelWrapperInitialized(model)) { printf("Failed to initialize.\n"); @@ -86,7 +86,7 @@ void GpuInfer(const char* model_dir, const char* image_file) { FD_C_RuntimeOptionWrapperUseGpu(option, 0); FD_C_PaddleClasModelWrapper* model = FD_C_CreatePaddleClasModelWrapper( - model_file, params_file, config_file, option, PADDLE); + model_file, params_file, config_file, option, FD_C_ModelFormat_PADDLE); if (!FD_C_PaddleClasModelWrapperInitialized(model)) { printf("Failed to initialize.\n"); diff --git a/examples/vision/detection/paddledetection/c/README.md b/examples/vision/detection/paddledetection/c/README.md index 9ab7110b33..eb5d91ffbb 100644 --- a/examples/vision/detection/paddledetection/c/README.md +++ b/examples/vision/detection/paddledetection/c/README.md @@ -93,7 +93,7 @@ FD_C_PPYOLOEWrapper* FD_C_CreatePPYOLOEWrapper( > * **params_file**(const char*): Parameter file path > * **config_file**(const char*): Configuration file path, which is the deployment yaml file exported by PaddleDetection > * **runtime_option**(FD_C_RuntimeOptionWrapper*): Backend inference configuration. None by default, which is the default configuration -> * **model_format**(FD_C_ModelFormat): Model format. Paddle format by default +> * **model_format**(FD_C_ModelFormat): Model format. FD_C_ModelFormat_PADDLE format by default > > **Return** > * **fd_c_ppyoloe_wrapper**(FD_C_PPYOLOEWrapper*): Pointer to manipulate PPYOLOE object. diff --git a/examples/vision/detection/paddledetection/c/infer_ppyoloe.c b/examples/vision/detection/paddledetection/c/infer_ppyoloe.c index fe64274c21..cdc019989f 100644 --- a/examples/vision/detection/paddledetection/c/infer_ppyoloe.c +++ b/examples/vision/detection/paddledetection/c/infer_ppyoloe.c @@ -36,7 +36,7 @@ void CpuInfer(const char* model_dir, const char* image_file) { FD_C_RuntimeOptionWrapperUseCpu(option); FD_C_PPYOLOEWrapper* model = FD_C_CreatePPYOLOEWrapper( - model_file, params_file, config_file, option, PADDLE); + model_file, params_file, config_file, option, FD_C_ModelFormat_PADDLE); if (!FD_C_PPYOLOEWrapperInitialized(model)) { printf("Failed to initialize.\n"); @@ -84,7 +84,7 @@ void GpuInfer(const char* model_dir, const char* image_file) { FD_C_RuntimeOptionWrapperUseGpu(option, 0); FD_C_PPYOLOEWrapper* model = FD_C_CreatePPYOLOEWrapper( - model_file, params_file, config_file, option, PADDLE); + model_file, params_file, config_file, option, FD_C_ModelFormat_PADDLE); if (!FD_C_PPYOLOEWrapperInitialized(model)) { printf("Failed to initialize.\n"); diff --git a/examples/vision/ocr/PP-OCRv2/c/infer.c b/examples/vision/ocr/PP-OCRv2/c/infer.c index 625b044f73..f7bb1b87dd 100644 --- a/examples/vision/ocr/PP-OCRv2/c/infer.c +++ b/examples/vision/ocr/PP-OCRv2/c/infer.c @@ -73,11 +73,12 @@ void CpuInfer(const char* det_model_dir, const char* cls_model_dir, FD_C_RuntimeOptionWrapperUseCpu(rec_option); FD_C_DBDetectorWrapper* det_model = FD_C_CreateDBDetectorWrapper( - det_model_file, det_params_file, det_option, PADDLE); + det_model_file, det_params_file, det_option, FD_C_ModelFormat_PADDLE); FD_C_ClassifierWrapper* cls_model = FD_C_CreateClassifierWrapper( - cls_model_file, cls_params_file, cls_option, PADDLE); + cls_model_file, cls_params_file, cls_option, FD_C_ModelFormat_PADDLE); FD_C_RecognizerWrapper* rec_model = FD_C_CreateRecognizerWrapper( - rec_model_file, rec_params_file, rec_label_file, rec_option, PADDLE); + rec_model_file, rec_params_file, rec_label_file, rec_option, + FD_C_ModelFormat_PADDLE); FD_C_PPOCRv2Wrapper* ppocr_v2 = FD_C_CreatePPOCRv2Wrapper(det_model, cls_model, rec_model); @@ -167,11 +168,12 @@ void GpuInfer(const char* det_model_dir, const char* cls_model_dir, FD_C_RuntimeOptionWrapperUseGpu(rec_option, 0); FD_C_DBDetectorWrapper* det_model = FD_C_CreateDBDetectorWrapper( - det_model_file, det_params_file, det_option, PADDLE); + det_model_file, det_params_file, det_option, FD_C_ModelFormat_PADDLE); FD_C_ClassifierWrapper* cls_model = FD_C_CreateClassifierWrapper( - cls_model_file, cls_params_file, cls_option, PADDLE); + cls_model_file, cls_params_file, cls_option, FD_C_ModelFormat_PADDLE); FD_C_RecognizerWrapper* rec_model = FD_C_CreateRecognizerWrapper( - rec_model_file, rec_params_file, rec_label_file, rec_option, PADDLE); + rec_model_file, rec_params_file, rec_label_file, rec_option, + FD_C_ModelFormat_PADDLE); FD_C_PPOCRv2Wrapper* ppocr_v2 = FD_C_CreatePPOCRv2Wrapper(det_model, cls_model, rec_model); diff --git a/examples/vision/ocr/PP-OCRv3/c/infer.c b/examples/vision/ocr/PP-OCRv3/c/infer.c index e3b0c0f50d..72486edfc4 100644 --- a/examples/vision/ocr/PP-OCRv3/c/infer.c +++ b/examples/vision/ocr/PP-OCRv3/c/infer.c @@ -73,11 +73,12 @@ void CpuInfer(const char* det_model_dir, const char* cls_model_dir, FD_C_RuntimeOptionWrapperUseCpu(rec_option); FD_C_DBDetectorWrapper* det_model = FD_C_CreateDBDetectorWrapper( - det_model_file, det_params_file, det_option, PADDLE); + det_model_file, det_params_file, det_option, FD_C_ModelFormat_PADDLE); FD_C_ClassifierWrapper* cls_model = FD_C_CreateClassifierWrapper( - cls_model_file, cls_params_file, cls_option, PADDLE); + cls_model_file, cls_params_file, cls_option, FD_C_ModelFormat_PADDLE); FD_C_RecognizerWrapper* rec_model = FD_C_CreateRecognizerWrapper( - rec_model_file, rec_params_file, rec_label_file, rec_option, PADDLE); + rec_model_file, rec_params_file, rec_label_file, rec_option, + FD_C_ModelFormat_PADDLE); FD_C_PPOCRv3Wrapper* ppocr_v3 = FD_C_CreatePPOCRv3Wrapper(det_model, cls_model, rec_model); @@ -167,11 +168,12 @@ void GpuInfer(const char* det_model_dir, const char* cls_model_dir, FD_C_RuntimeOptionWrapperUseGpu(rec_option, 0); FD_C_DBDetectorWrapper* det_model = FD_C_CreateDBDetectorWrapper( - det_model_file, det_params_file, det_option, PADDLE); + det_model_file, det_params_file, det_option, FD_C_ModelFormat_PADDLE); FD_C_ClassifierWrapper* cls_model = FD_C_CreateClassifierWrapper( - cls_model_file, cls_params_file, cls_option, PADDLE); + cls_model_file, cls_params_file, cls_option, FD_C_ModelFormat_PADDLE); FD_C_RecognizerWrapper* rec_model = FD_C_CreateRecognizerWrapper( - rec_model_file, rec_params_file, rec_label_file, rec_option, PADDLE); + rec_model_file, rec_params_file, rec_label_file, rec_option, + FD_C_ModelFormat_PADDLE); FD_C_PPOCRv3Wrapper* ppocr_v3 = FD_C_CreatePPOCRv3Wrapper(det_model, cls_model, rec_model); diff --git a/examples/vision/segmentation/paddleseg/cpu-gpu/c/infer.c b/examples/vision/segmentation/paddleseg/cpu-gpu/c/infer.c index be950b7d64..3225d52646 100644 --- a/examples/vision/segmentation/paddleseg/cpu-gpu/c/infer.c +++ b/examples/vision/segmentation/paddleseg/cpu-gpu/c/infer.c @@ -36,7 +36,7 @@ void CpuInfer(const char* model_dir, const char* image_file) { FD_C_RuntimeOptionWrapperUseCpu(option); FD_C_PaddleSegModelWrapper* model = FD_C_CreatePaddleSegModelWrapper( - model_file, params_file, config_file, option, PADDLE); + model_file, params_file, config_file, option, FD_C_ModelFormat_PADDLE); if (!FD_C_PaddleSegModelWrapperInitialized(model)) { printf("Failed to initialize.\n"); @@ -88,7 +88,7 @@ void GpuInfer(const char* model_dir, const char* image_file) { FD_C_RuntimeOptionWrapperUseGpu(option, 0); FD_C_PaddleSegModelWrapper* model = FD_C_CreatePaddleSegModelWrapper( - model_file, params_file, config_file, option, PADDLE); + model_file, params_file, config_file, option, FD_C_ModelFormat_PADDLE); if (!FD_C_PaddleSegModelWrapperInitialized(model)) { printf("Failed to initialize.\n");