* 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)
| 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…