hpc203 / 10kinds-light-face-detector-align-recognition

10种轻量级人脸检测算法的比拼,其中还包含人脸关键点检测与对齐,人脸特征向量提取和计算距离相似度
449 stars 115 forks source link

GPU版本完全没法跑啊,一个接一个的错误 #17

Open on-your-way opened 3 years ago

on-your-way commented 3 years ago

希望作者有空上传一下能跑通GPU的版本,感谢~

hpc203 commented 3 years ago

希望作者有空上传一下能跑通GPU的版本,感谢~

这套程序里,有的算法是基于pytorch框架运行的,有的是调用opencv运行的。在基于Pytorch框架运行的程序里,有device = 'cuda' if torch.cuda.is_available() else 'cpu'这行代码,它会根据运行设备自适应切换到cpu或者gpu环境的,而调用opencv的程序在cpu和gpu环境是通用的

on-your-way commented 3 years ago

嗯,检测到cuda可用,device是'cuda',可是跑不通啊,各种错误

on-your-way commented 3 years ago

比如pfld_mtcnn\detector.py报错如下:

Traceback (most recent call last): File "D:/studyFiles/CV/face_detection/ten_kinds/Run_all_compare_time.py", line 78, in mtcnnresult, = mtcnn_detect.detect(srcimg) File "D:\studyFiles\CV\face_detection\ten_kinds\mtcnn_pfld_landmark.py", line 15, in detect bounding_boxes, landmarks = self.mtcnn.detect(srcimg) ###landmarks: numpy array, n x 10 (x1, x2 ... x5, y1, y2 ..y5) File "D:\studyFiles\CV\face_detection\ten_kinds\pfld_mtcnn\detector.py", line 392, in detect boxes = run_first_stage(image, self.pnet, scale=s, threshold=self.thresholds[0]) File "D:\studyFiles\CV\face_detection\ten_kinds\pfld_mtcnn\detector.py", line 246, in run_first_stage output = net(img) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "D:\studyFiles\CV\face_detection\ten_kinds\pfld_mtcnn\detector.py", line 170, in forward x = self.features(x) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\container.py", line 119, in forward input = module(input) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\conv.py", line 399, in forward return self._conv_forward(input, self.weight, self.bias) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\conv.py", line 395, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

hpc203 commented 3 years ago

比如pfld_mtcnn\detector.py报错如下:

Traceback (most recent call last): File "D:/studyFiles/CV/face_detection/ten_kinds/Run_all_compare_time.py", line 78, in mtcnnresult, = mtcnn_detect.detect(srcimg) File "D:\studyFiles\CV\face_detection\ten_kinds\mtcnn_pfld_landmark.py", line 15, in detect bounding_boxes, landmarks = self.mtcnn.detect(srcimg) ###landmarks: numpy array, n x 10 (x1, x2 ... x5, y1, y2 ..y5) File "D:\studyFiles\CV\face_detection\ten_kinds\pfld_mtcnn\detector.py", line 392, in detect boxes = run_first_stage(image, self.pnet, scale=s, threshold=self.thresholds[0]) File "D:\studyFiles\CV\face_detection\ten_kinds\pfld_mtcnn\detector.py", line 246, in run_first_stage output = net(img) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "D:\studyFiles\CV\face_detection\ten_kinds\pfld_mtcnn\detector.py", line 170, in forward x = self.features(x) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\container.py", line 119, in forward input = module(input) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\conv.py", line 399, in forward return self._conv_forward(input, self.weight, self.bias) File "D:\Softwares\Anaconda3\envs\pytorch_env\lib\site-packages\torch\nn\modules\conv.py", line 395, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

这个错误的原因很简单呀,就是网络结构model转换到gpu环境了,但是输入张量Input没有转换到gpu环境,因此你需要在输入张量Input后加上.to(device) 这是我编写程序的一个疏忽,当初这些网络都是轻量级的,我就在win10-cpu机器上编写程序,没有放在gpu设备上调试,请谅解