Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function(add_fastdeploy_executable field url model)
function(add_fastdeploy_executable field url model)
# temp target name/file var in function scope
set(TEMP_TARGET_FILE ${PROJECT_SOURCE_DIR}/examples/${field}/${url}_${model}.cc)
set(TEMP_TARGET_NAME ${field}_${url}_${model})
Expand All @@ -7,7 +7,7 @@ function(add_fastdeploy_executable field url model)
target_link_libraries(${TEMP_TARGET_NAME} PUBLIC fastdeploy)
message(STATUS "Found source file: [${field}/${url}_${model}.cc], ADD!!! fastdeploy executable: [${TEMP_TARGET_NAME}] !")
else ()
message(WARNING "Can not found source file: [${field}/${url}_${model}.cc], SKIP!!! fastdeploy executable: [${TEMP_TARGET_NAME}] !")
message(WARNING "Can not found source file: [${field}/${url}_${model}.cc], SKIP!!! fastdeploy executable: [${TEMP_TARGET_NAME}] !")
endif()
unset(TEMP_TARGET_FILE)
unset(TEMP_TARGET_NAME)
Expand All @@ -16,9 +16,10 @@ endfunction()
# vision examples
if (WITH_VISION_EXAMPLES)
add_fastdeploy_executable(vision ultralytics yolov5)
add_fastdeploy_executable(vision ppdet ppyoloe)
add_fastdeploy_executable(vision meituan yolov6)
add_fastdeploy_executable(vision wongkinyiu yolov7)
add_fastdeploy_executable(vision megvii yolox)
endif()

# other examples ...
# other examples ...
51 changes: 51 additions & 0 deletions examples/vision/ppdet_ppyoloe.cc
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.

#include "fastdeploy/vision.h"

int main() {
namespace vis = fastdeploy::vision;

std::string model_file = "ppyoloe_crn_l_300e_coco/model.pdmodel";
std::string params_file = "ppyoloe_crn_l_300e_coco/model.pdiparams";
std::string config_file = "ppyoloe_crn_l_300e_coco/infer_cfg.yml";
std::string img_path = "test.jpeg";
std::string vis_path = "vis.jpeg";

auto model = vis::ppdet::PPYOLOE(model_file, params_file, config_file);
if (!model.Initialized()) {
std::cerr << "Init Failed." << std::endl;
return -1;
}

cv::Mat im = cv::imread(img_path);
cv::Mat vis_im = im.clone();

vis::DetectionResult res;
if (!model.Predict(&im, &res)) {
std::cerr << "Prediction Failed." << std::endl;
return -1;
} else {
std::cout << "Prediction Done!" << std::endl;
}

// 输出预测框结果
std::cout << res.Str() << std::endl;

// 可视化预测结果
vis::Visualize::VisDetection(&vis_im, res);
cv::imwrite(vis_path, vis_im);
std::cout << "Detect Done! Saved: " << vis_path << std::endl;
return 0;
}
2 changes: 1 addition & 1 deletion fastdeploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .fastdeploy_runtime import *
from . import fastdeploy_main as C
from . import vision
from .download import download
from .download import download, download_and_decompress


def TensorInfoStr(tensor_info):
Expand Down
2 changes: 1 addition & 1 deletion fastdeploy/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def decompress(fname):

def url2dir(url, path, rename=None):
full_name = download(url, path, rename, show_progress=True)
print("SDK is donwloaded, now extracting...")
print("File is donwloaded, now extracting...")
if url.count(".tgz") > 0 or url.count(".tar") > 0 or url.count("zip") > 0:
return decompress(full_name)

Expand Down
4 changes: 4 additions & 0 deletions fastdeploy/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class FASTDEPLOY_DECL FDLogger {
bool verbose_ = true;
};

#ifndef __REL_FILE__
#define __REL_FILE__ __FILE__
#endif

#define FDERROR \
FDLogger(true, "[ERROR]") \
<< __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t"
Expand Down
1 change: 1 addition & 0 deletions fastdeploy/vision.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "fastdeploy/core/config.h"
#ifdef ENABLE_VISION
#include "fastdeploy/vision/ppcls/model.h"
#include "fastdeploy/vision/ppdet/ppyoloe.h"
#include "fastdeploy/vision/ultralytics/yolov5.h"
#include "fastdeploy/vision/wongkinyiu/yolov7.h"
#include "fastdeploy/vision/meituan/yolov6.h"
Expand Down
1 change: 1 addition & 0 deletions fastdeploy/vision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from . import evaluation
from . import ppcls
from . import ppdet
from . import ultralytics
from . import meituan
from . import megvii
Expand Down
19 changes: 16 additions & 3 deletions fastdeploy/vision/ppcls/model.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// 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/ppcls/model.h"
#include "fastdeploy/vision/utils/utils.h"
Expand Down Expand Up @@ -135,6 +148,6 @@ bool Model::Predict(cv::Mat* im, ClassifyResult* result, int topk) {
return true;
}

} // namespace ppcls
} // namespace vision
} // namespace fastdeploy
} // namespace ppcls
} // namespace vision
} // namespace fastdeploy
16 changes: 15 additions & 1 deletion fastdeploy/vision/ppcls/model.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// 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/fastdeploy_model.h"
#include "fastdeploy/vision/common/result.h"
#include "fastdeploy/vision/common/processors/transform.h"
#include "fastdeploy/vision/common/result.h"

namespace fastdeploy {
namespace vision {
Expand Down
2 changes: 1 addition & 1 deletion fastdeploy/vision/ppcls/ppcls_pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "fastdeploy/pybind/main.h"

namespace fastdeploy {
void BindPpClsModel(pybind11::module& m) {
void BindPPCls(pybind11::module& m) {
auto ppcls_module = m.def_submodule("ppcls", "Module to deploy PaddleClas.");
pybind11::class_<vision::ppcls::Model, FastDeployModel>(ppcls_module, "Model")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Expand Down
39 changes: 39 additions & 0 deletions fastdeploy/vision/ppdet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

from __future__ import absolute_import
import logging
from ... import FastDeployModel, Frontend
from ... import fastdeploy_main as C


class PPYOLOE(FastDeployModel):
def __init__(self,
model_file,
params_file,
config_file,
backend_option=None,
model_format=Frontend.PADDLE):
super(PPYOLOE, self).__init__(backend_option)

assert model_format == Frontend.PADDLE, "PPYOLOE only support model format of Frontend.Paddle now."
self._model = C.vision.ppdet.PPYOLOE(model_file, params_file,
config_file, self._runtime_option,
model_format)
assert self.initialized, "PPYOLOE model initialize failed."

def predict(self, input_image, conf_threshold=0.5, nms_iou_threshold=0.7):
assert input_image is not None, "The input image data is None."
return self._model.predict(input_image, conf_threshold,
nms_iou_threshold)
32 changes: 32 additions & 0 deletions fastdeploy/vision/ppdet/ppdet_pybind.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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/pybind/main.h"

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,
"PPYOLOE")
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
Frontend>())
.def("predict", [](vision::ppdet::PPYOLOE& self, pybind11::array& data,
float conf_threshold, float nms_iou_threshold) {
auto mat = PyArrayToCvMat(data);
vision::DetectionResult res;
self.Predict(&mat, &res, conf_threshold, nms_iou_threshold);
return res;
});
}
} // namespace fastdeploy
Loading