Search code examples
pythonpyinstaller

PyInstaller: How to call "shape_predictor_68_face_landmarks.dat" file with dlib.shape_predictor, while imported it with 'binaries'?


I have an small app, which is used face_recognition library. And I already imported it with

face_models = [
('.//face_recognition_models//models//dlib_face_recognition_resnet_model_v1.dat', 
'./face_recognition_models/models'),
('.//face_recognition_models//models//mmod_human_face_detector.dat', 
'./face_recognition_models/models'),
('.//face_recognition_models//models//shape_predictor_5_face_landmarks.dat', 
'./face_recognition_models/models'),
('.//face_recognition_models//models//shape_predictor_68_face_landmarks.dat', 
'./face_recognition_models/models'),
]

 a = Analysis(['logic.py'],
         pathex=[],
         binaries=face_models,
         ...

in the logic.spec file. This means that my .exe already contain shape_predictor_68_face_landmarks.dat file. (I build it with --onefile param and it work perfectly). But when I tried to import the same shape_predictor_68_face_landmarks file with dlib.shape_predictor I got the RuntimeError: Unable to open models/shape_predictor_68_face_landmarks.dat.

So, my question is how can I import shape_predictor_68_face_landmarks.dat file with dlib.shape_predictor? (It should be already included in exe..)

Peace of code:

import dlib

predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks. dat')

Solution

  • The solution was as simple as possible:

    We can use face_recognition.face_landmarks function instead to get landmarks.