|
| 1 | +English | [简体中文](README_CN.md) |
| 2 | +# PaddleClas C Deployment Example |
| 3 | + |
| 4 | +This directory provides examples that `infer.c` fast finishes the deployment of PaddleClas models on CPU/GPU. |
| 5 | + |
| 6 | +Before deployment, two steps require confirmation. |
| 7 | + |
| 8 | +- 1. Software and hardware should meet the requirements. Please refer to [FastDeploy Environment Requirements](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md). |
| 9 | +- 2. Download the precompiled deployment library and samples code according to your development environment. Refer to [FastDeploy Precompiled Library](../../../../../docs/en/build_and_install/download_prebuilt_libraries.md). |
| 10 | + |
| 11 | +Taking ResNet50_vd inference on Linux as an example, the compilation test can be completed by executing the following command in this directory. FastDeploy version 1.0.4 or above (x.x.x>=1.0.4) is required to support this model. |
| 12 | + |
| 13 | +```bash |
| 14 | +mkdir build |
| 15 | +cd build |
| 16 | +# Download FastDeploy precompiled library. Users can choose your appropriate version in the`FastDeploy Precompiled Library` mentioned above |
| 17 | +wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz |
| 18 | +tar xvf fastdeploy-linux-x64-x.x.x.tgz |
| 19 | +cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x |
| 20 | +make -j |
| 21 | + |
| 22 | +# Download ResNet50_vd model file and test images |
| 23 | +wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz |
| 24 | +tar -xvf ResNet50_vd_infer.tgz |
| 25 | +wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg |
| 26 | + |
| 27 | + |
| 28 | +# CPU inference |
| 29 | +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 0 |
| 30 | +# GPU inference |
| 31 | +./infer_demo ResNet50_vd_infer ILSVRC2012_val_00000010.jpeg 1 |
| 32 | +``` |
| 33 | + |
| 34 | +The above command works for Linux or MacOS. Refer to |
| 35 | +- [How to use FastDeploy C++ SDK in Windows](../../../../../docs/cn/faq/use_sdk_on_windows.md) for SDK use-pattern in Windows |
| 36 | + |
| 37 | +## PaddleClas C Interface |
| 38 | + |
| 39 | +### RuntimeOption |
| 40 | + |
| 41 | +```c |
| 42 | +FD_C_RuntimeOptionWrapper* FD_C_CreateRuntimeOptionWrapper() |
| 43 | +``` |
| 44 | + |
| 45 | +> Create a RuntimeOption object, and return a pointer to manipulate it. |
| 46 | +> |
| 47 | +> **Return** |
| 48 | +> |
| 49 | +> * **fd_c_runtime_option_wrapper**(FD_C_RuntimeOptionWrapper*): Pointer to manipulate RuntimeOption object. |
| 50 | + |
| 51 | + |
| 52 | +```c |
| 53 | +void FD_C_RuntimeOptionWrapperUseCpu( |
| 54 | + FD_C_RuntimeOptionWrapper* fd_c_runtime_option_wrapper) |
| 55 | +``` |
| 56 | +
|
| 57 | +> Enable Cpu inference. |
| 58 | +> |
| 59 | +> **Params** |
| 60 | +> |
| 61 | +> * **fd_c_runtime_option_wrapper**(FD_C_RuntimeOptionWrapper*): Pointer to manipulate RuntimeOption object. |
| 62 | +
|
| 63 | +```c |
| 64 | +void FD_C_RuntimeOptionWrapperUseGpu( |
| 65 | + FD_C_RuntimeOptionWrapper* fd_c_runtime_option_wrapper, |
| 66 | + int gpu_id) |
| 67 | +``` |
| 68 | +> 开启GPU推理 |
| 69 | +> |
| 70 | +> **参数** |
| 71 | +> |
| 72 | +> * **fd_c_runtime_option_wrapper**(FD_C_RuntimeOptionWrapper*): Pointer to manipulate RuntimeOption object. |
| 73 | +> * **gpu_id**(int): gpu id |
| 74 | +
|
| 75 | + |
| 76 | +### Model |
| 77 | + |
| 78 | +```c |
| 79 | + |
| 80 | +FD_C_PaddleClasModelWrapper* FD_C_CreatePaddleClasModelWrapper( |
| 81 | + const char* model_file, const char* params_file, const char* config_file, |
| 82 | + FD_C_RuntimeOptionWrapper* runtime_option, |
| 83 | + const FD_C_ModelFormat model_format) |
| 84 | + |
| 85 | +``` |
| 86 | +
|
| 87 | +> Create a PaddleClas model object, and return a pointer to manipulate it. |
| 88 | +> |
| 89 | +> **Params** |
| 90 | +> |
| 91 | +> * **model_file**(const char*): Model file path |
| 92 | +> * **params_file**(const char*): Parameter file path |
| 93 | +> * **config_file**(const char*): Configuration file path, which is the deployment yaml file exported by PaddleClas. |
| 94 | +> * **runtime_option**(FD_C_RuntimeOptionWrapper*): Backend inference configuration. None by default, which is the default configuration |
| 95 | +> * **model_format**(FD_C_ModelFormat): Model format. Paddle format by default |
| 96 | +> |
| 97 | +> **Return** |
| 98 | +> * **fd_c_ppclas_wrapper**(FD_C_PaddleClasModelWrapper*): Pointer to manipulate PaddleClas object. |
| 99 | +
|
| 100 | +
|
| 101 | +#### Read and write image |
| 102 | +
|
| 103 | +```c |
| 104 | +FD_C_Mat FD_C_Imread(const char* imgpath) |
| 105 | +``` |
| 106 | + |
| 107 | +> Read an image, and return a pointer to cv::Mat. |
| 108 | +> |
| 109 | +> **Params** |
| 110 | +> |
| 111 | +> * **imgpath**(const char*): image path |
| 112 | +> |
| 113 | +> **Return** |
| 114 | +> |
| 115 | +> * **imgmat**(FD_C_Mat): pointer to cv::Mat object which holds the image. |
| 116 | +
|
| 117 | + |
| 118 | +```c |
| 119 | +FD_C_Bool FD_C_Imwrite(const char* savepath, FD_C_Mat img); |
| 120 | +``` |
| 121 | +
|
| 122 | +> Write image to a file. |
| 123 | +> |
| 124 | +> **Params** |
| 125 | +> |
| 126 | +> * **savepath**(const char*): save path |
| 127 | +> * **img**(FD_C_Mat): pointer to cv::Mat object |
| 128 | +> |
| 129 | +> **Return** |
| 130 | +> |
| 131 | +> * **result**(FD_C_Bool): bool to indicate success or failure |
| 132 | +
|
| 133 | +
|
| 134 | +#### Prediction |
| 135 | +
|
| 136 | +```c |
| 137 | +FD_C_Bool FD_C_PaddleClasModelWrapperPredict( |
| 138 | + __fd_take FD_C_PaddleClasModelWrapper* fd_c_ppclas_wrapper, FD_C_Mat img, |
| 139 | + FD_C_ClassifyResult* fd_c_ppclas_result) |
| 140 | +``` |
| 141 | +> |
| 142 | +> Predict an image, and generate classification result. |
| 143 | +> |
| 144 | +> **Params** |
| 145 | +> * **fd_c_ppclas_wrapper**(FD_C_PaddleClasModelWrapper*): pointer to manipulate PaddleClas object |
| 146 | +> * **img**(FD_C_Mat): pointer to cv::Mat object, which can be obained by FD_C_Imread interface |
| 147 | +> * **fd_c_ppclas_result** (FD_C_ClassifyResult*): The classification result, including label_id, and the corresponding confidence. Refer to [Visual Model Prediction Results](../../../../../docs/api/vision_results/) for the description of ClassifyResult |
| 148 | +
|
| 149 | + |
| 150 | +#### Result |
| 151 | + |
| 152 | +```c |
| 153 | +FD_C_ClassifyResultWrapper* FD_C_CreateClassifyResultWrapperFromData( |
| 154 | + FD_C_ClassifyResult* fd_c_classify_result) |
| 155 | +``` |
| 156 | +> |
| 157 | +> Create a pointer to FD_C_ClassifyResultWrapper structure, which contains `fastdeploy::vision::ClassifyResult` object in C++. You can call methods in C++ ClassifyResult object by C API with this pointer. |
| 158 | +> |
| 159 | +> **Params** |
| 160 | +> * **fd_c_classify_result**(FD_C_ClassifyResult*): pointer to FD_C_ClassifyResult structure |
| 161 | +> |
| 162 | +> **Return** |
| 163 | +> * **fd_c_classify_result_wrapper**(FD_C_ClassifyResultWrapper*): pointer to FD_C_ClassifyResultWrapper structure |
| 164 | +
|
| 165 | +
|
| 166 | +```c |
| 167 | +char* FD_C_ClassifyResultWrapperStr( |
| 168 | + FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper); |
| 169 | +``` |
| 170 | +> |
| 171 | +> Call Str() methods in `fastdeploy::vision::ClassifyResult` object contained in FD_C_ClassifyResultWrapper structure,and return a string to describe information in result. |
| 172 | +> |
| 173 | +> **Params** |
| 174 | +> * **fd_c_classify_result_wrapper**(FD_C_ClassifyResultWrapper*): pointer to FD_C_ClassifyResultWrapper structure |
| 175 | +> |
| 176 | +> **Return** |
| 177 | +> * **str**(char*): a string to describe information in result |
| 178 | +
|
| 179 | + |
| 180 | +- [Model Description](../../) |
| 181 | +- [Python Deployment](../python) |
| 182 | +- [Visual Model prediction results](../../../../../docs/api/vision_results/) |
| 183 | +- [How to switch the model inference backend engine](../../../../../docs/en/faq/how_to_change_backend.md) |
0 commit comments