The error is quite strange, as the dataset should check the number of samples and use it as the range for the indices. Could you add a print statement into the __getitem__ and check which value index has as well as was len(dataset) returns?