Solved by ptrblck in post #2 
              
              
                You could just sample in __getitem__ and stack the patches into the batch dimension: 
Here is a small example sampling 5x5 patches. These patches are returned as a 4-dimensional tensor from __getitem__. During the training you could push these patches into the batch dimension with view. 
class MyDat…