(
data: Tensor|Tensor[]|{[inputName: string]: Tensor}, names: string[],
shapes?: Shape[], checkBatchAxis = true, exceptionPrefix = '')
| 79 | * @throws ValueError: in case of improperly formatted user data. |
| 80 | */ |
| 81 | export function standardizeInputData( |
| 82 | data: Tensor|Tensor[]|{[inputName: string]: Tensor}, names: string[], |
| 83 | shapes?: Shape[], checkBatchAxis = true, exceptionPrefix = ''): Tensor[] { |
| 84 | if (names == null || names.length === 0) { |
| 85 | // Check for the case where the model expected no data, but some data got |
| 86 | // sent. |
| 87 | if (data != null) { |
| 88 | let gotUnexpectedData = false; |
| 89 | if (isDataArray(data) && (data as Tensor[]).length > 0) { |
| 90 | gotUnexpectedData = true; |
| 91 | } else if (isDataDict(data)) { |
| 92 | for (const key in data) { |
| 93 | if (data.hasOwnProperty(key)) { |
| 94 | gotUnexpectedData = true; |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } else { |
| 99 | // `data` is a singleton Tensor in this case. |
| 100 | gotUnexpectedData = true; |
| 101 | } |
| 102 | if (gotUnexpectedData) { |
| 103 | throw new ValueError( |
| 104 | `Error when checking model ${exceptionPrefix} expected no data, ` + |
| 105 | `but got ${data}`); |
| 106 | } |
| 107 | } |
| 108 | return []; |
| 109 | } |
| 110 | if (data == null) { |
| 111 | return names.map(name => null); |
| 112 | } |
| 113 | |
| 114 | let arrays: Tensor[]; |
| 115 | if (isDataDict(data)) { |
| 116 | data = data as {[inputName: string]: Tensor}; |
| 117 | arrays = []; |
| 118 | for (const name of names) { |
| 119 | if (data[name] == null) { |
| 120 | throw new ValueError( |
| 121 | `No data provided for "${name}". Need data for each key in: ` + |
| 122 | `${names}`); |
| 123 | } |
| 124 | arrays.push(data[name]); |
| 125 | } |
| 126 | } else if (isDataArray(data)) { |
| 127 | data = data as Tensor[]; |
| 128 | if (data.length !== names.length) { |
| 129 | throw new ValueError( |
| 130 | `Error when checking model ${exceptionPrefix}: the Array of ` + |
| 131 | `Tensors that you are passing to your model is not the size the ` + |
| 132 | `model expected. Expected to see ${names.length} Tensor(s), but ` + |
| 133 | `instead got the following list of Tensor(s): ${data}`); |
| 134 | } |
| 135 | arrays = data; |
| 136 | } else { |
| 137 | data = data as Tensor; |
| 138 | if (names.length > 1) { |
no test coverage detected
searching dependent graphs…