pub struct StreamingDataLoader { /* private fields */ }Expand description
A data loader that lazily reads batches from disk, using a background thread to prefetch the next batch while the current batch is being processed.
The loader scans a directory for numbered batch files (batch_0000.bin,
batch_0001.bin, etc.). Each file stores a pair of tensors (inputs + targets)
in a simple binary format:
[input_ndims: u32] [input_shape...] [input_data: f32...]
[target_ndims: u32] [target_shape...] [target_data: f32...]Implementations§
Source§impl StreamingDataLoader
impl StreamingDataLoader
Sourcepub fn new(
path: impl Into<PathBuf>,
batch_size: usize,
) -> Result<Self, ModelError>
pub fn new( path: impl Into<PathBuf>, batch_size: usize, ) -> Result<Self, ModelError>
Create a new streaming data loader that reads batch files from path.
The directory is scanned for files matching batch_NNNN.bin. If no
batch files are found, an empty loader is returned.
Sourcepub fn next_batch(&mut self) -> Option<(Tensor, Tensor)>
pub fn next_batch(&mut self) -> Option<(Tensor, Tensor)>
Returns the next batch of (inputs, targets), or None if all batches
have been consumed for this epoch.
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
Returns the configured batch size.
Sourcepub fn write_batch_file(
path: &Path,
inputs: &Tensor,
targets: &Tensor,
) -> Result<(), ModelError>
pub fn write_batch_file( path: &Path, inputs: &Tensor, targets: &Tensor, ) -> Result<(), ModelError>
Write a tensor pair to the simple binary format.
Auto Trait Implementations§
impl Freeze for StreamingDataLoader
impl !RefUnwindSafe for StreamingDataLoader
impl Send for StreamingDataLoader
impl !Sync for StreamingDataLoader
impl Unpin for StreamingDataLoader
impl UnsafeUnpin for StreamingDataLoader
impl !UnwindSafe for StreamingDataLoader
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