It seems you didn’t applied the suggested reshape operation on the data.
Here is a sample code:

patches_MR = torch.from_numpy(
    np.random.randn(18, 500, 32, 32, 32).reshape(-1, 32, 32, 32))
patches_CT = torch.from_numpy(
    np.random.randn(18, 500, 32, 32, 32).reshape(-1, 32, 32, 32))


train_dataset = Dataset(patches_MR,patches_CT)
print('train directory has {} samples'.format(len(train_dataset)))
> train directory has 9000 samples

train_loader = DataLoader(train_dataset,batch_size=5,shuffle=True)
x, y = next(iter(train_loader))
print(x.shape)
> torch.Size([5, 1, 32, 32, 32])
print(y.shape)
> torch.Size([5, 1, 32, 32, 32])

I think this is what you want, i.e. given batch_size=5, you’ll get 5 patches from each dataset for each iteration.
I’m wondering, why this seems to work:



 banikr:

# np.shape(train_dataset) 
# Out[242]: (18, 2, 500, 32, 32, 32)



np.shape throws an error if I pass my custom Dataset, which I would expect, but apparently you got some shape information?