|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | #include "fastdeploy/fastdeploy_runtime.h" |
| 16 | +#include "fastdeploy/utils/unique_ptr.h" |
16 | 17 | #include "fastdeploy/utils/utils.h" |
| 18 | + |
17 | 19 | #ifdef ENABLE_ORT_BACKEND |
18 | 20 | #include "fastdeploy/backends/ort/ort_backend.h" |
19 | 21 | #endif |
@@ -276,8 +278,8 @@ void Runtime::CreatePaddleBackend() { |
276 | 278 | pd_option.cpu_thread_num = option.cpu_thread_num; |
277 | 279 | FDASSERT(option.model_format == Frontend::PADDLE, |
278 | 280 | "PaddleBackend only support model format of Frontend::PADDLE."); |
279 | | - backend_ = new PaddleBackend(); |
280 | | - auto casted_backend = dynamic_cast<PaddleBackend*>(backend_); |
| 281 | + backend_ = utils::make_unique<PaddleBackend>(); |
| 282 | + auto casted_backend = dynamic_cast<PaddleBackend*>(backend_.get()); |
281 | 283 | FDASSERT(casted_backend->InitFromPaddle(option.model_file, option.params_file, |
282 | 284 | pd_option), |
283 | 285 | "Load model from Paddle failed while initliazing PaddleBackend."); |
@@ -306,8 +308,8 @@ void Runtime::CreateOrtBackend() { |
306 | 308 | option.model_format == Frontend::ONNX, |
307 | 309 | "OrtBackend only support model format of Frontend::PADDLE / " |
308 | 310 | "Frontend::ONNX."); |
309 | | - backend_ = new OrtBackend(); |
310 | | - auto casted_backend = dynamic_cast<OrtBackend*>(backend_); |
| 311 | + backend_ = utils::make_unique<OrtBackend>(); |
| 312 | + auto casted_backend = dynamic_cast<OrtBackend*>(backend_.get()); |
311 | 313 | if (option.model_format == Frontend::ONNX) { |
312 | 314 | FDASSERT(casted_backend->InitFromOnnx(option.model_file, ort_option), |
313 | 315 | "Load model from ONNX failed while initliazing OrtBackend."); |
@@ -344,8 +346,8 @@ void Runtime::CreateTrtBackend() { |
344 | 346 | option.model_format == Frontend::ONNX, |
345 | 347 | "TrtBackend only support model format of Frontend::PADDLE / " |
346 | 348 | "Frontend::ONNX."); |
347 | | - backend_ = new TrtBackend(); |
348 | | - auto casted_backend = dynamic_cast<TrtBackend*>(backend_); |
| 349 | + backend_ = utils::make_unique<TrtBackend>(); |
| 350 | + auto casted_backend = dynamic_cast<TrtBackend*>(backend_.get()); |
349 | 351 | if (option.model_format == Frontend::ONNX) { |
350 | 352 | FDASSERT(casted_backend->InitFromOnnx(option.model_file, trt_option), |
351 | 353 | "Load model from ONNX failed while initliazing TrtBackend."); |
|
0 commit comments