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.58k stars 3.38k forks source link

MacOS compile dlib library compile after executing the following code prompt: illegal instructions: 4! #1740

Closed Wang-Mings closed 5 years ago

Wang-Mings commented 5 years ago

Machine: 2010 System: masOS: 10.13.6 Python version: 3.7.6 ~ 3.6.5 Error executing the following code! Never found a solution!

Find the problem:face_descriptor = face_rec.compute_face_descriptor(img_gray, shape)

Test code:

import dlib import cv2 from skimage import io

Use dlib model

detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_5_face_landmarks.dat") face_rec=dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")

img_rd = io.imread("test.jpg") img_gray = cv2.cvtColor(img_rd, cv2.COLOR_BGR2RGB) faces = detector(img_gray, 1)

shape = predictor(img_gray, faces[0]) face_descriptor = face_rec.compute_face_descriptor(img_gray, shape)

print(face_descriptor)

Wang-Mings commented 5 years ago

I have referred to the official installation steps!

1, I download the source code in the official: http://dlib.net/

  1. Extract the package and compile it: cd dlib;cd examples;mkdir build;cd build;cmake ..;cmake --build . --config Release

Some code problems occurred during the compilation process:

[ 25%] Building C object dlib_build/CMakeFiles/dlib.dir/external/zlib/inflate.c.o /Users/mac/dlib/dlib/external/zlib/inflate.c:1507:61: warning: shifting a negative signed value is undefined [-Wshift-negative-value] if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;


1 warning generated.

[ 74%] Building CXX object CMakeFiles/train_object_detector.dir/train_object_detector.cpp.o
/Users/mac/dlib/examples/train_object_detector.cpp:65:45: warning: '/' within block comment
[-Wcomment]
./train_object_detector examples/faces/.jpg -u1
^
1 warning generated.

[ 86%] Building CXX object CMakeFiles/face_detection_ex.dir/face_detection_ex.cpp.o
/Users/mac/dlib/examples/face_detection_ex.cpp:11:34: warning: '/' within block comment [-Wcomment]
./face_detection_ex faces/.jpg
^
1 warning generated.

Problem specification:
This is where the compilation went wrong! From compile progress 1 to 100% nothing else goes wrong! I looked at the source code error! Have a plenty of annotation not standard bring about! There are some places where there is a lack of space

I ignored the previous error to install: python setup.py install
Installation progress to 50% error!
Explanation: this is one of the nice places! The basic error is the same

/Users/mac/dlib/dlib/external/pybind11/include/pybind11/detail/internals.h:169:33: warning:
'PyThread_create_key' is deprecated [-Wdeprecated-declarations]
internals_ptr->tstate = PyThread_create_key();
^
/Users/mac/.pyenv/versions/3.7.3/include/python3.7m/pythread.h:95:43: note: 'PyThread_create_key'
has been explicitly marked deprecated here
PyAPI_FUNC(int) PyThread_create_key(void) Py_DEPRECATED(3.7);
^
/Users/mac/.pyenv/versions/3.7.3/include/python3.7m/pyport.h:493:54: note: expanded from macro
'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) attribute((deprecated))

Use pip3 list to see if dlib was installed successfully:

Python 3.7.3 (default, Apr 19 2019, 11:27:39)
[Clang 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import dlib
dlib.DLIB_USE_CUDA
False
print(dlib)
<module 'dlib' from '/Users/mac/.pyenv/versions/3.7.3/lib/python3.7/site-packages/dlib-19.17.0-py3.7-macosx-10.13-x86_64.egg/dlib.cpython-37m-darwin.so'>

Still prompt: illegal instruction: 4 when executing the following code
eer: face_descriptor = face_rec.compute_face_descriptor(img_gray, shape)
import dlib
import cv2
from skimage import io

Use dlib model
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("data/data_dlib/shape_predictor_5_face_landmarks.dat")
face_rec = dlib.face_recognition_model_v1("data/data_dlib/dlib_face_recognition_resnet_model_v1.dat")

img_rd = io.imread("test.jpg")
img_gray = cv2.cvtColor(img_rd, cv2.COLOR_BGR2RGB)
faces = detector(img_gray, 1)

shape = predictor(img_gray, faces[0])
face_descriptor = face_rec.compute_face_descriptor(img_gray, shape)

print(face_descriptor)

Important: I have installed x11 and cmake, this is to view the online MAC installation dlib method
davisking commented 5 years ago

That's not how you install dlib in python. You run python setup.py install, as per the instructions http://dlib.net/compile.html

Wang-Mings commented 5 years ago

This is how I installed it: if you know, please tell me the correct installation steps! Thank you very much! I had tried countless ways before without success!