enterthevoidf22:

also, i guess since i use only one sample and the get_item function loads only one sample, the batch_size is ignored and the shape of the variable a is (1,1,64,64)


You are getting a single sample, since the __len__ of your custom Dataset is defined as 1 instead of the length of the loaded data.
Using random tensors the operation is question takes 56.7 ms ± 2.12 ms per loop on my laptop:
class HCP_sanity(Dataset):
    def __init__(self, sli=False):
        self.data = torch.randn(64,64,32,5)
        self.slice = sli

    def __len__(self):
        return len(self.data)

    def __getitem__(self, index):
        if self.slice:
            depth = 15  
            target = self.data[:,:,depth,0]
            x = target.clone()
            x[36:44,26:34] = 0
        else:
            target = self.data[:,:,:,0]
            x = target.clone()
            x[36:44,26:34,16:20] = 0
        return x.unsqueeze(0), target.unsqueeze(0)


dataset = HCP_sanity()
generator = DataLoader(dataset,batch_size = 64,shuffle=False,num_workers=0)
%timeit a,b = iter(generator).next()
> 56.7 ms ± 2.12 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)