Package ai.djl.training.dataset
Class ArrayDataset
- java.lang.Object
-
- ai.djl.training.dataset.RandomAccessDataset
-
- ai.djl.training.dataset.ArrayDataset
-
- All Implemented Interfaces:
Dataset
public class ArrayDataset extends RandomAccessDataset
ArrayDatasetis an implementation ofRandomAccessDatasetthat consist entirely of largeNDArrays. It is recommended only for datasets small enough to fit in memory that come in array formats. Otherwise, consider directly using theRandomAccessDatasetinstead.There can be multiple data and label
NDArrays within the dataset. Each sample will be retrieved by indexing eachNDArrayalong the first dimension.The following is an example of how to use ArrayDataset:
ArrayDataset dataset = new ArrayDataset.Builder() .setData(data1, data2) .optLabels(labels1, labels2, labels3) .setSampling(20, false) .build();Suppose you get a
Batchfromtrainer.iterateDataset(dataset)ordataset.getData(manager). In the data of this batch, it will be an NDList with one NDArray for each data input. In this case, it would be 2 arrays. Similarly, the labels would have 3 arrays.- See Also:
Dataset
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArrayDataset.BuilderThe Builder to construct anArrayDataset.-
Nested classes/interfaces inherited from class ai.djl.training.dataset.RandomAccessDataset
RandomAccessDataset.BaseBuilder<T extends RandomAccessDataset.BaseBuilder<T>>
-
Nested classes/interfaces inherited from interface ai.djl.training.dataset.Dataset
Dataset.Usage
-
-
Field Summary
Fields Modifier and Type Field Description protected NDArray[]dataprotected NDArray[]labels-
Fields inherited from class ai.djl.training.dataset.RandomAccessDataset
dataBatchifier, device, labelBatchifier, limit, pipeline, prefetchNumber, sampler, targetPipeline
-
-
Constructor Summary
Constructors Constructor Description ArrayDataset(RandomAccessDataset.BaseBuilder<?> builder)Creates a new instance ofArrayDatasetwith the arguments inArrayDataset.Builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longavailableSize()Returns the number of records available to be read in thisDataset.Recordget(NDManager manager, long index)Gets theRecordfor the given index from the dataset.voidprepare(ai.djl.util.Progress progress)Prepares the dataset for use with tracked progress.-
Methods inherited from class ai.djl.training.dataset.RandomAccessDataset
getData, getData, getData, getData, randomSplit, size, subDataset, toArray
-
-
-
-
Constructor Detail
-
ArrayDataset
public ArrayDataset(RandomAccessDataset.BaseBuilder<?> builder)
Creates a new instance ofArrayDatasetwith the arguments inArrayDataset.Builder.- Parameters:
builder- a builder with the required arguments
-
-
Method Detail
-
availableSize
protected long availableSize()
Returns the number of records available to be read in thisDataset.- Specified by:
availableSizein classRandomAccessDataset- Returns:
- the number of records available to be read in this
Dataset
-
get
public Record get(NDManager manager, long index)
Gets theRecordfor the given index from the dataset.- Specified by:
getin classRandomAccessDataset- Parameters:
manager- the manager used to create the arraysindex- the index of the requested data item- Returns:
- a
Recordthat contains the data and label of the requested data item
-
prepare
public void prepare(ai.djl.util.Progress progress) throws java.io.IOExceptionPrepares the dataset for use with tracked progress.- Parameters:
progress- the progress tracker- Throws:
java.io.IOException- for various exceptions depending on the dataset
-
-