Thanks for getting back to me!
I have an image which is of size 5176x3793 and I am breaking it up into patches of 128x128 pixels with the channels in the first dimension. Here’s the code:
img.data.shape # torch.Size([3, 5176, 3793])
patches = img.data.unfold(0, 3, 3).unfold(1, 128, 128).unfold(2, 128, 128)
patches.shape # torch.Size([1, 40, 29, 3, 128, 128])

I am processing the patches individually and after doing so I would like to reconstruct the image from the patches. I have put together a short stub which works but I am wondering if there is a more elegant way to achieve the same results using some in built methods.
patches = patches[0]
pw = patches.shape[-2] # patch width
ph = patches.shape[-1] # patch height
w = patches.shape[0] * pw 
h = patches.shape[1] * ph
new_img = torch.zeros([3, w, h])
for i in range(patches.shape[0]):
    for j in range(patches.shape[1]):
        patch_pixels = patches[i][j] # shape [3, pw, ph]
        new_img[:, pw*i: pw*(i+1), ph*j: ph*(j+1)] = patch_pixels
new_img.shape # torch.Size([3, 5120, 3712])

I also have another question, using torch.Tensor.unfold can result in pixels being lost in the slicing process because of the dimensions not matching up. Is there a way to avoid pixels being lost and keeping the original dimensions of the image?