You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/06/17 23:07:20 UTC

[GitHub] [incubator-mxnet] cyrusbehr opened a new issue #15261: C++ Can't load model with Symbol::Load when using static library

cyrusbehr opened a new issue #15261: C++ Can't load model with Symbol::Load when using static library
URL: https://github.com/apache/incubator-mxnet/issues/15261
 
 
   ## Description
   When I use the shared library for mxnet, I am able to load models as expected using `Symbol::Load(filepath)`
   However, when I switch to the static library, I get the following error on the `Symbol::Load` function call:
   ```
   terminate called after throwing an instance of 'dmlc::Error'
     what():  [15:42:04] /home/nchafni/Cyrus/myproject/include/mxnet-cpp/symbol.hpp:102: Check failed: MXSymbolCreateFromFile(file_name.c_str(), &(handle)) == 0 (-1 vs. 0) : 
   Stack trace:
     [bt] (0) /home/nchafni/Cyrus/myproject/myproject(dmlc::LogMessageFatal::~LogMessageFatal()+0x4a) [0x5593a17b4b9e]
     [bt] (1) /home/nchafni/Cyrus/myproject/myproject(mxnet::cpp::Symbol::Load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0xf8) [0x5593a17d2342]
     [bt] (2) /home/nchafni/Cyrus/myproject/myproject(myproject::loadModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x32) [0x5593a17cd488]
     [bt] (3) /home/nchafni/Cyrus/myproject/myproject(myproject::myproject()+0x181) [0x5593a17ccf47]
     [bt] (4) /home/nchafni/Cyrus/myproject/myproject(main+0x1a9) [0x5593a17b3664]
     [bt] (5) /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7fc680bd1b97]
     [bt] (6) /home/nchafni/Cyrus/myproject/myproject(_start+0x2a) [0x5593a17b2dfa]
   ```
   
   Due to the requirements of my project, I need to link mxnet as a static library. 
   
   ## Information
   I am using Ubuntu 18.04.2
   
   
   ## File Structure
   myproject
   | __ CMakeLists.txt
   | __ lib
   |     | __ libmxnet.so
   |     | __ libmxnet.a
   |     | __ libdmlc.a
   |     | __ libopencv_core.a
   |     | __ libopencv_highgui.a
   |     | __ libopencv_video.a
   | __ include
   |     | __ dlpack
   |     | __ dmlc
   |     | __ mkldnn
   |     | __ mshadow
   |     | __ mxnet
   |     | __ mxnet-cpp
   | __ main.cpp
   | __ models (mxnet models in here)
   
   ## CMakeLists.txt
   Here is my CMakeLists.txt used to link the **shared** mxnet. This one works as expected
   
   ```
   cmake_minimum_required(VERSION 2.8)
   project(myproject C CXX)
   
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   
   include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
   
   link_directories(${CMAKE_CURRENT_LIST_DIR}/lib)
   find_package(OpenCV REQUIRED)
   find_package(OpenMP REQUIRED)
   
   list(APPEND LINKER_LIBS opencv_core opencv_highgui opencv_video opencv_imgcodecs libmxnet.so)
   
   file(GLOB SRC ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
   
   set(COMPILE_CODE ${SRC})
   
   add_executable(myproject ${COMPILE_CODE})
   target_link_libraries(myproject ${LINKER_LIBS} ${OpenMP_CXX_LIBRARIES})
   
   ```
   Here is the CMakeLists.txt used to link the **static** mxnet library:
   
   ```
   cmake_minimum_required(VERSION 2.8)
   project(myproject C CXX)
   
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   
   include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
   
   link_directories(${CMAKE_CURRENT_LIST_DIR}/lib)
   find_package(OpenCV REQUIRED)
   find_package(OpenMP REQUIRED)
   
   list(APPEND LINKER_LIBS opencv_core opencv_highgui opencv_video opencv_imgcodecs libmxnet.a libdmlc.a rt)
   
   file(GLOB SRC ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
   
   set(COMPILE_CODE ${SRC})
   
   add_executable(myproject ${COMPILE_CODE})
   target_link_libraries(myproject ${LINKER_LIBS} ${OpenMP_CXX_LIBRARIES})
   
   ```
   ## The Code
   The code for loading the model was obtained from the example in the incubator-mxnet repo (https://github.com/apache/incubator-mxnet/blob/master/cpp-package/example/inference/inception_inference.cpp)
   
   Here is the code snippet used to load the model:
   
   ```
   void Predictor::LoadModel(const std::string& model_json_file) {
     if (!FileExists(model_json_file)) {
       LG << "Model file " << model_json_file << " does not exist";
       throw std::runtime_error("Model file does not exist");
     }
     LG << "Loading the model from " << model_json_file << std::endl;
     net = Symbol::Load(model_json_file);
   }
   ```
   Any help is much appreciated! 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services