Commit 138b5c25 authored by Will Frey's avatar Will Frey Committed by Francisco Massa
Browse files

Update fakedata.py (#780)

Raise an `IndexError` for `FakeData.__getitem__()` if the index would be out of range.
parent ef6e9afb
...@@ -37,6 +37,8 @@ class FakeData(data.Dataset): ...@@ -37,6 +37,8 @@ class FakeData(data.Dataset):
tuple: (image, target) where target is class_index of the target class. tuple: (image, target) where target is class_index of the target class.
""" """
# create random image that is consistent with the index id # 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() rng_state = torch.get_rng_state()
torch.manual_seed(index + self.random_offset) torch.manual_seed(index + self.random_offset)
img = torch.randn(*self.image_size) img = torch.randn(*self.image_size)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment