mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 09:07:10 +08:00
Fix some compile problem in Linux (#41)
* Add custom operator for onnxruntime ans fix paddle backend * Polish cmake files and runtime apis * Remove copy libraries * fix some issue * fix bug * fix bug * Support remove multiclass_nms to enable paddledetection run tensorrt * Support remove multiclass_nms to enable paddledetection run tensorrt * Support remove multiclass_nms to enable paddledetection run tensorrt * Support remove multiclass_nms to enable paddledetection run tensorrt * add common operator multiclassnms * fix compile problem * fix some compile problem in linux * remove debug log Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com>
This commit is contained in:
@@ -199,10 +199,10 @@ else()
|
|||||||
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
|
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(OpenMP)
|
#find_package(OpenMP)
|
||||||
if(OpenMP_CXX_FOUND)
|
#if(OpenMP_CXX_FOUND)
|
||||||
list(APPEND DEPEND_LIBS OpenMP::OpenMP_CXX)
|
# list(APPEND DEPEND_LIBS OpenMP::OpenMP_CXX)
|
||||||
endif()
|
#endif()
|
||||||
set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${FASTDEPLOY_VERSION})
|
set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${FASTDEPLOY_VERSION})
|
||||||
target_link_libraries(${LIBRARY_NAME} ${DEPEND_LIBS})
|
target_link_libraries(${LIBRARY_NAME} ${DEPEND_LIBS})
|
||||||
|
|
||||||
|
@@ -1 +1 @@
|
|||||||
0.3.0
|
0.2.0
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import logging
|
import logging
|
||||||
from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, RuntimeOption, Device
|
from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, Device
|
||||||
from .fastdeploy_runtime import *
|
from .fastdeploy_runtime import *
|
||||||
from . import fastdeploy_main as C
|
from . import fastdeploy_main as C
|
||||||
from . import vision
|
from . import vision
|
||||||
@@ -26,6 +26,71 @@ def TensorInfoStr(tensor_info):
|
|||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
class RuntimeOption:
|
||||||
|
def __init__(self):
|
||||||
|
self._option = C.RuntimeOption()
|
||||||
|
|
||||||
|
def set_model_path(self, model_path, params_path="", model_format="paddle"):
|
||||||
|
return self._option.set_model_path(model_path, params_path, model_format)
|
||||||
|
|
||||||
|
def use_gpu(self, device_id=0):
|
||||||
|
return self._option.use_gpu(device_id)
|
||||||
|
|
||||||
|
def use_cpu(self):
|
||||||
|
return self._option.use_cpu()
|
||||||
|
|
||||||
|
def set_cpu_thread_num(self, thread_num=8):
|
||||||
|
return self._option.set_cpu_thread_num(thread_num)
|
||||||
|
|
||||||
|
def use_paddle_backend(self):
|
||||||
|
return self._option.use_paddle_backend()
|
||||||
|
|
||||||
|
def use_ort_backend(self):
|
||||||
|
return self._option.use_ort_backend()
|
||||||
|
|
||||||
|
def use_trt_backend(self):
|
||||||
|
return self._option.use_trt_backend()
|
||||||
|
|
||||||
|
def enable_paddle_mkldnn(self):
|
||||||
|
return self._option.enable_paddle_mkldnn()
|
||||||
|
|
||||||
|
def disable_paddle_mkldnn(self):
|
||||||
|
return self._option.disable_paddle_mkldnn()
|
||||||
|
|
||||||
|
def set_paddle_mkldnn_cache_size(self, cache_size):
|
||||||
|
return self._option.set_paddle_mkldnn_cache_size(cache_size)
|
||||||
|
|
||||||
|
def set_trt_input_shape(self, tensor_name, min_shape, opt_shape=None, max_shape=None):
|
||||||
|
if opt_shape is None and max_shape is None:
|
||||||
|
opt_shape = min_shape
|
||||||
|
max_shape = min_shape
|
||||||
|
else:
|
||||||
|
assert opt_shape is not None and max_shape is not None, "Set min_shape only, or set min_shape, opt_shape, max_shape both."
|
||||||
|
return self._option.set_trt_input_shape(tensor_name, min_shape, opt_shape, max_shape)
|
||||||
|
|
||||||
|
def set_trt_cache_file(self, cache_file_path):
|
||||||
|
return self._option.set_trt_cache_file(cache_file_path)
|
||||||
|
|
||||||
|
def enable_trt_fp16(self):
|
||||||
|
return self._option.enable_trt_fp16()
|
||||||
|
|
||||||
|
def dissable_trt_fp16(self):
|
||||||
|
return self._option.disable_trt_fp16()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
attrs = dir(self._option)
|
||||||
|
message = "RuntimeOption(\n"
|
||||||
|
for attr in attrs:
|
||||||
|
if attr.startswith("__"):
|
||||||
|
continue
|
||||||
|
if hasattr(getattr(self._option, attr), "__call__"):
|
||||||
|
continue
|
||||||
|
message += " {} : {}\t\n".format(attr, getattr(self._option, attr))
|
||||||
|
message.strip("\n")
|
||||||
|
message += ")"
|
||||||
|
return message
|
||||||
|
|
||||||
|
|
||||||
def RuntimeOptionStr(runtime_option):
|
def RuntimeOptionStr(runtime_option):
|
||||||
attrs = dir(runtime_option)
|
attrs = dir(runtime_option)
|
||||||
message = "RuntimeOption(\n"
|
message = "RuntimeOption(\n"
|
||||||
@@ -38,7 +103,5 @@ def RuntimeOptionStr(runtime_option):
|
|||||||
message.strip("\n")
|
message.strip("\n")
|
||||||
message += ")"
|
message += ")"
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
C.TensorInfo.__repr__ = TensorInfoStr
|
C.TensorInfo.__repr__ = TensorInfoStr
|
||||||
C.RuntimeOption.__repr__ = RuntimeOptionStr
|
C.RuntimeOption.__repr__ = RuntimeOptionStr
|
||||||
|
@@ -208,6 +208,11 @@ void RuntimeOption::EnableTrtFP16() { trt_enable_fp16 = true; }
|
|||||||
|
|
||||||
void RuntimeOption::DisableTrtFP16() { trt_enable_fp16 = false; }
|
void RuntimeOption::DisableTrtFP16() { trt_enable_fp16 = false; }
|
||||||
|
|
||||||
|
void RuntimeOption::SetTrtCacheFile(const std::string& cache_file_path) {
|
||||||
|
trt_serialize_file = cache_file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Runtime::Init(const RuntimeOption& _option) {
|
bool Runtime::Init(const RuntimeOption& _option) {
|
||||||
option = _option;
|
option = _option;
|
||||||
if (option.model_format == Frontend::AUTOREC) {
|
if (option.model_format == Frontend::AUTOREC) {
|
||||||
|
@@ -87,16 +87,14 @@ struct FASTDEPLOY_DECL RuntimeOption {
|
|||||||
// disable half precision, change to full precision(float32)
|
// disable half precision, change to full precision(float32)
|
||||||
void DisableTrtFP16();
|
void DisableTrtFP16();
|
||||||
|
|
||||||
|
void SetTrtCacheFile(const std::string& cache_file_path);
|
||||||
|
|
||||||
Backend backend = Backend::UNKNOWN;
|
Backend backend = Backend::UNKNOWN;
|
||||||
// for cpu inference and preprocess
|
// for cpu inference and preprocess
|
||||||
int cpu_thread_num = 8;
|
int cpu_thread_num = 8;
|
||||||
int device_id = 0;
|
int device_id = 0;
|
||||||
|
|
||||||
#ifdef WITH_GPU
|
|
||||||
Device device = Device::GPU;
|
|
||||||
#else
|
|
||||||
Device device = Device::CPU;
|
Device device = Device::CPU;
|
||||||
#endif
|
|
||||||
|
|
||||||
// ======Only for ORT Backend========
|
// ======Only for ORT Backend========
|
||||||
// -1 means use default value by ort
|
// -1 means use default value by ort
|
||||||
|
@@ -19,7 +19,7 @@ from . import fastdeploy_main as C
|
|||||||
class FastDeployModel:
|
class FastDeployModel:
|
||||||
def __init__(self, option):
|
def __init__(self, option):
|
||||||
self._model = None
|
self._model = None
|
||||||
self._runtime_option = option
|
self._runtime_option = option._option
|
||||||
if self._runtime_option is None:
|
if self._runtime_option is None:
|
||||||
self._runtime_option = C.RuntimeOption()
|
self._runtime_option = C.RuntimeOption()
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@ void BindRuntime(pybind11::module& m) {
|
|||||||
.def("set_trt_input_shape", &RuntimeOption::SetTrtInputShape)
|
.def("set_trt_input_shape", &RuntimeOption::SetTrtInputShape)
|
||||||
.def("enable_trt_fp16", &RuntimeOption::EnableTrtFP16)
|
.def("enable_trt_fp16", &RuntimeOption::EnableTrtFP16)
|
||||||
.def("disable_trt_fp16", &RuntimeOption::DisableTrtFP16)
|
.def("disable_trt_fp16", &RuntimeOption::DisableTrtFP16)
|
||||||
|
.def("set_trt_cache_file", &RuntimeOption::SetTrtCacheFile)
|
||||||
.def_readwrite("model_file", &RuntimeOption::model_file)
|
.def_readwrite("model_file", &RuntimeOption::model_file)
|
||||||
.def_readwrite("params_file", &RuntimeOption::params_file)
|
.def_readwrite("params_file", &RuntimeOption::params_file)
|
||||||
.def_readwrite("model_format", &RuntimeOption::model_format)
|
.def_readwrite("model_format", &RuntimeOption::model_format)
|
||||||
|
@@ -23,9 +23,9 @@ class PPYOLOE(FastDeployModel):
|
|||||||
model_file,
|
model_file,
|
||||||
params_file,
|
params_file,
|
||||||
config_file,
|
config_file,
|
||||||
backend_option=None,
|
runtime_option=None,
|
||||||
model_format=Frontend.PADDLE):
|
model_format=Frontend.PADDLE):
|
||||||
super(PPYOLOE, self).__init__(backend_option)
|
super(PPYOLOE, self).__init__(runtime_option)
|
||||||
|
|
||||||
assert model_format == Frontend.PADDLE, "PPYOLOE only support model format of Frontend.Paddle now."
|
assert model_format == Frontend.PADDLE, "PPYOLOE only support model format of Frontend.Paddle now."
|
||||||
self._model = C.vision.ppdet.PPYOLOE(model_file, params_file,
|
self._model = C.vision.ppdet.PPYOLOE(model_file, params_file,
|
||||||
|
9
setup.py
9
setup.py
@@ -345,7 +345,7 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel":
|
|||||||
shutil.copy(
|
shutil.copy(
|
||||||
os.path.join(".setuptools-cmake-build", f), "fastdeploy/libs")
|
os.path.join(".setuptools-cmake-build", f), "fastdeploy/libs")
|
||||||
if f.count("fastdeploy_main.cpython-"):
|
if f.count("fastdeploy_main.cpython-"):
|
||||||
pybind_so_file = f
|
pybind_so_file = os.path.join(".setuptools-cmake-build", f)
|
||||||
|
|
||||||
if not os.path.exists(".setuptools-cmake-build/third_libs/install"):
|
if not os.path.exists(".setuptools-cmake-build/third_libs/install"):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
@@ -360,7 +360,7 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel":
|
|||||||
symlinks=True)
|
symlinks=True)
|
||||||
|
|
||||||
if platform.system().lower() == "linux":
|
if platform.system().lower() == "linux":
|
||||||
rpaths = ["${ORIGIN}"]
|
rpaths = ["$ORIGIN:$ORIGIN/libs"]
|
||||||
for root, dirs, files in os.walk(
|
for root, dirs, files in os.walk(
|
||||||
".setuptools-cmake-build/third_libs/install"):
|
".setuptools-cmake-build/third_libs/install"):
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
@@ -368,11 +368,10 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel":
|
|||||||
path = os.path.relpath(
|
path = os.path.relpath(
|
||||||
os.path.join(root, d),
|
os.path.join(root, d),
|
||||||
".setuptools-cmake-build/third_libs/install")
|
".setuptools-cmake-build/third_libs/install")
|
||||||
rpaths.append("${ORIGIN}/" + os.path.join(
|
rpaths.append("$ORIGIN/" + os.path.join(
|
||||||
"libs/third_libs", path))
|
"libs/third_libs", path))
|
||||||
rpaths = ":".join(rpaths)
|
rpaths = ":".join(rpaths)
|
||||||
command = "patchelf --set-rpath '{}' ".format(rpaths) + os.path.join(
|
command = "patchelf --set-rpath '{}' ".format(rpaths) + pybind_so_file
|
||||||
"fastdeploy/libs", pybind_so_file)
|
|
||||||
# The sw_64 not suppot patchelf, so we just disable that.
|
# The sw_64 not suppot patchelf, so we just disable that.
|
||||||
if platform.machine() != 'sw_64' and platform.machine() != 'mips64':
|
if platform.machine() != 'sw_64' and platform.machine() != 'mips64':
|
||||||
assert os.system(
|
assert os.system(
|
||||||
|
Reference in New Issue
Block a user