Skip to main content

DataLoader

Trait DataLoader 

Source
pub trait DataLoader<B: Backend, O>: Send + Sync {
    // Required methods
    fn iter<'a>(&'a self) -> Box<dyn DataLoaderIterator<O> + 'a>;
    fn num_items(&self) -> usize;
    fn to_device(&self, device: &B::Device) -> Arc<dyn DataLoader<B, O>>;
    fn slice(&self, start: usize, end: usize) -> Arc<dyn DataLoader<B, O>>;
}
Available on crate features std and dataset only.
Expand description

A data loader that can be used to iterate over a dataset.

Required Methods§

Source

fn iter<'a>(&'a self) -> Box<dyn DataLoaderIterator<O> + 'a>

Returns a boxed iterator to iterate over the data loader.

Source

fn num_items(&self) -> usize

The number of items (not the number of batches nor the number of iterations), corresponding to the items_total of the progress returned by the iterator.

Source

fn to_device(&self, device: &B::Device) -> Arc<dyn DataLoader<B, O>>

Move the data loader to the given device, ensuring the batches are assigned to the correct device.

Source

fn slice(&self, start: usize, end: usize) -> Arc<dyn DataLoader<B, O>>

Returns a new data loader containing a subset of the data.

The subset includes items from start (inclusive) to end (exclusive), preserving the batch size and ordering of the original data loader.

§Arguments
  • start - The starting index of the subset (inclusive).
  • end - The ending index of the subset (exclusive).
§Returns

A boxed DataLoader instance containing only the specified range.

Implementors§

Source§

impl<B, I, O> DataLoader<B, O> for BatchDataLoader<B, I, O>
where B: Backend, I: Send + Sync + Clone + 'static, O: Send + 'static,

Source§

impl<B: Backend, I, O> DataLoader<B, O> for MultiThreadDataLoader<B, I, O>
where I: Send + Sync + Clone + 'static, O: Send + 'static + Debug,