facenet-pytorch
facenet-pytorch copied to clipboard
About MTCNN on GPU
Thank you for your great work in facenet-pytorch, I'm a novice at these things, it really gives me useful help.However, I met a problem when I was using MTCNN.I want to put MTCNN on cuda to calculate, but I can't transform the input to the type "torch.cuda.FloatTensor", it usually told me ''Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same'', if possible can you give me some advice.
mtcnn = mtcnn.MTCNN(keep_all=True).eval().to('cuda') img = Image.open('………') img = np.array(img) img = torch.from_numpy(img) img = img.to('cuda') faces = mtcnn(img)
You really should read the code and the comments and not make wild guess. There is an argument “device” in the initialization method. If you set it to gpu (using torch) as usual then it will run on CUDA.
I know that both models have a parameter device
when instantiating the models. However, when using .to(device)
the models are not moved to the device and the to(...)
call has no effect. As this is a vital feature of PyTorch I think this should be implemented.