I’m pretty new to PyTorch so, please excuse me if this question is too remedial. I have the following code for inference of my trained model which takes an image, does some pre-processing on it, converts to a tensor and finally performs a forward pass through the network.
   img = np.array(Image.open(img_path))

        orig_size = img.shape[:2][::-1]

        img_inp = torch.tensor(prepare_img(img).transpose(2, 0, 1)[None]).float()
        if has_cuda:
            img_inp = img_inp.cuda()

        segm = net(img_inp)[0].data.cpu().numpy().transpose(1, 2, 0)

I have successfully trained this segmentation model on my desktop machine. The inference code runs perfectly on it, but when I clone it to my laptop it gives me the following error:
       img_inp = torch.tensor(prepare_img(img).transpose(2, 0, 1)[None]).float()
RuntimeError: unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.

I can bypass this error on my laptop by passing the result of prepare_img as a copy but that leads to memory leakages.
PS. On my Laptop I have built PyTorch from source for GPU compute and the torch version is 1.5.0a0+55c382e. I have a hunch that this is the problem.  My desktop machine has PyTorch installed simply from anaconda’s repo.
Any help on this will be greatly appreciated. Thanks