Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from develop #2

Merged
merged 22 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
02d29aa
update .gitignore
DefTruth Jul 12, 2022
f9caef2
Merge branch 'develop' of https://github.com/DefTruth/FastDeploy into…
DefTruth Jul 12, 2022
afa8114
Added checking for cmake include dir
DefTruth Jul 12, 2022
659c14c
fixed missing trt_backend option bug when init from trt
DefTruth Jul 12, 2022
17a43ce
remove un-need data layout and add pre-check for dtype
DefTruth Jul 12, 2022
75948f8
changed RGB2BRG to BGR2RGB in ppcls model
DefTruth Jul 12, 2022
0ed1e84
Update CMakeLists.txt
jiangjiajun Jul 12, 2022
ec19fb1
Add multi-label function for yolov5 (#15)
felixhjh Jul 12, 2022
6c5bd8a
fix compile for python
jiangjiajun Jul 13, 2022
b57244d
add yolov6 c++ and yolov6 pybind
DefTruth Jul 13, 2022
71cd83c
Merge branch 'develop' of https://github.com/DefTruth/FastDeploy into…
DefTruth Jul 13, 2022
5f83b3c
Fix doc and wrong variable name (#17)
felixhjh Jul 14, 2022
f847490
add model_zoo yolov6 c++/python demo
DefTruth Jul 14, 2022
c56fdc3
fixed CMakeLists.txt typos
DefTruth Jul 14, 2022
2300f57
update yolov6 cpp/README.md
DefTruth Jul 14, 2022
de7c06a
add yolov6 c++ and yolov6 pybind (#16)
DefTruth Jul 14, 2022
90061e1
Fix outputs order of tensorrt (#18)
jiangjiajun Jul 14, 2022
5670280
Merge branch 'PaddlePaddle:develop' into develop
DefTruth Jul 18, 2022
cb91b3c
add yolox c++/pybind and model_zoo demo
DefTruth Jul 18, 2022
9d7e9d9
move some helpers to private
DefTruth Jul 18, 2022
d2e51a2
fixed CMakeLists.txt typos
DefTruth Jul 18, 2022
eb63a0e
Merge branch 'develop' of https://github.com/DefTruth/FastDeploy into…
DefTruth Jul 18, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ build-debug.sh
*dist
fastdeploy.egg-info
.setuptools-cmake-build
fastdeploy/version.py
fastdeploy/version.py
fastdeploy/LICENSE*
fastdeploy/ThirdPartyNotices*
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ option(ENABLE_VISION_VISUALIZE "if to enable visualize vision model result toolb
option(ENABLE_OPENCV_CUDA "if to enable opencv with cuda, this will allow process image with GPU." OFF)
option(ENABLE_DEBUG "if to enable print debug information, this may reduce performance." OFF)

# Whether to build fastdeply with vision/text/... examples, only for testings.
option(WITH_VISION_EXAMPLES "Whether to build fastdeply with vision examples" ON)

if(ENABLE_DEBUG)
add_definitions(-DFASTDEPLOY_DEBUG)
endif()
Expand All @@ -50,6 +53,13 @@ option(BUILD_FASTDEPLOY_PYTHON "if build python lib for fastdeploy." OFF)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

if (WTIH_VISION_EXAMPLES AND EXISTS ${PROJECT_SOURCE_DIR}/examples)
# ENABLE_VISION and ENABLE_VISION_VISUALIZE must be ON if enable vision examples.
message(STATUS "Found WTIH_VISION_EXAMPLES ON, so, force ENABLE_VISION and ENABLE_VISION_VISUALIZE ON")
set(ENABLE_VISION ON CACHE BOOL "force to enable vision models usage" FORCE)
set(ENABLE_VISION_VISUALIZE ON CACHE BOOL "force to enable visualize vision model result toolbox" FORCE)
endif()

add_definitions(-DFASTDEPLOY_LIB)
file(GLOB_RECURSE ALL_DEPLOY_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/*.cc)
file(GLOB_RECURSE DEPLOY_ORT_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/backends/ort/*.cc)
Expand Down Expand Up @@ -131,6 +141,11 @@ if(ENABLE_VISION)
if(ENABLE_VISION_VISUALIZE)
add_definitions(-DENABLE_VISION_VISUALIZE)
endif()
else()
if(ENABLE_VISION_VISUALIZE)
message("While ENABLE_VISION=OFF, will force ENABLE_VISION_VISUALIZE=OFF.")
set(ENABLE_VISION_VISUALIZE OFF)
endif()
endif()

configure_file(${PROJECT_SOURCE_DIR}/fastdeploy/core/config.h.in ${PROJECT_SOURCE_DIR}/fastdeploy/core/config.h)
Expand Down Expand Up @@ -165,6 +180,13 @@ endif()
set_target_properties(fastdeploy PROPERTIES VERSION ${FASTDEPLOY_VERSION})
target_link_libraries(fastdeploy ${DEPEND_LIBS})

# add examples after prepare include paths for third-parties
if (WITH_VISION_EXAMPLES AND EXISTS ${PROJECT_SOURCE_DIR}/examples)
add_definitions(-DWITH_VISION_EXAMPLES)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/examples/bin)
add_subdirectory(examples)
endif()

include(external/summary.cmake)
fastdeploy_summary()

Expand Down Expand Up @@ -211,6 +233,10 @@ if(BUILD_FASTDEPLOY_PYTHON)
set(CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
endif()

if(NOT ENABLE_VISION)
file(GLOB_RECURSE VISION_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/vision/*_pybind.cc)
list(REMOVE_ITEM DEPLOY_PYBIND_SRCS ${VISION_PYBIND_SRCS})
endif()
add_library(fastdeploy_main MODULE ${DEPLOY_PYBIND_SRCS})
redefine_file_macro(fastdeploy_main)
set_target_properties(fastdeploy_main PROPERTIES PREFIX "")
Expand Down
12 changes: 6 additions & 6 deletions docs/api/runtime_option.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ option = fd.RuntimeOption()
option.backend = fd.Backend.TRT
# 当使用TRT后端,且为动态输入shape时
# 需配置输入shape信息
option.trt_min_shape = {"images": [1, 3, 224, 224]}
option.trt_opt_shape = {"images": [4, 3, 224, 224]}
option.trt_max_shape = {"images": [8, 3, 224, 224]}
option.trt_min_shape = {"x": [1, 3, 224, 224]}
option.trt_opt_shape = {"x": [4, 3, 224, 224]}
option.trt_max_shape = {"x": [8, 3, 224, 224]}

model = fd.vision.ppcls.Model("resnet50/inference.pdmodel",
"resnet50/inference.pdiparams",
Expand Down Expand Up @@ -117,9 +117,9 @@ model = fd.vision.ppcls.Model("resnet50/inference.pdmodel",

int main() {
auto option = fastdeploy::RuntimeOption();
option.trt_min_shape["images"] = {1, 3, 224, 224};
option.trt_opt_shape["images"] = {4, 3, 224, 224};
option.trt_max_shape["images"] = {8, 3, 224, 224};
option.trt_min_shape["x"] = {1, 3, 224, 224};
option.trt_opt_shape["x"] = {4, 3, 224, 224};
option.trt_max_shape["x"] = {8, 3, 224, 224};

auto model = fastdeploy::vision::ppcls.Model(
"resnet50/inference.pdmodel",
Expand Down
2 changes: 1 addition & 1 deletion docs/compile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| 选项 | 作用 | 备注 |
|:---- | :--- | :--- |
| ENABLE_ORT_BACKEND | 启用ONNXRuntime推理后端,默认ON | - |
| WIGH_GPU | 是否开启GPU使用,默认OFF | 当设为TRUE时,须通过CUDA_DIRECTORY指定cuda目录,如/usr/local/cuda; Mac上不支持设为ON |
| WITH_GPU | 是否开启GPU使用,默认OFF | 当设为TRUE时,须通过CUDA_DIRECTORY指定cuda目录,如/usr/local/cuda; Mac上不支持设为ON |
| ENABLE_TRT_BACKEND | 启用TensorRT推理后端,默认OFF | 当设为TRUE时,需通过TRT_DIRECTORY指定tensorrt目录,如/usr/downloads/TensorRT-8.4.0.1; Mac上不支持设为ON|
| ENABLE_VISION | 编译集成视觉模型模块,包括OpenCV的编译集成,默认OFF | - |
| ENABLE_PADDLE_FRONTEND | 编译集成Paddle2ONNX,默认ON | - |
Expand Down
8 changes: 8 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.jpg
*.png
*.jpeg
*.onnx
*.engine
*.pd*
*.nb
bin
23 changes: 23 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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})
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}] !")
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 megvii yolox)
endif()

# other examples ...
11 changes: 11 additions & 0 deletions examples/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
images/*.jpg
images/*.jpeg
images/*.png
models/*.onnx
models/*.pd*
models/*.engine
models/*.trt
models/*.nb
outputs/*.jpg
outputs/*.jpeg
outputs/*.png
3 changes: 3 additions & 0 deletions examples/resources/images/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.jpg
*.jpeg
*.png
5 changes: 5 additions & 0 deletions examples/resources/models/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.onnx
*.engine
*.pd*
*.nb
*.trt
3 changes: 3 additions & 0 deletions examples/resources/outputs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.jpg
*.png
*.jpeg
52 changes: 52 additions & 0 deletions examples/vision/megvii_yolox.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 = "../resources/models/yolox_s.onnx";
std::string img_path = "../resources/images/bus.jpg";
std::string vis_path = "../resources/outputs/megvii_yolox_vis_result.jpg";

auto model = vis::megvii::YOLOX(model_file);
if (!model.Initialized()) {
std::cerr << "Init Failed! Model: " << model_file << std::endl;
return -1;
} else {
std::cout << "Init Done! Model:" << model_file << std::endl;
}
model.EnableDebug();

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;
}
52 changes: 52 additions & 0 deletions examples/vision/meituan_yolov6.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 = "../resources/models/yolov6s.onnx";
std::string img_path = "../resources/images/bus.jpg";
std::string vis_path = "../resources/outputs/meituan_yolov6_vis_result.jpg";

auto model = vis::meituan::YOLOv6(model_file);
if (!model.Initialized()) {
std::cerr << "Init Failed! Model: " << model_file << std::endl;
return -1;
} else {
std::cout << "Init Done! Model:" << model_file << std::endl;
}
model.EnableDebug();

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;
}
52 changes: 52 additions & 0 deletions examples/vision/ultralytics_yolov5.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 = "../resources/models/yolov5s.onnx";
std::string img_path = "../resources/images/bus.jpg";
std::string vis_path = "../resources/outputs/ultralytics_yolov5_vis_result.jpg";

auto model = vis::ultralytics::YOLOv5(model_file);
if (!model.Initialized()) {
std::cerr << "Init Failed! Model: " << model_file << std::endl;
return -1;
} else {
std::cout << "Init Done! Model:" << model_file << std::endl;
}
model.EnableDebug();

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 external/paddle2onnx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ else()
endif(WIN32)

set(PADDLE2ONNX_URL_BASE "https://bj.bcebos.com/paddle2onnx/libs/")
set(PADDLE2ONNX_VERSION "0.9.9")
set(PADDLE2ONNX_VERSION "1.0.0rc1")
if(WIN32)
set(PADDLE2ONNX_FILE "paddle2onnx-win-x64-${PADDLE2ONNX_VERSION}.zip")
elseif(APPLE)
Expand Down
Loading