as_dataloader {luz}R Documentation

Creates a dataloader from its input

Description

as_dataloader is used internally by luz to convert input data and valid_data as passed to fit.luz_module_generator() to a torch::dataloader

Usage

as_dataloader(x, ...)

## S3 method for class 'dataset'
as_dataloader(x, ..., batch_size = 32)

## S3 method for class 'list'
as_dataloader(x, ...)

## S3 method for class 'dataloader'
as_dataloader(x, ...)

## S3 method for class 'matrix'
as_dataloader(x, ...)

## S3 method for class 'numeric'
as_dataloader(x, ...)

## S3 method for class 'array'
as_dataloader(x, ...)

## S3 method for class 'torch_tensor'
as_dataloader(x, ...)

Arguments

x

the input object.

...

Passed to torch::dataloader().

batch_size

(int, optional): how many samples per batch to load (default: 1).

Details

as_dataloader methods should have sensible defaults for batch_size, parallel workers, etc.

It allows users to quickly experiment with fit.luz_module_generator() by not requiring to create a torch::dataset and a torch::dataloader in simple experiments.

Methods (by class)

Overriding

You can implement your own as_dataloader S3 method if you want your data structure to be automatically supported by luz's fit.luz_module_generator(). The method must satisfy the following conditions:

It's better to avoid implementing as_dataloader methods for common S3 classes like data.frames. In this case, its better to assign a different class to the inputs and implement as_dataloader for it.


[Package luz version 0.4.0 Index]