diff --git a/torchvision/datasets/fakedata.py b/torchvision/datasets/fakedata.py index 9d3566f9a9f..ce2d275e286 100644 --- a/torchvision/datasets/fakedata.py +++ b/torchvision/datasets/fakedata.py @@ -37,6 +37,8 @@ def __getitem__(self, index): tuple: (image, target) where target is class_index of the target class. """ # create random image that is consistent with the index id + if index >= len(self): + raise IndexError("{} index out of range".format(self.__class__.__name__)) rng_state = torch.get_rng_state() torch.manual_seed(index + self.random_offset) img = torch.randn(*self.image_size)