Skip to content

Commit

Permalink
Cleaned up image classification cpp example (apache#9799)
Browse files Browse the repository at this point in the history
* Cleaned up cpp image classification example

* Added gpg key

* Revert "Added gpg key"

This reverts commit d5c29d7.

* Adressed review comments, made other small improvements

* Reverted default device type to cpu

* Minor type change

* Applied review comments

* Brought back the static linking option
  • Loading branch information
lebeg authored and marcoabreu committed Mar 2, 2018
1 parent 8a05a46 commit d373070
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 244 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mxnet_option(USE_GPROF "Compile with gprof (profiling) flag" OFF)
mxnet_option(USE_CXX14_IF_AVAILABLE "Build with C++14 if the compiler supports it" OFF)
mxnet_option(USE_VTUNE "Enable use of Intel Amplifier XE (VTune)" OFF) # one could set VTUNE_ROOT for search path
mxnet_option(ENABLE_CUDA_RTC "Build with CUDA runtime compilation support" ON)
mxnet_option(BUILD_CPP_EXAMPLES "Build cpp examples" ON)
mxnet_option(INSTALL_EXAMPLES "Install the example source files." OFF)
mxnet_option(USE_SIGNAL_HANDLER "Print stack traces on segfaults." OFF)

Expand Down Expand Up @@ -690,8 +691,7 @@ if(USE_CPP_PACKAGE)
add_subdirectory(cpp-package)
endif()

# Problems on Mac OS X: 1. librt not available 2. mxnet built as MODULE library, which can't be linked.
if(NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin"))
if(BUILD_CPP_EXAMPLES)
add_subdirectory(example/image-classification/predict-cpp)
endif()

Expand Down
60 changes: 31 additions & 29 deletions example/image-classification/predict-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
if(USE_OPENCV)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
endif()
# Check OpenCV
if(NOT USE_OPENCV OR NOT OpenCV_FOUND)
message(WARNING "\
OpenCV should be enabled and found to build image classification example, skipping...")
return()
endif()

if(NOT MSVC)
set(UNITTEST_STATIC_LINK ON)
endif()
if(NOT MSVC)
set(IMG_CLASSIFICATION_EXAMPLE_STATIC_LINK ON CACHE BOOL "\
Link mxnet library statically in the c++ image classification example")
else()
# disable static linking on Windows
set(IMG_CLASSIFICATION_EXAMPLE_STATIC_LINK OFF)
endif()

add_executable(image-classification-predict image-classification-predict.cc)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
add_executable(image-classification-predict image-classification-predict.cc)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})

if(UNITTEST_STATIC_LINK)
target_link_libraries(image-classification-predict
${BEGIN_WHOLE_ARCHIVE} mxnet_static ${END_WHOLE_ARCHIVE}
dmlc
${mxnet_LINKER_LIBS}
)
else()
target_link_libraries(image-classification-predict
dmlc
${nnvm_LINKER_LIBS}
${mxnet_LINKER_LIBS}
mxnet
)
endif()
target_link_libraries(image-classification-predict ${OpenCV_LIBS})
if(UNIX)
target_link_libraries(image-classification-predict rt)
endif()
list(APPEND mxnet_LINKER_LIBS ${OpenCV_LIBS})
if(IMG_CLASSIFICATION_EXAMPLE_STATIC_LINK)
target_link_libraries(image-classification-predict
${BEGIN_WHOLE_ARCHIVE} mxnet_static ${END_WHOLE_ARCHIVE}
dmlc
${mxnet_LINKER_LIBS}
)
add_dependencies(image-classification-predict mxnet_static)
else()
target_link_libraries(image-classification-predict
dmlc
${nnvm_LINKER_LIBS}
${mxnet_LINKER_LIBS}
mxnet
)
add_dependencies(image-classification-predict mxnet)
endif()


Loading

0 comments on commit d373070

Please sign in to comment.