pub struct DataLoaderBuilder<D: Dataset> { /* private fields */ }Expand description
Builder for DataLoader
Provides a fluent API for configuring DataLoader instances with various options such as batch size, shuffling, number of workers, and memory pinning.
§Examples
use torsh_data::dataloader::core::DataLoaderBuilder;
use torsh_data::dataset::TensorDataset;
let dataset = TensorDataset::new(vec![1, 2, 3, 4, 5]);
let dataloader = DataLoaderBuilder::new(dataset)
.batch_size(32)
.shuffle(true)
.num_workers(4)
.pin_memory(true)
.drop_last(true)
.build()?;Implementations§
Source§impl<D: Dataset> DataLoaderBuilder<D>
impl<D: Dataset> DataLoaderBuilder<D>
Sourcepub fn batch_size(self, batch_size: usize) -> Self
pub fn batch_size(self, batch_size: usize) -> Self
Sourcepub fn num_workers(self, num_workers: usize) -> Self
pub fn num_workers(self, num_workers: usize) -> Self
Set the number of worker threads
§Arguments
num_workers- Number of worker threads for parallel data loading
Sourcepub fn pin_memory(self, pin_memory: bool) -> Self
pub fn pin_memory(self, pin_memory: bool) -> Self
Sourcepub fn drop_last(self, drop_last: bool) -> Self
pub fn drop_last(self, drop_last: bool) -> Self
Set whether to drop the last incomplete batch
§Arguments
drop_last- Whether to drop the last batch if it’s smaller than batch_size
Sourcepub fn build(
self,
) -> Result<DataLoader<D, BatchingSampler<SequentialSampler>, DefaultCollate>>
pub fn build( self, ) -> Result<DataLoader<D, BatchingSampler<SequentialSampler>, DefaultCollate>>
Build the DataLoader with sequential sampling
Creates a DataLoader that processes the dataset in sequential order. This is the default behavior when shuffle is false or not specified.
Sourcepub fn build_with_random_sampling(
self,
) -> Result<DataLoader<D, BatchingSampler<RandomSampler>, DefaultCollate>>
pub fn build_with_random_sampling( self, ) -> Result<DataLoader<D, BatchingSampler<RandomSampler>, DefaultCollate>>
Build the DataLoader with random sampling (shuffled)
Creates a DataLoader that randomly shuffles the dataset order. Useful for training scenarios where data order should be randomized.
Sourcepub fn build_auto(
self,
) -> Result<Box<dyn DataLoaderTrait<D, DefaultCollate> + Send + Sync>>
pub fn build_auto( self, ) -> Result<Box<dyn DataLoaderTrait<D, DefaultCollate> + Send + Sync>>
Build the DataLoader with auto-selected sampling strategy
Automatically chooses between sequential and random sampling based on the shuffle setting configured in the builder.
Auto Trait Implementations§
impl<D> Freeze for DataLoaderBuilder<D>where
D: Freeze,
impl<D> RefUnwindSafe for DataLoaderBuilder<D>where
D: RefUnwindSafe,
impl<D> Send for DataLoaderBuilder<D>
impl<D> Sync for DataLoaderBuilder<D>
impl<D> Unpin for DataLoaderBuilder<D>where
D: Unpin,
impl<D> UnsafeUnpin for DataLoaderBuilder<D>where
D: UnsafeUnpin,
impl<D> UnwindSafe for DataLoaderBuilder<D>where
D: UnwindSafe,
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
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.