mtcnn-pytorch icon indicating copy to clipboard operation
mtcnn-pytorch copied to clipboard

how to run the this code using gpu

Open sunguwei opened this issue 5 years ago • 5 comments

I found that it is a bit slow when I run this code. Then I check the usage of gpu and I found this code was run on the cpu. So I want to change the code to run on the gpu. But I found the type of weight of this model is torch.FloatTensor. Is that mean I cannot use the gpu to run this code directly? Is that any solution can help me to run this code on gpu?

Here is the error: RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight'

sunguwei avatar Oct 28 '18 09:10 sunguwei

I also meet this issue. Have you solve it?

oyxhust avatar Jan 14 '19 01:01 oyxhust

same issue

lianuo avatar Jan 15 '19 18:01 lianuo

You can call .cuda() or to('gpu:0') to move model to gpu. For example:

pnet = Pnet().cuda()
output = pnet(input_tensor)

BrightXiaoHan avatar Jan 31 '19 05:01 BrightXiaoHan

Like this, For example: pnet.cuda() rnet.cuda() onet.cuda() offsets = output[0].cpu().data.numpy() probs = output[1].cpu().data.numpy()

finish the rest like that

fuxuliu avatar Mar 07 '19 08:03 fuxuliu

Hi sunguwei,

I just refactor this repo, you can check it in https://github.com/mayuanjason/MTCNN_face_detection_alignment_pytorch

It can run on GPU.

Here are some improvments I made: • Transfer all numpy operation to torch operation, so that it can benefit from GPU acceleration. • Automatic run on 'CPU' or 'GPU'. • Based on the latest version of pytorch (1.3) • Real-time face tracking

mayuanjason avatar Dec 17 '19 01:12 mayuanjason