Refine paddledetection directory (#88)

This commit is contained in:
Jason
2022-08-10 10:13:22 +08:00
committed by GitHub
parent 79120251b7
commit de2a87a8f2
20 changed files with 149 additions and 182 deletions

View File

@@ -23,14 +23,16 @@
#include "fastdeploy/vision/deepinsight/partial_fc.h" #include "fastdeploy/vision/deepinsight/partial_fc.h"
#include "fastdeploy/vision/deepinsight/scrfd.h" #include "fastdeploy/vision/deepinsight/scrfd.h"
#include "fastdeploy/vision/deepinsight/vpl.h" #include "fastdeploy/vision/deepinsight/vpl.h"
#include "fastdeploy/vision/detection/contrib/scaledyolov4.h" #include "fastdeploy/vision/detection/contrib/scaledyolov4.h"
#include "fastdeploy/vision/detection/contrib/yolor.h" #include "fastdeploy/vision/detection/contrib/yolor.h"
#include "fastdeploy/vision/detection/contrib/yolov7.h" #include "fastdeploy/vision/detection/contrib/yolov7.h"
#include "fastdeploy/vision/detection/ppdet/model.h"
#include "fastdeploy/vision/linzaer/ultraface.h" #include "fastdeploy/vision/linzaer/ultraface.h"
#include "fastdeploy/vision/megvii/yolox.h" #include "fastdeploy/vision/megvii/yolox.h"
#include "fastdeploy/vision/meituan/yolov6.h" #include "fastdeploy/vision/meituan/yolov6.h"
#include "fastdeploy/vision/ppcls/model.h" #include "fastdeploy/vision/ppcls/model.h"
#include "fastdeploy/vision/ppdet/model.h"
#include "fastdeploy/vision/ppogg/yolov5lite.h" #include "fastdeploy/vision/ppogg/yolov5lite.h"
#include "fastdeploy/vision/ppseg/model.h" #include "fastdeploy/vision/ppseg/model.h"
#include "fastdeploy/vision/rangilyu/nanodet_plus.h" #include "fastdeploy/vision/rangilyu/nanodet_plus.h"

View File

@@ -19,10 +19,12 @@ namespace fastdeploy {
void BindYOLOv7(pybind11::module& m); void BindYOLOv7(pybind11::module& m);
void BindScaledYOLOv4(pybind11::module& m); void BindScaledYOLOv4(pybind11::module& m);
void BindYOLOR(pybind11::module& m); void BindYOLOR(pybind11::module& m);
void BindPPDet(pybind11::module& m);
void BindDetection(pybind11::module& m) { void BindDetection(pybind11::module& m) {
auto detection_module = auto detection_module =
m.def_submodule("detection", "Image object detection models."); m.def_submodule("detection", "Image object detection models.");
BindPPDet(detection_module);
BindYOLOv7(detection_module); BindYOLOv7(detection_module);
BindScaledYOLOv4(detection_module); BindScaledYOLOv4(detection_module);
BindYOLOR(detection_module); BindYOLOR(detection_module);

View File

@@ -13,9 +13,9 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "fastdeploy/vision/ppdet/picodet.h" #include "fastdeploy/vision/detection/ppdet/picodet.h"
#include "fastdeploy/vision/ppdet/ppyolo.h" #include "fastdeploy/vision/detection/ppdet/ppyolo.h"
#include "fastdeploy/vision/ppdet/ppyoloe.h" #include "fastdeploy/vision/detection/ppdet/ppyoloe.h"
#include "fastdeploy/vision/ppdet/rcnn.h" #include "fastdeploy/vision/detection/ppdet/rcnn.h"
#include "fastdeploy/vision/ppdet/yolov3.h" #include "fastdeploy/vision/detection/ppdet/yolov3.h"
#include "fastdeploy/vision/ppdet/yolox.h" #include "fastdeploy/vision/detection/ppdet/yolox.h"

View File

@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "fastdeploy/vision/ppdet/picodet.h" #include "fastdeploy/vision/detection/ppdet/picodet.h"
#include "yaml-cpp/yaml.h" #include "yaml-cpp/yaml.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
PicoDet::PicoDet(const std::string& model_file, const std::string& params_file, PicoDet::PicoDet(const std::string& model_file, const std::string& params_file,
const std::string& config_file, const std::string& config_file,
@@ -61,6 +61,6 @@ bool PicoDet::CheckIfContainDecodeAndNMS() {
return true; return true;
} }
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -13,11 +13,11 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "fastdeploy/vision/ppdet/ppyoloe.h" #include "fastdeploy/vision/detection/ppdet/ppyoloe.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
class FASTDEPLOY_DECL PicoDet : public PPYOLOE { class FASTDEPLOY_DECL PicoDet : public PPYOLOE {
public: public:
@@ -29,8 +29,8 @@ class FASTDEPLOY_DECL PicoDet : public PPYOLOE {
// Only support picodet contains decode and nms // Only support picodet contains decode and nms
bool CheckIfContainDecodeAndNMS(); bool CheckIfContainDecodeAndNMS();
virtual std::string ModelName() const { return "PaddleDetection/PicoDet"; } virtual std::string ModelName() const { return "PicoDet"; }
}; };
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -15,68 +15,77 @@
namespace fastdeploy { namespace fastdeploy {
void BindPPDet(pybind11::module& m) { void BindPPDet(pybind11::module& m) {
auto ppdet_module = pybind11::class_<vision::detection::PPYOLOE, FastDeployModel>(m,
m.def_submodule("ppdet", "Module to deploy PaddleDetection.");
pybind11::class_<vision::ppdet::PPYOLOE, FastDeployModel>(ppdet_module,
"PPYOLOE") "PPYOLOE")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption, .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>()) Frontend>())
.def("predict", [](vision::ppdet::PPYOLOE& self, pybind11::array& data) { .def("predict", [](vision::detection::PPYOLOE& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data); auto mat = PyArrayToCvMat(data);
vision::DetectionResult res; vision::DetectionResult res;
self.Predict(&mat, &res); self.Predict(&mat, &res);
return res; return res;
}); });
pybind11::class_<vision::ppdet::PPYOLO, FastDeployModel>(ppdet_module, pybind11::class_<vision::detection::PPYOLO, FastDeployModel>(m,
"PPYOLO") "PPYOLO")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption, .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>()) Frontend>())
.def("predict", [](vision::ppdet::PPYOLO& self, pybind11::array& data) { .def("predict", [](vision::detection::PPYOLO& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data); auto mat = PyArrayToCvMat(data);
vision::DetectionResult res; vision::DetectionResult res;
self.Predict(&mat, &res); self.Predict(&mat, &res);
return res; return res;
}); });
pybind11::class_<vision::ppdet::PicoDet, FastDeployModel>(ppdet_module, pybind11::class_<vision::detection::PPYOLOv2, FastDeployModel>(m,
"PPYOLOv2")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.def("predict", [](vision::detection::PPYOLOv2& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data);
vision::DetectionResult res;
self.Predict(&mat, &res);
return res;
});
pybind11::class_<vision::detection::PicoDet, FastDeployModel>(m,
"PicoDet") "PicoDet")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption, .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>()) Frontend>())
.def("predict", [](vision::ppdet::PicoDet& self, pybind11::array& data) { .def("predict", [](vision::detection::PicoDet& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data); auto mat = PyArrayToCvMat(data);
vision::DetectionResult res; vision::DetectionResult res;
self.Predict(&mat, &res); self.Predict(&mat, &res);
return res; return res;
}); });
pybind11::class_<vision::ppdet::YOLOX, FastDeployModel>(ppdet_module, "YOLOX") pybind11::class_<vision::detection::PaddleYOLOX, FastDeployModel>(m, "PaddleYOLOX")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption, .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>()) Frontend>())
.def("predict", [](vision::ppdet::YOLOX& self, pybind11::array& data) { .def("predict", [](vision::detection::PaddleYOLOX& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data); auto mat = PyArrayToCvMat(data);
vision::DetectionResult res; vision::DetectionResult res;
self.Predict(&mat, &res); self.Predict(&mat, &res);
return res; return res;
}); });
pybind11::class_<vision::ppdet::FasterRCNN, FastDeployModel>(ppdet_module, pybind11::class_<vision::detection::FasterRCNN, FastDeployModel>(m,
"FasterRCNN") "FasterRCNN")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption, .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>()) Frontend>())
.def("predict", .def("predict",
[](vision::ppdet::FasterRCNN& self, pybind11::array& data) { [](vision::detection::FasterRCNN& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data); auto mat = PyArrayToCvMat(data);
vision::DetectionResult res; vision::DetectionResult res;
self.Predict(&mat, &res); self.Predict(&mat, &res);
return res; return res;
}); });
pybind11::class_<vision::ppdet::YOLOv3, FastDeployModel>(ppdet_module, pybind11::class_<vision::detection::YOLOv3, FastDeployModel>(m,
"YOLOv3") "YOLOv3")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption, .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>()) Frontend>())
.def("predict", [](vision::ppdet::YOLOv3& self, pybind11::array& data) { .def("predict", [](vision::detection::YOLOv3& self, pybind11::array& data) {
auto mat = PyArrayToCvMat(data); auto mat = PyArrayToCvMat(data);
vision::DetectionResult res; vision::DetectionResult res;
self.Predict(&mat, &res); self.Predict(&mat, &res);

View File

@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "fastdeploy/vision/ppdet/ppyolo.h" #include "fastdeploy/vision/detection/ppdet/ppyolo.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
PPYOLO::PPYOLO(const std::string& model_file, const std::string& params_file, PPYOLO::PPYOLO(const std::string& model_file, const std::string& params_file,
const std::string& config_file, const std::string& config_file,
@@ -73,6 +73,6 @@ bool PPYOLO::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
return true; return true;
} }
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -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<FDTensor>* 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

View File

@@ -1,4 +1,4 @@
#include "fastdeploy/vision/ppdet/ppyoloe.h" #include "fastdeploy/vision/detection/ppdet/ppyoloe.h"
#include "fastdeploy/vision/utils/utils.h" #include "fastdeploy/vision/utils/utils.h"
#include "yaml-cpp/yaml.h" #include "yaml-cpp/yaml.h"
#ifdef ENABLE_PADDLE_FRONTEND #ifdef ENABLE_PADDLE_FRONTEND
@@ -7,7 +7,7 @@
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
PPYOLOE::PPYOLOE(const std::string& model_file, const std::string& params_file, PPYOLOE::PPYOLOE(const std::string& model_file, const std::string& params_file,
const std::string& config_file, const std::string& config_file,
@@ -253,6 +253,6 @@ bool PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) {
return true; return true;
} }
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -21,7 +21,7 @@
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel { class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel {
public: public:
@@ -63,10 +63,6 @@ class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel {
void GetNmsInfo(); void GetNmsInfo();
}; };
// Read configuration and build pipeline to process input image } // namespace detection
bool BuildPreprocessPipelineFromConfig(
std::vector<std::shared_ptr<Processor>>* processors,
const std::string& config_file);
} // namespace ppdet
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "fastdeploy/vision/ppdet/rcnn.h" #include "fastdeploy/vision/detection/ppdet/rcnn.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
FasterRCNN::FasterRCNN(const std::string& model_file, FasterRCNN::FasterRCNN(const std::string& model_file,
const std::string& params_file, const std::string& params_file,
@@ -79,6 +79,6 @@ bool FasterRCNN::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
return true; return true;
} }
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -13,11 +13,11 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "fastdeploy/vision/ppdet/ppyoloe.h" #include "fastdeploy/vision/detection/ppdet/ppyoloe.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
class FASTDEPLOY_DECL FasterRCNN : public PPYOLOE { class FASTDEPLOY_DECL FasterRCNN : public PPYOLOE {
public: public:
@@ -34,6 +34,6 @@ class FASTDEPLOY_DECL FasterRCNN : public PPYOLOE {
protected: protected:
FasterRCNN() {} FasterRCNN() {}
}; };
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "fastdeploy/vision/ppdet/yolov3.h" #include "fastdeploy/vision/detection/ppdet/yolov3.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
YOLOv3::YOLOv3(const std::string& model_file, const std::string& params_file, YOLOv3::YOLOv3(const std::string& model_file, const std::string& params_file,
const std::string& config_file, const std::string& config_file,
@@ -59,6 +59,6 @@ bool YOLOv3::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
return true; return true;
} }
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -13,11 +13,11 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "fastdeploy/vision/ppdet/ppyoloe.h" #include "fastdeploy/vision/detection/ppdet/ppyoloe.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
class FASTDEPLOY_DECL YOLOv3 : public PPYOLOE { class FASTDEPLOY_DECL YOLOv3 : public PPYOLOE {
public: public:
@@ -30,6 +30,6 @@ class FASTDEPLOY_DECL YOLOv3 : public PPYOLOE {
virtual bool Preprocess(Mat* mat, std::vector<FDTensor>* outputs); virtual bool Preprocess(Mat* mat, std::vector<FDTensor>* outputs);
}; };
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "fastdeploy/vision/ppdet/yolox.h" #include "fastdeploy/vision/detection/ppdet/yolox.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { 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 std::string& config_file, const RuntimeOption& custom_option,
const Frontend& model_format) { const Frontend& model_format) {
config_file_ = config_file; config_file_ = config_file;
@@ -38,7 +38,7 @@ YOLOX::YOLOX(const std::string& model_file, const std::string& params_file,
initialized = Initialize(); initialized = Initialize();
} }
bool YOLOX::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) { bool PaddleYOLOX::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
int origin_w = mat->Width(); int origin_w = mat->Width();
int origin_h = mat->Height(); int origin_h = mat->Height();
float scale[2] = {1.0, 1.0}; float scale[2] = {1.0, 1.0};
@@ -67,6 +67,6 @@ bool YOLOX::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
ptr[1] = scale[1]; ptr[1] = scale[1];
return true; return true;
} }
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -13,15 +13,15 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "fastdeploy/vision/ppdet/ppyoloe.h" #include "fastdeploy/vision/detection/ppdet/ppyoloe.h"
namespace fastdeploy { namespace fastdeploy {
namespace vision { namespace vision {
namespace ppdet { namespace detection {
class FASTDEPLOY_DECL YOLOX : public PPYOLOE { class FASTDEPLOY_DECL PaddleYOLOX : public PPYOLOE {
public: 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 std::string& config_file,
const RuntimeOption& custom_option = RuntimeOption(), const RuntimeOption& custom_option = RuntimeOption(),
const Frontend& model_format = Frontend::PADDLE); const Frontend& model_format = Frontend::PADDLE);
@@ -30,6 +30,6 @@ class FASTDEPLOY_DECL YOLOX : public PPYOLOE {
virtual std::string ModelName() const { return "PaddleDetection/YOLOX"; } virtual std::string ModelName() const { return "PaddleDetection/YOLOX"; }
}; };
} // namespace ppdet } // namespace detection
} // namespace vision } // namespace vision
} // namespace fastdeploy } // namespace fastdeploy

View File

@@ -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<std::shared_ptr<Processor>>* 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<BGR2RGB>());
for (const auto& op : cfg["Preprocess"]) {
std::string op_name = op["type"].as<std::string>();
if (op_name == "NormalizeImage") {
auto mean = op["mean"].as<std::vector<float>>();
auto std = op["std"].as<std::vector<float>>();
bool is_scale = op["is_scale"].as<bool>();
processors->push_back(std::make_shared<Normalize>(mean, std, is_scale));
} else if (op_name == "Resize") {
bool keep_ratio = op["keep_ratio"].as<bool>();
auto target_size = op["target_size"].as<std::vector<int>>();
int interp = op["interp"].as<int>();
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<Resize>(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<ResizeByShort>(
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<std::vector<int>>();
auto value = op["fill_value"].as<std::vector<float>>();
processors->push_back(std::make_shared<Cast>("float"));
processors->push_back(
std::make_shared<PadToSize>(size[1], size[0], value));
} else if (op_name == "PadStride") {
auto stride = op["stride"].as<int>();
processors->push_back(
std::make_shared<StridePad>(stride, std::vector<float>(3, 0)));
} else {
FDERROR << "Unexcepted preprocess operator: " << op_name << "."
<< std::endl;
return false;
}
}
processors->push_back(std::make_shared<HWC2CHW>());
return true;
}
} // namespace vision
} // namespace fastdeploy

View File

@@ -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<FDTensor>* outputs);
virtual bool Initialize();
protected:
PPYOLO() {}
};
} // namespace ppdet
} // namespace vision
} // namespace fastdeploy

View File

@@ -16,3 +16,5 @@ from __future__ import absolute_import
from .yolov7 import YOLOv7 from .yolov7 import YOLOv7
from .yolor import YOLOR from .yolor import YOLOR
from .scaled_yolov4 import ScaledYOLOv4 from .scaled_yolov4 import ScaledYOLOv4
from .ppdet import PPYOLOE, PPYOLO, PPYOLOv2, PaddleYOLOX, PicoDet, FasterRCNN, YOLOv3

View File

@@ -28,7 +28,7 @@ class PPYOLOE(FastDeployModel):
super(PPYOLOE, self).__init__(runtime_option) super(PPYOLOE, self).__init__(runtime_option)
assert model_format == Frontend.PADDLE, "PPYOLOE model only support model format of Frontend.Paddle now." 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, config_file, self._runtime_option,
model_format) model_format)
assert self.initialized, "PPYOLOE model initialize failed." assert self.initialized, "PPYOLOE model initialize failed."
@@ -48,13 +48,13 @@ class PPYOLO(PPYOLOE):
super(PPYOLOE, self).__init__(runtime_option) super(PPYOLOE, self).__init__(runtime_option)
assert model_format == Frontend.PADDLE, "PPYOLO model only support model format of Frontend.Paddle now." 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, config_file, self._runtime_option,
model_format) model_format)
assert self.initialized, "PPYOLO model initialize failed." assert self.initialized, "PPYOLO model initialize failed."
class YOLOX(PPYOLOE): class PPYOLOv2(PPYOLOE):
def __init__(self, def __init__(self,
model_file, model_file,
params_file, params_file,
@@ -63,11 +63,27 @@ class YOLOX(PPYOLOE):
model_format=Frontend.PADDLE): model_format=Frontend.PADDLE):
super(PPYOLOE, self).__init__(runtime_option) super(PPYOLOE, self).__init__(runtime_option)
assert model_format == Frontend.PADDLE, "YOLOX model only support model format of Frontend.Paddle now." assert model_format == Frontend.PADDLE, "PPYOLOv2 model only support model format of Frontend.Paddle now."
self._model = C.vision.ppdet.YOLOX(model_file, params_file, 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, config_file, self._runtime_option,
model_format) model_format)
assert self.initialized, "YOLOX model initialize failed." assert self.initialized, "PaddleYOLOX model initialize failed."
class PicoDet(PPYOLOE): class PicoDet(PPYOLOE):
@@ -80,7 +96,7 @@ class PicoDet(PPYOLOE):
super(PPYOLOE, self).__init__(runtime_option) super(PPYOLOE, self).__init__(runtime_option)
assert model_format == Frontend.PADDLE, "PicoDet model only support model format of Frontend.Paddle now." 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, config_file, self._runtime_option,
model_format) model_format)
assert self.initialized, "PicoDet model initialize failed." assert self.initialized, "PicoDet model initialize failed."
@@ -96,7 +112,7 @@ class FasterRCNN(PPYOLOE):
super(PPYOLOE, self).__init__(runtime_option) super(PPYOLOE, self).__init__(runtime_option)
assert model_format == Frontend.PADDLE, "FasterRCNN model only support model format of Frontend.Paddle now." 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_file, params_file, config_file, self._runtime_option,
model_format) model_format)
assert self.initialized, "FasterRCNN model initialize failed." assert self.initialized, "FasterRCNN model initialize failed."
@@ -112,7 +128,7 @@ class YOLOv3(PPYOLOE):
super(PPYOLOE, self).__init__(runtime_option) super(PPYOLOE, self).__init__(runtime_option)
assert model_format == Frontend.PADDLE, "YOLOv3 model only support model format of Frontend.Paddle now." 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, config_file, self._runtime_option,
model_format) model_format)
assert self.initialized, "YOLOv3 model initialize failed." assert self.initialized, "YOLOv3 model initialize failed."