|
| DataLoader (size_t batch_size) |
| Constructs a new DataLoader with the specified batch size.
|
|
virtual | ~DataLoader ()=default |
| Virtual destructor to ensure proper cleanup in derived classes.
|
|
size_t | batchSize () const |
| Gets the size of each batch.
|
|
size_t | currentBatch () const |
| Gets the current batch index.
|
|
virtual const Tensor< TInput, TMemoryResource > & | inputs () const =0 |
| Gets the input tensor containing the current batch of input data (const version).
|
|
virtual Tensor< TInput, TMemoryResource > & | inputs ()=0 |
| Gets the input tensor containing the current batch of input data.
|
|
virtual void | nextBatch ()=0 |
| Loads the next batch of data from the dataset.
|
|
virtual size_t | numBatches () const =0 |
| Gets the total number of batches in the dataset.
|
|
virtual void | reset () |
| Resets the loader to the beginning of the dataset.
|
|
virtual const Tensor< TTarget, TMemoryResource > & | targets () const =0 |
| Gets the target tensor containing the current batch of target data (const version).
|
|
virtual Tensor< TTarget, TMemoryResource > & | targets ()=0 |
| Gets the target tensor containing the current batch of target data.
|
|
template<typename TInput, typename TTarget = TInput, typename TMemoryResource = CpuMemoryResource>
requires ValidTensorTypes<TInput, TTarget> && (std::is_same_v<TMemoryResource,
CudaPinnedMemoryResource> || std::is_same_v<TMemoryResource,
CpuMemoryResource>)
class Mila::Dnn::Data::DataLoader< TInput, TTarget, TMemoryResource >
Abstract base class for data loaders used in training and evaluation.
The DataLoader class provides a generic interface for loading batches of data from various sources (files, databases, etc.) into tensors that can be used for model training and evaluation. It supports both CPU and CUDA pinned memory resources for efficient data transfer to GPU devices.
- Template Parameters
-
TInput | The data type for input and target tensors (must be a valid floating point type). |
TMemoryResource | The memory resource type to use (either CudaPinnedMemoryResource or CpuMemoryResource). |
template<typename TInput , typename TTarget = TInput, typename TMemoryResource = CpuMemoryResource>
Loads the next batch of data from the dataset.
This method must be implemented by derived classes to load the next batch of data into the input and target tensors. The implementation should update the current_batch_ counter after successfully loading a new batch.
template<typename TInput , typename TTarget = TInput, typename TMemoryResource = CpuMemoryResource>
Resets the loader to the beginning of the dataset.
Calling this method resets the internal state of the data loader to start from the first batch again. Derived classes may override this method to implement additional reset functionality.
template<typename TInput , typename TTarget = TInput, typename TMemoryResource = CpuMemoryResource>
Gets the target tensor containing the current batch of target data (const version).
This method must be implemented by derived classes to provide read-only access to the tensor containing target/label data for the current batch.
- Returns
- const Tensor<TTarget, TMemoryResource>& Const reference to the target tensor.