diff --git a/src/io/api_paddle_mobile.cc b/src/io/api_paddle_mobile.cc index 4609438ec9fbdb5b5030b56a4bf18b9437bf7c2e..b07232867c0c66a9d064469f279dffe55b4b75bb 100644 --- a/src/io/api_paddle_mobile.cc +++ b/src/io/api_paddle_mobile.cc @@ -101,6 +101,11 @@ bool PaddleMobilePredictor::Run( return true; } +template +PaddleMobilePredictor::~PaddleMobilePredictor() { + paddle_mobile_->Clear(); +} + // A factory to help create difference predictor. template <> std::unique_ptr diff --git a/src/io/api_paddle_mobile.h b/src/io/api_paddle_mobile.h index 66c6a4d5d9f8fc81b96642c6d5b62757dd581bc3..bdeb7e18653843ec9547f027068768532ba04fb2 100644 --- a/src/io/api_paddle_mobile.h +++ b/src/io/api_paddle_mobile.h @@ -32,7 +32,7 @@ namespace paddle_mobile { template class PaddleMobilePredictor : public PaddlePredictor { public: - PaddleMobilePredictor() {} + PaddleMobilePredictor() = delete; explicit PaddleMobilePredictor(const PaddleMobileConfig& config); @@ -40,7 +40,7 @@ class PaddleMobilePredictor : public PaddlePredictor { std::vector* output_data, int batch_size = -1) override; - ~PaddleMobilePredictor() override{}; + ~PaddleMobilePredictor() override; private: std::unique_ptr> paddle_mobile_; diff --git a/src/io/paddle_inference_api.h b/src/io/paddle_inference_api.h index 97564f4132d2e43cf736c2eb4a95d437584be24f..104ba11153cdb9b3bb5e249a771a2cd27ad7dbac 100644 --- a/src/io/paddle_inference_api.h +++ b/src/io/paddle_inference_api.h @@ -87,7 +87,6 @@ enum class PaddleEngineKind { class PaddlePredictor { public: struct Config; - PaddlePredictor() = default; PaddlePredictor(const PaddlePredictor&) = delete; PaddlePredictor& operator=(const PaddlePredictor&) = delete; @@ -107,6 +106,9 @@ class PaddlePredictor { struct Config { std::string model_dir; // path to the model directory. }; + + protected: + PaddlePredictor() = default; }; struct PaddleMobileConfig : public PaddlePredictor::Config { diff --git a/test/framework/test_inference_api.cpp b/test/framework/test_inference_api.cpp index 7dec2fe29753c75ee70f31428d104450acce9404..e1713bb203dc011f0fd7c48ff3b736f48d56eb44 100644 --- a/test/framework/test_inference_api.cpp +++ b/test/framework/test_inference_api.cpp @@ -46,7 +46,12 @@ int main() { tensor_out.dtype = PaddleDType::FLOAT32; std::vector outputs(1, tensor_out); - assert(predictor->Run(paddle_tensor_feeds, &outputs)); + std::cout << " before predict " << std::endl; + + predictor->Run(paddle_tensor_feeds, &outputs); + + std::cout << " after predict " << std::endl; + // assert(); float* data_o = static_cast(outputs[0].data.data()); for (size_t j = 0; j < outputs[0].data.length() / sizeof(float); ++j) {