Samples elements randomly from a given list of indices, without replacement. Arguments: indices (sequence): a sequence of indices
| 14 | |
| 15 | |
| 16 | class SubsetRandomSampler(torch.utils.data.Sampler): |
| 17 | """Samples elements randomly from a given list of indices, without |
| 18 | replacement. |
| 19 | |
| 20 | Arguments: |
| 21 | indices (sequence): a sequence of indices |
| 22 | """ |
| 23 | |
| 24 | def __init__(self, indices): |
| 25 | self.epoch = 0 |
| 26 | self.indices = indices |
| 27 | |
| 28 | def __iter__(self): |
| 29 | return (self.indices[i] for i in torch.randperm(len(self.indices))) |
| 30 | |
| 31 | def __len__(self): |
| 32 | return len(self.indices) |
| 33 | |
| 34 | def set_epoch(self, epoch): |
| 35 | self.epoch = epoch |
| 36 | |
| 37 | |
| 38 | class NodeDistributedSampler(Sampler): |