[Model] Add Picodet RKNPU2 (#635)

* * 更新picodet cpp代码

* * 更新文档
* 更新picodet cpp example

* * 删除无用的debug代码
* 新增python example

* * 修改c++代码

* * 修改python代码

* * 修改postprocess代码

* 修复没有scale_factor导致的bug

* 修复错误

* 更正代码格式

* 更正代码格式
This commit is contained in:
Zheng_Bicheng
2022-11-21 13:44:34 +08:00
committed by GitHub
parent 5ca779ee32
commit 3e1fc69a0c
20 changed files with 340 additions and 195 deletions
+20 -11
View File
@@ -6,10 +6,12 @@ namespace fastdeploy {
namespace vision {
namespace detection {
PPDetBase::PPDetBase(const std::string& model_file, const std::string& params_file,
const std::string& config_file,
const RuntimeOption& custom_option,
const ModelFormat& model_format) : preprocessor_(config_file) {
PPDetBase::PPDetBase(const std::string& model_file,
const std::string& params_file,
const std::string& config_file,
const RuntimeOption& custom_option,
const ModelFormat& model_format)
: preprocessor_(config_file) {
runtime_option = custom_option;
runtime_option.model_format = model_format;
runtime_option.model_file = model_file;
@@ -37,7 +39,8 @@ bool PPDetBase::Predict(const cv::Mat& im, DetectionResult* result) {
return true;
}
bool PPDetBase::BatchPredict(const std::vector<cv::Mat>& imgs, std::vector<DetectionResult>* results) {
bool PPDetBase::BatchPredict(const std::vector<cv::Mat>& imgs,
std::vector<DetectionResult>* results) {
std::vector<FDMat> fd_images = WrapMat(imgs);
if (!preprocessor_.Run(&fd_images, &reused_input_tensors_)) {
FDERROR << "Failed to preprocess the input image." << std::endl;
@@ -46,8 +49,13 @@ bool PPDetBase::BatchPredict(const std::vector<cv::Mat>& imgs, std::vector<Detec
reused_input_tensors_[0].name = "image";
reused_input_tensors_[1].name = "scale_factor";
reused_input_tensors_[2].name = "im_shape";
// Some models don't need im_shape as input
if (NumInputsOfRuntime() == 2) {
if(postprocessor_.DecodeAndNMSApplied()){
postprocessor_.SetScaleFactor(static_cast<float*>(reused_input_tensors_[1].Data()));
}
// Some models don't need scale_factor and im_shape as input
while (reused_input_tensors_.size() != NumInputsOfRuntime()) {
reused_input_tensors_.pop_back();
}
@@ -57,12 +65,13 @@ bool PPDetBase::BatchPredict(const std::vector<cv::Mat>& imgs, std::vector<Detec
}
if (!postprocessor_.Run(reused_output_tensors_, results)) {
FDERROR << "Failed to postprocess the inference results by runtime." << std::endl;
FDERROR << "Failed to postprocess the inference results by runtime."
<< std::endl;
return false;
}
return true;
}
} // namespace detection
} // namespace vision
} // namespace fastdeploy
} // namespace detection
} // namespace vision
} // namespace fastdeploy