* Check inputs provided by the user. * * Porting Note: This corresponds to _standardize_input_data() in Python * Keras. Because of the strong typing in TF.js, we do not need to convert * the data. Specifically: * 1) in PyKeras, `data` can be `DataFrame` instances from pandas, for *
(
data: Tensor|Tensor[], names: string[], shapes?: Shape[],
checkBatchAxis = true, exceptionPrefix = '')
| 295 | * @throws ValueError: on incorrect number of inputs or mismatches in shapes. |
| 296 | */ |
| 297 | function checkInputData( |
| 298 | data: Tensor|Tensor[], names: string[], shapes?: Shape[], |
| 299 | checkBatchAxis = true, exceptionPrefix = '') { |
| 300 | let arrays: Tensor[]; |
| 301 | if (Array.isArray(data)) { |
| 302 | if (data.length !== names.length) { |
| 303 | throw new ValueError( |
| 304 | `Error when checking model ${exceptionPrefix}: the Array of ` + |
| 305 | `Tensors that you are passing to your model is not the size the ` + |
| 306 | `the model expected. Expected to see ${names.length} Tensor(s),` + |
| 307 | ` but instead got ${data.length} Tensors(s).`); |
| 308 | } |
| 309 | arrays = data; |
| 310 | } else { |
| 311 | if (names.length > 1) { |
| 312 | throw new ValueError( |
| 313 | `The model expects ${names.length} ${exceptionPrefix} Tensors, ` + |
| 314 | `but only received one Tensor. Found: array with shape ` + |
| 315 | `${JSON.stringify(data.shape)}.`); |
| 316 | } |
| 317 | arrays = [data]; |
| 318 | } |
| 319 | |
| 320 | if (shapes != null) { |
| 321 | for (let i = 0; i < names.length; ++i) { |
| 322 | if (shapes[i] == null) { |
| 323 | continue; |
| 324 | } |
| 325 | const array = arrays[i]; |
| 326 | if (array.shape.length !== shapes[i].length) { |
| 327 | throw new ValueError( |
| 328 | `Error when checking ${exceptionPrefix}: expected ${names[i]} ` + |
| 329 | `to have ${shapes[i].length} dimension(s), but got array with ` + |
| 330 | `shape ${JSON.stringify(array.shape)}`); |
| 331 | } |
| 332 | for (let j = 0; j < shapes[i].length; ++j) { |
| 333 | if (j === 0 && !checkBatchAxis) { |
| 334 | continue; |
| 335 | } |
| 336 | const dim = array.shape[j]; |
| 337 | const refDim = shapes[i][j]; |
| 338 | if (refDim != null) { |
| 339 | if (refDim !== dim) { |
| 340 | throw new ValueError( |
| 341 | `Error when checking ${exceptionPrefix}: expected ` + |
| 342 | `${names[i]} to have shape ${JSON.stringify(shapes[i])} but ` + |
| 343 | `got array with shape ${JSON.stringify(array.shape)}.`); |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Maps metric functions to model outputs. |
no outgoing calls
no test coverage detected
searching dependent graphs…