RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach(), in Pytorch 1.1.0

Im trying to to do this:
Img_.data.resize_(Img.size()).copy_(Img)
and got this error:

 RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach()

Any suggestion why?
It was working for pytorch 1.0.1 but now gives me this error in 1.1.0 version

Img has size torch.Size([1, 3, 256, 256]) abd Img_ has size torch.Size([1])

1 Like

.data.resize_ was an unsupported operation (infact using .data is being discouraged). It worked in 1.0.1 because we still didn’t finish part of a refactor.

You should now use:

with torch.no_grad():
    Img_.resize_(Img.size()).copy_(Img))
2 Likes