airlab-unibas / airlab

Image registration laboratory for 2D and 3D image data
Apache License 2.0
408 stars 92 forks source link

pytorch error in unsqueeze_(0) [pytorch 1.0.1] #9

Closed adizhol closed 5 years ago

adizhol commented 5 years ago

Was airlab tested with pytorch 1.0.1? I'm getting an error in registration code. It works with pytorch 0.4.1

    registration.start()
 Fairlab/registration/registration.py", line 203, in start
    regulariser.regularise(self._transformation.parameters())
  airlab/regulariser/demons.py", line 80, in regularise
    self._regulariser(parameter)
airlab/regulariser/demons.py", line 65, in _regularise_2d
    data.data.unsqueeze_(0)
RuntimeError: set_storage_offset is not allowed on Tensor created from .data or .detach()

Thanks

ChristophJud commented 5 years ago

Dear adizhol, could you provide more details where the error occurs? Is it an example from airlab or is it your own example?

mattiaspaul commented 5 years ago

I can replicate this error (occurs directly when running one of the examples)

import torch
A = torch.randn(4,5,6)
A.requires_grad = True
B = torch.randn(4,5,6)
B.requires_grad = True
displacement = (A*B).data
displacement = torch.transpose(displacement.unsqueeze_(0),0,3).unsqueeze_(0)

shows the same error: RuntimeError: set_storageoffset is not allowed on Tensor created from .data or .detach() I would suggest to replace all unsqueeze calls that are not inline with unsqueeze these are in: utils.py in upsample_displacement and image.py initializeForTensors initializeForImages, _reverse_axis (only line 168 and not 169), image_from_numpy, and potentially some more Btw: great work on Airlab, I'm just exploring it, but suppose it will be very useful for us

RobinSandkuehler commented 5 years ago

Hi, Thank you very much. We will fix this issue.

RobinSandkuehler commented 5 years ago

According to your suggestions, we replaced all the in-place operations. Thanks for your help.