mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-13 20:34:02 +08:00
[Other]Fastdeploy supports set_model_buffer function for encrypted model (#930)
* Update keypointdetection result docs * Update im.copy() to im in examples * Update new Api, fastdeploy::vision::Visualize to fastdeploy::vision * Update SwapBackgroundSegmentation && SwapBackgroundMatting to SwapBackground * Update README_CN.md * Update README_CN.md * Support set_model_buffer function
This commit is contained in:
@@ -213,6 +213,31 @@ void RuntimeOption::SetModelPath(const std::string& model_path,
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeOption::SetModelBuffer(const char * model_buffer,
|
||||
size_t model_buffer_size,
|
||||
const char * params_buffer,
|
||||
size_t params_buffer_size,
|
||||
const ModelFormat& format) {
|
||||
model_buffer_size_ = model_buffer_size;
|
||||
params_buffer_size_ = params_buffer_size;
|
||||
model_from_memory_ = true;
|
||||
if (format == ModelFormat::PADDLE) {
|
||||
model_buffer_ = std::string(model_buffer, model_buffer + model_buffer_size);
|
||||
params_buffer_ = std::string(params_buffer, params_buffer + params_buffer_size);
|
||||
model_format = ModelFormat::PADDLE;
|
||||
} else if (format == ModelFormat::ONNX) {
|
||||
model_buffer_ = std::string(model_buffer, model_buffer + model_buffer_size);
|
||||
model_format = ModelFormat::ONNX;
|
||||
} else if (format == ModelFormat::TORCHSCRIPT) {
|
||||
model_buffer_ = std::string(model_buffer, model_buffer + model_buffer_size);
|
||||
model_format = ModelFormat::TORCHSCRIPT;
|
||||
} else {
|
||||
FDASSERT(false,
|
||||
"The model format only can be "
|
||||
"ModelFormat::PADDLE/ModelFormat::ONNX/ModelFormat::TORCHSCRIPT.");
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeOption::UseGpu(int gpu_id) {
|
||||
#ifdef WITH_GPU
|
||||
device = Device::GPU;
|
||||
@@ -646,6 +671,13 @@ void Runtime::CreatePaddleBackend() {
|
||||
pd_option.cpu_thread_num = option.cpu_thread_num;
|
||||
pd_option.enable_pinned_memory = option.enable_pinned_memory;
|
||||
pd_option.external_stream_ = option.external_stream_;
|
||||
pd_option.model_from_memory_ = option.model_from_memory_;
|
||||
if (pd_option.model_from_memory_) {
|
||||
pd_option.model_buffer_ = option.model_buffer_;
|
||||
pd_option.params_buffer_ = option.params_buffer_;
|
||||
pd_option.model_buffer_size_ = option.model_buffer_size_;
|
||||
pd_option.params_buffer_size_ = option.params_buffer_size_;
|
||||
}
|
||||
#ifdef ENABLE_TRT_BACKEND
|
||||
if (pd_option.use_gpu && option.pd_enable_trt) {
|
||||
pd_option.enable_trt = true;
|
||||
@@ -683,9 +715,15 @@ void Runtime::CreatePaddleBackend() {
|
||||
"PaddleBackend only support model format of ModelFormat::PADDLE.");
|
||||
backend_ = utils::make_unique<PaddleBackend>();
|
||||
auto casted_backend = dynamic_cast<PaddleBackend*>(backend_.get());
|
||||
FDASSERT(casted_backend->InitFromPaddle(option.model_file, option.params_file,
|
||||
if (pd_option.model_from_memory_) {
|
||||
FDASSERT(casted_backend->InitFromPaddle(option.model_buffer_, option.params_buffer_,
|
||||
pd_option),
|
||||
"Load model from Paddle failed while initliazing PaddleBackend.");
|
||||
} else {
|
||||
FDASSERT(casted_backend->InitFromPaddle(option.model_file, option.params_file,
|
||||
pd_option),
|
||||
"Load model from Paddle failed while initliazing PaddleBackend.");
|
||||
}
|
||||
#else
|
||||
FDASSERT(false, "PaddleBackend is not available, please compiled with "
|
||||
"ENABLE_PADDLE_BACKEND=ON.");
|
||||
|
Reference in New Issue
Block a user