oeway / pytorch-deform-conv

PyTorch implementation of Deformable Convolution
MIT License
911 stars 151 forks source link

GPU mode is not available ! #4

Closed shwoo93 closed 6 years ago

shwoo93 commented 7 years ago

Hello oeway

Firstly, thanks for sharing your pytorch version code of deformable convolution. When I tried to port your code to another code which uses CUDA mode, it gives me an error saying like below.

'Type torch.cuda.FloatTensor doesn't implement stateless method range'

However, when I change it to CPU mode, there is no error.

It seems like 'torch.range' does not fit on GPU mode in torch. Then what should be the solution?

Thanks in advance

oeway commented 7 years ago

hi @shwoo93 , the library meant to work with GPU/cuda and cpu, in https://github.com/oeway/pytorch-deform-conv/blob/master/scaled_mnist.py you can see we use it in cuda mode, and when I test it, I use cuda as well, I am sure it will work with GPU.

Plus, I couldn't find torch.range in my code, perhaps it from your own code?

shwoo93 commented 7 years ago

@oeway Thanks for reply. Actually in the deform_conv.py file there is a function called "th_batch_map_coordinates" which uses torch.range. Anyway, you mean that there is no problem in usage of it and also did not the error occured in torch.range?

oeway commented 7 years ago

hi, that's right, there is indeed a torch.range:

    idx = th_repeat(torch.range(0, batch_size-1), n_coords).long()
    idx = Variable(idx, requires_grad=False)
    if input.is_cuda:
        idx = idx.cuda()

however, if you read the code, you will found that my torch.range is actually working in cpu mode, and after it may convert to cuda if the input is in cuda mode. So it still doesn't mean it caused by torch.range.

Come back to your question, yes, we have no problem when running in cuda mode.