forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com>
- Loading branch information
1 parent
e25e4f2
commit e8a8439
Showing
29 changed files
with
818 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
function(add_fastdeploy_executable field url model) | ||
function(add_fastdeploy_executable FIELD CC_FILE) | ||
# 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}) | ||
set(TEMP_TARGET_FILE ${CC_FILE}) | ||
string(REGEX MATCHALL "[0-9A-Za-z_]*.cc" FILE_NAME ${CC_FILE}) | ||
string(REGEX REPLACE ".cc" "" FILE_PREFIX ${FILE_NAME}) | ||
set(TEMP_TARGET_NAME ${FIELD}_${FILE_PREFIX}) | ||
if (EXISTS ${TEMP_TARGET_FILE} AND TARGET fastdeploy) | ||
add_executable(${TEMP_TARGET_NAME} ${TEMP_TARGET_FILE}) | ||
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(STATUS " Added FastDeploy Executable : ${TEMP_TARGET_NAME}") | ||
endif() | ||
unset(TEMP_TARGET_FILE) | ||
unset(TEMP_TARGET_NAME) | ||
endfunction() | ||
|
||
# vision examples | ||
if (WITH_VISION_EXAMPLES) | ||
add_fastdeploy_executable(vision ultralytics yolov5) | ||
add_fastdeploy_executable(vision meituan yolov6) | ||
add_fastdeploy_executable(vision wongkinyiu yolov7) | ||
add_fastdeploy_executable(vision megvii yolox) | ||
if(WITH_VISION_EXAMPLES AND EXISTS ${PROJECT_SOURCE_DIR}/examples/vision) | ||
message(STATUS "") | ||
message(STATUS "*************FastDeploy Examples Summary**********") | ||
file(GLOB ALL_VISION_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/vision/*.cc) | ||
foreach(_CC_FILE ${ALL_VISION_EXAMPLE_SRCS}) | ||
add_fastdeploy_executable(vision ${_CC_FILE}) | ||
endforeach() | ||
endif() | ||
|
||
# other examples ... | ||
# other examples ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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/convert.h" | ||
|
||
namespace fastdeploy { | ||
|
||
namespace vision { | ||
|
||
Convert::Convert(const std::vector<float>& alpha, | ||
const std::vector<float>& beta) { | ||
FDASSERT(alpha.size() == beta.size(), | ||
"Convert: requires the size of alpha equal to the size of beta."); | ||
FDASSERT(alpha.size() != 0, | ||
"Convert: requires the size of alpha and beta > 0."); | ||
alpha_.assign(alpha.begin(), alpha.end()); | ||
beta_.assign(beta.begin(), beta.end()); | ||
} | ||
|
||
bool Convert::CpuRun(Mat* mat) { | ||
cv::Mat* im = mat->GetCpuMat(); | ||
std::vector<cv::Mat> split_im; | ||
cv::split(*im, split_im); | ||
for (int c = 0; c < im->channels(); c++) { | ||
split_im[c].convertTo(split_im[c], CV_32FC1, alpha_[c], beta_[c]); | ||
} | ||
cv::merge(split_im, *im); | ||
return true; | ||
} | ||
|
||
#ifdef ENABLE_OPENCV_CUDA | ||
bool Convert::GpuRun(Mat* mat) { | ||
cv::cuda::GpuMat* im = mat->GetGpuMat(); | ||
std::vector<cv::cuda::GpuMat> split_im; | ||
cv::cuda::split(*im, split_im); | ||
for (int c = 0; c < im->channels(); c++) { | ||
split_im[c].convertTo(split_im[c], CV_32FC1, alpha_[c], beta_[c]); | ||
} | ||
cv::cuda::merge(split_im, *im); | ||
return true; | ||
} | ||
#endif | ||
|
||
bool Convert::Run(Mat* mat, const std::vector<float>& alpha, | ||
const std::vector<float>& beta, ProcLib lib) { | ||
auto c = Convert(alpha, beta); | ||
return c(mat, lib); | ||
} | ||
|
||
} // namespace vision | ||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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/common/processors/base.h" | ||
|
||
namespace fastdeploy { | ||
namespace vision { | ||
class Convert : public Processor { | ||
public: | ||
Convert(const std::vector<float>& alpha, const std::vector<float>& beta); | ||
|
||
bool CpuRun(Mat* mat); | ||
#ifdef ENABLE_OPENCV_CUDA | ||
bool GpuRun(Mat* mat); | ||
#endif | ||
std::string Name() { return "Convert"; } | ||
|
||
// Compute `result = mat * alpha + beta` directly by channel. | ||
// The default behavior is the same as OpenCV's convertTo method. | ||
static bool Run(Mat* mat, const std::vector<float>& alpha, | ||
const std::vector<float>& beta, | ||
ProcLib lib = ProcLib::OPENCV_CPU); | ||
|
||
private: | ||
std::vector<float> alpha_; | ||
std::vector<float> beta_; | ||
}; | ||
} // namespace vision | ||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.