Creating patches of 3D images

PytorchandAIBeginner: <p>Hey Everyone,</p>
<p>I have two images, the input image is of the size (64,64,32) and the label or ground truth is (128, 128, 64), I want to create patches of these two images of patch sizes (32,32,32) and (64,64,64) respectively. The problem here is I am unable to create patches of these images at the same positions. That is, first (32,32,32) patch has label in first (64,64,64) of ground truth. But the problem is first (32,32,32) is forming label say at last (64,64,64). Please find the below images as reference to the said issue. I would be very thankful, if I could get some inputs on how to resolve this issue. <img src="https://discuss.pytorch.org/uploads/default/original/3X/5/a/5a33e0007f75113761f120347f3b4a5b8816b661.png" alt="Issue" data-base62-sha1="cRY74kVp8rHaJh7GQjDPXVrkvQt" width="533" height="494"></p>
<p>Note: I have used sequential patch loader of pytorch ( torch.utils.data.sampler.SequentialSampler)</p>

ptrblck: <p>I don’t fully understand the question.<br>
Could you explain a bit more what the issue is and what this means:</p>
<aside class="quote no-group" data-username="PytorchandAIBeginner" data-post="1" data-topic="95916">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/8e7dd6/48.png" class="avatar"> PytorchandAIBeginner:</div>
<blockquote>
<p>That is, first (32,32,32) patch has label in first (64,64,64) of ground truth. But the problem is first (32,32,32) is forming label say at last (64,64,64).</p>
</blockquote>
</aside>

PytorchandAIBeginner: <p>So I am trying to super resolve an image, that is use images of size (64,64,32)  and (128,128,64) for a network to learn to increase the resolution from (64,64,32) to (128,128,64)… I saw my network was over fitting and when I debugged I noticed that the issue with the patch volume mismatch. I am trying to use a patch size of 32 cuboid for low resolution image and 64 cuboid for the high resolution image (which is the target value/label/what the network is learning). So I am unable to map the patch(32 cuboid) from low resolution image with the patch (64 cuboid) in the high resolution image. I have tried to illustrate this with a 2D normal image, but conceptually this is how I aim to provide to 3D MRI data to the network for training</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/a/5abe2bb381fa71691907fcb949a1967bedd64bf7.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/5abe2bb381fa71691907fcb949a1967bedd64bf7" title="Issue_example"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5abe2bb381fa71691907fcb949a1967bedd64bf7_2_532x500.jpeg" alt="Issue_example" data-base62-sha1="cWKpuF9doqCp4rFIFg5FfFpLYID" width="532" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5abe2bb381fa71691907fcb949a1967bedd64bf7_2_532x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/5/a/5abe2bb381fa71691907fcb949a1967bedd64bf7_2_798x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/5/a/5abe2bb381fa71691907fcb949a1967bedd64bf7.jpeg 2x" data-dominant-color="C2CCD4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Issue_example</span><span class="informations">1056×992 396 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

PytorchandAIBeginner: <p>Hope this explanation helps. Thanks in advance</p>

ptrblck: <p>If the target image is scaled by an integer factor (in your case 2x), you could increase the kernel size and stride by the same factor in the <code>unfold</code> method, which should create the same number of patches for the input and target (of course with a different size).</p>

PytorchandAIBeginner: <p>I did all that, I am able to create the patches in the size I need, but the problem is the shuffled patches… The input and ground truth patches are not of the same piece of information…</p>