导入face_recognition模块遇RuntimeError:浮点数反序列化错误求助
Hey there, let's work through this face_recognition import error together! That deserialization error you're seeing is almost always tied to a corrupted or incomplete dlib face landmark model file—here's how to fix it:
What's Causing This?
When you import face_recognition, it automatically tries to load the shape_predictor_68_face_landmarks.dat model (used to detect key facial points). If this file was interrupted during download, got corrupted, or is missing critical data, dlib can't parse the floating-point values stored in it, hence the runtime error.
Step-by-Step Solutions
1. Replace the Corrupted Model File
The quickest fix is to get a fresh copy of the official model:
- Grab the latest
shape_predictor_68_face_landmarks.datmodel file (from dlib's official resources). Make sure it's fully downloaded and uncompressed. - Locate your
face_recognitioninstallation directory—your error message shows it's at/home/.local/lib/python3.7/site-packages/face_recognition/. - Swap out the existing
shape_predictor_68_face_landmarks.datfile in that folder with your new, intact model file.
2. Reinstall face_recognition (and Dependencies)
If replacing the model doesn't resolve the issue, a clean reinstall will ensure all components are properly set up:
- Uninstall the current packages first:
pip uninstall -y dlib face_recognition - Reinstall
face_recognition—this will automatically pull a compatible version of dlib and fresh, uncorrupted model files:pip install face_recognition
3. Manually Specify the Model Path (Optional)
If you prefer keeping the model in a custom location, you can explicitly point to it in your code to avoid path issues:
import dlib import face_recognition # Replace this path with the actual location of your intact model file custom_predictor = dlib.shape_predictor("/your/custom/path/shape_predictor_68_face_landmarks.dat") # Now you can use face_recognition functions normally
Any of these steps should fix the deserialization error by ensuring dlib has access to a complete, uncorrupted model file.
内容的提问来源于stack exchange,提问作者Aman Malhotra

