mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
[Model] Update PPSeg Preprocess (#1007)
* 更新PPSeg pybind and python * 更新PPSeg pybind and python
This commit is contained in:
@@ -64,8 +64,8 @@ cd ./build/install
|
|||||||
|
|
||||||
## 运行结果展示
|
## 运行结果展示
|
||||||
ClassifyResult(
|
ClassifyResult(
|
||||||
label_ids: 153,
|
label_ids: 153,
|
||||||
scores: 0.684570,
|
scores: 0.684570,
|
||||||
)
|
)
|
||||||
|
|
||||||
## 注意事项
|
## 注意事项
|
||||||
@@ -75,4 +75,4 @@ DisablePermute(C++)或`disable_permute(Python),在预处理阶段禁用数据
|
|||||||
## 其它文档
|
## 其它文档
|
||||||
- [ResNet50_vd Python 部署](../python)
|
- [ResNet50_vd Python 部署](../python)
|
||||||
- [模型预测结果说明](../../../../../../docs/api/vision_results/)
|
- [模型预测结果说明](../../../../../../docs/api/vision_results/)
|
||||||
- [转换ResNet50_vd RKNN模型文档](../README.md)
|
- [转换ResNet50_vd RKNN模型文档](../README.md)
|
||||||
|
@@ -19,8 +19,8 @@ python3 infer.py --model_file ./ResNet50_vd_infer/ResNet50_vd_infer_rk3588.rknn
|
|||||||
|
|
||||||
# 运行完成后返回结果如下所示
|
# 运行完成后返回结果如下所示
|
||||||
ClassifyResult(
|
ClassifyResult(
|
||||||
label_ids: 153,
|
label_ids: 153,
|
||||||
scores: 0.684570,
|
scores: 0.684570,
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -32,4 +32,4 @@ DisablePermute(C++)或`disable_permute(Python),在预处理阶段禁用数据
|
|||||||
## 其它文档
|
## 其它文档
|
||||||
- [ResNet50_vd C++部署](../cpp)
|
- [ResNet50_vd C++部署](../cpp)
|
||||||
- [模型预测结果说明](../../../../../../docs/api/vision_results/)
|
- [模型预测结果说明](../../../../../../docs/api/vision_results/)
|
||||||
- [转换ResNet50_vd RKNN模型文档](../README.md)
|
- [转换ResNet50_vd RKNN模型文档](../README.md)
|
||||||
|
@@ -62,7 +62,8 @@ void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) {
|
|||||||
std::cerr << "Failed to initialize." << std::endl;
|
std::cerr << "Failed to initialize." << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
model.GetPreprocessor().DisableNormalizeAndPermute();
|
model.GetPreprocessor().DisablePermute();
|
||||||
|
model.GetPreprocessor().DisableNormalize();
|
||||||
|
|
||||||
fastdeploy::TimeCounter tc;
|
fastdeploy::TimeCounter tc;
|
||||||
tc.Start();
|
tc.Start();
|
||||||
|
@@ -49,7 +49,8 @@ model = fd.vision.segmentation.PaddleSegModel(
|
|||||||
runtime_option=runtime_option,
|
runtime_option=runtime_option,
|
||||||
model_format=fd.ModelFormat.RKNN)
|
model_format=fd.ModelFormat.RKNN)
|
||||||
|
|
||||||
model.preprocessor.disable_normalize_and_permute()
|
model.preprocessor.disable_normalize()
|
||||||
|
model.preprocessor.disable_permute()
|
||||||
|
|
||||||
# 预测图片分割结果
|
# 预测图片分割结果
|
||||||
im = cv2.imread(args.image)
|
im = cv2.imread(args.image)
|
||||||
|
@@ -36,9 +36,12 @@ void BindPPSeg(pybind11::module& m) {
|
|||||||
}
|
}
|
||||||
return make_pair(outputs, imgs_info);;
|
return make_pair(outputs, imgs_info);;
|
||||||
})
|
})
|
||||||
.def("disable_normalize_and_permute",
|
.def("disable_normalize", [](vision::segmentation::PaddleSegPreprocessor& self) {
|
||||||
&vision::segmentation::PaddleSegPreprocessor::DisableNormalizeAndPermute)
|
self.DisableNormalize();
|
||||||
|
})
|
||||||
|
.def("disable_permute", [](vision::segmentation::PaddleSegPreprocessor& self) {
|
||||||
|
self.DisablePermute();
|
||||||
|
})
|
||||||
.def_property("is_vertical_screen",
|
.def_property("is_vertical_screen",
|
||||||
&vision::segmentation::PaddleSegPreprocessor::GetIsVerticalScreen,
|
&vision::segmentation::PaddleSegPreprocessor::GetIsVerticalScreen,
|
||||||
&vision::segmentation::PaddleSegPreprocessor::SetIsVerticalScreen);
|
&vision::segmentation::PaddleSegPreprocessor::SetIsVerticalScreen);
|
||||||
|
@@ -43,7 +43,7 @@ bool PaddleSegPreprocessor::BuildPreprocessPipelineFromConfig() {
|
|||||||
FDASSERT(op.IsMap(),
|
FDASSERT(op.IsMap(),
|
||||||
"Require the transform information in yaml be Map type.");
|
"Require the transform information in yaml be Map type.");
|
||||||
if (op["type"].as<std::string>() == "Normalize") {
|
if (op["type"].as<std::string>() == "Normalize") {
|
||||||
if (!disable_normalize_and_permute_) {
|
if (!disable_normalize_) {
|
||||||
std::vector<float> mean = {0.5, 0.5, 0.5};
|
std::vector<float> mean = {0.5, 0.5, 0.5};
|
||||||
std::vector<float> std = {0.5, 0.5, 0.5};
|
std::vector<float> std = {0.5, 0.5, 0.5};
|
||||||
if (op["mean"]) {
|
if (op["mean"]) {
|
||||||
@@ -55,7 +55,7 @@ bool PaddleSegPreprocessor::BuildPreprocessPipelineFromConfig() {
|
|||||||
processors_.push_back(std::make_shared<Normalize>(mean, std));
|
processors_.push_back(std::make_shared<Normalize>(mean, std));
|
||||||
}
|
}
|
||||||
} else if (op["type"].as<std::string>() == "Resize") {
|
} else if (op["type"].as<std::string>() == "Resize") {
|
||||||
is_contain_resize_op = true;
|
is_contain_resize_op_ = true;
|
||||||
const auto& target_size = op["target_size"];
|
const auto& target_size = op["target_size"];
|
||||||
int resize_width = target_size[0].as<int>();
|
int resize_width = target_size[0].as<int>();
|
||||||
int resize_height = target_size[1].as<int>();
|
int resize_height = target_size[1].as<int>();
|
||||||
@@ -73,13 +73,13 @@ bool PaddleSegPreprocessor::BuildPreprocessPipelineFromConfig() {
|
|||||||
auto input_shape = cfg["Deploy"]["input_shape"];
|
auto input_shape = cfg["Deploy"]["input_shape"];
|
||||||
int input_height = input_shape[2].as<int>();
|
int input_height = input_shape[2].as<int>();
|
||||||
int input_width = input_shape[3].as<int>();
|
int input_width = input_shape[3].as<int>();
|
||||||
if (input_height != -1 && input_width != -1 && !is_contain_resize_op) {
|
if (input_height != -1 && input_width != -1 && !is_contain_resize_op_) {
|
||||||
is_contain_resize_op = true;
|
is_contain_resize_op_ = true;
|
||||||
processors_.insert(processors_.begin(),
|
processors_.insert(processors_.begin(),
|
||||||
std::make_shared<Resize>(input_width, input_height));
|
std::make_shared<Resize>(input_width, input_height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!disable_normalize_and_permute_) {
|
if (!disable_permute_) {
|
||||||
processors_.push_back(std::make_shared<HWC2CHW>());
|
processors_.push_back(std::make_shared<HWC2CHW>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ bool PaddleSegPreprocessor::Run(std::vector<FDMat>* images, std::vector<FDTensor
|
|||||||
}
|
}
|
||||||
size_t img_num = images->size();
|
size_t img_num = images->size();
|
||||||
// Batch preprocess : resize all images to the largest image shape in batch
|
// Batch preprocess : resize all images to the largest image shape in batch
|
||||||
if (!is_contain_resize_op && img_num > 1) {
|
if (!is_contain_resize_op_ && img_num > 1) {
|
||||||
int max_width = 0;
|
int max_width = 0;
|
||||||
int max_height = 0;
|
int max_height = 0;
|
||||||
for (size_t i = 0; i < img_num; ++i) {
|
for (size_t i = 0; i < img_num; ++i) {
|
||||||
@@ -156,14 +156,20 @@ bool PaddleSegPreprocessor::Run(std::vector<FDMat>* images, std::vector<FDTensor
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaddleSegPreprocessor::DisableNormalizeAndPermute(){
|
void PaddleSegPreprocessor::DisableNormalize() {
|
||||||
disable_normalize_and_permute_ = true;
|
this->disable_normalize_ = true;
|
||||||
// the DisableNormalizeAndPermute function will be invalid if the configuration file is loaded during preprocessing
|
// the DisableNormalize function will be invalid if the configuration file is loaded during preprocessing
|
||||||
|
if (!BuildPreprocessPipelineFromConfig()) {
|
||||||
|
FDERROR << "Failed to build preprocess pipeline from configuration file." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void PaddleSegPreprocessor::DisablePermute() {
|
||||||
|
this->disable_permute_ = true;
|
||||||
|
// the DisablePermute function will be invalid if the configuration file is loaded during preprocessing
|
||||||
if (!BuildPreprocessPipelineFromConfig()) {
|
if (!BuildPreprocessPipelineFromConfig()) {
|
||||||
FDERROR << "Failed to build preprocess pipeline from configuration file." << std::endl;
|
FDERROR << "Failed to build preprocess pipeline from configuration file." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace segmentation
|
} // namespace segmentation
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
} // namespace fastdeploy
|
} // namespace fastdeploy
|
||||||
|
@@ -49,8 +49,10 @@ class FASTDEPLOY_DECL PaddleSegPreprocessor {
|
|||||||
is_vertical_screen_ = value;
|
is_vertical_screen_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function will disable normalize and hwc2chw in preprocessing step.
|
/// This function will disable normalize in preprocessing step.
|
||||||
void DisableNormalizeAndPermute();
|
void DisableNormalize();
|
||||||
|
/// This function will disable hwc2chw in preprocessing step.
|
||||||
|
void DisablePermute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool BuildPreprocessPipelineFromConfig();
|
virtual bool BuildPreprocessPipelineFromConfig();
|
||||||
@@ -61,10 +63,12 @@ class FASTDEPLOY_DECL PaddleSegPreprocessor {
|
|||||||
*/
|
*/
|
||||||
bool is_vertical_screen_ = false;
|
bool is_vertical_screen_ = false;
|
||||||
|
|
||||||
// for recording the switch of normalize and hwc2chw
|
// for recording the switch of hwc2chw
|
||||||
bool disable_normalize_and_permute_ = false;
|
bool disable_permute_ = false;
|
||||||
|
// for recording the switch of normalize
|
||||||
|
bool disable_normalize_ = false;
|
||||||
|
|
||||||
bool is_contain_resize_op = false;
|
bool is_contain_resize_op_ = false;
|
||||||
|
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
};
|
};
|
||||||
|
@@ -104,10 +104,17 @@ class PaddleSegPreprocessor:
|
|||||||
"""
|
"""
|
||||||
return self._preprocessor.run(input_ims)
|
return self._preprocessor.run(input_ims)
|
||||||
|
|
||||||
def disable_normalize_and_permute(self):
|
def disable_normalize(self):
|
||||||
"""To disable normalize and hwc2chw in preprocessing step.
|
|
||||||
"""
|
"""
|
||||||
return self._preprocessor.disable_normalize_and_permute()
|
This function will disable normalize in preprocessing step.
|
||||||
|
"""
|
||||||
|
self._preprocessor.disable_normalize()
|
||||||
|
|
||||||
|
def disable_permute(self):
|
||||||
|
"""
|
||||||
|
This function will disable hwc2chw in preprocessing step.
|
||||||
|
"""
|
||||||
|
self._preprocessor.disable_permute()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_vertical_screen(self):
|
def is_vertical_screen(self):
|
||||||
|
Reference in New Issue
Block a user