Represents a fixed sequence of data set indices. Subsets can be created by specifying a subset of output indexes.
| 17 | from torch.utils.data.sampler import Sampler |
| 18 | |
| 19 | class FixedSubsetSampler(Sampler): |
| 20 | """Represents a fixed sequence of data set indices. |
| 21 | Subsets can be created by specifying a subset of output indexes. |
| 22 | """ |
| 23 | def __init__(self, samples): |
| 24 | self.samples = samples |
| 25 | |
| 26 | def __iter__(self): |
| 27 | return iter(self.samples) |
| 28 | |
| 29 | def __len__(self): |
| 30 | return len(self.samples) |
| 31 | |
| 32 | def __getitem__(self, key): |
| 33 | return self.samples[key] |
| 34 | |
| 35 | def subset(self, new_subset): |
| 36 | return FixedSubsetSampler(self.dereference(new_subset)) |
| 37 | |
| 38 | def dereference(self, indices): |
| 39 | ''' |
| 40 | Translate output sample indices (small numbers indexing the sample) |
| 41 | to input sample indices (larger number indexing the original full set) |
| 42 | ''' |
| 43 | return [self.samples[i] for i in indices] |
| 44 | |
| 45 | |
| 46 | class FixedRandomSubsetSampler(FixedSubsetSampler): |
no outgoing calls
no test coverage detected