Class Batch
- java.lang.Object
-
- ai.djl.training.dataset.Batch
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class Batch extends java.lang.Object implements java.lang.AutoCloseable
ABatch
is used to hold multiple items (data and label pairs) from aDataset
.When training and performing inference, it is often more efficient to run multiple items through a network simultaneously rather than one at a time. For this reason, much of the API is oriented around the
Batch
class.In a
Batch
, data and label are each anNDList
. The dataNDList
represents the data for each input in the batch. The number ofNDArray
s in the NDList is based on the number of different kinds of inputs, not the batch size. Similarly, the labelNDList
represents the labels for each kind of output.For example, an Image Question and Answer dataset has two inputs: an image and a question. In this case, the data in the
Batch
will be anNDList
containing an NCHW imageNDArray
and an NTC questionNDArray
. The label will be anNDList
containing only an NTC answerNDArray
.In order to differentiate a batch vs a single record (despite them both consisting of two
NDList
s), we have theBatch
and theRecord
respectively.
-
-
Constructor Summary
Constructors Constructor Description Batch(NDManager manager, NDList data, NDList labels, int size, Batchifier dataBatchifier, Batchifier labelBatchifier, long progress, long progressTotal)
Creates a new instance ofBatch
with the given manager, data and labels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
NDList
getData()
Gets the data of thisBatch
.NDList
getLabels()
Gets the labels corresponding to the data of thisBatch
.NDManager
getManager()
Gets theNDManager
that is attached to thisBatch
.long
getProgress()
Returns the progress of the batch if it is part of some kind of iteration like a dataset iteration.long
getProgressTotal()
Returns the total or end value for the progress of the batch if it is part of some kind of iteration like a dataset iteration.int
getSize()
Returns the batchSize.Batch[]
split(Device[] devices, boolean evenSplit)
Splits the data and labels in theBatch
across the given devices.
-
-
-
Constructor Detail
-
Batch
public Batch(NDManager manager, NDList data, NDList labels, int size, Batchifier dataBatchifier, Batchifier labelBatchifier, long progress, long progressTotal)
Creates a new instance ofBatch
with the given manager, data and labels.- Parameters:
manager
- the manager for theBatch
data
- theNDList
containing the datalabels
- theNDList
containing the labelssize
- (batchSize) the number ofRecord
s in the batchdataBatchifier
- theBatchifier
that is used to split datalabelBatchifier
- theBatchifier
that is used for split labelsprogress
- the progress of the batch if it is part of some kind of iteration like a dataset iteration. Returns 0 if there is no iteration.progressTotal
- the total or end value for the progress of the batch if it is part of
-
-
Method Detail
-
getManager
public NDManager getManager()
Gets theNDManager
that is attached to thisBatch
.- Returns:
- the
NDManager
attached to thisBatch
-
getData
public NDList getData()
Gets the data of thisBatch
.- Returns:
- an
NDList
that contains the data
-
getLabels
public NDList getLabels()
Gets the labels corresponding to the data of thisBatch
.- Returns:
- an
NDList
that contains the labels
-
getSize
public int getSize()
Returns the batchSize.- Returns:
- the batchSize or number of
Record
s in the batch
-
getProgress
public long getProgress()
Returns the progress of the batch if it is part of some kind of iteration like a dataset iteration.- Returns:
- the progress of the batch if it is part of some kind of iteration like a dataset iteration. Returns 0 if there is no iteration
-
getProgressTotal
public long getProgressTotal()
Returns the total or end value for the progress of the batch if it is part of some kind of iteration like a dataset iteration.- Returns:
- the total or end value for the progress of the batch if it is part of some kind of iteration like a dataset iteration. Returns 0 if there is no iteration
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-