* Execute internal tensors of the model with input data feed. * @param inputs Input data feed. Must match the inputs of the model. * @param outputs Names of the output tensors to be fetched. Must match * names of the SymbolicTensors that belong to the graph. * @returns Fetched values f
(inputs: Tensor|Tensor[]|NamedTensorMap, outputs: string|string[])
| 934 | * @returns Fetched values for `outputs`. |
| 935 | */ |
| 936 | execute(inputs: Tensor|Tensor[]|NamedTensorMap, outputs: string|string[]): |
| 937 | Tensor|Tensor[] { |
| 938 | if (Array.isArray(outputs) && outputs.length === 0) { |
| 939 | throw new ValueError( |
| 940 | '`outputs` is an empty Array, which is not allowed.'); |
| 941 | } |
| 942 | |
| 943 | const outputsIsArray = Array.isArray(outputs); |
| 944 | const outputNames = |
| 945 | (outputsIsArray ? outputs : [outputs]); |
| 946 | const outputSymbolicTensors = this.retrieveSymbolicTensors(outputNames); |
| 947 | |
| 948 | // Format the input into a FeedDict. |
| 949 | const feedDict = new FeedDict(); |
| 950 | if (inputs instanceof Tensor) { |
| 951 | inputs = [inputs]; |
| 952 | } |
| 953 | if (Array.isArray(inputs)) { |
| 954 | if (inputs.length !== this.inputs.length) { |
| 955 | throw new ValueError( |
| 956 | `The number of inputs provided (${inputs.length}) ` + |
| 957 | `does not match the number of inputs of this model ` + |
| 958 | `(${this.inputs.length}).`); |
| 959 | } |
| 960 | for (let i = 0; i < this.inputs.length; ++i) { |
| 961 | feedDict.add(this.inputs[i], inputs[i]); |
| 962 | } |
| 963 | } else { |
| 964 | for (const input of this.inputs) { |
| 965 | const tensorValue = inputs[input.name]; |
| 966 | if (tensorValue == null) { |
| 967 | throw new ValueError( |
| 968 | `No value is provided for the model's input ${input.name}`); |
| 969 | } |
| 970 | feedDict.add(input, tensorValue); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | // Run execution. |
| 975 | const executeOutputs = execute(outputSymbolicTensors, feedDict) as Tensor[]; |
| 976 | return outputsIsArray ? executeOutputs : executeOutputs[0]; |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * Retrieve the model's internal symbolic tensors from symbolic-tensor names. |
nothing calls this directly
no test coverage detected