public class Batch
extends java.lang.Object
implements java.lang.AutoCloseable
Batch
is used to hold multiple items (data and labels) 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 NDArray
s 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 output.
For example, an Image Question and Answer dataset has two inputs: an image and the question.
In this case, the data in the Batch
will be an NDList
containing a NCHW image
NDArray
and a NTC question NDArray
. The label will
be an NDList
containing only a NTC answer NDArray
.
In order to differentiate a batch vs a single record (despite them both consisting of two
NDList
s), we have the Batch
and the Record
respectively.
Constructor and Description |
---|
Batch(NDManager manager,
NDList data,
NDList labels)
Creates a new instance of
Batch with the given manager, data and labels. |
Batch(NDManager manager,
NDList data,
NDList labels,
Batchifier batchifier)
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 . |
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)
Batch
with the given manager, data and labels.public Batch(NDManager manager, NDList data, NDList labels, Batchifier batchifier)
Batch
with the given manager, data and labels.manager
- the NDManager
to be attached to data and labelsdata
- the NDList
containing the datalabels
- the NDList
containing the labelsbatchifier
- the Batchifier
that is used for splitpublic NDManager getManager()
NDManager
that is attached to this Batch
.NDManager
attached to this Batch
public NDList getData()
Batch
.NDList
that contains the datapublic NDList getLabels()
Batch
.NDList
that contains the labelspublic void close()
close
in interface java.lang.AutoCloseable