dlib icon indicating copy to clipboard operation
dlib copied to clipboard

Unable to cast Python instance to C++ type

Open maromcik opened this issue 7 years ago • 4 comments

I'm trying to implement face clustering in Python. Unfortunately function dlib.chinese_whispers_clustering(descriptors,0.5) triggers a Runtime error: Unable to cast Python instance to C++ type (compile in debug mode for details). I can't get it to install in debug mode with python setup.py build --debug. It fails near the end with an error: c++: internal compiler error: Killed (program cc1plus). Although it installs fine with command python setup.py install. Function dlib.chinese_whispers() works fine, however I don't know how to cluster faces using this function. So alternatively I'd appreciate any outline on how to cluster faces using chinese_whispers() instead of chinese_whispers_clustering(). I couldn't find any details on how the latter one works.

Expected Behavior

Cluster descriptors of faces and return list of labels of those faces. By getting the length of the labels I could find out how many faces there are in the dataset.

Current Behavior

Triggers a runtime error Unable to cast Python instance to C++ type (compile in debug mode for details)

Steps to Reproduce

  1. Install dlib on Ubuntu with python setup.py install
  2. Import dlib and try to run function dlib.chinese_whispers_clustering(descriptors, 0.5).

Thank you very much.

  • Version: 19.17
  • Where did you get dlib: dlib.net
  • Platform: Ubuntu 18.04
  • Compiler: gcc 7.3

maromcik avatar Apr 30 '19 06:04 maromcik

Please post a small python program that runs and illustrates the issue.

davisking avatar May 01 '19 00:05 davisking

Hello, I've just sorted it out. I was converting descriptors to a numpy array, and it apparently isn't accepted by dlib. I didn't imagine that it could be a problem with the code. I was thinking only about dlib installation. Thank you again

maromcik avatar May 01 '19 09:05 maromcik

@maromcik, What did you do to solve this problem. I tried to converting the embeddings into a list, but the problem is not solved.

AhmadShaik avatar May 09 '19 12:05 AhmadShaik

I stumbled into this aswell and solved it by printing the descriptors from the example script and noticed that they are of type dlib.vector. Converted all my python lists to dlib.vectors and now its works.

descriptor = dlib.vector([0.1, 0.2, 0.3, ...])

bobmoff avatar May 14 '19 09:05 bobmoff