pub struct DataLoader<'a, B: Backend> { /* private fields */ }Expand description
A DataLoader wraps a Dataset and produces batches of tensors.
Each batch is a HashMap<String, Tensor<B>> with keys "input" and
"target", matching the format expected by Executor::run() and
Trainer::train().
Implementations§
Source§impl<'a, B: Backend> DataLoader<'a, B>
impl<'a, B: Backend> DataLoader<'a, B>
Sourcepub fn new(
dataset: &'a dyn Dataset,
device: B::Device,
config: DataLoaderConfig,
) -> Self
pub fn new( dataset: &'a dyn Dataset, device: B::Device, config: DataLoaderConfig, ) -> Self
Create a new DataLoader over a dataset.
Sourcepub fn with_transform(self, t: Box<dyn Transform>) -> Self
pub fn with_transform(self, t: Box<dyn Transform>) -> Self
Add a transform to apply to each sample.
Sourcepub fn num_batches(&self) -> usize
pub fn num_batches(&self) -> usize
The number of batches per epoch.
Sourcepub fn epoch_batches(
&mut self,
input_name: &str,
target_name: &str,
) -> Result<Vec<HashMap<String, Tensor<B>>>, Error>
pub fn epoch_batches( &mut self, input_name: &str, target_name: &str, ) -> Result<Vec<HashMap<String, Tensor<B>>>, Error>
Produce all batches for one epoch as a Vec of HashMap tensors.
Each HashMap has keys matching the input/target names you’ll pass
to the executor. By default: "input" and "target".
Sourcepub fn iter_batches(
&mut self,
input_name: &str,
target_name: &str,
) -> BatchIterator<'_, 'a, B> ⓘ
pub fn iter_batches( &mut self, input_name: &str, target_name: &str, ) -> BatchIterator<'_, 'a, B> ⓘ
Iterate over batches one at a time (lower memory than epoch_batches).
Auto Trait Implementations§
impl<'a, B> Freeze for DataLoader<'a, B>
impl<'a, B> !RefUnwindSafe for DataLoader<'a, B>
impl<'a, B> Send for DataLoader<'a, B>
impl<'a, B> Sync for DataLoader<'a, B>
impl<'a, B> Unpin for DataLoader<'a, B>
impl<'a, B> UnsafeUnpin for DataLoader<'a, B>
impl<'a, B> !UnwindSafe for DataLoader<'a, 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