TropComplique / mtcnn-pytorch

Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks
MIT License
659 stars 161 forks source link

how to run the this code using gpu #10

Open sunguwei opened 6 years ago

sunguwei commented 6 years ago

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'

oyxhust commented 5 years ago

I also meet this issue. Have you solve it?

lianuo commented 5 years ago

same issue

BrightXiaoHan commented 5 years ago

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

pnet = Pnet().cuda()
output = pnet(input_tensor)
fuxuliu commented 5 years ago

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

mayuanjason commented 4 years ago

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