From 0d2913b52f8949e547d3b98e48dd644f54c73129 Mon Sep 17 00:00:00 2001 From: HyoungjooAhn Date: Tue, 30 Oct 2018 13:07:38 +0900 Subject: [PATCH] [Filter] change model download policy add a flag 'DISABLE_MODEL_DOWNLOAD' and block it at gbs build. It will be improved as rpm packaging for the model files rather than download them. Signed-off-by: HyoungjooAhn --- CMakeLists.txt | 13 ++--- gst/tensor_filter/CMakeLists.txt | 22 ++++---- gst/tensor_filter/tensor_filter.c | 12 ++--- .../example_object_detection/CMakeLists.txt | 62 ++++++++++++---------- packaging/nnstreamer.spec | 2 +- 5 files changed, 58 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 385a153..c7301bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(nnstreamer C CXX) OPTION(TIZEN "Enable Tizen build mode" OFF) -OPTION(DISABLE_TENSORFLOW_LITE "Disable tensorflow-lite support" OFF) -OPTION(DISABLE_TENSORFLOW "Disable tensorflow support" ON) +OPTION(ENABLE_TENSORFLOW_LITE "Enable tensorflow-lite support" ON) +OPTION(ENABLE_TENSORFLOW "Enable tensorflow support" OFF) +OPTION(ENABLE_MODEL_DOWNLOAD "Enable download the model files" ON) OPTION(INSTALL_EXAMPLE_APP "Install example applications" OFF) OPTION(SINGLE_BINARY "Generate a single binary for all nnstreamer elements" ON) IF(SINGLE_BINARY) @@ -131,14 +132,14 @@ ENDFOREACH(PRJ) SET(FILTER_LIB dl) SET(FILTER_DEP) -IF(NOT DISABLE_TENSORFLOW_LITE) +IF(ENABLE_TENSORFLOW_LITE) LIST(APPEND FILTER_LIB tensor_filter_tflitecore) LIST(APPEND FILTER_DEP tensor_filter_tflitecore) -ENDIF(NOT DISABLE_TENSORFLOW_LITE) -IF(NOT DISABLE_TENSORFLOW) +ENDIF(ENABLE_TENSORFLOW_LITE) +IF(ENABLE_TENSORFLOW) LIST(APPEND FILTER_LIB tensor_filter_tfcore) LIST(APPEND FILTER_DEP tensor_filter_tfcore) -ENDIF(NOT DISABLE_TENSORFLOW) +ENDIF(ENABLE_TENSORFLOW) LIST(LENGTH FILTER_DEP FILTER_DEP_LEN) IF (SINGLE_BINARY) diff --git a/gst/tensor_filter/CMakeLists.txt b/gst/tensor_filter/CMakeLists.txt index 0eea06f..2924cc6 100644 --- a/gst/tensor_filter/CMakeLists.txt +++ b/gst/tensor_filter/CMakeLists.txt @@ -1,18 +1,18 @@ # check whether TENSORFLOW_LITE is available. -# DISABLE_TENSORFLOW_LITE is defined at /debian/rules according to the build environment +# ENABLE_TENSORFLOW_LITE is defined at /debian/rules according to the build environment set(FILTER_SOURCE tensor_filter.c tensor_filter_custom.c) set(FILTER_TARGET) -IF(DISABLE_TENSORFLOW_LITE) # NOT AVAILABLE - ADD_DEFINITIONS(-DDISABLE_TENSORFLOW_LITE) -ENDIF(DISABLE_TENSORFLOW_LITE) +IF(ENABLE_TENSORFLOW_LITE) # AVAILABLE + ADD_DEFINITIONS(-DENABLE_TENSORFLOW_LITE) +ENDIF(ENABLE_TENSORFLOW_LITE) -IF(DISABLE_TENSORFLOW) # NOT AVAILABLE - ADD_DEFINITIONS(-DDISABLE_TENSORFLOW) -ENDIF(DISABLE_TENSORFLOW) +IF(ENABLE_TENSORFLOW) # AVAILABLE + ADD_DEFINITIONS(-DENABLE_TENSORFLOW) +ENDIF(ENABLE_TENSORFLOW) -IF(NOT DISABLE_TENSORFLOW_LITE) +IF(ENABLE_TENSORFLOW_LITE) list(APPEND FILTER_SOURCE tensor_filter_tensorflow_lite.c) list(APPEND FILTER_TARGET tensor_filter_tflitecore) list(APPEND FILTER_TARGET tensor_filter_tflitecoreStatic) @@ -32,9 +32,9 @@ IF(NOT DISABLE_TENSORFLOW_LITE) TARGET_LINK_LIBRARIES(tensor_filter_tflitecoreStatic ${pkgs_LIBRARIES} tensorflow-lite) TARGET_INCLUDE_DIRECTORIES(tensor_filter_tflitecoreStatic PUBLIC ${pkgs_INCLUDE_DIRS} ${TENSORFLOW_LITE_INCLUDE_DIRS}) TARGET_COMPILE_OPTIONS(tensor_filter_tflitecoreStatic PUBLIC ${pkgs_CFLAGS_OTHER}) -ENDIF(NOT DISABLE_TENSORFLOW_LITE) +ENDIF(ENABLE_TENSORFLOW_LITE) -IF(NOT DISABLE_TENSORFLOW) +IF(ENABLE_TENSORFLOW) list(APPEND FILTER_SOURCE tensor_filter_tensorflow.c) list(APPEND FILTER_TARGET tensor_filter_tfcore) list(APPEND FILTER_TARGET tensor_filter_tfcoreStatic) @@ -51,7 +51,7 @@ IF(NOT DISABLE_TENSORFLOW) TARGET_LINK_LIBRARIES(tensor_filter_tfcoreStatic ${pkgs_LIBRARIES} ${TENSORFLOW_LIBRARIES}) TARGET_INCLUDE_DIRECTORIES(tensor_filter_tfcoreStatic PUBLIC ${pkgs_INCLUDE_DIRS} ${TENSORFLOW_INCLUDE_DIRS}) TARGET_COMPILE_OPTIONS(tensor_filter_tfcoreStatic PUBLIC ${pkgs_CFLAGS_OTHER}) -ENDIF(NOT DISABLE_TENSORFLOW) +ENDIF(ENABLE_TENSORFLOW) MESSAGE(filterOBJ ${FILTER_SOURCE}) ADD_LIBRARY(tensor_filterOBJ OBJECT ${FILTER_SOURCE}) diff --git a/gst/tensor_filter/tensor_filter.c b/gst/tensor_filter/tensor_filter.c index e8c8548..d105965 100644 --- a/gst/tensor_filter/tensor_filter.c +++ b/gst/tensor_filter/tensor_filter.c @@ -106,15 +106,15 @@ GstTensorFilterFramework *tensor_filter_supported[] = { [_T_F_CUSTOM] = &NNS_support_custom, -#ifdef DISABLE_TENSORFLOW_LITE - [_T_F_TENSORFLOW_LITE] = NULL, -#else +#ifdef ENABLE_TENSORFLOW_LITE [_T_F_TENSORFLOW_LITE] = &NNS_support_tensorflow_lite, -#endif -#ifdef DISABLE_TENSORFLOW - [_T_F_TENSORFLOW] = NULL, #else + [_T_F_TENSORFLOW_LITE] = NULL, +#endif +#ifdef ENABLE_TENSORFLOW [_T_F_TENSORFLOW] = &NNS_support_tensorflow, +#else + [_T_F_TENSORFLOW] = NULL, #endif [_T_F_CAFFE2] = NULL, diff --git a/nnstreamer_example/example_object_detection/CMakeLists.txt b/nnstreamer_example/example_object_detection/CMakeLists.txt index fd542bb..ef9f82e 100644 --- a/nnstreamer_example/example_object_detection/CMakeLists.txt +++ b/nnstreamer_example/example_object_detection/CMakeLists.txt @@ -1,35 +1,39 @@ # demo app pkg_check_modules(cairo_pkg REQUIRED cairo) -if(NOT EXISTS "${CMAKE_BINARY_DIR}/tflite_model_ssd/ssd_mobilenet_v2_coco.tflite") - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tflite_model_ssd) - - message("-- [START TO DOWNLOAD REQUIRED RESOURCES: Model]") - file(DOWNLOAD - "https://github.com/nnsuite/testcases/raw/master/DeepLearningModels/tensorflow-lite/ssd_mobilenet_v2_coco/ssd_mobilenet_v2_coco.tflite" - "${CMAKE_BINARY_DIR}/tflite_model_ssd/ssd_mobilenet_v2_coco.tflite" - SHOW_PROGRESS - ) -endif() - -if(NOT EXISTS "${CMAKE_BINARY_DIR}/tflite_model_ssd/coco_labels_list.txt") - message("-- [START TO DOWNLOAD REQUIRED RESOURCES: Label]") - file(DOWNLOAD - "https://github.com/nnsuite/testcases/raw/master/DeepLearningModels/tensorflow-lite/ssd_mobilenet_v2_coco/coco_labels_list.txt" - "${CMAKE_BINARY_DIR}/tflite_model_ssd/coco_labels_list.txt" - SHOW_PROGRESS - ) -endif() - - -if(NOT EXISTS "${CMAKE_BINARY_DIR}/tflite_model_ssd/box_priors.txt") - message("-- [START TO DOWNLOAD REQUIRED RESOURCES: Box_prior]") - file(DOWNLOAD - "https://github.com/nnsuite/testcases/raw/master/DeepLearningModels/tensorflow-lite/ssd_mobilenet_v2_coco/box_priors.txt" - "${CMAKE_BINARY_DIR}/tflite_model_ssd/box_priors.txt" - SHOW_PROGRESS - ) -endif() +if(ENABLE_MODEL_DOWNLOAD) + if(NOT EXISTS "${CMAKE_BINARY_DIR}/tflite_model_ssd/ssd_mobilenet_v2_coco.tflite") + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tflite_model_ssd) + + message("-- [START TO DOWNLOAD REQUIRED RESOURCES: Model]") + file(DOWNLOAD + "https://github.com/nnsuite/testcases/raw/master/DeepLearningModels/tensorflow-lite/ssd_mobilenet_v2_coco/ssd_mobilenet_v2_coco.tflite" + "${CMAKE_BINARY_DIR}/tflite_model_ssd/ssd_mobilenet_v2_coco.tflite" + SHOW_PROGRESS + ) + endif() + + if(NOT EXISTS "${CMAKE_BINARY_DIR}/tflite_model_ssd/coco_labels_list.txt") + message("-- [START TO DOWNLOAD REQUIRED RESOURCES: Label]") + file(DOWNLOAD + "https://github.com/nnsuite/testcases/raw/master/DeepLearningModels/tensorflow-lite/ssd_mobilenet_v2_coco/coco_labels_list.txt" + "${CMAKE_BINARY_DIR}/tflite_model_ssd/coco_labels_list.txt" + SHOW_PROGRESS + ) + endif() + + + if(NOT EXISTS "${CMAKE_BINARY_DIR}/tflite_model_ssd/box_priors.txt") + message("-- [START TO DOWNLOAD REQUIRED RESOURCES: Box_prior]") + file(DOWNLOAD + "https://github.com/nnsuite/testcases/raw/master/DeepLearningModels/tensorflow-lite/ssd_mobilenet_v2_coco/box_priors.txt" + "${CMAKE_BINARY_DIR}/tflite_model_ssd/box_priors.txt" + SHOW_PROGRESS + ) + endif() +else() + message("-- [MODEL DOWNLOAD IS BLOCKED]") +endif(ENABLE_MODEL_DOWNLOAD) ADD_EXECUTABLE(nnstreamer_example_object_detection nnstreamer_example_object_detection.cc) diff --git a/packaging/nnstreamer.spec b/packaging/nnstreamer.spec index 381afb1..619bb26 100644 --- a/packaging/nnstreamer.spec +++ b/packaging/nnstreamer.spec @@ -84,7 +84,7 @@ CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" mkdir -p build pushd build -%cmake .. -DTIZEN=ON -DGST_INSTALL_DIR=%{gstlibdir} +%cmake .. -DTIZEN=ON -DGST_INSTALL_DIR=%{gstlibdir} -DENABLE_MODEL_DOWNLOAD=OFF make %{?_smp_mflags} popd -- 2.7.4