How Grain's data loading paradigm works
mainGrain follows a source-sampler-loader paradigm for handling input data:
- DataSource: Implements the
grain.RandomAccessDataSourceinterface. It defines how to access individual records via__getitem__and provides the total length via__len__. - Sampler: Determines the order in which records are processed. For example,
grain.IndexSamplercan be used to shuffle data or iterate through specific epochs. - DataLoader: Orchestrates the loading process. It takes a
DataSourceand aSampler, and appliesoperations(likegrain.Batch) to produce batches. It supports multiprocessing viaworker_countto parallelize data transformations.