diff --git a/csrcs/fastdeploy/vision.h b/csrcs/fastdeploy/vision.h index 376aaaf28..be1aa91a4 100644 --- a/csrcs/fastdeploy/vision.h +++ b/csrcs/fastdeploy/vision.h @@ -23,14 +23,16 @@ #include "fastdeploy/vision/deepinsight/partial_fc.h" #include "fastdeploy/vision/deepinsight/scrfd.h" #include "fastdeploy/vision/deepinsight/vpl.h" + #include "fastdeploy/vision/detection/contrib/scaledyolov4.h" #include "fastdeploy/vision/detection/contrib/yolor.h" #include "fastdeploy/vision/detection/contrib/yolov7.h" +#include "fastdeploy/vision/detection/ppdet/model.h" + #include "fastdeploy/vision/linzaer/ultraface.h" #include "fastdeploy/vision/megvii/yolox.h" #include "fastdeploy/vision/meituan/yolov6.h" #include "fastdeploy/vision/ppcls/model.h" -#include "fastdeploy/vision/ppdet/model.h" #include "fastdeploy/vision/ppogg/yolov5lite.h" #include "fastdeploy/vision/ppseg/model.h" #include "fastdeploy/vision/rangilyu/nanodet_plus.h" diff --git a/csrcs/fastdeploy/vision/detection/detection_pybind.cc b/csrcs/fastdeploy/vision/detection/detection_pybind.cc index 2ab8e20bb..4516e4717 100644 --- a/csrcs/fastdeploy/vision/detection/detection_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/detection_pybind.cc @@ -19,10 +19,12 @@ namespace fastdeploy { void BindYOLOv7(pybind11::module& m); void BindScaledYOLOv4(pybind11::module& m); void BindYOLOR(pybind11::module& m); +void BindPPDet(pybind11::module& m); void BindDetection(pybind11::module& m) { auto detection_module = m.def_submodule("detection", "Image object detection models."); + BindPPDet(detection_module); BindYOLOv7(detection_module); BindScaledYOLOv4(detection_module); BindYOLOR(detection_module); diff --git a/csrcs/fastdeploy/vision/ppdet/model.h b/csrcs/fastdeploy/vision/detection/ppdet/model.h similarity index 66% rename from csrcs/fastdeploy/vision/ppdet/model.h rename to csrcs/fastdeploy/vision/detection/ppdet/model.h index 17541d7fe..f40c6b7fe 100644 --- a/csrcs/fastdeploy/vision/ppdet/model.h +++ b/csrcs/fastdeploy/vision/detection/ppdet/model.h @@ -13,9 +13,9 @@ // limitations under the License. #pragma once -#include "fastdeploy/vision/ppdet/picodet.h" -#include "fastdeploy/vision/ppdet/ppyolo.h" -#include "fastdeploy/vision/ppdet/ppyoloe.h" -#include "fastdeploy/vision/ppdet/rcnn.h" -#include "fastdeploy/vision/ppdet/yolov3.h" -#include "fastdeploy/vision/ppdet/yolox.h" +#include "fastdeploy/vision/detection/ppdet/picodet.h" +#include "fastdeploy/vision/detection/ppdet/ppyolo.h" +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" +#include "fastdeploy/vision/detection/ppdet/rcnn.h" +#include "fastdeploy/vision/detection/ppdet/yolov3.h" +#include "fastdeploy/vision/detection/ppdet/yolox.h" diff --git a/csrcs/fastdeploy/vision/ppdet/picodet.cc b/csrcs/fastdeploy/vision/detection/ppdet/picodet.cc similarity index 95% rename from csrcs/fastdeploy/vision/ppdet/picodet.cc rename to csrcs/fastdeploy/vision/detection/ppdet/picodet.cc index 5f912b8cf..d89fab2ae 100644 --- a/csrcs/fastdeploy/vision/ppdet/picodet.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/picodet.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ppdet/picodet.h" +#include "fastdeploy/vision/detection/ppdet/picodet.h" #include "yaml-cpp/yaml.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { PicoDet::PicoDet(const std::string& model_file, const std::string& params_file, const std::string& config_file, @@ -61,6 +61,6 @@ bool PicoDet::CheckIfContainDecodeAndNMS() { return true; } -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/picodet.h b/csrcs/fastdeploy/vision/detection/ppdet/picodet.h similarity index 87% rename from csrcs/fastdeploy/vision/ppdet/picodet.h rename to csrcs/fastdeploy/vision/detection/ppdet/picodet.h index 7b45b9baf..984e56222 100644 --- a/csrcs/fastdeploy/vision/ppdet/picodet.h +++ b/csrcs/fastdeploy/vision/detection/ppdet/picodet.h @@ -13,11 +13,11 @@ // limitations under the License. #pragma once -#include "fastdeploy/vision/ppdet/ppyoloe.h" +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { class FASTDEPLOY_DECL PicoDet : public PPYOLOE { public: @@ -29,8 +29,8 @@ class FASTDEPLOY_DECL PicoDet : public PPYOLOE { // Only support picodet contains decode and nms bool CheckIfContainDecodeAndNMS(); - virtual std::string ModelName() const { return "PaddleDetection/PicoDet"; } + virtual std::string ModelName() const { return "PicoDet"; } }; -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/ppdet_pybind.cc b/csrcs/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc similarity index 65% rename from csrcs/fastdeploy/vision/ppdet/ppdet_pybind.cc rename to csrcs/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc index bcc1a0478..2f4b0fefc 100644 --- a/csrcs/fastdeploy/vision/ppdet/ppdet_pybind.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/ppdet_pybind.cc @@ -15,68 +15,77 @@ namespace fastdeploy { void BindPPDet(pybind11::module& m) { - auto ppdet_module = - m.def_submodule("ppdet", "Module to deploy PaddleDetection."); - pybind11::class_(ppdet_module, + pybind11::class_(m, "PPYOLOE") .def(pybind11::init()) - .def("predict", [](vision::ppdet::PPYOLOE& self, pybind11::array& data) { + .def("predict", [](vision::detection::PPYOLOE& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res); return res; }); - pybind11::class_(ppdet_module, + pybind11::class_(m, "PPYOLO") .def(pybind11::init()) - .def("predict", [](vision::ppdet::PPYOLO& self, pybind11::array& data) { + .def("predict", [](vision::detection::PPYOLO& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res); return res; }); - pybind11::class_(ppdet_module, + pybind11::class_(m, + "PPYOLOv2") + .def(pybind11::init()) + .def("predict", [](vision::detection::PPYOLOv2& self, pybind11::array& data) { + auto mat = PyArrayToCvMat(data); + vision::DetectionResult res; + self.Predict(&mat, &res); + return res; + }); + + pybind11::class_(m, "PicoDet") .def(pybind11::init()) - .def("predict", [](vision::ppdet::PicoDet& self, pybind11::array& data) { + .def("predict", [](vision::detection::PicoDet& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res); return res; }); - pybind11::class_(ppdet_module, "YOLOX") + pybind11::class_(m, "PaddleYOLOX") .def(pybind11::init()) - .def("predict", [](vision::ppdet::YOLOX& self, pybind11::array& data) { + .def("predict", [](vision::detection::PaddleYOLOX& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res); return res; }); - pybind11::class_(ppdet_module, + pybind11::class_(m, "FasterRCNN") .def(pybind11::init()) .def("predict", - [](vision::ppdet::FasterRCNN& self, pybind11::array& data) { + [](vision::detection::FasterRCNN& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res); return res; }); - pybind11::class_(ppdet_module, + pybind11::class_(m, "YOLOv3") .def(pybind11::init()) - .def("predict", [](vision::ppdet::YOLOv3& self, pybind11::array& data) { + .def("predict", [](vision::detection::YOLOv3& self, pybind11::array& data) { auto mat = PyArrayToCvMat(data); vision::DetectionResult res; self.Predict(&mat, &res); diff --git a/csrcs/fastdeploy/vision/ppdet/ppyolo.cc b/csrcs/fastdeploy/vision/detection/ppdet/ppyolo.cc similarity index 96% rename from csrcs/fastdeploy/vision/ppdet/ppyolo.cc rename to csrcs/fastdeploy/vision/detection/ppdet/ppyolo.cc index 194ad4f69..6c202f0d0 100644 --- a/csrcs/fastdeploy/vision/ppdet/ppyolo.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/ppyolo.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ppdet/ppyolo.h" +#include "fastdeploy/vision/detection/ppdet/ppyolo.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { PPYOLO::PPYOLO(const std::string& model_file, const std::string& params_file, const std::string& config_file, @@ -73,6 +73,6 @@ bool PPYOLO::Preprocess(Mat* mat, std::vector* outputs) { return true; } -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/detection/ppdet/ppyolo.h b/csrcs/fastdeploy/vision/detection/ppdet/ppyolo.h new file mode 100644 index 000000000..1b3b48780 --- /dev/null +++ b/csrcs/fastdeploy/vision/detection/ppdet/ppyolo.h @@ -0,0 +1,51 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" + +namespace fastdeploy { +namespace vision { +namespace detection { + +class FASTDEPLOY_DECL PPYOLO : public PPYOLOE { + public: + PPYOLO(const std::string& model_file, const std::string& params_file, + const std::string& config_file, + const RuntimeOption& custom_option = RuntimeOption(), + const Frontend& model_format = Frontend::PADDLE); + + virtual std::string ModelName() const { return "PaddleDetection/PPYOLO"; } + + virtual bool Preprocess(Mat* mat, std::vector* outputs); + virtual bool Initialize(); + + protected: + PPYOLO() {} +}; + +class FASTDEPLOY_DECL PPYOLOv2 : public PPYOLO { + public: + PPYOLOv2(const std::string& model_file, const std::string& params_file, + const std::string& config_file, + const RuntimeOption& custom_option = RuntimeOption(), + const Frontend& model_format = Frontend::PADDLE) : PPYOLO(model_file, params_file, config_file, custom_option, model_format) { + } + + virtual std::string ModelName() const { return "PaddleDetection/PPYOLOv2"; } +}; + +} // namespace detection +} // namespace vision +} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/ppyoloe.cc b/csrcs/fastdeploy/vision/detection/ppdet/ppyoloe.cc similarity index 98% rename from csrcs/fastdeploy/vision/ppdet/ppyoloe.cc rename to csrcs/fastdeploy/vision/detection/ppdet/ppyoloe.cc index 0e7d00c64..2e4b56ecb 100644 --- a/csrcs/fastdeploy/vision/ppdet/ppyoloe.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/ppyoloe.cc @@ -1,4 +1,4 @@ -#include "fastdeploy/vision/ppdet/ppyoloe.h" +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" #include "fastdeploy/vision/utils/utils.h" #include "yaml-cpp/yaml.h" #ifdef ENABLE_PADDLE_FRONTEND @@ -7,7 +7,7 @@ namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { PPYOLOE::PPYOLOE(const std::string& model_file, const std::string& params_file, const std::string& config_file, @@ -253,6 +253,6 @@ bool PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) { return true; } -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/ppyoloe.h b/csrcs/fastdeploy/vision/detection/ppdet/ppyoloe.h similarity index 90% rename from csrcs/fastdeploy/vision/ppdet/ppyoloe.h rename to csrcs/fastdeploy/vision/detection/ppdet/ppyoloe.h index 3b7e24479..2d8cca99f 100644 --- a/csrcs/fastdeploy/vision/ppdet/ppyoloe.h +++ b/csrcs/fastdeploy/vision/detection/ppdet/ppyoloe.h @@ -21,7 +21,7 @@ namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel { public: @@ -63,10 +63,6 @@ class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel { void GetNmsInfo(); }; -// Read configuration and build pipeline to process input image -bool BuildPreprocessPipelineFromConfig( - std::vector>* processors, - const std::string& config_file); -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/rcnn.cc b/csrcs/fastdeploy/vision/detection/ppdet/rcnn.cc similarity index 96% rename from csrcs/fastdeploy/vision/ppdet/rcnn.cc rename to csrcs/fastdeploy/vision/detection/ppdet/rcnn.cc index c976293a8..38ecc3d1c 100644 --- a/csrcs/fastdeploy/vision/ppdet/rcnn.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/rcnn.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ppdet/rcnn.h" +#include "fastdeploy/vision/detection/ppdet/rcnn.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { FasterRCNN::FasterRCNN(const std::string& model_file, const std::string& params_file, @@ -79,6 +79,6 @@ bool FasterRCNN::Preprocess(Mat* mat, std::vector* outputs) { return true; } -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/rcnn.h b/csrcs/fastdeploy/vision/detection/ppdet/rcnn.h similarity index 92% rename from csrcs/fastdeploy/vision/ppdet/rcnn.h rename to csrcs/fastdeploy/vision/detection/ppdet/rcnn.h index 2a9255a54..d44ca852e 100644 --- a/csrcs/fastdeploy/vision/ppdet/rcnn.h +++ b/csrcs/fastdeploy/vision/detection/ppdet/rcnn.h @@ -13,11 +13,11 @@ // limitations under the License. #pragma once -#include "fastdeploy/vision/ppdet/ppyoloe.h" +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { class FASTDEPLOY_DECL FasterRCNN : public PPYOLOE { public: @@ -34,6 +34,6 @@ class FASTDEPLOY_DECL FasterRCNN : public PPYOLOE { protected: FasterRCNN() {} }; -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/yolov3.cc b/csrcs/fastdeploy/vision/detection/ppdet/yolov3.cc similarity index 95% rename from csrcs/fastdeploy/vision/ppdet/yolov3.cc rename to csrcs/fastdeploy/vision/detection/ppdet/yolov3.cc index a02853dbb..309d65640 100644 --- a/csrcs/fastdeploy/vision/ppdet/yolov3.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/yolov3.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ppdet/yolov3.h" +#include "fastdeploy/vision/detection/ppdet/yolov3.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { YOLOv3::YOLOv3(const std::string& model_file, const std::string& params_file, const std::string& config_file, @@ -59,6 +59,6 @@ bool YOLOv3::Preprocess(Mat* mat, std::vector* outputs) { return true; } -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/yolov3.h b/csrcs/fastdeploy/vision/detection/ppdet/yolov3.h similarity index 91% rename from csrcs/fastdeploy/vision/ppdet/yolov3.h rename to csrcs/fastdeploy/vision/detection/ppdet/yolov3.h index 27b1352c9..1b65bfca1 100644 --- a/csrcs/fastdeploy/vision/ppdet/yolov3.h +++ b/csrcs/fastdeploy/vision/detection/ppdet/yolov3.h @@ -13,11 +13,11 @@ // limitations under the License. #pragma once -#include "fastdeploy/vision/ppdet/ppyoloe.h" +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { class FASTDEPLOY_DECL YOLOv3 : public PPYOLOE { public: @@ -30,6 +30,6 @@ class FASTDEPLOY_DECL YOLOv3 : public PPYOLOE { virtual bool Preprocess(Mat* mat, std::vector* outputs); }; -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/yolox.cc b/csrcs/fastdeploy/vision/detection/ppdet/yolox.cc similarity index 89% rename from csrcs/fastdeploy/vision/ppdet/yolox.cc rename to csrcs/fastdeploy/vision/detection/ppdet/yolox.cc index 44f4ec055..a60ebfcc4 100644 --- a/csrcs/fastdeploy/vision/ppdet/yolox.cc +++ b/csrcs/fastdeploy/vision/detection/ppdet/yolox.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "fastdeploy/vision/ppdet/yolox.h" +#include "fastdeploy/vision/detection/ppdet/yolox.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { -YOLOX::YOLOX(const std::string& model_file, const std::string& params_file, +PaddleYOLOX::PaddleYOLOX(const std::string& model_file, const std::string& params_file, const std::string& config_file, const RuntimeOption& custom_option, const Frontend& model_format) { config_file_ = config_file; @@ -38,7 +38,7 @@ YOLOX::YOLOX(const std::string& model_file, const std::string& params_file, initialized = Initialize(); } -bool YOLOX::Preprocess(Mat* mat, std::vector* outputs) { +bool PaddleYOLOX::Preprocess(Mat* mat, std::vector* outputs) { int origin_w = mat->Width(); int origin_h = mat->Height(); float scale[2] = {1.0, 1.0}; @@ -67,6 +67,6 @@ bool YOLOX::Preprocess(Mat* mat, std::vector* outputs) { ptr[1] = scale[1]; return true; } -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/yolox.h b/csrcs/fastdeploy/vision/detection/ppdet/yolox.h similarity index 81% rename from csrcs/fastdeploy/vision/ppdet/yolox.h rename to csrcs/fastdeploy/vision/detection/ppdet/yolox.h index e689674a4..4ffe2f39c 100644 --- a/csrcs/fastdeploy/vision/ppdet/yolox.h +++ b/csrcs/fastdeploy/vision/detection/ppdet/yolox.h @@ -13,15 +13,15 @@ // limitations under the License. #pragma once -#include "fastdeploy/vision/ppdet/ppyoloe.h" +#include "fastdeploy/vision/detection/ppdet/ppyoloe.h" namespace fastdeploy { namespace vision { -namespace ppdet { +namespace detection { -class FASTDEPLOY_DECL YOLOX : public PPYOLOE { +class FASTDEPLOY_DECL PaddleYOLOX : public PPYOLOE { public: - YOLOX(const std::string& model_file, const std::string& params_file, + PaddleYOLOX(const std::string& model_file, const std::string& params_file, const std::string& config_file, const RuntimeOption& custom_option = RuntimeOption(), const Frontend& model_format = Frontend::PADDLE); @@ -30,6 +30,6 @@ class FASTDEPLOY_DECL YOLOX : public PPYOLOE { virtual std::string ModelName() const { return "PaddleDetection/YOLOX"; } }; -} // namespace ppdet +} // namespace detection } // namespace vision } // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/build_preprocess.cc b/csrcs/fastdeploy/vision/ppdet/build_preprocess.cc deleted file mode 100644 index 20348214e..000000000 --- a/csrcs/fastdeploy/vision/ppdet/build_preprocess.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "fastdeploy/vision/common/processors/transform.h" -#include "fastdeploy/vision/ppdet/ppyoloe.h" -#include "yaml-cpp/yaml.h" - -namespace fastdeploy { -namespace vision { - -bool BuildPreprocessPipelineFromConfig( - std::vector>* processors, - const std::string& config_file) { - processors->clear(); - YAML::Node cfg; - try { - cfg = YAML::LoadFile(config_file); - } catch (YAML::BadFile& e) { - FDERROR << "Failed to load yaml file " << config_file - << ", maybe you should check this file." << std::endl; - return false; - } - - processors->push_back(std::make_shared()); - - for (const auto& op : cfg["Preprocess"]) { - std::string op_name = op["type"].as(); - if (op_name == "NormalizeImage") { - auto mean = op["mean"].as>(); - auto std = op["std"].as>(); - bool is_scale = op["is_scale"].as(); - processors->push_back(std::make_shared(mean, std, is_scale)); - } else if (op_name == "Resize") { - bool keep_ratio = op["keep_ratio"].as(); - auto target_size = op["target_size"].as>(); - int interp = op["interp"].as(); - FDASSERT(target_size.size(), - "Require size of target_size be 2, but now it's " + - std::to_string(target_size.size()) + "."); - if (!keep_ratio) { - int width = target_size[1]; - int height = target_size[0]; - processors->push_back( - std::make_shared(width, height, -1.0, -1.0, interp, false)); - } else { - int min_target_size = std::min(target_size[0], target_size[1]); - int max_target_size = std::max(target_size[0], target_size[1]); - processors->push_back(std::make_shared( - min_target_size, interp, true, max_target_size)); - } - } else if (op_name == "Permute") { - // Do nothing, do permute as the last operation - continue; - } else if (op_name == "Pad") { - auto size = op["size"].as>(); - auto value = op["fill_value"].as>(); - processors->push_back(std::make_shared("float")); - processors->push_back( - std::make_shared(size[1], size[0], value)); - } else if (op_name == "PadStride") { - auto stride = op["stride"].as(); - processors->push_back( - std::make_shared(stride, std::vector(3, 0))); - } else { - FDERROR << "Unexcepted preprocess operator: " << op_name << "." - << std::endl; - return false; - } - } - processors->push_back(std::make_shared()); - return true; -} - -} // namespace vision -} // namespace fastdeploy diff --git a/csrcs/fastdeploy/vision/ppdet/ppyolo.h b/csrcs/fastdeploy/vision/ppdet/ppyolo.h deleted file mode 100644 index b17f54b3e..000000000 --- a/csrcs/fastdeploy/vision/ppdet/ppyolo.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "fastdeploy/vision/ppdet/ppyoloe.h" - -namespace fastdeploy { -namespace vision { -namespace ppdet { - -class FASTDEPLOY_DECL PPYOLO : public PPYOLOE { - public: - PPYOLO(const std::string& model_file, const std::string& params_file, - const std::string& config_file, - const RuntimeOption& custom_option = RuntimeOption(), - const Frontend& model_format = Frontend::PADDLE); - - virtual std::string ModelName() const { return "PaddleDetection/PPYOLO"; } - - virtual bool Preprocess(Mat* mat, std::vector* outputs); - virtual bool Initialize(); - - protected: - PPYOLO() {} -}; -} // namespace ppdet -} // namespace vision -} // namespace fastdeploy diff --git a/fastdeploy/vision/detection/__init__.py b/fastdeploy/vision/detection/__init__.py index 9d412774a..92a292b54 100644 --- a/fastdeploy/vision/detection/__init__.py +++ b/fastdeploy/vision/detection/__init__.py @@ -16,3 +16,5 @@ from __future__ import absolute_import from .yolov7 import YOLOv7 from .yolor import YOLOR from .scaled_yolov4 import ScaledYOLOv4 + +from .ppdet import PPYOLOE, PPYOLO, PPYOLOv2, PaddleYOLOX, PicoDet, FasterRCNN, YOLOv3 diff --git a/fastdeploy/vision/ppdet/__init__.py b/fastdeploy/vision/detection/ppdet/__init__.py similarity index 76% rename from fastdeploy/vision/ppdet/__init__.py rename to fastdeploy/vision/detection/ppdet/__init__.py index 6d3738412..775ba6a20 100644 --- a/fastdeploy/vision/ppdet/__init__.py +++ b/fastdeploy/vision/detection/ppdet/__init__.py @@ -28,7 +28,7 @@ class PPYOLOE(FastDeployModel): super(PPYOLOE, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "PPYOLOE model only support model format of Frontend.Paddle now." - self._model = C.vision.ppdet.PPYOLOE(model_file, params_file, + self._model = C.vision.detection.PPYOLOE(model_file, params_file, config_file, self._runtime_option, model_format) assert self.initialized, "PPYOLOE model initialize failed." @@ -48,13 +48,13 @@ class PPYOLO(PPYOLOE): super(PPYOLOE, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "PPYOLO model only support model format of Frontend.Paddle now." - self._model = C.vision.ppdet.PPYOLO(model_file, params_file, + self._model = C.vision.detection.PPYOLO(model_file, params_file, config_file, self._runtime_option, model_format) assert self.initialized, "PPYOLO model initialize failed." -class YOLOX(PPYOLOE): +class PPYOLOv2(PPYOLOE): def __init__(self, model_file, params_file, @@ -63,11 +63,27 @@ class YOLOX(PPYOLOE): model_format=Frontend.PADDLE): super(PPYOLOE, self).__init__(runtime_option) - assert model_format == Frontend.PADDLE, "YOLOX model only support model format of Frontend.Paddle now." - self._model = C.vision.ppdet.YOLOX(model_file, params_file, + assert model_format == Frontend.PADDLE, "PPYOLOv2 model only support model format of Frontend.Paddle now." + self._model = C.vision.detection.PPYOLOv2(model_file, params_file, + config_file, self._runtime_option, + model_format) + assert self.initialized, "PPYOLOv2 model initialize failed." + + +class PaddleYOLOX(PPYOLOE): + def __init__(self, + model_file, + params_file, + config_file, + runtime_option=None, + model_format=Frontend.PADDLE): + super(PPYOLOE, self).__init__(runtime_option) + + assert model_format == Frontend.PADDLE, "PaddleYOLOX model only support model format of Frontend.Paddle now." + self._model = C.vision.detection.PaddleYOLOX(model_file, params_file, config_file, self._runtime_option, model_format) - assert self.initialized, "YOLOX model initialize failed." + assert self.initialized, "PaddleYOLOX model initialize failed." class PicoDet(PPYOLOE): @@ -80,7 +96,7 @@ class PicoDet(PPYOLOE): super(PPYOLOE, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "PicoDet model only support model format of Frontend.Paddle now." - self._model = C.vision.ppdet.PicoDet(model_file, params_file, + self._model = C.vision.detection.PicoDet(model_file, params_file, config_file, self._runtime_option, model_format) assert self.initialized, "PicoDet model initialize failed." @@ -96,7 +112,7 @@ class FasterRCNN(PPYOLOE): super(PPYOLOE, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "FasterRCNN model only support model format of Frontend.Paddle now." - self._model = C.vision.ppdet.FasterRCNN( + self._model = C.vision.detection.FasterRCNN( model_file, params_file, config_file, self._runtime_option, model_format) assert self.initialized, "FasterRCNN model initialize failed." @@ -112,7 +128,7 @@ class YOLOv3(PPYOLOE): super(PPYOLOE, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "YOLOv3 model only support model format of Frontend.Paddle now." - self._model = C.vision.ppdet.YOLOv3(model_file, params_file, + self._model = C.vision.detection.YOLOv3(model_file, params_file, config_file, self._runtime_option, model_format) assert self.initialized, "YOLOv3 model initialize failed."