MCPcopy Create free account
hub / github.com/FreeformRobotics/OTS / DataLoader

Class DataLoader

lib/utils/data/dataloader.py:341–425  ·  view source on GitHub ↗

Data loader. Combines a dataset and a sampler, and provides single- or multi-process iterators over the dataset. Arguments: dataset (Dataset): dataset from which to load the data. batch_size (int, optional): how many samples per batch to load (default: 1).

Source from the content-addressed store, hash-verified

339
340
341class DataLoader(object):
342 """
343 Data loader. Combines a dataset and a sampler, and provides
344 single- or multi-process iterators over the dataset.
345
346 Arguments:
347 dataset (Dataset): dataset from which to load the data.
348 batch_size (int, optional): how many samples per batch to load
349 (default: 1).
350 shuffle (bool, optional): set to ``True`` to have the data reshuffled
351 at every epoch (default: False).
352 sampler (Sampler, optional): defines the strategy to draw samples from
353 the dataset. If specified, ``shuffle`` must be False.
354 batch_sampler (Sampler, optional): like sampler, but returns a batch of
355 indices at a time. Mutually exclusive with batch_size, shuffle,
356 sampler, and drop_last.
357 num_workers (int, optional): how many subprocesses to use for data
358 loading. 0 means that the data will be loaded in the main process.
359 (default: 0)
360 collate_fn (callable, optional): merges a list of samples to form a mini-batch.
361 pin_memory (bool, optional): If ``True``, the data loader will copy tensors
362 into CUDA pinned memory before returning them.
363 drop_last (bool, optional): set to ``True`` to drop the last incomplete batch,
364 if the dataset size is not divisible by the batch size. If ``False`` and
365 the size of dataset is not divisible by the batch size, then the last batch
366 will be smaller. (default: False)
367 timeout (numeric, optional): if positive, the timeout value for collecting a batch
368 from workers. Should always be non-negative. (default: 0)
369 worker_init_fn (callable, optional): If not None, this will be called on each
370 worker subprocess with the worker id (an int in ``[0, num_workers - 1]``) as
371 input, after seeding and before data loading. (default: None)
372
373 .. note:: By default, each worker will have its PyTorch seed set to
374 ``base_seed + worker_id``, where ``base_seed`` is a long generated
375 by main process using its RNG. You may use ``torch.initial_seed()`` to access
376 this value in :attr:`worker_init_fn`, which can be used to set other seeds
377 (e.g. NumPy) before data loading.
378
379 .. warning:: If ``spawn'' start method is used, :attr:`worker_init_fn` cannot be an
380 unpicklable object, e.g., a lambda function.
381 """
382
383 def __init__(self, dataset, batch_size=1, shuffle=False, sampler=None, batch_sampler=None,
384 num_workers=0, collate_fn=default_collate, pin_memory=False, drop_last=False,
385 timeout=0, worker_init_fn=None):
386 self.dataset = dataset
387 self.batch_size = batch_size
388 self.num_workers = num_workers
389 self.collate_fn = collate_fn
390 self.pin_memory = pin_memory
391 self.drop_last = drop_last
392 self.timeout = timeout
393 self.worker_init_fn = worker_init_fn
394
395 if timeout < 0:
396 raise ValueError('timeout option should be non-negative')
397
398 if batch_sampler is not None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected