Skip to content

Common Errors

Adam Geitgey edited this page Oct 8, 2018 · 5 revisions
Issue: It's not detecting faces in my very simple image I took with my iPhone / Android phone!

Cell phones often save images sideways and encode an EXIF rotation attribute in the image that tells you which way the phone was rotated when the picture was taken. In other words, the actual image on disk is sideways and it's up to the program reading the image to rotate the image so that it's facing the right way. This library does not automatically handle EXIF rotation - that's up to you.

So if you captured your images with a cell phone or a camera that uses EXIF rotation tags and stores the image sideways instead of capturing the image the way you saw it on screen, you'll need to rotate the images yourself before this library can find the faces in them. You can do that using an external tool or you can search on Google and find an example of handling EXIF rotation in Python.

See this issue for more information: https://github.com/ageitgey/face_recognition/issues/553

Issue: Illegal instruction (core dumped) when using face_recognition or running examples.

dlib is compiled with SSE4 or AVX support, but your CPU is too old and doesn't support that. You'll need to recompile dlib after making the code change outlined here.

Issue: RuntimeError: Unsupported image type, must be 8bit gray or RGB image. when running the webcam examples.

Your webcam probably isn't set up correctly with OpenCV. Look here for more.

Issue: Assertion failed (ssize.width > 0 && ssize.height > 0) when running the webcam examples.

Same issue as above - your webcam probably isn't set up correctly with OpenCV. That could be because the webcam isn't working at all or it could be an issue specific to it talking to OpenCV (or how OpenCV was compiled).

To check your camera, run a normal webcam viewer app and make sure that works before doing anything else.

If you are running your code inside a VM, make sure your vm host software (i.e. VM Ware) is properly set up to expose the camera inside the VM and that other video applications inside the VM can access and see use camera correctly.

If none of that works, you might have to re-compile OpenCV to make sure it was compiled with webcam support.

Unfortunately this problem is somewhat specific to your computer so there isn't a single answer that will fix it for everyone. Look here for more.

Issue: MemoryError when running pip2 install face_recognition

The face_recognition_models file is too big for your available pip cache memory. Instead, try pip2 --no-cache-dir install face_recognition to avoid the issue.

AttributeError: 'module' object has no attribute 'face_recognition_model_v1'

The version of dlib you have installed is too old. You need version 19.7 or newer. Upgrade dlib.

Attribute Error: 'Module' object has no attribute 'cnn_face_detection_model_v1'

The version of dlib you have installed is too old. You need version 19.7 or newer. Upgrade dlib.

TypeError: imread() got an unexpected keyword argument 'mode'

This error should go away in the latest version of face_recognition as scipy is no longer a requirement.

But the root cause in older versions was that the version of scipy you have installed is too old. You need version 0.17 or newer.

List Index out of Range errors

If you write code like this:

    unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]

You might get an error like this:

IndexError: list index out of range

This has nothing to do with this library. This is a bug in your own code. The face_recognition.face_encodings(unknown_image) function returns an array with one element for each face detected in the image. If you check the first element of the array directly (i.e. element [0]) without first testing the length of the array, you'll get this error if no faces were detected in the image.

The safe way to fix the code to avoid this error is like this:

    unknown_face_encodings = face_recognition.face_encodings(unknown_image)

    if len(unknown_face_encodings) > 0:
        unknown_face_encoding = unknown_face_encodings[0]