Pytorch: Erro ao fazer CUDA Conv2d com kernel 1x1.

Criado em 23 jan. 2017  ·  3Comentários  ·  Fonte: pytorch/pytorch

Conv2d com kernel 1x1 não funciona na GPU, embora funcione bem na CPU:

net = nn.Conv2d(1, 6, kernel_size=(1,1))
net.cuda()
x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()
net(x)

Mensagem de erro:

TypeError: FloatSpatialConvolutionMM_updateOutput received an invalid combination of arguments - got (int, torch.FloatTensor, torch.FloatTensor, torch.cuda.FloatTensor, torch.cuda.FloatTensor, torch.FloatTensor, torch.FloatTensor, int, int, int, int, int, int), but expected (int state, torch.FloatTensor input, torch.FloatTensor output, torch.FloatTensor weight, [torch.FloatTensor bias or None], torch.FloatTensor finput, torch.FloatTensor fgradInput, int kW, int kH, int dW, int dH, int padW, int padH)

Tentei desabilitar cudnn com torch.backends.cudnn.enabled = False mas ainda recebi a mesma mensagem de erro.

Eu uso Ubuntu 14.04, Cuda 7.5, Cudnn 5.1.5, Python 3.5.2 e Pytorch é instalado a partir de binários.

Comentários muito úteis

Para esclarecer, em vez de:

x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()  # This creates a copy on the GPU and immediately discards it. "x" is still on the CPU

Você deve escrever:

x = Variable(torch.randn(1, 1, 100, 100).cuda())

Todos 3 comentários

Se você olhar atentamente para os tipos de argumento que foram dados para conv, você verá que alguns dos tensores são torch.cuda.FloatTensor s, enquanto os outros são torch.FloatTensor s. Você provavelmente se esqueceu de enviar a entrada para a GPU.

Para esclarecer, em vez de:

x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()  # This creates a copy on the GPU and immediately discards it. "x" is still on the CPU

Você deve escrever:

x = Variable(torch.randn(1, 1, 100, 100).cuda())

Acho melhor fazer model.cuda() e x.cuda() se comportar de forma consistente para evitar confusão.

Esta página foi útil?
0 / 5 - 0 avaliações