public class Batch
extends java.lang.Object
implements java.lang.AutoCloseable
Batch is used to hold multiple items (data and label pairs) from a Dataset.
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 an NDList. The data NDList
represents the data for each input in the batch. The number of NDArrays in
the NDList is based on the number of different kinds of inputs, not the batch size. Similarly,
the label NDList 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 an NDList containing an NCHW image
NDArray and an NTC question NDArray. The label will
be an NDList containing only an NTC answer NDArray.
In order to differentiate a batch vs a single record (despite them both consisting of two
NDLists), we have the Batch and the Record respectively.
| Constructor and Description |
|---|
Batch(NDManager manager,
NDList data,
NDList labels,
int size,
Batchifier dataBatchifier,
Batchifier labelBatchifier,
long progress,
long progressTotal)
Creates a new instance of
Batch with the given manager, data and labels. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
NDList |
getData()
Gets the data of this
Batch. |
NDList |
getLabels()
Gets the labels corresponding to the data of this
Batch. |
NDManager |
getManager()
Gets the
NDManager that is attached to this Batch. |
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 the
Batch across the given devices. |
public Batch(NDManager manager, NDList data, NDList labels, int size, Batchifier dataBatchifier, Batchifier labelBatchifier, long progress, long progressTotal)
Batch with the given manager, data and labels.manager - the manager for the Batchdata - the NDList containing the datalabels - the NDList containing the labelssize - (batchSize) the number of Records in the batchdataBatchifier - the Batchifier that is used to split datalabelBatchifier - the Batchifier 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 ofpublic NDManager getManager()
NDManager that is attached to this Batch.NDManager attached to this Batchpublic NDList getData()
Batch.NDList that contains the datapublic NDList getLabels()
Batch.NDList that contains the labelspublic int getSize()
Records in the batchpublic long getProgress()
public long getProgressTotal()
public void close()
close in interface java.lang.AutoCloseable