From: Роман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 Date: Thu, 20 Dec 2018 11:29:07 +0000 (+0300) Subject: [nnc] Refactor ONNX importer and fix ONNX importer build bug (#2733) X-Git-Tag: nncc_backup~1036 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49c91582a492138c91d73ad7fd34c5c10770c310;p=platform%2Fcore%2Fml%2Fnnfw.git [nnc] Refactor ONNX importer and fix ONNX importer build bug (#2733) * remove redundant classes from ONNX Signed-off-by: Roman Rusyaev --- diff --git a/contrib/nnc/CMakeLists.txt b/contrib/nnc/CMakeLists.txt index 41be6a6..1e5393c 100644 --- a/contrib/nnc/CMakeLists.txt +++ b/contrib/nnc/CMakeLists.txt @@ -112,6 +112,7 @@ set(NNC_INTERPRETER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/interpreter) set(NNC_CAFFE_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/caffe_frontend) set(NNC_CAFFE2_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/caffe2_frontend) set(NNC_TFLITE_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/tflite_frontend) +set(NNC_ONNX_FRONTEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes/onnx_frontend) set(NNC_CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core) set(NNC_SUPPORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/support) diff --git a/contrib/nnc/include/passes/onnx_frontend/ONNXImporter.h b/contrib/nnc/include/passes/onnx_frontend/ONNXImporter.h deleted file mode 100644 index ec92e4b..0000000 --- a/contrib/nnc/include/passes/onnx_frontend/ONNXImporter.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. - */ - -#ifndef NNCC_ONNXFRONTEND_H -#define NNCC_ONNXFRONTEND_H - -#include "pass/Pass.h" -#include "pass/PassData.h" - - -namespace nnc { -/** - * @brief class represent frontend of ONNX NN framework - */ -class ONNXImporter : public Pass -{ -public: - ONNXImporter() = default; - ~ONNXImporter() override = default; - PassData run(PassData data) override; -}; -} // namespace nnc - -#endif //NNCC_ONNXFRONTEND_H diff --git a/contrib/nnc/passes/common_frontend/CMakeLists.txt b/contrib/nnc/passes/common_frontend/CMakeLists.txt index d9508c3..d26fde6 100644 --- a/contrib/nnc/passes/common_frontend/CMakeLists.txt +++ b/contrib/nnc/passes/common_frontend/CMakeLists.txt @@ -8,8 +8,22 @@ add_library(nn_import_common STATIC ${COMMON_SOURCES}) set_target_properties(nn_import_common PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(nn_import_common PRIVATE nnc_core nnc_support) +# # This library depends on other frontends to provide uniform interface for those who use frontends +# set(IMPORTER_SUPPORT_SOURCES NNImporter.cpp) add_nnc_library(nn_importer_support STATIC ${IMPORTER_SUPPORT_SOURCES}) -target_include_directories(nn_importer_support PRIVATE ${NNC_CAFFE_FRONTEND_DIR} ${NNC_CAFFE2_FRONTEND_DIR} ${NNC_TFLITE_FRONTEND_DIR}) -target_link_libraries(nn_importer_support caffe_importer caffe2_importer tflite_importer) +target_include_directories(nn_importer_support PRIVATE ${NNC_CAFFE_FRONTEND_DIR} + ${NNC_CAFFE2_FRONTEND_DIR} ${NNC_TFLITE_FRONTEND_DIR} ${NNC_ONNX_FRONTEND_DIR}) +if (NNC_FRONTEND_CAFFE_ENABLED) + target_link_libraries(nn_importer_support caffe_importer) +endif() +if (NNC_FRONTEND_CAFFE2_ENABLED) + target_link_libraries(nn_importer_support caffe2_importer) +endif() +if (NNC_FRONTEND_TFLITE_ENABLED) + target_link_libraries(nn_importer_support tflite_importer) +endif() +if (NNC_FRONTEND_ONNX_ENABLED) + target_link_libraries(nn_importer_support onnx_importer) +endif() diff --git a/contrib/nnc/passes/common_frontend/NNImporter.cpp b/contrib/nnc/passes/common_frontend/NNImporter.cpp index 0654a8d..7ceb1fa 100644 --- a/contrib/nnc/passes/common_frontend/NNImporter.cpp +++ b/contrib/nnc/passes/common_frontend/NNImporter.cpp @@ -4,9 +4,18 @@ #include "option/Options.h" #include "passes/common_frontend/NNImporter.h" -#include "tflite_importer.h" -#include "caffe_importer.h" -#include "caffe2_importer.h" +#ifdef NNC_FRONTEND_TFLITE_ENABLED +# include "tflite_importer.h" +#endif // NNC_FRONTEND_TFLITE_ENABLED +#ifdef NNC_FRONTEND_CAFFE_ENABLED +# include "caffe_importer.h" +#endif // NNC_FRONTEND_CAFFE_ENABLED +#ifdef NNC_FRONTEND_CAFFE2_ENABLED +# include "caffe2_importer.h" +#endif // NNC_FRONTEND_CAFFE2_ENABLED +#ifdef NNC_FRONTEND_ONNX_ENABLED +# include "ONNXImporterImpl.h" +#endif // NNC_FRONTEND_ONNX_ENABLED namespace nnc { @@ -26,7 +35,7 @@ std::unique_ptr NNImporter::createNNImporter() { #endif // NNC_FRONTEND_CAFFE2_ENABLED } else if (cli::onnxFrontend) { #ifdef NNC_FRONTEND_ONNX_ENABLED - importer.reset(new ONNXImporter()); + importer.reset(new ONNXImporterImpl(cli::inputFile)); #endif // NNC_FRONTEND_ONNX_ENABLED } else if (cli::tflFrontend) { #ifdef NNC_FRONTEND_TFLITE_ENABLED diff --git a/contrib/nnc/passes/onnx_frontend/ONNXImporter.cpp b/contrib/nnc/passes/onnx_frontend/ONNXImporter.cpp deleted file mode 100644 index e439f88..0000000 --- a/contrib/nnc/passes/onnx_frontend/ONNXImporter.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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 "option/Options.h" -#include "passes/onnx_frontend/ONNXImporter.h" -#include "ONNXImporterImpl.h" - -namespace nnc { -PassData ONNXImporter::run(PassData data) { - ONNXImporterImpl importer{cli::inputFile}; - return importer.createIR(); -} -} // namespace nnc diff --git a/contrib/nnc/passes/onnx_frontend/ONNXImporterImpl.h b/contrib/nnc/passes/onnx_frontend/ONNXImporterImpl.h index 706ec4b..3f0cd3f 100644 --- a/contrib/nnc/passes/onnx_frontend/ONNXImporterImpl.h +++ b/contrib/nnc/passes/onnx_frontend/ONNXImporterImpl.h @@ -25,7 +25,7 @@ #include "core/modelIR/Graph.h" #include "ONNXOpType.h" #include "ONNXOpCreator.h" -#include "passes/common_frontend/nn_importer.h" +#include "passes/common_frontend/NNImporter.h" namespace nnc {