* Run inference on manually-input Iris flower data. * * @param model The instance of `tf.Model` to run the inference with.
(model)
| 96 | * @param model The instance of `tf.Model` to run the inference with. |
| 97 | */ |
| 98 | async 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. |
no test coverage detected