dlib.shape_predictor not work with Boost Python

Created on 29 May 2016  路  10Comments  路  Source: davisking/dlib

Dlib v18.18 is sucessfully installed to system. However, the shape_predictor is not working with python boost. The system version of boost used is: boost 1.58.

The error message is shown below:

python face_landmark_detection.py shape_predictor_68_face_landmarks.dat ../examples/faces/
Traceback (most recent call last):
  File "face_landmark_detection.py", line 52, in <module>
    predictor = dlib.shape_predictor(predictor_path)
Boost.Python.ArgumentError: Python argument types in
    shape_predictor.__init__(shape_predictor, str)
did not match C++ signature:
    __init__(boost::python::api::object, std::string)
    __init__(_object*)

Most helpful comment

For me, it helped to compile with g++-5 instead of 4.9.
sudo apt-get install g++-5
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 60
(you might as well just change the cmake arguments)

All 10 comments

This is a common error. Are you sure your copy of boost was compiled
against the version of python you are running?

I have tried to install dlib with pip and setup.py with source code. These two installation have same problem.

Could you give some hints on how to debug the installation and solve the problem?

Thank you for hint, I found that pythonlibs are not correctly selected. The correct pythonlibs should be in a customized python virtualenv.

-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable version "2.7.10", minimum required is "2.6")
-- USING BOOST_LIBS: /usr/lib/x86_64-linux-gnu/libboost_python.so
-- USING PYTHON_LIBS: /usr/lib/x86_64-linux-gnu/libpython2.7.so

How to make setup.py find the correct path?

You might be able to set CMAKE_PREFIX_PATH to the folder you want to use.
However, you will need to recompile boost.python to use that version of
python as well.

Why don't you use the system version of python? That looks like it's the
one all these things are compiled against.

In any case. The problem is that you are mixing things from different
versions of python. The important thing is to make sure all the python
modules you are trying to roll together are compiled against the same
version of python and also that that's the version of the python
interpreter you are actually running.

I also tried the system python. And it has the same problem.

The compile log is shown below:

running build
Detected Python architecture: 64bit
Removing build directory /home/shixudongleo/dlib/./tools/python/build
Configuring cmake ...
-- The C compiler identification is GNU 5.2.1
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   python
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable version "2.7.10", minimum required is "2.6")
-- USING BOOST_LIBS: /usr/lib/x86_64-linux-gnu/libboost_python.so
-- USING PYTHON_LIBS: /usr/lib/x86_64-linux-gnu/libpython2.7.so
-- Enabling SSE4 instructions
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Looking for png_create_read_struct
-- Looking for png_create_read_struct - found
-- Looking for jpeg_read_header
-- Looking for jpeg_read_header - found
-- Searching for BLAS and LAPACK
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Found OpenBLAS library
-- Looking for sgetrf_single
-- Looking for sgetrf_single - found
-- Using OpenBLAS's built in LAPACK
-- Looking for cblas_ddot
-- Looking for cblas_ddot - found
-- Check for STD namespace
-- Check for STD namespace - found
-- Looking for C++ include iostream
-- Looking for C++ include iostream - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/shixudongleo/dlib/tools/python/build
Build using cmake ...
Scanning dependencies of target dlib
[  1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/base64/base64_kernel_1.o
[  2%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bigint/bigint_kernel_1.o
[  4%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bigint/bigint_kernel_2.o
[  5%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bit_stream/bit_stream_kernel_1.o
[  7%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_1.o
[  8%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_2.o
[ 10%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_1.o
[ 11%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_2.o
[ 13%] Building CXX object dlib_build/CMakeFiles/dlib.dir/md5/md5_kernel_1.o
[ 14%] Building CXX object dlib_build/CMakeFiles/dlib.dir/tokenizer/tokenizer_kernel_1.o
[ 16%] Building CXX object dlib_build/CMakeFiles/dlib.dir/unicode/unicode.o
[ 17%] Building CXX object dlib_build/CMakeFiles/dlib.dir/data_io/image_dataset_metadata.o
[ 19%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockets/sockets_kernel_1.o
[ 20%] Building CXX object dlib_build/CMakeFiles/dlib.dir/bsp/bsp.o
[ 22%] Building CXX object dlib_build/CMakeFiles/dlib.dir/dir_nav/dir_nav_kernel_1.o
[ 23%] Building CXX object dlib_build/CMakeFiles/dlib.dir/dir_nav/dir_nav_kernel_2.o
[ 25%] Building CXX object dlib_build/CMakeFiles/dlib.dir/dir_nav/dir_nav_extensions.o
[ 26%] Building CXX object dlib_build/CMakeFiles/dlib.dir/linker/linker_kernel_1.o
[ 28%] Building CXX object dlib_build/CMakeFiles/dlib.dir/logger/extra_logger_headers.o
[ 29%] Building CXX object dlib_build/CMakeFiles/dlib.dir/logger/logger_kernel_1.o
[ 31%] Building CXX object dlib_build/CMakeFiles/dlib.dir/logger/logger_config_file.o
[ 32%] Building CXX object dlib_build/CMakeFiles/dlib.dir/misc_api/misc_api_kernel_1.o
[ 34%] Building CXX object dlib_build/CMakeFiles/dlib.dir/misc_api/misc_api_kernel_2.o
[ 35%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockets/sockets_extensions.o
[ 37%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockets/sockets_kernel_2.o
[ 38%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockstreambuf/sockstreambuf.o
[ 40%] Building CXX object dlib_build/CMakeFiles/dlib.dir/sockstreambuf/sockstreambuf_unbuffered.o
[ 41%] Building CXX object dlib_build/CMakeFiles/dlib.dir/server/server_kernel.o
[ 43%] Building CXX object dlib_build/CMakeFiles/dlib.dir/server/server_iostream.o
[ 44%] Building CXX object dlib_build/CMakeFiles/dlib.dir/server/server_http.o
[ 46%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/multithreaded_object_extension.o
[ 47%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threaded_object_extension.o
[ 49%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threads_kernel_1.o
[ 50%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threads_kernel_2.o
[ 52%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/threads_kernel_shared.o
[ 53%] Building CXX object dlib_build/CMakeFiles/dlib.dir/threads/thread_pool_extension.o
[ 55%] Building CXX object dlib_build/CMakeFiles/dlib.dir/timer/timer.o
[ 56%] Building CXX object dlib_build/CMakeFiles/dlib.dir/stack_trace.o
[ 58%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o
[ 59%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/widgets.o
[ 61%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/drawable.o
[ 62%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/canvas_drawing.o
[ 64%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/style.o
[ 65%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/base_widgets.o
[ 67%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_core/gui_core_kernel_1.o
[ 68%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_core/gui_core_kernel_2.o
[ 70%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_loader/png_loader.o
[ 71%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_saver/save_png.o
[ 73%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_loader/jpeg_loader.o
[ 74%] Building CXX object dlib_build/CMakeFiles/dlib.dir/image_saver/save_jpeg.o
Linking CXX static library libdlib.a
[ 74%] Built target dlib
Scanning dependencies of target dlib_
[ 76%] Building CXX object CMakeFiles/dlib_.dir/src/dlib.cpp.o
[ 77%] Building CXX object CMakeFiles/dlib_.dir/src/matrix.cpp.o
[ 79%] Building CXX object CMakeFiles/dlib_.dir/src/vector.cpp.o
[ 80%] Building CXX object CMakeFiles/dlib_.dir/src/svm_c_trainer.cpp.o
[ 82%] Building CXX object CMakeFiles/dlib_.dir/src/svm_rank_trainer.cpp.o
[ 83%] Building CXX object CMakeFiles/dlib_.dir/src/decision_functions.cpp.o
[ 85%] Building CXX object CMakeFiles/dlib_.dir/src/other.cpp.o
[ 86%] Building CXX object CMakeFiles/dlib_.dir/src/basic.cpp.o
[ 88%] Building CXX object CMakeFiles/dlib_.dir/src/cca.cpp.o
[ 89%] Building CXX object CMakeFiles/dlib_.dir/src/sequence_segmenter.cpp.o
[ 91%] Building CXX object CMakeFiles/dlib_.dir/src/svm_struct.cpp.o
[ 92%] Building CXX object CMakeFiles/dlib_.dir/src/image.cpp.o
[ 94%] Building CXX object CMakeFiles/dlib_.dir/src/rectangles.cpp.o
[ 95%] Building CXX object CMakeFiles/dlib_.dir/src/object_detection.cpp.o
[ 97%] Building CXX object CMakeFiles/dlib_.dir/src/shape_predictor.cpp.o
[ 98%] Building CXX object CMakeFiles/dlib_.dir/src/correlation_tracker.cpp.o
[100%] Building CXX object CMakeFiles/dlib_.dir/src/gui.cpp.o
Linking CXX shared library dlib.so
[100%] Built target dlib_
Install the project...
-- Install configuration: "Release"
-- Installing: /home/shixudongleo/dlib/tools/python/../../python_examples/dlib.so
Populating the distribution directory /home/shixudongleo/dlib/./dist/dlib ...
Copying file /home/shixudongleo/dlib/./python_examples/correlation_tracker.py -> /home/shixudongleo/dlib/./dist/dlib/examples/correlation_tracker.py.
Copying file /home/shixudongleo/dlib/./python_examples/svm_rank.py -> /home/shixudongleo/dlib/./dist/dlib/examples/svm_rank.py.
Copying file /home/shixudongleo/dlib/./python_examples/svm_struct.py -> /home/shixudongleo/dlib/./dist/dlib/examples/svm_struct.py.
Copying file /home/shixudongleo/dlib/./python_examples/face_landmark_detection.py -> /home/shixudongleo/dlib/./dist/dlib/examples/face_landmark_detection.py.
Copying file /home/shixudongleo/dlib/./python_examples/LICENSE_FOR_EXAMPLE_PROGRAMS.txt -> /home/shixudongleo/dlib/./dist/dlib/examples/LICENSE_FOR_EXAMPLE_PROGRAMS.txt.
Copying file /home/shixudongleo/dlib/./python_examples/max_cost_assignment.py -> /home/shixudongleo/dlib/./dist/dlib/examples/max_cost_assignment.py.
Copying file /home/shixudongleo/dlib/./python_examples/sequence_segmenter.py -> /home/shixudongleo/dlib/./dist/dlib/examples/sequence_segmenter.py.
Copying file /home/shixudongleo/dlib/./python_examples/find_candidate_object_locations.py -> /home/shixudongleo/dlib/./dist/dlib/examples/find_candidate_object_locations.py.
Copying file /home/shixudongleo/dlib/./python_examples/train_object_detector.py -> /home/shixudongleo/dlib/./dist/dlib/examples/train_object_detector.py.
Copying file /home/shixudongleo/dlib/./python_examples/dlib.so -> /home/shixudongleo/dlib/./dist/dlib/dlib.so.
Copying file /home/shixudongleo/dlib/./python_examples/train_shape_predictor.py -> /home/shixudongleo/dlib/./dist/dlib/examples/train_shape_predictor.py.
Copying file /home/shixudongleo/dlib/./python_examples/face_detector.py -> /home/shixudongleo/dlib/./dist/dlib/examples/face_detector.py.
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/dlib
copying dist/dlib/__init__.py -> build/lib.linux-x86_64-2.7/dlib
running egg_info
creating dist/dlib.egg-info
writing dist/dlib.egg-info/PKG-INFO
writing top-level names to dist/dlib.egg-info/top_level.txt
writing dependency_links to dist/dlib.egg-info/dependency_links.txt
writing manifest file 'dist/dlib.egg-info/SOURCES.txt'
reading manifest file 'dist/dlib.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'dist/dlib.egg-info/SOURCES.txt'
copying dist/dlib/dlib.so -> build/lib.linux-x86_64-2.7/dlib
creating build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/LICENSE_FOR_EXAMPLE_PROGRAMS.txt -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/__init__.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/correlation_tracker.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/face_detector.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/face_landmark_detection.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/find_candidate_object_locations.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/max_cost_assignment.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/sequence_segmenter.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/svm_rank.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/svm_struct.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/train_object_detector.py -> build/lib.linux-x86_64-2.7/dlib/examples
copying dist/dlib/examples/train_shape_predictor.py -> build/lib.linux-x86_64-2.7/dlib/examples
running build_ext

When run the landmark detection example:

$ python face_landmark_detection.py shape_predictor_68_face_landmarks.dat ../example/faces
Traceback (most recent call last):
  File "face_landmark_detection.py", line 66, in <module>
    predictor = dlib.shape_predictor(predictor_path)
Boost.Python.ArgumentError: Python argument types in
    shape_predictor.__init__(shape_predictor, str)
did not match C++ signature:
    __init__(boost::python::api::object, std::string)
    __init__(_object*)

Are you sure you are running the system python? Try running it by giving
the full path to the python interpreter. If that doesn't work then you
must have a version of boost python installed that is compiled against some
other python. I would compile it yourself if that's the problem.

Finally understand where the problem is. My system has two boost libraries:

  • /usr/include/boost, /usr/lib (ubuntu pre-build)
  • /usr/local/include/boost, /usr/local/lib (self-build)

The setup.py script always use the ubuntu pre-build boost library in /usr/include/boost, /usr/lib. There are bugs in the pre-build library. I guess is the mess up of python versions.

Once I remove /usr/include/boost, /usr/lib, dlib built against /usr/local/include/boost, /usr/local/lib will work properly. Now face landmark detection works greatly.

_One minor question:_
I want to keep both boost libraries: /usr/include/boost, /usr/lib and /usr/local/include/boost, /usr/local/lib.
Instead of removing /usr/include/boost, /usr/lib, how to make setup.py select the boost library in /usr/local/include/boost, /usr/local/lib ?

_Possible Solution:_
I add the cmake script to "dlib/tools/python/CMakeList.txt".

set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
  set(BOOST_ROOT "/usr/local")
  set(BOOST_INCLUDE_DIRS "${BOOST_ROOT}/include")
  set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/lib")
endif(Boost_NO_SYSTEM_PATHS)

find_package(Boost COMPONENTS python REQUIRED)
include_directories(${BOOST_INCLUDE_DIRS})
link_directories(${BOOST_LIBRARY_DIRS})

Cool. You should be able to set the CMAKE_PREFIX_PATH environment
variable to point to the version you want.

I have your exact problem. However I only have boost installed on /usr/include/boost. What should I try next to find the what's causing the problem? I have Ubuntu 16.04

For me, it helped to compile with g++-5 instead of 4.9.
sudo apt-get install g++-5
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 60
(you might as well just change the cmake arguments)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ardamavi picture ardamavi  路  3Comments

jackweiwang picture jackweiwang  路  4Comments

AivanF picture AivanF  路  4Comments

AeroClassics picture AeroClassics  路  4Comments

farazirfan47 picture farazirfan47  路  5Comments