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

Function predictOnManualInput

iris/index.js:92–114  ·  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

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

Callers 2

evaluateModelOnTestDataFunction · 0.70
irisFunction · 0.70

Calls 1

predictMethod · 0.45

Tested by

no test coverage detected