r"""Sample elements sequentially. Args: dataset: dataset to sample from. batch_size: batch size for batch method. drop_last: set ``True`` to drop the last incomplete batch, if the dataset size is not divisible by the batch size. If ``False`` and t
| 176 | |
| 177 | |
| 178 | class SequentialSampler(MapSampler): |
| 179 | r"""Sample elements sequentially. |
| 180 | |
| 181 | Args: |
| 182 | dataset: dataset to sample from. |
| 183 | batch_size: batch size for batch method. |
| 184 | drop_last: set ``True`` to drop the last incomplete batch, |
| 185 | if the dataset size is not divisible by the batch size. If ``False`` and |
| 186 | the size of dataset is not divisible by the batch_size, then the last batch will |
| 187 | be smaller. Default: False |
| 188 | indices: indice of samples. |
| 189 | world_size: number of ranks. |
| 190 | rank: rank id, non-negative interger within 0 and ``world_size``. |
| 191 | """ |
| 192 | |
| 193 | def __init__( |
| 194 | self, |
| 195 | dataset, |
| 196 | batch_size=1, |
| 197 | drop_last=False, |
| 198 | indices=None, |
| 199 | world_size=None, |
| 200 | rank=None, |
| 201 | ): |
| 202 | super().__init__(dataset, batch_size, drop_last, None, world_size, rank) |
| 203 | if indices is not None and not isinstance(indices, collections.abc.Sequence): |
| 204 | raise ValueError( |
| 205 | "indices should be None or a sequence, " |
| 206 | "but got indices={}".format(indices) |
| 207 | ) |
| 208 | self.indices = indices |
| 209 | |
| 210 | def sample(self) -> Iterator[Any]: |
| 211 | r"""Return a generator.""" |
| 212 | if self.indices is None: |
| 213 | return iter(range(len(self.dataset))) |
| 214 | else: |
| 215 | return self.indices |
| 216 | |
| 217 | |
| 218 | class RandomSampler(MapSampler): |
no outgoing calls