davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.57k stars 3.38k forks source link

[Bug]: RuntimeError in dlib.load_rgb_image: Failing expression was false with Python #2982

Closed MurphyZhangFC closed 3 months ago

MurphyZhangFC commented 4 months ago

What Operating System(s) are you seeing this problem on?

macOS (Apple Silicon)

dlib version

19.24.4

Python version

3.10

Compiler

appleclang15

Expected Behavior

I want to read some images for testing.

Current Behavior

I am encountering a RuntimeError when using dlib.load_rgb_image in my code. Here is the error message: `Traceback (most recent call last): File "/Users/**/test.py", line 7, in img = dlib.load_rgb_image("test.jpg") RuntimeError:

Error detected at line 111. Error detected in file /private/var/folders/b3/kmnj2pcj591_hr2nb1qntkr80000gn/T/pip-install-iu67w7fx/dlib_489a4994c89d4706a72473336f69874d/dlib/../dlib/python/numpy_image.h. Error detected in function auto dlib::assert_is_image(const py::array &)::(anonymous class)::operator()(char, size_t) const.

Failing expression was false. unknown type`

Steps to Reproduce

  1. Install dlib version 19.24.4 on macOS with Python 3.10.
  2. Use the provided code to load an image and detect faces.
  3. Run the script to see the error. Here is my code: `import dlib

detector = dlib.get_frontal_face_detector()

img = dlib.load_rgb_image("test.jpg")

faces = detector(img)

print("Number of faces detected: {}".format(len(faces)))`

Anything else?

I have tried running the same code on different computers and operating systems, but the same error occurs. Additionally, I have attempted to preprocess the image using OpenCV, but the error persists. I also have verified that the image file test.jpg exists and is accessible. The error seems to occur specifically when calling dlib.load_rgb_image.

Any help in resolving this issue would be greatly appreciated.

arrufat commented 4 months ago

What's your Numpy version? I bet it's 2.0. Try with 1.26. If you absolutely need Numpy 2.0 try building from master.

MurphyZhangFC commented 3 months ago

What's your Numpy version? I bet it's 2.0. Try with 1.26. If you absolutely need Numpy 2.0 try building from master.

@arrufat It works for me, Thank you!

arrufat commented 3 months ago

@davisking Maybe PyPI's dlib should be updated, as I guess we'll have more and more of bug reports like this, as NumPy 2.0 becomes more widespread.

davisking commented 3 months ago

Yeah, just pushed the latest dlib to PyPI. Hopefully we see less issues.

cchadowitz commented 3 months ago

Yeah, just pushed the latest dlib to PyPI. Hopefully we see less issues.

Just curious - are the changes in the latest dlib on PyPI just to adjust the numpy version requirements, or code changes to support numpy 2.0?

Thanks!

arrufat commented 3 months ago

As far as I understand, you should be good to go with dlib v19.24.5.

cchadowitz commented 3 months ago

I understand, but I was curious what the changes were for v19.24.5 😄

arrufat commented 3 months ago

Not much: https://github.com/davisking/dlib/compare/v19.24.4...v19.24.5

In Python, just a bug fix to the newly introduced load_rgb_alpha_image function.

cchadowitz commented 3 months ago

Ah I see, thanks - didn't realize there was a github tag for the versions as well!

cchadowitz commented 3 months ago

Actually, it does seem like there was also an additional pybind11 cmake option exposed: https://github.com/davisking/dlib/compare/v19.24.4...v19.24.5#diff-5bb9350d3c305fa87fad69732e4dcfe993fa9134993056e46b70aaf6b24baae0R114