pub struct AsyncDataLoader<B: Backend> { /* private fields */ }Expand description
A data loader that prefetches batches on background threads.
On each call to iter_epoch, the loader:
- Optionally reshuffles indices.
- Spawns worker threads that load, transform, and collate batches.
- Returns an iterator that pulls ready batches from a bounded channel.
The channel capacity is prefetch_factor * max(num_workers, 1), so at most
that many batches are materialised in memory at any time.
The dataset is held via Arc<dyn Dataset> so it can be safely shared with
background worker threads.
Implementations§
Source§impl<B: Backend> AsyncDataLoader<B>
impl<B: Backend> AsyncDataLoader<B>
Sourcepub fn new(
dataset: Arc<dyn Dataset>,
device: B::Device,
config: AsyncDataLoaderConfig,
) -> Self
pub fn new( dataset: Arc<dyn Dataset>, device: B::Device, config: AsyncDataLoaderConfig, ) -> Self
Create a new async data loader.
Sourcepub fn with_transform(self, t: Arc<dyn Transform>) -> Self
pub fn with_transform(self, t: Arc<dyn Transform>) -> Self
Add a transform.
Sourcepub fn num_batches(&self) -> usize
pub fn num_batches(&self) -> usize
Number of batches per epoch.
Sourcepub fn iter_epoch(
&mut self,
input_name: &str,
target_name: &str,
) -> PrefetchIterator<B> ⓘ
pub fn iter_epoch( &mut self, input_name: &str, target_name: &str, ) -> PrefetchIterator<B> ⓘ
Iterate over one epoch of prefetched batches.
Spawns background workers that load batches into a bounded channel.
The returned iterator yields Result<Batch<B>> — one per batch.
The background workers are joined when the iterator is dropped.
Auto Trait Implementations§
impl<B> Freeze for AsyncDataLoader<B>
impl<B> !RefUnwindSafe for AsyncDataLoader<B>
impl<B> Send for AsyncDataLoader<B>
impl<B> Sync for AsyncDataLoader<B>
impl<B> Unpin for AsyncDataLoader<B>
impl<B> UnsafeUnpin for AsyncDataLoader<B>
impl<B> !UnwindSafe for AsyncDataLoader<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more