MCPcopy Create free account
hub / github.com/LeapLabTHU/DAT / SubsetRandomSampler

Class SubsetRandomSampler

data/samplers.py:13–31  ·  view source on GitHub ↗

r"""Samples elements randomly from a given list of indices, without replacement. Arguments: indices (sequence): a sequence of indices

Source from the content-addressed store, hash-verified

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

Callers 1

build_loaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected