mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 17:17:14 +08:00
[Backend] Enable TensorRT BatchedNMSDynamic_TRT plugin (#449)
* Enable TensorRT EfficientNMS plugin * remove some temporary code * Update trt_backend.cc * Update utils.h
This commit is contained in:
@@ -124,48 +124,20 @@ bool TrtBackend::InitFromPaddle(const std::string& model_file,
|
||||
option_ = option;
|
||||
|
||||
#ifdef ENABLE_PADDLE_FRONTEND
|
||||
std::vector<paddle2onnx::CustomOp> custom_ops;
|
||||
for (auto& item : option_.custom_op_info_) {
|
||||
paddle2onnx::CustomOp op;
|
||||
std::strcpy(op.op_name, item.first.c_str());
|
||||
std::strcpy(op.export_op_name, item.second.c_str());
|
||||
custom_ops.emplace_back(op);
|
||||
}
|
||||
char* model_content_ptr;
|
||||
int model_content_size = 0;
|
||||
char* calibration_cache_ptr;
|
||||
int calibration_cache_size = 0;
|
||||
if (!paddle2onnx::Export(model_file.c_str(), params_file.c_str(),
|
||||
&model_content_ptr, &model_content_size, 11, true,
|
||||
verbose, true, true, true, custom_ops.data(),
|
||||
custom_ops.size(), "tensorrt",
|
||||
verbose, true, true, true, nullptr,
|
||||
0, "tensorrt",
|
||||
&calibration_cache_ptr, &calibration_cache_size)) {
|
||||
FDERROR << "Error occured while export PaddlePaddle to ONNX format."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option_.remove_multiclass_nms_) {
|
||||
char* new_model = nullptr;
|
||||
int new_model_size = 0;
|
||||
if (!paddle2onnx::RemoveMultiClassNMS(model_content_ptr, model_content_size,
|
||||
&new_model, &new_model_size)) {
|
||||
FDERROR << "Try to remove MultiClassNMS failed." << std::endl;
|
||||
return false;
|
||||
}
|
||||
delete[] model_content_ptr;
|
||||
std::string onnx_model_proto(new_model, new_model + new_model_size);
|
||||
delete[] new_model;
|
||||
if (calibration_cache_size) {
|
||||
std::string calibration_str(
|
||||
calibration_cache_ptr,
|
||||
calibration_cache_ptr + calibration_cache_size);
|
||||
calibration_str_ = calibration_str;
|
||||
delete[] calibration_cache_ptr;
|
||||
}
|
||||
return InitFromOnnx(onnx_model_proto, option, true);
|
||||
}
|
||||
|
||||
std::string onnx_model_proto(model_content_ptr,
|
||||
model_content_ptr + model_content_size);
|
||||
delete[] model_content_ptr;
|
||||
|
@@ -73,10 +73,6 @@ struct TrtBackendOption {
|
||||
std::string serialize_file = "";
|
||||
bool enable_pinned_memory = false;
|
||||
void* external_stream_ = nullptr;
|
||||
|
||||
// inside parameter, maybe remove next version
|
||||
bool remove_multiclass_nms_ = false;
|
||||
std::map<std::string, std::string> custom_op_info_;
|
||||
};
|
||||
|
||||
std::vector<int> toVec(const nvinfer1::Dims& dim);
|
||||
|
Reference in New Issue
Block a user