Skip to content

Commit

Permalink
Refine paddledetection directory (PaddlePaddle#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangjiajun authored Aug 10, 2022
1 parent 7912025 commit de2a87a
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 182 deletions.
4 changes: 3 additions & 1 deletion csrcs/fastdeploy/vision.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions csrcs/fastdeploy/vision/detection/detection_pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -61,6 +61,6 @@ bool PicoDet::CheckIfContainDecodeAndNMS() {
return true;
}

} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,77 @@

namespace fastdeploy {
void BindPPDet(pybind11::module& m) {
auto ppdet_module =
m.def_submodule("ppdet", "Module to deploy PaddleDetection.");
pybind11::class_<vision::ppdet::PPYOLOE, FastDeployModel>(ppdet_module,
pybind11::class_<vision::detection::PPYOLOE, FastDeployModel>(m,
"PPYOLOE")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.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_<vision::ppdet::PPYOLO, FastDeployModel>(ppdet_module,
pybind11::class_<vision::detection::PPYOLO, FastDeployModel>(m,
"PPYOLO")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.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_<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")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.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_<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,
Frontend>())
.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_<vision::ppdet::FasterRCNN, FastDeployModel>(ppdet_module,
pybind11::class_<vision::detection::FasterRCNN, FastDeployModel>(m,
"FasterRCNN")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.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_<vision::ppdet::YOLOv3, FastDeployModel>(ppdet_module,
pybind11::class_<vision::detection::YOLOv3, FastDeployModel>(m,
"YOLOv3")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -73,6 +73,6 @@ bool PPYOLO::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
return true;
}

} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
51 changes: 51 additions & 0 deletions csrcs/fastdeploy/vision/detection/ppdet/ppyolo.h
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -253,6 +253,6 @@ bool PPYOLOE::Predict(cv::Mat* im, DetectionResult* result) {
return true;
}

} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace fastdeploy {
namespace vision {
namespace ppdet {
namespace detection {

class FASTDEPLOY_DECL PPYOLOE : public FastDeployModel {
public:
Expand Down Expand Up @@ -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<std::shared_ptr<Processor>>* processors,
const std::string& config_file);
} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -79,6 +79,6 @@ bool FasterRCNN::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
return true;
}

} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,6 +34,6 @@ class FASTDEPLOY_DECL FasterRCNN : public PPYOLOE {
protected:
FasterRCNN() {}
};
} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -59,6 +59,6 @@ bool YOLOv3::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
return true;
}

} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -30,6 +30,6 @@ class FASTDEPLOY_DECL YOLOv3 : public PPYOLOE {

virtual bool Preprocess(Mat* mat, std::vector<FDTensor>* outputs);
};
} // namespace ppdet
} // namespace detection
} // namespace vision
} // namespace fastdeploy
Loading

0 comments on commit de2a87a

Please sign in to comment.