forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Build] Support build with source code of Paddle2ONNX (PaddlePaddle#1559
) * Add notes for tensors * Optimize some apis * move some warnings * Support build with Paddle2ONNX * Add protobuf support * Fix compile on mac * add clearn package script * Add paddle2onnx code * remove submodule * Add onnx ocde * remove softlink * add onnx code * fix error * Add cmake file * fix patchelf * update paddle2onnx * Delete .gitmodules --------- Co-authored-by: PaddleCI <[email protected]> Co-authored-by: pangyoki <[email protected]> Co-authored-by: jiangjiajun <[email protected]>
- Loading branch information
1 parent
f568c59
commit 6343b0d
Showing
5,052 changed files
with
222,092 additions
and
32 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
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,41 @@ | ||
add_definitions(-DMAX_ONNX_OPSET_VERSION=16) | ||
add_definitions(-DPADDLE2ONNX_LIB) | ||
|
||
# Third dependency: onnx | ||
if(NOT TARGET onnx_proto) | ||
if(NOT ONNX_NAMESPACE) | ||
set(ONNX_NAMESPACE "paddle2onnx") | ||
endif() | ||
add_definitions("-DONNX_NAMESPACE=${ONNX_NAMESPACE}") | ||
|
||
set(MSVC_STATIC_CRT ON) | ||
if(ONNX_CUSTOM_PROTOC_PATH) | ||
if(WIN32) | ||
if(MSVC_STATIC_CRT) | ||
# MT | ||
set(ONNX_USE_MSVC_STATIC_RUNTIME ON) | ||
else() | ||
# MD | ||
set(ONNX_USE_MSVC_STATIC_RUNTIME OFF) | ||
endif() | ||
set(ONNX_CUSTOM_PROTOC_PATH "${ONNX_CUSTOM_PROTOC_PATH};$ENV{PATH}") | ||
else() | ||
set(ONNX_CUSTOM_PROTOC_PATH "${ONNX_CUSTOM_PROTOC_PATH}:$ENV{PATH}") | ||
endif() | ||
set(ENV{PATH} ${ONNX_CUSTOM_PROTOC_PATH}) | ||
endif() | ||
|
||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/onnx) | ||
endif() | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}) | ||
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/third_party/onnx) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}/third_party/optimizer) | ||
add_subdirectory(${PROJECT_SOURCE_DIR}/paddle2onnx/proto) | ||
|
||
file(GLOB_RECURSE PADDLE2ONNX_ALL_SRCS ${PROJECT_SOURCE_DIR}/paddle2onnx/*.cc ${PROJECT_SOURCE_DIR}/third_party/optimizer/onnxoptimizer/*.cc) | ||
list(REMOVE_ITEM PADDLE2ONNX_ALL_SRCS ${PROJECT_SOURCE_DIR}/paddle2onnx/cpp2py_export.cc ${PROJECT_SOURCE_DIR}/third_party/optimizer/onnxoptimizer/cpp2py_export.cc) | ||
|
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,57 @@ | ||
# 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. | ||
|
||
function(download_patchelf) | ||
if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) | ||
set(PATCHELF_EXE "patchelf") | ||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/patchelf-0.15.0-aarch64.tar.gz) | ||
download_and_decompress(${PATCHELF_URL} ${CMAKE_CURRENT_BINARY_DIR}/patchelf-0.15.0-aarch64.tar.gz ${THIRD_PARTY_PATH}/patchelf) | ||
else() | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/patchelf-0.15.0-x86_64.tar.gz) | ||
download_and_decompress(${PATCHELF_URL} ${CMAKE_CURRENT_BINARY_DIR}/patchelf-0.15.0-x86_64.tar.gz ${THIRD_PARTY_PATH}/patchelf) | ||
endif() | ||
endif() | ||
endfunction() | ||
|
||
function(download_protobuf) | ||
if(WIN32) | ||
if(NOT CMAKE_CL_64) | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/protobuf-win-x86-3.16.0.zip) | ||
else() | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/protobuf-win-x64-3.16.0.zip) | ||
endif() | ||
set(ORIGIN_ENV_PATH "$ENV{PATH}") | ||
download_and_decompress(${PATCHELF_URL} ${CMAKE_CURRENT_BINARY_DIR}/protobuf-win-3.16.0.tgz ${THIRD_PARTY_PATH}/protobuf) | ||
set(ENV{PATH} "${THIRD_PARTY_PATH}\\protobuf\\bin;${ORIGIN_ENV_PATH}") | ||
elseif(APPLE) | ||
if(CURRENT_OSX_ARCH MATCHES "arm64") | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/protobuf-osx-arm64-3.16.0.tgz) | ||
else() | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/protobuf-osx-x86_64-3.16.0.tgz) | ||
endif() | ||
set(ORIGIN_ENV_PATH "$ENV{PATH}") | ||
download_and_decompress(${PATCHELF_URL} ${CMAKE_CURRENT_BINARY_DIR}/protobuf-osx-3.16.0.tgz ${THIRD_PARTY_PATH}/protobuf) | ||
set(ENV{PATH} "${THIRD_PARTY_PATH}/protobuf/bin/:${ORIGIN_ENV_PATH}") | ||
else() | ||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/protobuf-linux-aarch64-3.16.0.tgz) | ||
else() | ||
set(PATCHELF_URL https://bj.bcebos.com/fastdeploy/third_libs/protobuf-linux-x64-3.16.0.tgz) | ||
endif() | ||
set(ORIGIN_ENV_PATH "$ENV{PATH}") | ||
download_and_decompress(${PATCHELF_URL} ${CMAKE_CURRENT_BINARY_DIR}/protobuf-linux-3.16.0.tgz ${THIRD_PARTY_PATH}/protobuf) | ||
set(ENV{PATH} "${THIRD_PARTY_PATH}/protobuf/bin/:${ORIGIN_ENV_PATH}") | ||
endif() | ||
endfunction() |
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 was deleted.
Oops, something went wrong.
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
Empty file.
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,65 @@ | ||
# 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 paddle2onnx.utils import logging | ||
from . import command | ||
from .convert import dygraph2onnx | ||
from .convert import program2onnx | ||
from .version import version | ||
from .version import git_version | ||
|
||
__version__ = version | ||
__commit_id__ = git_version | ||
|
||
|
||
def run_convert(model, input_shape_dict=None, scope=None, opset_version=9): | ||
logging.warning( | ||
"[Deprecated] `paddle2onnx.run_convert` will be deprecated in the future version, the recommended usage is `paddle2onnx.export`" | ||
) | ||
from paddle2onnx.legacy import run_convert | ||
return run_convert(model, input_shape_dict, scope, opset_version) | ||
|
||
|
||
def export(model_file, | ||
params_file="", | ||
save_file=None, | ||
opset_version=11, | ||
auto_upgrade_opset=True, | ||
verbose=True, | ||
enable_onnx_checker=True, | ||
enable_experimental_op=True, | ||
enable_optimize=True, | ||
custom_op_info=None, | ||
deploy_backend="onnxruntime", | ||
calibration_file="", | ||
external_file="", | ||
export_fp16_model=False): | ||
import paddle2onnx.paddle2onnx_cpp2py_export as c_p2o | ||
deploy_backend = deploy_backend.lower() | ||
if custom_op_info is None: | ||
onnx_model_str = c_p2o.export( | ||
model_file, params_file, opset_version, auto_upgrade_opset, verbose, | ||
enable_onnx_checker, enable_experimental_op, enable_optimize, {}, | ||
deploy_backend, calibration_file, external_file, export_fp16_model) | ||
else: | ||
onnx_model_str = c_p2o.export( | ||
model_file, params_file, opset_version, auto_upgrade_opset, verbose, | ||
enable_onnx_checker, enable_experimental_op, enable_optimize, | ||
custom_op_info, deploy_backend, calibration_file, external_file, | ||
export_fp16_model) | ||
if save_file is not None: | ||
with open(save_file, "wb") as f: | ||
f.write(onnx_model_str) | ||
else: | ||
return onnx_model_str |
Oops, something went wrong.