face_recognition: Malloc - Runs Out Of Memory

  • face_recognition version: latest
  • Python version: 3.6.3
  • Operating System: Arch Linux

Description

When attempting to identify faces, I use face_location with model=“cnn”. It should work but it instead fails.

What I Did

face_location = face_recognition.face_locations(image, model="cnn")
Traceback (most recent call last):
  File "example.py", line 12, in <module>
    compare_faces(unknown_persons,known_list)
  File "/home/aaron/Development/bulk-image-facial-recognition/ml_face.py", line 36, in compare_faces
    recognize_faces(image)
  File "/home/aaron/Development/bulk-image-facial-recognition/ml_face.py", line 19, in recognize_faces
    face_locations = face_recognition.face_locations(image, model="cnn")
  File "/usr/lib/python3.6/site-packages/face_recognition/api.py", line 111, in face_locations
    return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
  File "/usr/lib/python3.6/site-packages/face_recognition/api.py", line 95, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaMalloc(&data, new_size*sizeof(float)) in file /home/aaron/Development/tmp/dlib/dlib/dnn/gpu_data.cpp:195. code: 2, reason: out of memory

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@Mekhak Your only solution is to get more ram and a better video card or to scale your images to a lower resolution.

If you use number_of_times_to_upsample=3, you are asking it to double the image, double it again, and double it again. With a 1920x1080 image, that’s a huge amount of pixel data, so it makes sense it won’t fit into GPU memory.

On the other hand, there’s no reason to shrink the image more (losing quality) only to turn around and upsample it more. That’s not accomplishing anything except shrinking and un-shrinking the size of the image. It would be better to keep the image the original size and upsample less.

Scaling the images down to 800x600 makes the application function. It would appear that my hardware is unable to handle images that are much larger than that. Thank you for your assistance in this matter.

Hi All,

@IWriteThings Down-scaling image solves the problem but it decreases the detection accuracy.

I am using 8GB Geforce 1070 TI.

But I am wondering how much GPU memory requires DLib’s face_detection model at python face_locations(img, number_of_times_to_upsample) function call point? I have debugged the DLib’s face detection part: the cudaMalloc out of memory crash happens here:

file: “dlib/tools/python/src/cnn_face_detector.cpp” function: “cnn_face_detection_model_v1::detect(py::array, const int)” line: 54: “auto dets = net(image);”

An high resolution image (say 1200:1340) with number_of_times_to_upsample = 2 is “eating” the whole 8 GB GPU memory and the cudaMalloc out of memory crash happens.

Can please anyone point whether the specified resolution, upsample number and memory usage are normal for face_detector model?

Thanks and Regards, Mekhak