The error is raised, if out is a LongTensor, while (some of) the batch tensors are DoubleTensors as seen here:
batch = [
    torch.randn(3, 24, 24, dtype=torch.float64),
    torch.randn(3, 24, 24, dtype=torch.float64)
]

out = torch.empty(2, 3, 24, 24).long()
torch.stack(batch, 0, out=out)
> RuntimeError: result type Double can't be cast to the desired output type Long

These lines of code 8 check the first element of batch and use its dtype to create out. Could you check, if you are returning different dtypes in the __getitem__ of your Dataset?