PyTorch Sampler for Intensional Overfitting!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch.utils.data.sampler import Sampler | |
class MySampler(Sampler): | |
def __init__(self, main_source, indices): | |
self.main_source = main_source | |
self.indices = indices | |
main_source_len = len(self.main_source) | |
how_many = int(round(main_source_len / len(self.indices))) | |
self.to_iter_from = [] | |
for _ in range(how_many): | |
self.to_iter_from.extend(self.indices) | |
def __iter__(self): | |
return iter(self.to_iter_from) | |
def __len__(self): | |
return len(self.main_source) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment