diff --git a/.daq_pm/configs/onnx_infer b/.daq_pm/configs/onnx_infer new file mode 100644 index 0000000..58e28ff --- /dev/null +++ b/.daq_pm/configs/onnx_infer @@ -0,0 +1,6 @@ +name DNNLibrary +type cpp +target dnn_retrieve_result +build_dir build_onnxinfer +cmake_options -DCMAKE_SYSTEM_NAME=Android -DCMAKE_TOOLCHAIN_FILE=~/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_CPP_FEATURES=exceptions -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DDNN_READ_ONNX=ON -DONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc +program_arguments ~/adb_push_and_run.sh binaries/dnn_retrieve_result diff --git a/CMakeLists.txt b/CMakeLists.txt index f0feff4..138a804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(DNNLibrary) option(DNN_BUILD_BIN "Build binaries" ON) option(DNN_BUILD_JNI "Build Java Wrapper" OFF) +option(DNN_READ_ONNX "Read ONNX model directly instead of converting to .daq" ON) option(DNN_SYSTEM_PROTOBUF "Use system protobuf when building onnx2daq" OFF) include(cmake/system.cmake) @@ -14,7 +15,13 @@ configure_glog() if (${CMAKE_SYSTEM_NAME} STREQUAL "Android") set (CMAKE_CXX_STANDARD 17) - add_compile_options(-Os -fno-rtti) + add_compile_options(-Os) + if (${DNN_READ_ONNX} AND NOT TARGET onnx) + include(cmake/onnx.cmake) + configure_onnx() + else() + add_compile_options(-fno-rtti) + endif() add_subdirectory(dnnlibrary) add_subdirectory(binaries) else() diff --git a/dnnlibrary/CMakeLists.txt b/dnnlibrary/CMakeLists.txt index 60e8b09..efada60 100644 --- a/dnnlibrary/CMakeLists.txt +++ b/dnnlibrary/CMakeLists.txt @@ -1,6 +1,6 @@ # dnn_protobuf_generate_cpp(ONNX_SRCS ONNX_HDRS onnx.proto3) -add_library(dnnlibrary +set(dnnlibrary_src include/ModelBuilder.h include/Model.h include/DaqReader.h @@ -14,6 +14,15 @@ add_library(dnnlibrary ${PROJECT_SOURCE_DIR}/common/Shaper.cpp ${PROJECT_SOURCE_DIR}/common/StrKeyMap.h ) +if (DNN_READ_ONNX) + list(APPEND dnnlibrary_src + src/OnnxReader.cpp + src/OnnxReader.h) +endif() + +add_library(dnnlibrary + ${dnnlibrary_src} + ) target_include_directories( dnnlibrary @@ -48,6 +57,14 @@ target_link_libraries( ${neural-networks-lib} ) +if (DNN_READ_ONNX) + target_link_libraries( + dnnlibrary + onnx + ) +endif() + + treat_warnings_as_errors(dnnlibrary) if (DNN_BUILD_JNI) diff --git a/dnnlibrary/src/OnnxReader.cpp b/dnnlibrary/src/OnnxReader.cpp new file mode 100644 index 0000000..b73defe --- /dev/null +++ b/dnnlibrary/src/OnnxReader.cpp @@ -0,0 +1,3 @@ +#include "OnnxReader.h" + + diff --git a/dnnlibrary/src/OnnxReader.h b/dnnlibrary/src/OnnxReader.h new file mode 100644 index 0000000..3ec2ded --- /dev/null +++ b/dnnlibrary/src/OnnxReader.h @@ -0,0 +1 @@ +#include