dlib: Boost.Python.ArgumentError in shape_landmark_detection.py

Hello,

I have a problem using shape_predictor for face landmarks detection using python 2.7 in anaconda.

I compiled dlib and verified boost lib path according to these issues:

I also tried to rebuild Boost from source, but still having the same error:

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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
    __init__(_object*)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Yeah, boost.python has an awful build process. I’ll switch to pybind11 instead of boost.python at some point in the future (https://github.com/davisking/dlib/issues/293). That should make building the python extensions pretty trivial.

Sorry to necro this, but maybe my note will help someone.

I had similar error message on Debian with self-compiled Python, Boost, and dlib:

Traceback (most recent call last):
  File "my_dlib_tests.py", line 102, in <module>
    predictor = dlib.shape_predictor(face_landmarks_path)
Boost.Python.ArgumentError: Python argument types in
    shape_predictor.__init__(shape_predictor, PosixPath)
did not match C++ signature:
    __init__(boost::python::api::object, std::string)
    __init__(_object*)

Based on above discussion I figured I also had compilation issue between different versions of Boost and Python. And I did have those previously due to apt-get giving different libboost version.

After fighting for hours I realized that that error is telling me that the shape_predictormethod expects a string, and I’m feeding it a pathlib.Path object. Code for clarity:

from pathlib import Path
import dlib

fname = 'shape_predictor_68_face_landmarks.dat'
# This gives the error above:
f_as_path = Path(fname)
dlib.shape_predictor(f_as_path)
# And this is the correct way to call that method:
dlib.shape_predictor(fname)

Lesson: Learn to read Boost.Python errors.

@davisking Yes, I commented it for someone with the same problem.

I tried all the solutions written above, but none worked on my machine. The problem was that python from anaconda kept on find the boost version installed in anaconda. After run the code blow and build dlib it worked.

pip uninstall dlib
conda clean --packages

I found a fix for my case (Ubuntu 16.04, python 2.7 with conda).

First, I needed to uninstall Ubuntu’s Boost: sudo apt-get remove libboost-dev

as well as conda’s boost: conda uninstall boost.

After this, dlib’s setup.py identified the Boost that I had manually compiled and installed: Boost version: 1.62.0. However, there were some lingering dependencies that remained in anaconda, as indicated by: USING BOOST_LIBS: /home/jrking/anaconda/lib/_libboost_python-mt.so

I manually removed (after a backup) ~/anaconda/lib/libboost_python-mt.a and ~/home/jrking/anaconda/lib/libboost_python-mt.so

and it now seems to works.

I hope this helps others.