MCPcopy
hub / github.com/tensorflow/tfjs / checkArrayLengths

Function checkArrayLengths

tfjs-layers/src/engine/training.ts:194–219  ·  view source on GitHub ↗
(
    inputs: Tensor[], targets: Tensor[], weights?: Tensor[])

Source from the content-addressed store, hash-verified

192 * @throws ValueError: in case of incorrectly formatted data.
193 */
194export function checkArrayLengths(
195 inputs: Tensor[], targets: Tensor[], weights?: Tensor[]) {
196 const setX = unique(inputs.map(input => input.shape[0]));
197 setX.sort();
198 const setY = unique(targets.map(target => target.shape[0]));
199 setY.sort();
200 // TODO(cais): Check `weights` as well.
201 if (setX.length > 1) {
202 throw new ValueError(
203 `All input Tensors (x) should have the same number of samples. ` +
204 `Got array shapes: ` +
205 `${JSON.stringify(inputs.map(input => input.shape))}`);
206 }
207 if (setY.length > 1) {
208 throw new ValueError(
209 `All target Tensors (y) should have the same number of samples. ` +
210 `Got array shapes: ` +
211 `${JSON.stringify(targets.map(target => target.shape))}`);
212 }
213 if (setX.length > 0 && setY.length > 0 && !util.arraysEqual(setX, setY)) {
214 throw new ValueError(
215 `Input Tensors should have the same number of samples as target ` +
216 `Tensors. Found ${setX[0]} input sample(s) and ${setY[0]} target ` +
217 `sample(s).`);
218 }
219}
220
221/**
222 * Validation on the compatibility of targes and loss functions.

Callers 2

training_test.tsFile · 0.90
standardizeUserDataXYMethod · 0.85

Calls 1

uniqueFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…