Skip to content

Commit

Permalink
[Other] Update deprecated segmentation apis && segmentation label map…
Browse files Browse the repository at this point in the history
… resize interinterpolation (PaddlePaddle#790)

* Refactor PaddleSeg with preprocessor && postprocessor

* Fix bugs

* Delete redundancy code

* Modify by comments

* Refactor according to comments

* Add batch evaluation

* Add single test script

* Add ppliteseg single test script && fix eval(raise) error

* fix bug

* Fix evaluation segmentation.py batch predict

* Fix segmentation evaluation bug

* Fix evaluation segmentation bugs

* Update segmentation result docs

* Update old predict api and DisableNormalizeAndPermute

* Update resize segmentation label map with cv::INTER_NEAREST

Co-authored-by: Jason <[email protected]>
  • Loading branch information
felixhjh and jiangjiajun authored Dec 5, 2022
1 parent d74e120 commit 6c31198
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/vision/segmentation/paddleseg/cpp/infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void CpuInfer(const std::string& model_dir, const std::string& image_file) {
auto im = cv::imread(image_file);

fastdeploy::vision::SegmentationResult res;
if (!model.Predict(&im, &res)) {
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file) {
auto im = cv::imread(image_file);

fastdeploy::vision::SegmentationResult res;
if (!model.Predict(&im, &res)) {
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file) {
auto im = cv::imread(image_file);

fastdeploy::vision::SegmentationResult res;
if (!model.Predict(&im, &res)) {
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
auto im_bak = im.clone();

fastdeploy::vision::SegmentationResult res;
if (!model.Predict(&im, &res)) {
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void InferHumanPPHumansegv2Lite(const std::string& device) {
auto im = cv::imread(image_file);

if (device == "npu") {
model.DisableNormalizeAndPermute();
model.GetPreprocessor().DisableNormalizeAndPermute();
}

fastdeploy::vision::SegmentationResult res;
clock_t start = clock();
if (!model.Predict(&im, &res)) {
if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
Expand Down
10 changes: 7 additions & 3 deletions fastdeploy/vision/segmentation/ppseg/postprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,17 @@ bool PaddleSegPostprocessor::Run(

FDMat mat;
std::vector<uint8_t> uint8_result_buffer;
// Resize interpration
int interpolation = cv::INTER_LINEAR;
if (is_resized) {
if (infer_results_dtype == FDDataType::INT64 ||
infer_results_dtype == FDDataType::INT32 ){
FDTensorCast2Uint8(&infer_result, infer_chw, &uint8_result_buffer);
}
FDTensorCast2Uint8(&infer_result, infer_chw, &uint8_result_buffer);
// label map resize with nearest interpolation
interpolation = cv::INTER_NEAREST;
}
mat = std::move(Mat::Create(infer_result, ProcLib::OPENCV));
Resize::Run(&mat, input_width, input_height, -1.0f, -1.0f, 1, false, ProcLib::OPENCV);
Resize::Run(&mat, input_width, input_height, -1.0f, -1.0f, interpolation, false, ProcLib::OPENCV);
mat.ShareWithTensor(&infer_result);
}
result->shape = infer_result.shape;
Expand Down

0 comments on commit 6c31198

Please sign in to comment.