MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / predictOnManualInput

Function predictOnManualInput

iris-fitDataset/index.js:98–120  ·  view source on GitHub ↗

* Run inference on manually-input Iris flower data. * * @param model The instance of `tf.Model` to run the inference with.

(model)

Source from the content-addressed store, hash-verified

96 * @param model The instance of `tf.Model` to run the inference with.
97 */
98async function predictOnManualInput(model) {
99 if (model == null) {
100 ui.setManualInputWinnerMessage('ERROR: Please load or train model first.');
101 return;
102 }
103
104 // Use a `tf.tidy` scope to make sure that WebGL memory allocated for the
105 // `predict` call is released at the end.
106 tf.tidy(() => {
107 // Prepare input data as a 2D `tf.Tensor`.
108 const inputData = ui.getManualInputData();
109 const input = tf.tensor2d([inputData], [1, 4]);
110
111 // Call `model.predict` to get the prediction output as probabilities for
112 // the Iris flower categories.
113
114 const predictOut = model.predict(input);
115 const logits = Array.from(predictOut.dataSync());
116 const winner = data.IRIS_CLASSES[predictOut.argMax(-1).dataSync()[0]];
117 ui.setManualInputWinnerMessage(winner);
118 ui.renderLogitsForManualInput(logits);
119 });
120}
121
122/**
123 * Draw confusion matrix.

Callers 2

evaluateModelOnTestDataFunction · 0.70
irisFunction · 0.70

Calls 1

predictMethod · 0.45

Tested by

no test coverage detected