ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
53.12k stars 13.46k forks source link

MemoryError: std::bad_alloc #691

Open arpsyapathy opened 5 years ago

arpsyapathy commented 5 years ago

Hello! I use script encode_faces.py from https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/ for encoding my dataset in pickle. But I get error "MemoryError: std::bad_alloc" when [INFO] processing image 12/69.


[INFO] processing image 11/69
[INFO] processing image 12/69
Traceback (most recent call last):
  File "encode_faces.py", line 45, in <module>
    model=args["detection_method"])
  File "/usr/local/lib/python2.7/dist-packages/face_recognition/api.py", line 116, 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/local/lib/python2.7/dist-packages/face_recognition/api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
MemoryError: std::bad_alloc

Help please. Thank you advance

ageitgey commented 5 years ago

That means you ran out of memory. Maybe that particular image was really large in resolution?

LightTemplar commented 5 years ago

I had the same problem, and my images are 3120x4208. Is this that big? How much memory does it need?

laviua commented 5 years ago

yep, i tried to run dlib with cnn detection and 1k dimension size with 16gb ram on linux vps > the same. macbook with 16gb - ok. something wrong with memory allocation during upscaling. i guess workaround is to resize the input image before detection

hemusqwerty commented 5 years ago

It is not happening because of photo resolution. Because I was getting error at 17/218 then I deleted 2 pictures at 17& 18 position but now I getting error at 15/216 . If someone got the solution please help.

jrosebr1 commented 5 years ago

Resize your input images prior to passing them through the network. Your input images are too large and your GPU is running out of memory.

hemusqwerty commented 5 years ago

Thank You So much After resizing the images it did work.

jayanthsrinivas commented 5 years ago

Thank You So much After resizing the images it did work.

Can you share the code @rotyweb

sbourdette commented 5 years ago

I have the same issue on virtuabox machine. When changing detection-method to hog instead of cnn it works

rajapratapk commented 5 years ago

This could be because PyImageSearch dataset images are of different size. I resized the image 400x300 before calling face_recognition.face_locations and "bad alloc" error disappeared. However dlib does not use CUDA despite compling, seems it is a known issue in dlib

dhanpalrajpurohit commented 5 years ago

First of all, resize your image then send it to the model or network.