MCPcopy Index your code
hub / github.com/tensorflow/tfjs / batch

Function batch

tfjs-data/src/dataset.ts:136–159  ·  view source on GitHub ↗

* Groups elements into batches. * * It is assumed that each of the incoming dataset elements has the same * structure -- i.e. the same set of keys at each location in an object * hierarchy. For each key, the resulting `Dataset` provides a batched * element collecting all of the incom

(batchSize: number, smallLastBatch = true)

Source from the content-addressed store, hash-verified

134 * @doc {heading: 'Data', subheading: 'Classes'}
135 */
136 batch(batchSize: number, smallLastBatch = true): Dataset<tf.TensorContainer> {
137 const base = this;
138 tf.util.assert(
139 batchSize > 0, () => `batchSize needs to be positive, but it is
140 ${batchSize}`);
141 let size;
142 if (this.size === Infinity || this.size == null) {
143 // If the size of this dataset is infinity or null, the new size keeps the
144 // same.
145 size = this.size;
146 } else if (smallLastBatch) {
147 // If the size of this dataset is known and include small last batch, the
148 // new size is full batch count plus last batch.
149 size = Math.ceil(this.size / batchSize);
150 } else {
151 // If the size of this dataset is known and not include small last batch,
152 // the new size is full batch count.
153 size = Math.floor(this.size / batchSize);
154 }
155 return datasetFromIteratorFn(async () => {
156 return (await base.iterator())
157 .columnMajorBatch(batchSize, smallLastBatch, deepBatchConcat);
158 }, size);
159 }
160
161 /**
162 * Concatenates this `Dataset` with another.

Callers

nothing calls this directly

Calls 4

datasetFromIteratorFnFunction · 0.85
ceilMethod · 0.80
floorMethod · 0.80
iteratorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…