Dlib(支持GPU)无法正常工作,不确定吗? [英] Dlib (GPU supported) is not working properly, not sure?

查看:100
本文介绍了Dlib(支持GPU)无法正常工作,不确定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统配置:

Windows 10,Nvidia 940mx 2GB GDDR5 GPU,8GB RAM,i5第8代.

Windows 10, Nvidia 940mx 2GB GDDR5 GPU, 8GB RAM, i5 8th generation.

已安装软件:

  1. CUDA工具包9.0
  2. cuDNN 7.1.4

使用以下命令安装上述要求后,我已经成功安装了具有GPU支持的dlib:

I have successfully installed dlib with GPU support after installing above requirements using commands below:

$ git clone https://github.com/davisking/dlib.git
$ python setup.py install --clean

正如dlib的创建者@Davis King所说,在我的jupyter笔记本上执行了:

As stated by dlib's creater @Davis King, on my jupyter notebook I executed :

import dlib
dlib.DLIB_USE_CUDA
[Out 17] :True

验证我的"dlib"是否正在通过CUDA使用GPU,并且所有其他依赖dlib的库(如@adma ageitgey的"face_recognition")也将使用cuda加速.

Which verifies that my 'dlib' is using GPU through CUDA, and all other libraries depend on dlib like @adma ageitgey's 'face_recognition' will also use cuda acceleration.

所以我正在运行一个用于训练图像的代码,以便可以使用以下代码识别视频中的人脸:

So I was running a code for training images so that I can recognize faces in a video, using the code below:

import face_recognition
img = face_recognition.load_image_file('./training images/John_Cena/Gifts-John-Cena-Fans.jpg')
locations = face_recognition.face_loactions(img,model='cnn')

它显示如下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Tushar\Anaconda3\lib\site-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 "C:\Users\Tushar\Anaconda3\lib\site-packages\face_recognition\api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudaMalloc(&data, n) in file C:\Users\Tushar\Desktop\face_recognition\dlib\dlib\cuda\cuda_data_ptr.cpp:28. code: 2, reason: out of memory

再次尝试获取另一张图片后:

After trying again for another image :

img = face_recognition.load_image_file('./training images/John_Cena/Images.jpg')
locations = face_recognition.face_loactions(img,model='cnn')

它给出了错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Tushar\Anaconda3\lib\site-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 "C:\Users\Tushar\Anaconda3\lib\site-packages\face_recognition\api.py", line 100, in _raw_face_locations
    return cnn_face_detector(img, number_of_times_to_upsample)
RuntimeError: Error while calling cudnnConvolutionForward( context(), &alpha, descriptor(data), data.device(), (const cudnnFilterDescriptor_t)filter_handle, filters.device(), (const cudnnConvolutionDescriptor_t)conv_handle, (cudnnConvolutionFwdAlgo_t)forward_algo, forward_workspace, forward_workspace_size_in_bytes, &beta, descriptor(output), output.device()) in file C:\Users\Tushar\Desktop\face_recognition\dlib\dlib\cuda\cudnn_dlibapi.cpp:1007. code: 3, reason: CUDNN_STATUS_BAD_PARAM

然后,我重新启动了jupyter的内核,并再次尝试使用其他图像:

Then I restarted the jupyter's kernel and tried once again for different image :

face_recognition.face_locations(face_recognition.load_image_file('./training 
   images/John_Cena/images.jpg'),model='cnn')
[Out] : [(21, 136, 61, 97)]

这一次它给出了图像中人脸位置的坐标.

This time it gave the coordinates of the location of the face in the image.

所以这一次又一次地发生,对于某些图像来说,它运行得很好,对于某些图像,它给出了两种错误之一(如上所述).

So this is happening again and again, for some images it just runs fine and for some, it gives one of the 2 errors(as stated above).

使用model ='hog'时,对于与model ='cnn'中使用的所有相似图像都运行良好.

While using model='hog' it's running fine for all the similar images as used in model='cnn'.

因此,当我尝试使用for循环在不同文件夹中的图像上训练分类器时:

So when I try to train the classifier on images in different folders using for loop:

from face_recognition.face_detection_cli import image_files_in_folder
import os
import os.path
import face_recognition
for class_dir in os.listdir('./training images/'):
    count = 0
    for img_path in image_files_in_folder(os.path.join('./training images/', class_dir)):  
                count += 1
                image = face_recognition.load_image_file(img_path)
                face_bounding_boxes = face_recognition.face_locations(image,model='cnn')
                print(face_bounding_boxes, count)

在处理了一些显示相同的2个错误中的任何图像后,它总是停止(如上所述).我尝试了所有可能的方法来安装具有GPU支持,CUDA 9.0工具包和cuDNN 7.1.4的dlib.他们都工作正常!

It always stops after processing some images showing the same any of 2 errors(as stated above). I tried every possible way to install dlib with GPU support, CUDA 9.0 toolkit and cuDNN 7.1.4. They all are working fine!

我不知道这里真正的问题是图形卡的内存(2 GB)不足还是其他.

I don't know what's the real issue here, Is the memory (2 GB) of Graphic Card is less or something else.

我真的很想利用GPU的功能来更快地识别视频.

I really want to use GPU's power to make recognition in video faster.

推荐答案

我发现face_encodings被快速赋予"Indexerror".如果脸微微旋转而不是笔直.尽管它找到了具有坐标的脸部位置,并且当向作物图像提供具有"face_encodings"的坐标时,仍然可以找到具有坐标的脸部位置.它因索引错误而失败...

I found that face_encodings is given quick "Indexerror" if the face is slighty rotate and not straight. Despite It found the face locations with the coordinates and when supply the crop image with the coordinates to "face_encodings" it failed with the index error...

这篇关于Dlib(支持GPU)无法正常工作,不确定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆