MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / shuffle_dataset

Function shuffle_dataset

slowfast/datasets/loader.py:173–202  ·  view source on GitHub ↗

" Shuffles the data. Args: loader (loader): data loader to perform shuffle. cur_epoch (int): number of the current epoch.

(loader, cur_epoch)

Source from the content-addressed store, hash-verified

171
172
173def shuffle_dataset(loader, cur_epoch):
174 """ "
175 Shuffles the data.
176 Args:
177 loader (loader): data loader to perform shuffle.
178 cur_epoch (int): number of the current epoch.
179 """
180 if (
181 loader._dataset_kind
182 == torch.utils.data.dataloader._DatasetKind.Iterable
183 ):
184 if hasattr(loader.dataset, "sampler"):
185 sampler = loader.dataset.sampler
186 else:
187 raise RuntimeError(
188 "Unknown sampler for IterableDataset when shuffling dataset"
189 )
190 else:
191 sampler = (
192 loader.batch_sampler.sampler
193 if isinstance(loader.batch_sampler, ShortCycleBatchSampler)
194 else loader.sampler
195 )
196 assert isinstance(
197 sampler, (RandomSampler, DistributedSampler)
198 ), "Sampler type '{}' not supported".format(type(sampler))
199 # RandomSampler handles shuffling automatically
200 if isinstance(sampler, DistributedSampler):
201 # DistributedSampler shuffles data based on epoch
202 sampler.set_epoch(cur_epoch)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected