MCPcopy Create free account
hub / github.com/CSAILVision/gandissect / FixedSubsetSampler

Class FixedSubsetSampler

netdissect/sampler.py:19–43  ·  view source on GitHub ↗

Represents a fixed sequence of data set indices. Subsets can be created by specifying a subset of output indexes.

Source from the content-addressed store, hash-verified

17from torch.utils.data.sampler import Sampler
18
19class 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
46class FixedRandomSubsetSampler(FixedSubsetSampler):

Callers 2

subsetMethod · 0.85
generate_imagesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected