0

Yesterday I built a Streamlit project that uses .dat and .xml files to detect faces and facial landmarks. It was working perfectly the day I built it, but today it cannot find the .xml and .dat files. They are located in the same folder as my project is on my machine.

When I check to see if they exist using:

os.access(‘shape_predictor_68_face_landmarks.dat’, os.F_OK)

it returns false, but I see them in the project folder. I found the following solution on these forums but it did not work:

predictor = Path(file).parents[0] / "shape_predictor_68_face_landmarks.dat"
dlib_facelandmark = dlib.shape_predictor(predictor)

This is the exact error I am receiving:

File “C:\Users\hanna\PycharmProjects\FaceDetector\main.py”, line 87, in detect_faces dlib_facelandmark = dlib.shape_predictor(‘shape_predictor_68_face_landmarks.dat’) RuntimeError: Unable to open shape_predictor_68_face_landmarks.dat

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 02 '22 at 23:39

1 Answers1

0

When you write os.access(‘shape_predictor_68_face_landmarks.dat’, os.F_OK), you are using a relative reference, which assumes that your code is running from the same repository as where your data is located. This does not have to be the case.

The simplest, but more brittle solution, is to exactly specify the directory path to your files instead of the relative reference. Once you are convinced that it works, you can use something like pathlib to programmatically determine where your files are located.

Randy Zwitch
  • 1,994
  • 1
  • 11
  • 19
  • Thank you! Specifying the path on my computer fixed the problem. I wanted to avoid using the path for my pc so my program can be ran on someone else's pc. The pathlib library makes this possible? – Braden Hanna Mar 03 '22 at 02:14
  • Yes, pathlib is one of many solutions to programmatically determine where the files are. – Randy Zwitch Mar 03 '22 at 20:50