From 013c6a290d5f7b35b3e4e32d9f836a4682841937 Mon Sep 17 00:00:00 2001 From: daquexian Date: Fri, 24 May 2019 16:58:10 +0800 Subject: [PATCH] Use protobuf-lite instead of protobuf --- cmake/DNNLibraryConfig.cmake.in | 2 +- cmake/ONNX2daqConfig.cmake.in | 2 +- cmake/onnx.cmake | 1 + dnnlibrary/src/OnnxReader.cpp | 10 +++++++++- tools/onnx2daq/CMakeLists.txt | 5 +---- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmake/DNNLibraryConfig.cmake.in b/cmake/DNNLibraryConfig.cmake.in index 20bc806..3a9bcd0 100644 --- a/cmake/DNNLibraryConfig.cmake.in +++ b/cmake/DNNLibraryConfig.cmake.in @@ -1,7 +1,7 @@ get_filename_component(DNNLibrary_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) if (@DNN_READ_ONNX@) - if (NOT TARGET protobuf::libprotobuf) + if (NOT TARGET protobuf::libprotobuf-lite) find_package(Protobuf REQUIRED) endif() if (NOT TARGET onnx) diff --git a/cmake/ONNX2daqConfig.cmake.in b/cmake/ONNX2daqConfig.cmake.in index a1a5171..97f621d 100644 --- a/cmake/ONNX2daqConfig.cmake.in +++ b/cmake/ONNX2daqConfig.cmake.in @@ -1,6 +1,6 @@ get_filename_component(ONNX2daq_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -if (NOT TARGET protobuf::libprotobuf) +if (NOT TARGET protobuf::libprotobuf-lite) find_package(Protobuf REQUIRED) endif() diff --git a/cmake/onnx.cmake b/cmake/onnx.cmake index 74e53e1..d3f00e2 100644 --- a/cmake/onnx.cmake +++ b/cmake/onnx.cmake @@ -28,6 +28,7 @@ function(configure_onnx) message(FATAL ERROR "DNN_CUSTOM_PROTOC_EXECUTABLE is not set or wrong.") endif() set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${DNN_CUSTOM_PROTOC_EXECUTABLE}) + option(ONNX_USE_LITE_PROTO "" ON) add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/onnx) target_compile_definitions(onnx_proto PRIVATE ONNX_BUILD_MAIN_LIB) # Since https://github.com/onnx/onnx/pull/1318 is merged, we don't need to set it manually diff --git a/dnnlibrary/src/OnnxReader.cpp b/dnnlibrary/src/OnnxReader.cpp index e61ad2e..03c8bf1 100644 --- a/dnnlibrary/src/OnnxReader.cpp +++ b/dnnlibrary/src/OnnxReader.cpp @@ -1,15 +1,22 @@ #include +#include #include +#include #include +#include +#include namespace dnn { void OnnxReader::ReadOnnx(const std::string &filepath, ModelBuilder &builder) { ONNX_NAMESPACE::ModelProto model_proto; { std::ifstream ifs(filepath, std::ios::in | std::ios::binary); - model_proto.ParseFromIstream(&ifs); + std::stringstream ss; + ss << ifs.rdbuf(); + // FIXME: Handle the return value + model_proto.ParseFromString(ss.str()); ifs.close(); } ReadOnnx(model_proto, builder); @@ -17,6 +24,7 @@ void OnnxReader::ReadOnnx(const std::string &filepath, ModelBuilder &builder) { void OnnxReader::ReadOnnx(const uint8_t *buf, const size_t size, ModelBuilder &builder) { ONNX_NAMESPACE::ModelProto model_proto; + // FIXME: Handle the return value model_proto.ParseFromArray(buf, size); ReadOnnx(model_proto, builder); } diff --git a/tools/onnx2daq/CMakeLists.txt b/tools/onnx2daq/CMakeLists.txt index 37ef3c2..394038d 100644 --- a/tools/onnx2daq/CMakeLists.txt +++ b/tools/onnx2daq/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(onnx2daq ${PROJECT_SOURCE_DIR}/common/Shaper.cpp ) target_link_libraries(onnx2daq - protobuf::libprotobuf + protobuf::libprotobuf-lite glog::glog onnx) target_include_directories(onnx2daq @@ -72,9 +72,6 @@ if (NOT ONNX2DAQ_ONLY_LIB) target_link_libraries(_onnx2daq PUBLIC - protobuf::libprotobuf - glog::glog - onnx onnx2daq pybind11::pybind11 )