diff --git a/deploy/cpp_infer/include/cls.h b/deploy/cpp_infer/include/cls.h index f954957321f9756d1659bdc3117be60c18981d3d..f55d3952530b28f56291f64132f396dddf385294 100644 --- a/deploy/cpp_infer/include/cls.h +++ b/deploy/cpp_infer/include/cls.h @@ -40,13 +40,16 @@ public: const std::string ¶ms_path, const bool &use_gpu, const int &gpu_id, const int &gpu_mem, const int &cpu_math_library_num_threads, - const bool &use_mkldnn, const int &resize_short_size, + const bool &use_mkldnn, const bool &use_tensorrt, + const bool &use_fp16, const int &resize_short_size, const int &crop_size) { this->use_gpu_ = use_gpu; this->gpu_id_ = gpu_id; this->gpu_mem_ = gpu_mem; this->cpu_math_library_num_threads_ = cpu_math_library_num_threads; this->use_mkldnn_ = use_mkldnn; + this->use_tensorrt_ = use_tensorrt; + this->use_fp16_ = use_fp16; this->resize_short_size_ = resize_short_size; this->crop_size_ = crop_size; @@ -68,6 +71,8 @@ private: int gpu_mem_ = 4000; int cpu_math_library_num_threads_ = 4; bool use_mkldnn_ = false; + bool use_tensorrt_ = false; + bool use_fp16_ = false; std::vector mean_ = {0.485f, 0.456f, 0.406f}; std::vector scale_ = {1 / 0.229f, 1 / 0.224f, 1 / 0.225f}; diff --git a/deploy/cpp_infer/include/cls_config.h b/deploy/cpp_infer/include/cls_config.h index 4d40347f5b15507df3d767af1144f9d6b675c786..7377573c332a77bdee237181ecab342414e07bf9 100644 --- a/deploy/cpp_infer/include/cls_config.h +++ b/deploy/cpp_infer/include/cls_config.h @@ -41,6 +41,9 @@ public: this->use_mkldnn = bool(stoi(config_map_["use_mkldnn"])); + this->use_tensorrt = bool(stoi(config_map_["use_tensorrt"])); + this->use_fp16 = bool(stoi(config_map_["use_fp16"])); + this->cls_model_path.assign(config_map_["cls_model_path"]); this->cls_params_path.assign(config_map_["cls_params_path"]); @@ -60,6 +63,9 @@ public: bool use_mkldnn = false; + bool use_tensorrt = false; + bool use_fp16 = false; + std::string cls_model_path; std::string cls_params_path; diff --git a/deploy/cpp_infer/readme.md b/deploy/cpp_infer/readme.md index aad8d87dff01c40afa3a493edc5d23589e56ce03..db045adff95ab0462b0af64192127403b7331e0e 100644 --- a/deploy/cpp_infer/readme.md +++ b/deploy/cpp_infer/readme.md @@ -175,7 +175,7 @@ cmake .. \ -DDEMO_NAME=clas_system \ -DWITH_GPU=OFF \ -DWITH_STATIC_LIB=OFF \ - -DUSE_TENSORRT=OFF \ + -DWITH_TENSORRT=OFF \ -DOPENCV_DIR=${OPENCV_DIR} \ -DCUDNN_LIB=${CUDNN_LIB_DIR} \ -DCUDA_LIB=${CUDA_LIB_DIR} \ diff --git a/deploy/cpp_infer/readme_en.md b/deploy/cpp_infer/readme_en.md index 56be75491bffe86367553a6c312864b954731648..1d706afd14c6e9c262718cb8e27b8384a8e377a0 100644 --- a/deploy/cpp_infer/readme_en.md +++ b/deploy/cpp_infer/readme_en.md @@ -183,7 +183,7 @@ cmake .. \ -DDEMO_NAME=ocr_system \ -DWITH_GPU=OFF \ -DWITH_STATIC_LIB=OFF \ - -DUSE_TENSORRT=OFF \ + -DWITH_TENSORRT=OFF \ -DOPENCV_DIR=${OPENCV_DIR} \ -DCUDNN_LIB=${CUDNN_LIB_DIR} \ -DCUDA_LIB=${CUDA_LIB_DIR} \ diff --git a/deploy/cpp_infer/src/cls.cpp b/deploy/cpp_infer/src/cls.cpp index 0755eed15e86a31ac415a5507dbd55a042825e20..d304ff5eebf0902b500cc53b5df7c3c1470de535 100644 --- a/deploy/cpp_infer/src/cls.cpp +++ b/deploy/cpp_infer/src/cls.cpp @@ -23,6 +23,13 @@ void Classifier::LoadModel(const std::string &model_path, if (this->use_gpu_) { config.EnableUseGpu(this->gpu_mem_, this->gpu_id_); + if (this->use_tensorrt_) { + config.EnableTensorRtEngine( + 1 << 20, 1, 3, + this->use_fp16_ ? paddle_infer::Config::Precision::kHalf + : paddle_infer::Config::Precision::kFloat32, + false, false); + } } else { config.DisableGpu(); if (this->use_mkldnn_) { diff --git a/deploy/cpp_infer/src/main.cpp b/deploy/cpp_infer/src/main.cpp index 9b562adcf2b45e06f578149f0889fc483348f851..8885cc23bbc22d621cfb7ed6ceab94bb3bedca01 100644 --- a/deploy/cpp_infer/src/main.cpp +++ b/deploy/cpp_infer/src/main.cpp @@ -62,6 +62,7 @@ int main(int argc, char **argv) { Classifier classifier(config.cls_model_path, config.cls_params_path, config.use_gpu, config.gpu_id, config.gpu_mem, config.cpu_math_library_num_threads, config.use_mkldnn, + config.use_tensorrt, config.use_fp16, config.resize_short_size, config.crop_size); double elapsed_time = 0.0; diff --git a/deploy/cpp_infer/tools/config.txt b/deploy/cpp_infer/tools/config.txt index 5277f36609b348255d0c0851f0a83f996621060f..b0becad61c415bb63958eb20f0f96fe4edb81da5 100755 --- a/deploy/cpp_infer/tools/config.txt +++ b/deploy/cpp_infer/tools/config.txt @@ -4,6 +4,8 @@ gpu_id 0 gpu_mem 4000 cpu_math_library_num_threads 10 use_mkldnn 1 +use_tensorrt 0 +use_fp16 0 # cls config cls_model_path /PaddleClas/inference/cls_infer.pdmodel