davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.53k stars 3.37k forks source link

RuntimeError: Error while calling cudaMalloc() in file gpu_data.cpp; reason: out of memory #2112

Closed harshlavingia closed 4 years ago

harshlavingia commented 4 years ago

I am getting a runtime exception in dlib while using face_recognition.face_locations(). I have copied the sample code and error log below.

Expected Behavior

Current Behavior

Steps to Reproduce

# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
    print("[INFO] processing image {}/{}".format(i + 1, len(imagePaths)))
    name = imagePath.split(os.path.sep)[-2]

    # load the input image and convert it from RGB (OpenCV ordering) to dlib ordering (RGB)
    image = cv2.imread(imagePath)
    rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    print(f"Image: {imagePath}, {rgb.shape}")

    boxes = face_recognition.face_locations(rgb, model=args["detection_method"])

[INFO] processing image 1/219 Image: dataset\alan_grant\00000000.jpg, (653, 1440, 3) Traceback (most recent call last): File "encode_faces.py", line 39, in boxes = face_recognition.face_locations(rgb, model=args["detection_method"]) File "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 119, 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 "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 103, 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 C:\Users\harsh\Desktop\dlib\dlib\cuda\gpu_data.cpp:221. code: 2, reason: out of memory

ghost commented 4 years ago

I am getting a runtime exception in dlib while using face_recognition.face_locations(). I have copied the sample code and error log below.

Expected Behavior

Current Behavior

Steps to Reproduce

# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
  print("[INFO] processing image {}/{}".format(i + 1, len(imagePaths)))
  name = imagePath.split(os.path.sep)[-2]

  # load the input image and convert it from RGB (OpenCV ordering) to dlib ordering (RGB)
  image = cv2.imread(imagePath)
  rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  print(f"Image: {imagePath}, {rgb.shape}")

  boxes = face_recognition.face_locations(rgb, model=args["detection_method"])

[INFO] processing image 1/219 Image: dataset\alan_grant\00000000.jpg, (653, 1440, 3) Traceback (most recent call last): File "encode_faces.py", line 39, in boxes = face_recognition.face_locations(rgb, model=args["detection_method"]) File "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 119, 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 "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 103, 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 C:\Users\harsh\Desktop\dlib\dlib\cuda\gpu_data.cpp:221. code: 2, reason: out of memory

  • Version: dlib-19.20.0
  • Where did you get dlib: From Githum - https://github.com/davisking/dlib
  • Platform: Windows 10 64 bit, Python 3.7.6 (Anaconda), VS 2019 Community
  • Compiler:

This is beacuse your GPU does not have enough VRAM to process the image. You could either get a a GPU with more VRAM or make your image smaller..

This is what I did to get my project going forward.. I am using GTX 1060 with 6GB of VRAM and the size of 2160 is specific to my image and GPU, you should probably play with you image size to get this working..

`from imutils import paths, resize

size = 2160 if image.shape[1] > image.shape[0]: if image.shape[1] > size: image = resize(image, width=size) else: if image.shape[0] > size: image = resize(image, height=size) `

dlib-issue-bot commented 4 years ago

Warning: this issue has been inactive for 35 days and will be automatically closed on 2020-08-13 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot commented 4 years ago

Warning: this issue has been inactive for 42 days and will be automatically closed on 2020-08-13 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot commented 4 years ago

Notice: this issue has been closed because it has been inactive for 45 days. You may reopen this issue if it has been closed in error.