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

Run_all_compare_time.py 里如果用GPU跑报错 #6

Open
licc0431 opened this issue Nov 9, 2020 · 4 comments
Open

Run_all_compare_time.py 里如果用GPU跑报错 #6

licc0431 opened this issue Nov 9, 2020 · 4 comments

Comments

@licc0431
Copy link

licc0431 commented Nov 9, 2020

电脑装的cuda,Run_all_compare_time.py 里如果用GPU跑,报错如下:
Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
错误定位在 mtcnn_result, _ = mtcnn_detect.detect(srcimg)里,本人才学,代码能力一般,不知怎么修改,先用CPU了,等待作者和他人完善。

@hpc203
Copy link
Owner

hpc203 commented Nov 9, 2020

这个错误的原因是,输入数据没有转换到gpu设备上。在mtcnn_detect.detect()函数里对输入做设备转换,Input.to(device)

@licc0431
Copy link
Author

licc0431 commented Nov 9, 2020

好的,谢谢大神

@licc0431
Copy link
Author

licc0431 commented Nov 9, 2020

cv读入的numpy,先torch_from_numpy(),到Tensor,再Input.to(device)。可是这样变成gpu上tensor,后面算法又调用numpy,我不知道咋改了,本文才学,请大神指教

@hpc203
Copy link
Owner

hpc203 commented Nov 10, 2020

cv读入的numpy,先torch_from_numpy(),到Tensor,再Input.to(device)。可是这样变成gpu上tensor,后面算法又调用numpy,我不知道咋改了,本文才学,请大神指教

gpu上的tensor转换到numpy的语法是: Input.data.cpu().numpy()
cpu上的tensor转换到numpy的语法是: Input.data.numpy()

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