Trait DataLoader
pub trait DataLoader<B, O>: Sendwhere
B: Backend,{
// Required methods
fn iter<'a>(&'a self) -> Box<dyn DataLoaderIterator<O, Item = O> + 'a>;
fn num_items(&self) -> usize;
fn to_device(
&self,
device: &<B as Backend>::Device,
) -> Arc<dyn DataLoader<B, O>>;
fn slice(&self, start: usize, end: usize) -> Arc<dyn DataLoader<B, O>>;
}
Expand description
A data loader that can be used to iterate over a dataset.
Required Methods§
fn iter<'a>(&'a self) -> Box<dyn DataLoaderIterator<O, Item = O> + 'a>
fn iter<'a>(&'a self) -> Box<dyn DataLoaderIterator<O, Item = O> + 'a>
Returns a boxed iterator to iterate over the data loader.
fn num_items(&self) -> usize
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.
fn to_device(
&self,
device: &<B as Backend>::Device,
) -> Arc<dyn DataLoader<B, O>>
fn to_device( &self, device: &<B as Backend>::Device, ) -> Arc<dyn DataLoader<B, O>>
Move the data loader to the given device, ensuring the batches are assigned to the correct device.
fn slice(&self, start: usize, end: usize) -> Arc<dyn DataLoader<B, O>>
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.