MCPcopy
hub / github.com/microsoft/Swin-Transformer / SubsetRandomSampler

Class SubsetRandomSampler

data/samplers.py:11–29  ·  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

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

Callers 1

build_loaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected