Download annotations/annotation_13/SISS/data/utils/repeat_sampler.py from mcy98/RECODE-H: direct link, hf CLI and curl.
- Browser
- Download file 802 Bytes
-
https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_13/SISS/data/utils/repeat_sampler.py
- Command line
-
hf download hf://datasets/mcy98/RECODE-H/annotations/annotation_13/SISS/data/utils/repeat_sampler.py
-
curl -L -o repeat_sampler.py https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_13/SISS/data/utils/repeat_sampler.py
802 Bytes
| import torch | |
| from torch.utils.data import Sampler | |
| class RepeatedSampler(Sampler): | |
| def __init__(self, data_source, num_repeats): | |
| """ | |
| Arguments: | |
| - data_source (Dataset): The dataset to sample from. | |
| - num_repeats (int): The number of times each image should be repeated. | |
| """ | |
| self.data_source = data_source | |
| self.num_repeats = num_repeats | |
| def __len__(self): | |
| # The length of the sampler is the number of samples multiplied by the number of repeats | |
| return len(self.data_source) * self.num_repeats | |
| def __iter__(self): | |
| # Repeat each index 'num_repeats' times in place without shuffling | |
| indices = torch.arange(len(self.data_source)).repeat_interleave(self.num_repeats) | |
| return iter(indices.tolist()) | |