I try to run a Python code for face detection using Dlib. But when I try to load the file shape_predictor_68_face_landmarks.dat
using the following command
face_detector =dlib.cnn_face_detection_model_v1('shape_predictor_68_face_landmarks.dat')
I get the following error:
Traceback (most recent call last):
File "face_detector.py", line 6, in <module>
face_detector = dlib.cnn_face_detection_model_v1('shape_predictor_68_face_landmarks.dat')
RuntimeError: An error occurred while trying to read the first object from the file shape_predictor_68_face_landmarks.dat.
ERROR: Error deserializing object of type unsigned long
while deserializing object of type std::string
I have downloaded the shape predictor file from github: https://github.com/davisking/dlib-models
This is my Python code
import dlib
import cv2
face_detector = dlib.cnn_face_detection_model_v1('shape_predictor_68_face_landmarks.dat')
The rest of the code is omitted because it's not necessary
I am using:
Ubuntu 18.04
and Python 3.6
UPDATE 1:
If use the same file with the function dlib.shape_predictor(shape_predictor_68_face_landmarks.dat)
it runs without any problems!
It seems that there is a problem with the function dlib.cnn_face_detection_model_v1
. Please correct me if I'm wrong!
I have contacted Davis King on twitter and he tshape_predictor_68_face_landmarks.dat
is not the correct file.
I have to load mmod_human_face_detector.dat
file for function dlib.cnn_face_detection_model_v1()
It must be called like this
face_detector = dlib.cnn_face_detection_model_v1('mmod_human_face_detector.dat')