Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
on-your-way opened this issue Mar 20, 2021 · 4 comments
Open

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

on-your-way opened this issue Mar 20, 2021 · 4 comments

Comments

@on-your-way
Copy link

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

@hpc203
Copy link
Owner

hpc203 commented Mar 21, 2021

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

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

@on-your-way
Copy link
Author

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

@on-your-way
Copy link
Author

比如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
mtcnn_result, _ = 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
Copy link
Owner

hpc203 commented Mar 22, 2021

比如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
mtcnn_result, _ = 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设备上调试,请谅解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants