@ -1,26 +1,27 @@
cmake_minimum_required ( VERSION 2.8 )
if ( ${ CMAKE_PROJECT_NAME } STREQUAL "OpenCV" ) # b u i l d a s O p e n C V m o d u l e
set ( the_description "Deep neural network module. It allows to load models and to make forward pass" )
set ( the_description "Deep neural network module. It allows to load models from different frameworks and to make forward pass" )
set ( OPENCV_MODULE_IS_PART_OF_WORLD OFF )
OCV_OPTION ( BUILD_LIBPROTOBUF_FROM_SOURCES "Force to build libprotobuf from sources (don't try to find it in system)" OFF )
include ( cmake/find_protobuf.cmake )
ocv_add_module ( dnn opencv_imgproc opencv_core opencv_highgui WRAP python matlab )
ocv_add_module ( dnn opencv_core opencv_imgproc WRAP python matlab )
ocv_warnings_disable ( CMAKE_CXX_FLAGS -Wno-shadow -Wno-parentheses -Wmaybe-uninitialized -Wsign-promo -Wmissing-declarations -Wmissing-prototypes )
ocv_warnings_disable ( CMAKE_CXX_FLAGS /wd4701 )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# R e s o l v e l i b p r o t o b u f d e p e n d e n c y
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
include ( cmake/OpenCVFindLibProtobuf.cmake )
ocv_glob_module_sources ( ${ PROTOBUF_SRCS } ${ PROTOBUF_HDRS } )
ocv_source_group ( "Src\\protobuf" FILES ${ PROTOBUF_SRCS } ${ PROTOBUF_HDRS } )
ocv_module_include_directories ( include ${ PROTOBUF_INCLUDE_DIR } )
ocv_create_module ( ${ PROTOBUF_LIBRARIES } )
ocv_add_samples ( )
ocv_add_accuracy_tests ( )
ocv_add_perf_tests ( )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# D o w n l o a d p r e - t r a i n e d m o d e l s f o r c o m p l e x t e s t i n g o n G o o g L e N e t a n d A l e x N e t
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OCV_OPTION ( ${ the_module } _DOWNLOAD_CAFFE_MODELS "Use GoogLeNet Caffe model for testing" ON IF BUILD_TESTS AND PYTHON2_EXECUTABLE AND DEFINED ENV{OPENCV_TEST_DATA_PATH} )
if ( BUILD_TESTS AND ${ the_module } _DOWNLOAD_CAFFE_MODELS )
add_custom_command ( TARGET opencv_test_ ${ name } POST_BUILD
@ -29,13 +30,19 @@ if(BUILD_TESTS AND ${the_module}_DOWNLOAD_CAFFE_MODELS)
add_definitions ( -DENABLE_CAFFE_MODEL_TESTS=1 )
endif ( )
OCV_OPTION ( ${ the_module } _BUILD_TORCH_IMPORTER "Build Torch model importer" OFF )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# T o r c h 7 i m p o r t e r o f b l o b s a n d m o d e l s , p r o d u c e d b y T o r c h . n n m o d u l e
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OCV_OPTION ( ${ the_module } _BUILD_TORCH_IMPORTER "Build Torch model importer (experimental functionality!)" OFF )
if ( ${ the_module } _BUILD_TORCH_IMPORTER )
add_definitions ( -DENABLE_TORCH_IMPORTER=1 )
ocv_warnings_disable ( CMAKE_CXX_FLAGS /wd4702 /wd4127 /wd4267 )
ocv_warnings_disable ( CMAKE_CXX_FLAGS /wd4702 /wd4127 /wd4267 ) # s u p r e s s w a r n i n g s i n o r i g i n a l t o r c h f i l e s
endif ( )
OCV_OPTION ( ${ the_module } _BUILD_TORCH_TESTS "Build Torch tests (installed Torch7 with nn module is required)" ON IF BUILD_TESTS AND ${ the_module } _BUILD_TORCH_IMPORTER )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# G e n e r a t i n g t e s t d a t a f o r T o r c h i m p o r t e r
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OCV_OPTION ( ${ the_module } _BUILD_TORCH_TESTS "Build Torch tests (installed torch7 with nn module is required)" ON IF BUILD_TESTS AND ${ the_module } _BUILD_TORCH_IMPORTER )
if ( ${ the_module } _BUILD_TORCH_TESTS )
if ( NOT DEFINED ENV{OPENCV_TEST_DATA_PATH} )
@ -51,24 +58,4 @@ if(${the_module}_BUILD_TORCH_TESTS)
C O M M A N D t h $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / t e s t d a t a / d n n / t o r c h / t o r c h _ g e n _ t e s t _ d a t a . l u a
W O R K I N G _ D I R E C T O R Y $ E N V { O P E N C V _ T E S T _ D A T A _ P A T H } / d n n / t o r c h )
add_definitions ( -DENABLE_TORCH_TESTS=1 )
endif ( )
else ( ) # b u i l d a s s t a n d a l o n e module ( for development purposes )
project ( dnn_standalone )
include ( cmake/find_protobuf.cmake )
find_package ( OpenCV 3.0 REQUIRED )
file ( GLOB_RECURSE MODULE_SOURCES "src/*.cpp" )
file ( GLOB_RECURSE MODULE_HEADERS "src/*.hpp" "src/*.h" "include/*.h*" )
file ( GLOB_RECURSE MODULE_TEST_SOURCES "test/*.cpp" "test/*.hpp" "test/*.h" )
include_directories ( include ${ OpenCV_INCLUDE_DIRS } )
add_library ( _opencv_dnn SHARED ${ MODULE_SOURCES } ${ MODULE_HEADERS } ${ PROTO_FILES } ${ PROTO_HDRS } )
add_executable ( _opencv_test_dnn ${ MODULE_TEST_SOURCES } )
target_link_libraries ( _opencv_dnn ${ OpenCV_LIBS } ${ PROTOBUF_LIBRARIES } )
target_link_libraries ( _opencv_test_dnn _opencv_dnn opencv_ts )
target_include_directories ( _opencv_dnn PRIVATE src src/caffe ${ PROTOBUF_INCLUDE_DIR } ${ CMAKE_CURRENT_BINARY_DIR } )
endif ( )
endif ( )