mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +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(
|
||||
label_ids: 153,
|
||||
scores: 0.684570,
|
||||
label_ids: 153,
|
||||
scores: 0.684570,
|
||||
)
|
||||
|
||||
## 注意事项
|
||||
@@ -75,4 +75,4 @@ DisablePermute(C++)或`disable_permute(Python),在预处理阶段禁用数据
|
||||
## 其它文档
|
||||
- [ResNet50_vd Python 部署](../python)
|
||||
- [模型预测结果说明](../../../../../../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(
|
||||
label_ids: 153,
|
||||
scores: 0.684570,
|
||||
label_ids: 153,
|
||||
scores: 0.684570,
|
||||
)
|
||||
```
|
||||
|
||||
@@ -32,4 +32,4 @@ DisablePermute(C++)或`disable_permute(Python),在预处理阶段禁用数据
|
||||
## 其它文档
|
||||
- [ResNet50_vd C++部署](../cpp)
|
||||
- [模型预测结果说明](../../../../../../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;
|
||||
return;
|
||||
}
|
||||
model.GetPreprocessor().DisableNormalizeAndPermute();
|
||||
model.GetPreprocessor().DisablePermute();
|
||||
model.GetPreprocessor().DisableNormalize();
|
||||
|
||||
fastdeploy::TimeCounter tc;
|
||||
tc.Start();
|
||||
|
@@ -49,7 +49,8 @@ model = fd.vision.segmentation.PaddleSegModel(
|
||||
runtime_option=runtime_option,
|
||||
model_format=fd.ModelFormat.RKNN)
|
||||
|
||||
model.preprocessor.disable_normalize_and_permute()
|
||||
model.preprocessor.disable_normalize()
|
||||
model.preprocessor.disable_permute()
|
||||
|
||||
# 预测图片分割结果
|
||||
im = cv2.imread(args.image)
|
||||
|
@@ -36,9 +36,12 @@ void BindPPSeg(pybind11::module& m) {
|
||||
}
|
||||
return make_pair(outputs, imgs_info);;
|
||||
})
|
||||
.def("disable_normalize_and_permute",
|
||||
&vision::segmentation::PaddleSegPreprocessor::DisableNormalizeAndPermute)
|
||||
|
||||
.def("disable_normalize", [](vision::segmentation::PaddleSegPreprocessor& self) {
|
||||
self.DisableNormalize();
|
||||
})
|
||||
.def("disable_permute", [](vision::segmentation::PaddleSegPreprocessor& self) {
|
||||
self.DisablePermute();
|
||||
})
|
||||
.def_property("is_vertical_screen",
|
||||
&vision::segmentation::PaddleSegPreprocessor::GetIsVerticalScreen,
|
||||
&vision::segmentation::PaddleSegPreprocessor::SetIsVerticalScreen);
|
||||
|
@@ -43,7 +43,7 @@ bool PaddleSegPreprocessor::BuildPreprocessPipelineFromConfig() {
|
||||
FDASSERT(op.IsMap(),
|
||||
"Require the transform information in yaml be Map type.");
|
||||
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> std = {0.5, 0.5, 0.5};
|
||||
if (op["mean"]) {
|
||||
@@ -55,7 +55,7 @@ bool PaddleSegPreprocessor::BuildPreprocessPipelineFromConfig() {
|
||||
processors_.push_back(std::make_shared<Normalize>(mean, std));
|
||||
}
|
||||
} 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"];
|
||||
int resize_width = target_size[0].as<int>();
|
||||
int resize_height = target_size[1].as<int>();
|
||||
@@ -73,13 +73,13 @@ bool PaddleSegPreprocessor::BuildPreprocessPipelineFromConfig() {
|
||||
auto input_shape = cfg["Deploy"]["input_shape"];
|
||||
int input_height = input_shape[2].as<int>();
|
||||
int input_width = input_shape[3].as<int>();
|
||||
if (input_height != -1 && input_width != -1 && !is_contain_resize_op) {
|
||||
is_contain_resize_op = true;
|
||||
if (input_height != -1 && input_width != -1 && !is_contain_resize_op_) {
|
||||
is_contain_resize_op_ = true;
|
||||
processors_.insert(processors_.begin(),
|
||||
std::make_shared<Resize>(input_width, input_height));
|
||||
}
|
||||
}
|
||||
if (!disable_normalize_and_permute_) {
|
||||
if (!disable_permute_) {
|
||||
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();
|
||||
// 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_height = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
void PaddleSegPreprocessor::DisableNormalizeAndPermute(){
|
||||
disable_normalize_and_permute_ = true;
|
||||
// the DisableNormalizeAndPermute function will be invalid if the configuration file is loaded during preprocessing
|
||||
void PaddleSegPreprocessor::DisableNormalize() {
|
||||
this->disable_normalize_ = true;
|
||||
// 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()) {
|
||||
FDERROR << "Failed to build preprocess pipeline from configuration file." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace segmentation
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
|
@@ -49,8 +49,10 @@ class FASTDEPLOY_DECL PaddleSegPreprocessor {
|
||||
is_vertical_screen_ = value;
|
||||
}
|
||||
|
||||
// This function will disable normalize and hwc2chw in preprocessing step.
|
||||
void DisableNormalizeAndPermute();
|
||||
/// This function will disable normalize in preprocessing step.
|
||||
void DisableNormalize();
|
||||
/// This function will disable hwc2chw in preprocessing step.
|
||||
void DisablePermute();
|
||||
|
||||
private:
|
||||
virtual bool BuildPreprocessPipelineFromConfig();
|
||||
@@ -61,10 +63,12 @@ class FASTDEPLOY_DECL PaddleSegPreprocessor {
|
||||
*/
|
||||
bool is_vertical_screen_ = false;
|
||||
|
||||
// for recording the switch of normalize and hwc2chw
|
||||
bool disable_normalize_and_permute_ = false;
|
||||
// for recording the switch of hwc2chw
|
||||
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;
|
||||
};
|
||||
|
@@ -104,10 +104,17 @@ class PaddleSegPreprocessor:
|
||||
"""
|
||||
return self._preprocessor.run(input_ims)
|
||||
|
||||
def disable_normalize_and_permute(self):
|
||||
"""To disable normalize and hwc2chw in preprocessing step.
|
||||
def disable_normalize(self):
|
||||
"""
|
||||
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
|
||||
def is_vertical_screen(self):
|
||||
|
Reference in New Issue
Block a user